/usr/include/linbox/algorithms/blackbox-block-container.h is in liblinbox-dev 1.3.2-1.1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | /* linbox/algorithms/blackbox-block-container.h
* Copyright (C) 2002 Pascal Giorgi
*
* Written by Pascal Giorgi pascal.giorgi@ens-lyon.fr
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
/*! @file algorithms/blackbox-block-container.h
* @ingroup algorithms
* @brief no doc.
*/
#ifndef __LINBOX_blackbox_block_container_H
#define __LINBOX_blackbox_block_container_H
#include "linbox/linbox-config.h"
#include "linbox/util/debug.h"
#include "linbox/algorithms/blackbox-block-container-base.h"
#include "linbox/matrix/blas-matrix.h"
#include "linbox/algorithms/blas-domain.h"
#define _BBC_TIMING
#ifdef _BBC_TIMING
#include <time.h>
#include "linbox/util/timer.h"
#endif
namespace LinBox
{
/*! @brief no doc.
*/
template<class _Field, class _Blackbox>
class BlackboxBlockContainer : public BlackboxBlockContainerBase<_Field,_Blackbox> {
public:
typedef _Field Field;
typedef typename Field::Element Element;
typedef typename Field::RandIter RandIter;
typedef BlasMatrix<Field> Block;
typedef BlasMatrix<Field> Value;
// Default constructor
BlackboxBlockContainer () {}
// constructor of the sequence from a blackbox, a field and one block projection
BlackboxBlockContainer(const _Blackbox *D, const Field &F, const Block &U0) :
BlackboxBlockContainerBase<Field,_Blackbox> (D, F, U0.rowdim(), U0.coldim()) , _blockW(D->rowdim(), U0.coldim()), _BMD(F)
{
#ifdef _BBC_TIMING
clearTimer();
tSequence.clear();
tSequence.start();
#endif
this->init (U0, U0);
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
// constructor of the sequence from a blackbox, a field and two blocks projection
BlackboxBlockContainer(const _Blackbox *D, const Field &F, const Block &U0, const Block& V0) :
BlackboxBlockContainerBase<Field,_Blackbox> (D, F,U0.rowdim(), V0.coldim())
, _blockW(F,D->rowdim(), V0.coldim()), _BMD(F)
{
#ifdef _BBC_TIMING
clearTimer();
tSequence.clear();
tSequence.start();
#endif
this->init (U0, V0);
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
// constructor of the sequence from a blackbox, a field and two blocks random projection
BlackboxBlockContainer(const _Blackbox *D, const Field &F, size_t m, size_t n, size_t seed= (size_t)time(NULL)) :
BlackboxBlockContainerBase<Field, _Blackbox> (D, F, m, n,seed)
, _blockW(F,D->rowdim(), n), _BMD(F)
{
#ifdef _BBC_TIMING
clearTimer();
tSequence.clear();
tSequence.start();
#endif
this->init (m, n);
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
#ifdef _BBC_TIMING
void clearTimer() {
ttSequence.clear();
}
void printTimer() {
std::cout<<"Sequence Computation "<<ttSequence<<std::endl<<std::endl;
}
#endif
protected:
Block _blockW;
BlasMatrixDomain<Field> _BMD;
#ifdef _BBC_TIMING
Timer ttSequence, tSequence;
#endif
// launcher of the next sequence element computation
void _launch () {
#ifdef _BBC_TIMING
tSequence.clear();
tSequence.start();
#endif
if (this->casenumber) {
this->Mul(_blockW,*this->_BB,this->_blockV);
_BMD.mul(this->_value, this->_blockU, _blockW);
this->casenumber = 0;
}
else {
this->Mul(this->_blockV,*this->_BB,_blockW);
_BMD.mul(this->_value, this->_blockU, this->_blockV);
this->casenumber = 1;
}
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence +=tSequence;
#endif
}
void _wait () {}
};
/*! @brief no doc.
*/
template<class _Field, class _Blackbox>
class BlackboxBlockContainerRecord : public BlackboxBlockContainerBase<_Field,_Blackbox> {
public:
typedef _Field Field;
typedef typename Field::Element Element;
typedef typename Field::RandIter RandIter;
typedef BlasMatrix<Field> Block;
typedef BlasMatrix<Field> Value;
enum Launcher {RowUpdate=0, ColUpdate=1, Nothing=2};
// Default constructor
BlackboxBlockContainerRecord () {}
// constructor of the sequence from a blackbox, a field and one block projection
BlackboxBlockContainerRecord(const _Blackbox *D, const Field &F, const Block &U0) :
BlackboxBlockContainerBase<Field,_Blackbox> (D, F, U0.rowdim(), U0.coldim())
, _blockW(F, D->rowdim(), U0.coldim()), _BMD(F), _launcher(Nothing), _iter(1)
{
this->init (U0, U0);
_rep = std::vector<Value> (this->_size, Value(F));
_Vcopy = this->_blockV;
for (size_t i=0;i< this->_size;++i){
_rep[i] = this->_value;
_launch_record();
}
this->_value=_rep[0];
}
// constructor of the sequence from a blackbox, a field and two blocks projection
BlackboxBlockContainerRecord(const _Blackbox *D, const Field &F, const Block &U0, const Block& V0, bool denseblock= true) :
BlackboxBlockContainerBase<Field,_Blackbox> (D, F,U0.rowdim(), V0.coldim())
, _blockW(F,D->rowdim(), V0.coldim()), _BMD(F), _launcher(Nothing), _iter(1)
{
#ifdef _BBC_TIMING
clearTimer();
tSequence.clear();
tSequence.start();
#endif
this->init (U0, V0);
_rep = std::vector<Value> (this->_size, Value(F));
_Vcopy = this->_blockV;
if (denseblock) {
for (size_t i=0;i< this->_size;++i){
_rep[i] = this->_value;
_launch_record();
}
}
else {
_rep.resize(_rep.size()-3);
size_t block= U0.rowdim();
size_t Nn = U0.coldim()/block;
_Special_U.resize(block, std::vector<typename Field::Element>(Nn));
for (size_t i=0;i<block;++i)
for (size_t j=0;j<Nn;++j)
F.assign(_Special_U[i][j], U0.getEntry(0, i*Nn+j));
for (size_t i=0;i< this->_size-3;++i){
_launch_record_notdense();
_rep[i] = this->_value;
}
}
this->_value=_rep[0];
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
// constructor of the sequence from a blackbox, a field and two blocks random projection
BlackboxBlockContainerRecord(const _Blackbox *D, const Field &F, size_t m, size_t n, size_t seed= (size_t)time(NULL)) :
BlackboxBlockContainerBase<Field, _Blackbox> (D, F, m, n,seed),
_blockW(D->rowdim(), n), _BMD(F), _launcher(Nothing), _iter(1)
{
#ifdef _BBC_TIMING
clearTimer();
tSequence.clear();
tSequence.start();
#endif
this->init (m,n);
_rep = std::vector<Value> (this->_size);
_Vcopy = this->_blockV;
for (size_t i=0;i< this->_size;++i){
_rep[i] = this->_value;
_launch_record();
}
this->_value=_rep[0];
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
void setU (const std::vector<Element> &b, size_t k)
{
linbox_check( b.size() == this->_row);
_launcher = RowUpdate;
_upd_idx = k;
_u = b;
_w.resize(this->_row);
_iter = 1;
_case = 1;
#ifdef _BBC_TIMING
tSequence.clear();
tSequence.start();
#endif
std::vector<Element> _row_value(this->_n);
_BMD.mul(_row_value, b, _Vcopy);
this->_value = _rep[0];
for (size_t j=0; j< this->_n; ++j)
this->_value.setEntry(_upd_idx, j, _row_value[j]);
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
void setV (const std::vector<Element> &b, size_t k)
{
linbox_check( b.size() == this->_col);
_launcher = ColUpdate;
_upd_idx = k;
_u = b;
_w.resize(this->_col);
_iter = 1;
_case = 1;
#ifdef _BBC_TIMING
tSequence.clear();
tSequence.start();
#endif
std::vector<Element> _col_value(this->_m);
_BMD.mul(_col_value, this->_blockU, b);
this->_value = _rep[0];
for (size_t j=0; j< this->_m; ++j)
this->_value.setEntry(j, _upd_idx, _col_value[j]);
#ifdef __BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
}
void recompute()
{
switch(_launcher) {
case Nothing:
this->_value=_rep[0];
_iter=1;
break;
case RowUpdate:
#ifdef _BBC_TIMING
tSequence.clear();
tSequence.start();
#endif
for (size_t i=0;i< this->_size;++i){
_rep[i]=this->_value;
_launch_record_row();
}
_launcher=Nothing;
this->_value=_rep[0];
_iter=1;
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
break;
case ColUpdate:
#ifdef _BBC_TIMING
tSequence.clear();
tSequence.start();
#endif
for (size_t i=0;i< this->_size;++i){
_rep[i]=this->_value;
_launch_record_col();
}
_launcher=Nothing;
this->_value=_rep[0];
_iter=1;
break;
#ifdef _BBC_TIMING
tSequence.stop();
ttSequence += tSequence;
#endif
default :
throw LinboxError ("Bad argument in BlackboxBlockContainerRecord, _launch() function\n");
break;
}
}
#ifdef _BBC_TIMING
void clearTimer()
{
ttSequence.clear();
}
void printTimer()
{
std::cout<<"Sequence Computation "<<ttSequence<<std::endl<<std::endl;
}
#endif
const std::vector<Value>& getRep() const { return _rep;}
protected:
Block _blockW;
Block _Vcopy;
BlasMatrixDomain<Field> _BMD;
std::vector<Value> _rep;
size_t _upd_idx;
std::vector<Element> _u;
std::vector<Element> _w;
Launcher _launcher;
size_t _iter;
size_t _case;
std::vector<std::vector<Element> > _Special_U;
#ifdef _BBC_TIMING
Timer ttSequence, tSequence;
#endif
// launcher of computation of sequence element
void _launch_record ()
{
if (this->casenumber) {
Mul(_blockW,*this->_BB,this->_blockV);
_BMD.mul(this->_value, this->_blockU, _blockW);
this->casenumber = 0;
}
else {
Mul(this->_blockV,*this->_BB,_blockW);
_BMD.mul(this->_value, this->_blockU, this->_blockV);
this->casenumber = 1;
}
}
// launcher of computation of sequence element
void _launch_record_notdense ()
{
size_t block= this->_blockV.coldim();
size_t numblock=_Special_U[0].size();
if (this->casenumber) {
Mul(_blockW,*this->_BB,this->_blockV);
std::vector<Element> tmp(block);
for (size_t i=0; i<block; ++i){
BlasMatrix<Field> T(_blockW, i*numblock, 0, numblock, block);
_BMD.mul(tmp, _Special_U[i], T);
for (size_t j=0;j<block;++j){
this->_field.assign(this->_value.refEntry(i,j), tmp[j]);
}
}
this->casenumber = 0;
}
else {
Mul(this->_blockV,*this->_BB,_blockW);
std::vector<Element> tmp(block);
for (size_t i=0; i< block; ++i){
BlasMatrix<Field> T(this->_blockV, i*numblock, 0, numblock, block);
_BMD.mul(tmp, _Special_U[i], T);
for (size_t j=0;j<block;++j)
this->_field.assign(this->_value.refEntry(i,j), tmp[j]);
}
this->casenumber = 1;
}
}
// launcher of computation of sequence element
// just update one row in the sequence element
void _launch_record_row()
{
if ( _iter < this->_size) {
if ( _case == 1) {
this->_BB->applyTranspose(_w,_u);
std::vector<Element> _row_value(this->_n);
_BMD.mul(_row_value, _w, _Vcopy);
this->_value = _rep[_iter];
for (size_t j=0; j< this->_n; ++j)
this->_value.setEntry(_upd_idx, j, _row_value[j]);
++_iter;
_case =0;
}
else {
this->_BB->applyTranspose(_u,_w);
std::vector<Element> _row_value(this->_n);
_BMD.mul(_row_value, _u, _Vcopy);
this->_value = _rep[_iter];
for (size_t j=0; j< this->_n; ++j)
this->_value.setEntry(_upd_idx, j, _row_value[j]);
++_iter;
_case =1;
}
}
}
// launcher of computation of sequence element
// just update one col in the sequence element
void _launch_record_col()
{
if ( _iter < this->_size) {
if ( _case == 1) {
this->_BB->apply(_w,_u);
std::vector<Element> _col_value(this->_m);
_BMD.mul(_col_value, this->_blockU, _w);
this->_value = _rep[_iter];
for (size_t j=0; j< this->_m; ++j)
this->_value.setEntry(j, _upd_idx, _col_value[j]);
++_iter;
_case =0;
}
else {
this->_BB->apply(_u,_w);
std::vector<Element> _col_value(this->_m);
_BMD.mul(_col_value, this->_blockU, _u);
this->_value = _rep[_iter];
for (size_t j=0; j< this->_m; ++j)
this->_value.setEntry(j, _upd_idx, _col_value[j]);
++_iter;
_case =1;
}
}
}
// launcher which be used as iterator on the sequence
void _launch()
{
switch (_launcher) {
case Nothing:
if (_iter < this->_size)
this->_value = _rep[_iter];
++_iter;
break;
case RowUpdate:
_launch_record_row();
break;
case ColUpdate:
_launch_record_col();
break;
default :
throw LinboxError ("Bad argument in BlackboxBlockContainerRecord, _launch() function\n");
break;
}
}
void _wait () {}
};
}
#undef _BBC_TIMING
#endif // __LINBOX_blackbox_block_container_H
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|