40 #ifndef CORE_DATATYPES_DENSECOLMAJMATRIX_H
41 #define CORE_DATATYPES_DENSECOLMAJMATRIX_H 1
44 #include <Core/Geometry/Transform.h>
51 #include <sci_defs/lapack_defs.h>
52 #include <sci_defs/blas_defs.h>
54 #include <Core/Util/Assert.h>
55 #include <Core/Util/FancyAssert.h>
129 return dataptr_[c * this->
nrows_ + r];
135 return dataptr_[c * this->
nrows_ + r];
153 virtual void print(std::string&)
const;
171 template <
typename T>
174 template <
typename T>
175 DenseColMajMatrixGeneric<T>*
181 template <
typename T>
191 template <
typename T>
198 template <
typename T>
207 template <
typename T>
209 Matrix<T>(m.nrows_, m.ncols_)
214 memcpy(dataptr_, m.dataptr_,
sizeof(
double) * this->nrows_ * this->ncols_);
217 template <
typename T>
224 template <
typename T>
228 return this->nrows() * this->ncols();
233 template <
typename T>
243 template <
typename T>
251 dataptr_ =
new double[this->nrows_ * this->ncols_];
252 memcpy(dataptr_, m.dataptr_,
sizeof(
double) * this->nrows_ * this->ncols_);
257 template <
typename T>
266 template <
typename T>
275 template <
typename T>
284 template <
typename T>
289 for (
index_type k=0; k<this->nrows_*this->ncols_; k++)
290 if (dataptr_[k] < min) min = dataptr_[k];
294 template <
typename T>
299 for (
index_type k=0; k<this->nrows_*this->ncols_; k++)
300 if (dataptr_[k] > max) max = dataptr_[k];
305 template <
typename T>
312 m->
iget(c, r) = iget(r, c);
316 template <
typename T>
323 stride = this->nrows_;
328 template <
typename T>
332 memset(dataptr_, 0,
sizeof(
double) * this->nrows_ * this->ncols_);
335 template <
typename T>
343 result->
iget(i, i) = 1.0;
349 template <
typename T>
353 std::ostringstream oss;
358 oss << iget(i, j) <<
" ";
362 str.assign(oss.str());
365 template <
typename T>
378 memcpy(mat->dataptr_ + (i - c1) * (r2 - r1 + 1),
379 dataptr_ + c1 * this->nrows_ + r1,
380 (r2 - r1 + 1) *
sizeof(
double));
385 #define DENSECOLMAJMATRIX_VERSION 3
387 template <
typename T>
398 int nrows =
static_cast<int>(this->nrows_);
399 int ncols =
static_cast<int>(this->ncols_);
402 this->nrows_ =
static_cast<size_type>(nrows);
403 this->ncols_ =
static_cast<size_type>(ncols);
407 long long nrows =
static_cast<long long>(this->nrows_);
408 long long ncols =
static_cast<long long>(this->ncols_);
411 this->nrows_ =
static_cast<size_type>(nrows);
412 this->ncols_ =
static_cast<size_type>(ncols);
417 dataptr_ =
new T[this->nrows_ * this->ncols_];
426 Pio(stream, this->separate_raw_);
427 if (this->separate_raw_)
429 Pio(stream, this->raw_filename_);
430 FILE *f = fopen(this->raw_filename_.c_str(),
"r");
433 fread(dataptr_,
sizeof(T), this->nrows_ * this->ncols_, f);
438 const std::string errmsg =
"Error reading separated file '" +
439 this->raw_filename_ +
"'";
440 std::cerr << errmsg <<
"\n";
447 this->separate_raw_ =
false;
449 split = this->separate_raw_;
453 std::string filename = this->raw_filename_;
454 split = this->separate_raw_;
461 size_t pos = stream.
file_name.rfind(
'.');
462 if (pos == std::string::npos) filename = stream.
file_name +
".raw";
463 else filename = stream.
file_name.substr(0,pos) +
".raw";
474 Pio(stream, filename);
475 FILE *f = fopen(filename.c_str(),
"w");
476 fwrite(dataptr_,
sizeof(T), this->nrows_ * this->ncols_, f);
483 size_t block_size = this->nrows_ * this->ncols_;
484 if (!stream.
block_io(dataptr_,
sizeof(T), block_size))
486 for (
size_t i = 0; i < block_size; i++)
488 stream.
io(dataptr_[i]);
virtual SparseRowMatrix * sparse()
Definition: MatrixTypeConverter.h:122
virtual DenseColMajMatrixGeneric * clone() const
Public member functions.
Definition: DenseColMajMatrix.h:176
#define DENSECOLMAJMATRIX_VERSION
Definition: DenseColMajMatrix.h:385
virtual bool block_io(void *, size_t, size_t)
Definition: Persistent.h:174
bool reading() const
Definition: Persistent.h:164
Definition: DenseMatrix.h:68
LockingHandle< Matrix< double > > MatrixHandle
Definition: MatrixFwd.h:55
virtual ColumnMatrix * column()
Definition: MatrixTypeConverter.h:112
virtual MatrixHandle submatrix(index_type r1, index_type c1, index_type r2, index_type c2)
Definition: DenseColMajMatrix.h:367
const T & operator()(index_type r, index_type c) const
Definition: DenseColMajMatrix.h:143
Definition: DenseColMajMatrix.h:73
virtual void io(bool &)
Definition: Persistent.cc:193
Definition: Persistent.h:89
DenseColMajMatrixGeneric & operator=(const DenseColMajMatrixGeneric &)
assignment operator
Definition: DenseColMajMatrix.h:245
virtual void zero()
slow setters/getter for polymorphic operations
Definition: DenseColMajMatrix.h:330
const T & iget(index_type r, index_type c) const
fast accessors
Definition: DenseColMajMatrix.h:133
int compute_checksum(T *data, std::size_t length)
Definition: CheckSum.h:38
DenseColMajMatrixGeneric()
Constructors.
Definition: DenseColMajMatrix.h:192
Definition: Persistent.h:187
static DenseColMajMatrixGeneric * identity(size_type size)
Definition: DenseColMajMatrix.h:337
virtual T min()
Definition: DenseColMajMatrix.h:286
static PersistentTypeID type_id
Definition: DenseColMajMatrix.h:157
virtual void begin_cheap_delim()
Definition: Persistent.cc:183
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
#define ASSERTRANGE(c, l, h)
Definition: Assert.h:99
T & iget(index_type r, index_type c)
fast accessors
Definition: DenseColMajMatrix.h:127
size_type ncols_
Definition: Matrix.h:113
virtual void add(index_type r, index_type c, T val)
Definition: DenseColMajMatrix.h:277
Definition: ParallelLinearAlgebraTests.cc:358
virtual void getRowNonzerosNoCopy(index_type r, size_type &size, size_type &stride, index_type *&cols, T *&vals)
Definition: DenseColMajMatrix.h:318
Generic exception for internal errors.
long long size_type
Definition: Types.h:40
T * end() const
Definition: Matrix.h:141
virtual void print(std::string &) const
Definition: DenseColMajMatrix.h:351
Definition: ColumnMatrix.h:55
virtual T * get_data_pointer() const
Definition: DenseColMajMatrix.h:219
T determinant()
Throws an assertion if not square.
size_type nrows_
Definition: Matrix.h:112
virtual size_type get_data_size() const
Definition: DenseColMajMatrix.h:226
virtual void end_cheap_delim()
Definition: Persistent.cc:188
DenseColMajMatrixGeneric< double > DenseColMajMatrix
Definition: MatrixFwd.h:52
virtual int compute_checksum()
Definition: DenseColMajMatrix.h:183
virtual DenseMatrix * dense()
Definition: MatrixTypeConverter.h:101
virtual ~DenseColMajMatrixGeneric()
Destructor.
Definition: DenseColMajMatrix.h:234
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
virtual DenseColMajMatrixGeneric * dense_col_maj()
Definition: MatrixTypeConverter.h:151
virtual void end_class()
Definition: Persistent.cc:178
virtual void io(Piostream &)
Persistent representation...
Definition: DenseColMajMatrix.h:389
virtual DenseColMajMatrixGeneric * make_transpose() const
Definition: DenseColMajMatrix.h:307
T & operator()(index_type r, index_type c)
Definition: DenseColMajMatrix.h:138
long long index_type
Definition: Types.h:39
virtual void mult(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: DenseColMajMatrixMultiplication.h:50
virtual void io(Piostream &)
Definition: Matrix.cc:58
virtual void put(index_type r, index_type c, T val)
Definition: DenseColMajMatrix.h:268
Definition: Persistent.h:64
boost::error_info< struct tag_file_not_found, std::string > FileNotFound
Definition: Exception.h:54
virtual void mult_transpose(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: DenseColMajMatrixMultiplication.h:90
std::string file_name
Definition: Persistent.h:135
virtual T get(index_type r, index_type c) const
Definition: DenseColMajMatrix.h:259
#define DEBUG_CONSTRUCTOR(type)
Definition: Debug.h:64
virtual T max()
Definition: DenseColMajMatrix.h:296
Definition: MatrixFwd.h:40
int size
Definition: eabLatVolData.py:2
#define DEBUG_DESTRUCTOR(type)
Definition: Debug.h:65