25 #include <tbb/scalable_allocator.h> 37 template<
typename scalar>
85 references =
new std::atomic<int64_t>(1);
112 references =
new std::atomic<int64_t>(1);
141 references =
new std::atomic<int64_t>(1);
169 references =
new std::atomic<int64_t>(1);
193 if (rows > 0 && cols>0) assert(data);
201 references =
new std::atomic<int64_t>(1);
224 if (references != NULL) {
225 references->fetch_add(1, std::memory_order_relaxed);
303 references =
new std::atomic<int64_t>(1);
313 if (references == NULL)
return;
315 std::atomic<int64_t>* references_loc =
references;
317 const bool owner_loc =
owner;
322 if (references_loc->fetch_sub(1, std::memory_order_acq_rel) == 1) {
324 scalable_aligned_free(data_loc);
326 delete references_loc;
370 if (references != NULL) {
371 references->fetch_add(1, std::memory_order_relaxed);
385 if ( idx >= rows*stride || idx < 0) {
386 std::cout <<
"Accessing element out of bonds. Exiting" << std::endl;
394 bool operator<(const matrix_base<scalar>& other)
const {
395 if (rows != other.rows)
return rows < other.rows;
396 if (cols != other.cols)
return cols < other.cols;
397 for (
int i = 0; i <
rows; ++i) {
398 for (
int j = 0; j <
cols; ++j) {
399 if (data[i * stride + j] != other.data[i * stride + j])
400 return data[i * stride + j] < other.data[i * stride + j];
421 memcpy( ret.
data, data, rows*stride*
sizeof(
scalar));
435 if (target.
rows != rows || target.
cols != cols || target.
stride != stride) {
439 if (data != NULL && target.
data != data) {
440 memcpy(target.
data, data, rows*stride*
sizeof(
scalar));
449 if (((uintptr_t)(
void*)data & (
CACHELINE-1)) == 0)
return;
451 memcpy( newdata, data, rows*stride*
sizeof(
scalar));
472 std::cout << std::endl <<
"The stored matrix:" << std::endl;
473 for (
int row_idx=0; row_idx <
rows; row_idx++ ) {
474 for (
int col_idx=0; col_idx <
cols; col_idx++ ) {
475 int element_idx = row_idx*stride + col_idx;
476 std::cout <<
" " << data[element_idx];
478 std::cout << std::endl;
480 std::cout << std::endl << std::endl << std::endl;
bool owner
logical value indicating whether the class instance is the owner of the stored data or not...
int stride
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
matrix_base< scalar > copy() const
Call to create a copy of the matrix.
scalar * data
pointer to the stored data
matrix_base(scalar *data_in, int rows_in, int cols_in)
Constructor of the class.
void release_data()
Call to release the data stored by the matrix.
matrix_base(scalar *data_in, int rows_in, int cols_in, int stride_in)
Constructor of the class.
bool transposed
logical variable indicating whether the matrix needs to be transposed in CBLAS operations ...
bool conjugated
logical variable indicating whether the matrix needs to be conjugated in CBLAS operations ...
scalar * get_data() const
Call to get the pointer to the stored data.
~matrix_base()
Destructor of the class.
Base Class to store data of arrays and its properties.
void operator=(const matrix_base &mtx)
Assignment operator.
scalar & operator[](int idx) const
Operator [] to access elements in array style (does not check the boundaries of the stored array) ...
int rows
The number of rows.
int cols
The number of columns.
void replace_data(scalar *data_in, bool owner_in)
Call to replace the stored data by an another data array.
matrix_base(int rows_in, int cols_in, int stride_in)
Constructor of the class.
Custom types for the SQUANDER package.
void print_matrix() const
Call to prints the stored matrix on the standard output.
void set_owner(bool owner_in)
Call to set the current class instance to be (or not to be) the owner of the stored data array...
void copy_to(matrix_base< scalar > &target) const
Copy the current matrix storage into a reusable target matrix.
std::atomic< int64_t > * references
the number of the current references of the present object
int size() const
Call to get the number of the allocated elements.
void transpose()
Call to transpose (or un-transpose) the matrix for CBLAS functions.
matrix_base()
Default constructor of the class.
bool is_conjugated() const
Call to get whether the matrix should be conjugated in CBLAS functions or not.
matrix_base(int rows_in, int cols_in)
Constructor of the class.
void conjugate()
Call to conjugate (or un-conjugate) the matrix for CBLAS functions.
matrix_base(const matrix_base< scalar > &in)
Copy constructor of the class.
bool is_transposed() const
Call to get whether the matrix should be conjugated in CBLAS functions or not.