/usr/include/linbox/blackbox/toeplitz.inl is in liblinbox-dev 1.1.6~rc0-4.1.
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 | /* -*- mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* toeplitz.inl NTL_Toeplitz.cpp file
*
* Copyright (C) 2002 Austin Lobo, B. David Saunders
* Author: Austin Lobo
* Linbox version 2001 and 2002
*
* This file is included in the template description of ntl-Toeplitz.h
* it contains the implementations of templatized member functions in the
* partial template specialization for toeplitz matrices that
* are manipulated in fields and rings according to the arithmetic
* in the ntl package from V. Shoup
*
* Everything is in the Linbox namespace by virtue of the #include
* in ntl-Toeplitz.h
*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
#include <iostream>
#include <fstream>
#include <assert.h> // JGD 26.09.2003
#include <linbox/algorithms/toeplitz-det.h>
namespace LinBox
{
/*-----------------------------------------------------------------
*---- Destructor
*----------------------------------------------------------------*/
template <class _CField, class _PField>
inline ToeplitzBase<_CField,_PField>::~ToeplitzBase()
{
#ifdef DBGMSGS
std::cout << "Toeplitz::~Toeplitz():\tDestroyed a " << rowDim << "x"<< this->colDim<<
" Toeplitz matrix "<< std::endl;
#endif
}//---- Destructor ---- [Tested 6/14/02 -- Works]
/*-----------------------------------------------------------------
*---- Field-only Constructor
*----------------------------------------------------------------*/
template <class _CField, class _PField>
ToeplitzBase<_CField, _PField>::ToeplitzBase(const Field& F)
:P(F), K(F)
{
sysDim = // Default dimension is 0
rowDim = // Default row dim is 0
this->colDim = 0; // Default col dim is 0
shape.shape(BlackboxSpecifier::TOEPLITZ);
#ifdef DBGMSGS
std::cout << "Toeplitz::Toeplitz():\tCreated a " << rowDim << "x"<< this->colDim<<
" Toeplitz matrix "<< std::endl;
#endif
}//----- Field-only Constructor
/*-----------------------------------------------------------------
*---- Zero Parameter Constructor
*----------------------------------------------------------------*/
template <class _CField, class _PField>
ToeplitzBase<_CField, _PField>::ToeplitzBase()
: P(0), K(0)
{
sysDim = // Default dimension is 0
rowDim = // Default row dim is 0
this->colDim = 0; // Default col dim is 0
shape.shape(BlackboxSpecifier::TOEPLITZ);
#ifdef DBGMSGS
std::cout << "Toeplitz::Toeplitz():\tCreated a " << rowDim << "x"<< this->colDim<<
" Toeplitz matrix "<< std::endl;
#endif
}//----- Zero Param Constructor ---- [Tested 6/14/02 -- Works]
/*-----------------------------------------------------------------
*------ Polynomial Field constructor
*-----------------------------------------------------------------*/
template< class _CField, class _PField >
ToeplitzBase<_CField,_PField>::ToeplitzBase( const PField& PF )
:P(PF), K(PF.getCoeffField())
{
sysDim = rowDim = this->colDim = 0;
shape.shape(BlackboxSpecifier::TOEPLITZ);
}//------ Polynomial Field constructor
/*-----------------------------------------------------------------
*------ Polynomial constructor
*-----------------------------------------------------------------*/
template< class _CField, class _PField >
ToeplitzBase<_CField,_PField>::ToeplitzBase
( const PField& PF, const Poly& p, size_t m, size_t n )
:P(PF), K(PF.getCoeffField()), rowDim(m), colDim(n), pdata(p)
{
shape.shape(BlackboxSpecifier::TOEPLITZ);
if( n == 0 ) this->colDim = rowDim;
if( rowDim >= this->colDim ) sysDim = rowDim;
else sysDim = this->colDim;
assert( P.deg(p) <= rowDim + this->colDim - 2 );
P.rev(rpdata, pdata);
// Account for possible trailing zeroes
if( P.deg(pdata) < rowDim + this->colDim - 2 ) {
Poly x;
P.init(x,0);
Element one;
K.init(one,1);
P.setCoeff(x, (rowDim + this->colDim - 2 - P.deg(pdata)), one);
P.mulin( rpdata, x );
}
}//------ Polynomial constructor
/*-----------------------------------------------------------------
*----- Constructor With User-Supplied First Row And Column
*----------------------------------------------------------------*/
template <class _PField>
void Toeplitz<typename _PField::CoeffField, _PField>::init_vector( const std::vector<Element>&v)
{
if ( (1 & v.size()) == 0)
{
std::cout << "There must be an ODD number of entries in the input vector " <<
"The length given is " << v.size();
}
assert( (1 & v.size()) == 1);
this->P.init(this->pdata, v);
this->P.rev(this->rpdata, this->pdata);
// Account for possible trailing zeroes
if( this->P.deg(this->pdata) < v.size() - 1 ) {
Poly x;
this->P.init(x,0);
Element one;
this->K.init(one,1);
this->P.setCoeff(x, (v.size() - 1 - this->P.deg(this->pdata)), one);
this->P.mulin( this->rpdata, x );
}
this->rowDim = this->colDim = this->sysDim = (v.size()+1)/2;
//data = v;
#ifdef DBGMSGS
std::cout << "Toeplitz::Toeplitz(F,V):\tCreated a " << rowDim << "x"<< this->colDim<<
" Toeplitz matrix "<< std::endl;
#endif
}//----- Constructor given a vector---- [Tested 6/14/02 -- Works]
/*-----------------------------------------------------------------
*----- Print The Matrix To Screen
*----------------------------------------------------------------*/
template <class _PField>
void Toeplitz<typename _PField::CoeffField,_PField>::print(std::ostream& os) const
{
register int i, N;
register unsigned int j;
Element temp;
os<< this->rowDim << " " << this->colDim << " " << this->shape.shape() << std::endl;
N = this->rowDim + this->colDim -1;
if ( N < 20 ) // Print small matrices in dense format
{
for (i = this->colDim-1; i < N; i++)
{
for ( j = 0; j < this->colDim ; j++)
os << " " ;
this->K.write(os,this->P.getCoeff(temp,this->pdata,static_cast<size_t>(i-j))) ;
os << std::endl;
}
}
else
{ // Print large matrices' first row and col
os << "[";
for (size_t i = this->rowDim + this->colDim - 2; i> 0;i--)
this->K.write(os, this->P.getCoeff(temp,this->pdata,i) ) << " ";
this->K.write(os,this->P.getCoeff(temp,this->pdata,0)) << "]\n";
this->P.write(os, this->pdata) << std::endl;
} //[v(2n-2),....,v(0)]; where v(0) is the top right entry of the matrix
return;
} //---- print()----- [Tested 6/14/02 -- Works]
// /*-----------------------------------------------------------------
// *---- The infamous clone has been created here
// *----------------------------------------------------------------*/
// template <class Field, class Vector>
// BlackboxArchetype<Vector>* Toeplitz<Field, Vector>::clone() const
// {
// return new Toeplitz(*this);
// }// ------ This is not tested.
/*-----------------------------------------------------------------
*---- Save To File, Given Destination Filename
*----------------------------------------------------------------*/
template <class _PField>
void Toeplitz<typename _PField::CoeffField, _PField>::print( char *outFileName) const
{
Element temp;
std::cout << "Printing toeplitz matrix to " << outFileName << std::endl;
if ( outFileName == NULL )
print(); // Print to stdout if no file is specified
else
{
std::ofstream o_fp(outFileName, std::ios::out);
o_fp << this->rowDim << " " << this->colDim << " " << this->shape.shape() << std::endl ;
o_fp << "[";
for (size_t i = this->rowDim + this->colDim - 2; i>= 0;i--)
this->K.write(o_fp,this->P.getCoeff(temp,this->pdata,i))
<< " ";
o_fp << "]\n";
o_fp.close();
}
return;
} // print(char *) [Tested 6/14/02 -- Works]
/*-----------------------------------------------------------------
* Make the matrix upper triangular with determinant 1.
* i.e. clear the last N-1 elements in the data vector
*----------------------------------------------------------------*/
template <class _CField, class _PField>
void ToeplitzBase<_CField, _PField>::setToUniModUT()
{
typename PField::Coeff zero, one;
P.getCoeffField().init(zero,0);
P.getCoeffField().init(one,1);
for( size_t i = sysDim; i <= P.deg(pdata); ++i )
P.setCoeff(pdata,i,zero);
for( size_t i = 0; i < sysDim - 1; ++i )
P.setCoeff(rpdata,i,zero);
P.setCoeff(pdata,sysDim-1,one);
P.setCoeff(rpdata,sysDim-1,one);
shape.shape(BlackboxSpecifier::UNIMOD_UT);
return;
}// [UNCOMMENTED PART Tested 6/14/02 -- Works]
/*-----------------------------------------------------------------
* Make matrix a unimodular Lower Triangular with det 1
* i.e. clear the first N-1 elements in the data vector
*----------------------------------------------------------------*/
template <class _CField, class _PField>
void ToeplitzBase<_CField, _PField>::setToUniModLT()
{
typename PField::Coeff zero, one;
P.getCoeffField().init(zero,0);
P.getCoeffField().init(one,1);
for( size_t i = sysDim; i <= P.deg(rpdata); ++i )
P.setCoeff(rpdata,i,zero);
for( size_t i = 0; i < sysDim - 1; ++i )
P.setCoeff(pdata,i,zero);
P.setCoeff(pdata,sysDim-1,one);
P.setCoeff(rpdata,sysDim-1,one);
shape.shape(BlackboxSpecifier::UNIMOD_LT);
return;
}// [UNCOMMENTED PART Tested 6/14/02 -- Works]
/*-----------------------------------------------------------------
* Compute the determinant of the matrix
*-----------------------------------------------------------------*/
template<class _PField>
typename Toeplitz<typename _PField::CoeffField,_PField>::Element&
Toeplitz<typename _PField::CoeffField,_PField>::det
( Element& res ) const
{
return toeplitz_determinant( this->P, res, this->pdata, this->sysDim );
}
/*-----------------------------------------------------------------
* Apply the matrix to a vector
*----------------------------------------------------------------*/
template <class _PField>
template <class OutVector, class InVector>
OutVector& Toeplitz<typename _PField::CoeffField,_PField>::apply( OutVector &v_out,
const InVector& v_in) const
{
if (v_out.size() != this->rowdim())
std::cout << "\tToeplitz::apply()\t output vector not correct size, at "
<< v_out.size() << ". System rowdim is" << this->rowdim() << std::endl;
if ( v_in.size() != this->coldim() )
std::cout << "\tToeplitz::apply()\t input vector not correct size at "
<< v_in.size() << ". System colDim is" << this->coldim() << std::endl;
assert((v_out.size() == this->rowdim()) &&
(v_in.size() == this->coldim())) ;
Poly pOut, pIn;
this->P.init( pIn, v_in );
#ifdef DBGMSGS
std::cout << "\npX in is " << pxIn << std::endl;
std::cout << "multiplied by " << this->pdata << std::endl;
#endif
this->P.mul(pOut, pIn, this->pdata);
#ifdef DBGMSGS
std::cout <<"pxOut is " << pxOut << std::endl;
#endif
size_t N = this->rowdim();
for( size_t i = 0; i < N; ++i )
this->P.getCoeff(v_out[i], pOut, N-1+i);
return v_out;
}
/*-----------------------------------------------------------------
* Apply the transposed matrix to a vector
*----------------------------------------------------------------*/
template <class _PField>
template<class OutVector, class InVector>
OutVector& Toeplitz<typename _PField::CoeffField,_PField>::applyTranspose( OutVector &v_out,
const InVector& v_in) const
{
if (v_out.size() != this->coldim())
std::cout << "\tToeplitz::apply()\t output vector not correct size, at "
<< v_out.size() << ". System rowDim is" << this->coldim() << std::endl;
if ( v_in.size() != this->rowdim() )
std::cout << "\tToeplitz::apply()\t input vector not correct size at "
<< v_in.size() << ". System colDim is" << this->rowdim() << std::endl;
assert((v_out.size() == this->coldim()) &&
(v_in.size() == this->rowdim())) ;
Poly pOut, pIn;
this->P.init( pIn, v_in );
#ifdef DBGMSGS
std::cout << "\npX in is " << pxIn << std::endl;
std::cout << "multiplied by " << this->rpdata << std::endl;
#endif
this->P.mul(pOut, pIn, this->rpdata);
#ifdef DBGMSGS
std::cout <<"pxOut is " << pxOut << std::endl;
#endif
size_t N = this->coldim();
for( size_t i = 0; i < N; ++i )
this->P.getCoeff(v_out[i], pOut, N-1+i);
return v_out;
}
} // namespace LinBox
|