![]() |
planc
Parallel Lowrank Approximation with Non-negativity Constraints
|
Data is stored such that the unfolding is column major.
More...
#include <tensor.hpp>
Public Member Functions | |
Tensor () | |
Tensor (const UVEC &i_dimensions) | |
Constructor that takes only dimensions of every mode as a vector. More... | |
Tensor (const UVEC &i_dimensions, const UVEC &i_start_idx) | |
Tensor (const UVEC &i_dimensions, double *i_data) | |
Need when copying from matrix to Tensor. More... | |
~Tensor () | |
Tensor (const Tensor &src) | |
copy constructor More... | |
Tensor & | operator= (const Tensor &other) |
void | swap (Tensor &in) |
void | clear () |
Clears the data and also destroys the storage. More... | |
int | modes () const |
Return the number of modes. It is a scalar value. More... | |
UVEC | dimensions () const |
Returns a vector of dimensions on every mode. More... | |
UVEC | global_idx () const |
int | dimension (int i) const |
Returns the dimension of the input mode. More... | |
UWORD | numel () const |
Returns total number of elements. More... | |
void | set_idx (const UVEC &i_start_idx) |
UWORD | dimensions_leave_out_one (int i) const |
Return the product of dimensions except mode i. More... | |
void | zeros () |
Zeros out the entire tensor. More... | |
void | rand () |
set the tensor with uniform random. More... | |
void | randi () |
set the tensor with uniform int values More... | |
void | randu (const int i_seed=-1) |
set the tensor with uniform random values starting with a seed. More... | |
void | mttkrp (const int i_n, const MAT &i_krp, MAT *o_mttkrp) const |
size of krp must be product of all dimensions leaving out nxk. More... | |
void | print () const |
prints the value of the tensor. More... | |
void | print (const UVEC &global_dims, const UVEC &global_start_sub) |
double | norm () const |
returns the frobenius norm of the tensor More... | |
double | err (const Tensor &b) const |
Computes the squared error with the input tensor. More... | |
template<typename NumericType > | |
void | scale (NumericType scale) |
Scales the tensor with the constant value. More... | |
template<typename NumericType > | |
void | shift (NumericType i_shift) |
Shifts (add or subtract) the tensor with the constant value. More... | |
template<typename NumericType > | |
void | bound (NumericType min, NumericType max) |
Truncate all the value between min and max. More... | |
template<typename NumericType > | |
void | lower_bound (NumericType min) |
Sets only the lower bound. More... | |
void | write (std::string filename, std::ios_base::openmode mode=std::ios_base::out) |
Write the tensor to the given filename. More... | |
void | read (std::string filename, std::ios_base::openmode mode=std::ios_base::in) |
Reads a tensor from the file. More... | |
UWORD | sub2ind (UVEC sub) |
Given a vector of subscripts, it return the linear index in the tensor. More... | |
double | at (UVEC sub) |
Public Attributes | |
std::vector< double > | m_data |
Data is stored such that the unfolding is column major.
This means the flattening is row-major, and any other flattening
can be represented as a set of
row major matrices, each of which is
.
Definition at line 32 of file tensor.hpp.
|
inline |
Definition at line 75 of file tensor.hpp.
|
inlineexplicit |
Constructor that takes only dimensions of every mode as a vector.
Definition at line 82 of file tensor.hpp.
Definition at line 90 of file tensor.hpp.
|
inline |
Need when copying from matrix to Tensor.
otherwise copy constructor will be called. The data will be passed in row major order
Definition at line 104 of file tensor.hpp.
|
inline |
Definition at line 112 of file tensor.hpp.
|
inline |
copy constructor
Definition at line 117 of file tensor.hpp.
|
inline |
Definition at line 516 of file tensor.hpp.
|
inline |
Truncate all the value between min and max.
Any value beyond the min and max will be truncated to min and max.
[in] | min | - any value less than min will be set to min |
[in] | max | - any value greater than max will be set to max |
Definition at line 399 of file tensor.hpp.
|
inline |
Clears the data and also destroys the storage.
Definition at line 153 of file tensor.hpp.
|
inline |
Returns the dimension of the input mode.
[in] | a | mode of the tensor. |
Definition at line 170 of file tensor.hpp.
|
inline |
Returns a vector of dimensions on every mode.
Definition at line 161 of file tensor.hpp.
|
inline |
Return the product of dimensions except mode i.
[in] | mode | i |
Definition at line 180 of file tensor.hpp.
|
inline |
Computes the squared error with the input tensor.
[in] | b | an input tensor |
Definition at line 357 of file tensor.hpp.
|
inline |
Definition at line 162 of file tensor.hpp.
|
inline |
Sets only the lower bound.
[in] | min | - any value less than min will be set to min |
Definition at line 413 of file tensor.hpp.
|
inline |
Return the number of modes. It is a scalar value.
Definition at line 159 of file tensor.hpp.
size of krp must be product of all dimensions leaving out nxk.
o_mttkrp will be of size dimension[n]xk. Memory must be allocated and freed by the caller
[in] | i_n | mode number |
[in] | i_krp | Khatri-rao product matrix leaving out mode i_n |
[out] | o_mttkrp | pointer to the mttkrp matrix. |
Definition at line 242 of file tensor.hpp.
|
inline |
returns the frobenius norm of the tensor
Definition at line 346 of file tensor.hpp.
|
inline |
Returns total number of elements.
Definition at line 172 of file tensor.hpp.
Definition at line 127 of file tensor.hpp.
|
inline |
prints the value of the tensor.
Definition at line 325 of file tensor.hpp.
Definition at line 332 of file tensor.hpp.
|
inline |
set the tensor with uniform random.
Definition at line 191 of file tensor.hpp.
|
inline |
set the tensor with uniform int values
Definition at line 200 of file tensor.hpp.
|
inline |
set the tensor with uniform random values starting with a seed.
can be used to generate the same tensor again and again.
[in] | an | integer seed value preferrably a relative prime number |
Definition at line 215 of file tensor.hpp.
|
inline |
Reads a tensor from the file.
Compile with -D_FILE_OFFSET_BITS=64 to support large files greater than 2GB
[in] | filename | as std::string |
Definition at line 460 of file tensor.hpp.
|
inline |
Scales the tensor with the constant value.
[in] | scale | can be an int, float or double value |
Definition at line 372 of file tensor.hpp.
|
inline |
Definition at line 174 of file tensor.hpp.
|
inline |
Shifts (add or subtract) the tensor with the constant value.
If the i_shift is negative it subtracts, otherwise it adds.
[in] | i_shift | can be an int, float or double value |
Definition at line 385 of file tensor.hpp.
Given a vector of subscripts, it return the linear index in the tensor.
[in] | vector | of subscript |
Definition at line 508 of file tensor.hpp.
|
inline |
Definition at line 140 of file tensor.hpp.
|
inline |
Write the tensor to the given filename.
Compile with -D_FILE_OFFSET_BITS=64 to support large files greater than 2GB
[in] | filename | as std::string |
Definition at line 426 of file tensor.hpp.
|
inline |
Zeros out the entire tensor.
Definition at line 185 of file tensor.hpp.
std::vector<double> planc::Tensor::m_data |
Definition at line 73 of file tensor.hpp.