|
openGPMP
Open Source Mathematics Package
|
Represents a 3D tensor with basic operations. More...
#include <tensor.hpp>
Public Member Functions | |
| Tensor () | |
| Default constructor Creates an empty tensor. More... | |
| Tensor (const std::vector< size_t > &dimensions) | |
| Constructor with specified dimensions. More... | |
| Tensor (const std::vector< std::vector< std::vector< double >>> &data) | |
| Constructor with initial data. More... | |
| Tensor | add (const Tensor &other) const |
| Adds another tensor to the current tensor. More... | |
| Tensor | multiply (double scalar) const |
| Multiplies the tensor by a scalar value. More... | |
| Tensor | multiply (const Tensor &other) const |
| Multiplies the tensor by another tensor. More... | |
| double | get (const std::vector< size_t > &indices) const |
| Gets the value at the specified indices. More... | |
| void | set (const std::vector< size_t > &indices, double value) |
| Sets the value at the specified indices. More... | |
| void | display () const |
| Displays the tensor. More... | |
Private Attributes | |
| std::vector< std::vector< std::vector< double > > > | data_ |
| < 3D vector representing the tensor data More... | |
| size_t | dimensions_ [3] |
Represents a 3D tensor with basic operations.
This class provides basic operations for a 3D tensor, including addition, multiplication, element access, and display functionality
Definition at line 51 of file tensor.hpp.
| gpmp::linalg::Tensor::Tensor | ( | ) |
Default constructor Creates an empty tensor.
Definition at line 38 of file tensor.cpp.
|
explicit |
Constructor with specified dimensions.
| dimensions | A vector containing three dimensions for the tensor |
| std::invalid_argument | if dimensions are empty |
Constructs a tensor with specified dimensions and initializes the data
Definition at line 41 of file tensor.cpp.
| gpmp::linalg::Tensor::Tensor | ( | const std::vector< std::vector< std::vector< double >>> & | data | ) |
Constructor with initial data.
| data | 3D vector representing the initial data for the tensor |
| std::invalid_argument | if data is empty |
Constructs a tensor with the given initial data and sets dimensions accordingly
Definition at line 62 of file tensor.cpp.
References dimensions_.
| gpmp::linalg::Tensor gpmp::linalg::Tensor::add | ( | const Tensor & | other | ) | const |
Adds another tensor to the current tensor.
| other | Tensor to be added |
| std::invalid_argument | if dimensions do not match |
Definition at line 75 of file tensor.cpp.
References data_, and dimensions_.
| void gpmp::linalg::Tensor::display | ( | ) | const |
| double gpmp::linalg::Tensor::get | ( | const std::vector< size_t > & | indices | ) | const |
Gets the value at the specified indices.
| indices | Vector containing three indices |
| std::out_of_range | if the number of indices is not 3 or if an index is out of bounds |
Definition at line 143 of file tensor.cpp.
| gpmp::linalg::Tensor gpmp::linalg::Tensor::multiply | ( | const Tensor & | other | ) | const |
Multiplies the tensor by another tensor.
| other | Tensor to be multiplied |
| std::invalid_argument | if dimensions do not match |
Definition at line 112 of file tensor.cpp.
References data_, and dimensions_.
| gpmp::linalg::Tensor gpmp::linalg::Tensor::multiply | ( | double | scalar | ) | const |
Multiplies the tensor by a scalar value.
| scalar | The scalar value |
Definition at line 97 of file tensor.cpp.
References data_.
| void gpmp::linalg::Tensor::set | ( | const std::vector< size_t > & | indices, |
| double | value | ||
| ) |
Sets the value at the specified indices.
| indices | Vector containing three indices |
| value | The value to set |
| std::out_of_range | if the number of indices is not 3 or if an index is out of bounds |
Definition at line 159 of file tensor.cpp.
|
private |
< 3D vector representing the tensor data
Array representing the dimensions of the tensor
Definition at line 125 of file tensor.hpp.
Referenced by add(), and multiply().
|
private |
Definition at line 127 of file tensor.hpp.
Referenced by add(), multiply(), and Tensor().