#include <eckit/linalg/Tensor.h>
template<typename S>
Tensor class
Dense Tensor in column major storage order This class is not meant to be accessed 1 element at a time, as its access isn't efficient enough in tight loops. It is meant to be passed as a contiguous piece of data into linear algebra packages. The operator() is only provided for inspection and testing.
Supports 2 memory layouts:
- Column-major (as in Fortran) where [fast idx] .... [slow idx] - also known as "left" layout
- Row-major (as in C) where [slow idx] .... [fast idx] - also known as "right" layout
Public types
Public static functions
-
static auto flatSize(const std::
vector<Size>& shape) -> Size -
static auto strides(Layout layout,
const std::
vector<Size>& shape) -> std:: vector<Size>
Constructors, destructors, conversion operators
- Tensor(Layout layout = Layout::ColMajor)
- Default constructor (empty tensor)
-
Tensor(const std::
vector<Size>& shape, Layout layout = Layout::ColMajor) - Construct tensor with given rows and columns (allocates memory, not initialised)
-
Tensor(S* array,
const std::
vector<Size>& shape, Layout layout = Layout::ColMajor) - Construct tensor from existing data (does NOT take ownership)
- Tensor(Stream& s)
- Constructor from Stream.
- Tensor(const Tensor& other)
- Copy constructor.
- Tensor(Tensor&& other) noexcept
- Move constructor.
- ~Tensor()
- Destructor.
Public functions
- auto operator=(const Tensor& other) -> Tensor&
- auto operator=(Tensor&& other) -> Tensor& noexcept
- Move assignment operator.
- void swap(Tensor& other)
- Swap this tensor with another.
-
void resize(const std::
vector<Size>& shape) - void zero()
- Set data to zero.
- void fill(S value)
- Fill vector with given S.
- void encode(Stream& s) const
- auto size() const -> Size
-
auto shape() const -> std::
vector<Size> - auto operator[](Size i) -> S&
- Access to linearised storage.
- auto operator[](Size i) const -> const S&
- auto data() -> S*
- auto data() const -> const S*
- auto begin() -> S*
- auto begin() const -> const S*
- auto end() -> S*
- auto end() const -> const S*
-
void print(std::
ostream& s) const - auto layout() const -> Layout
-
template<typename... Idx>auto operator()(Idx... idx) -> S&
- Multidimensional index operator A(i,j,k,...)
-
template<typename... Idx>auto operator()(Idx... idx) const -> const S&
- Multidimensional index operator A(i,j,k,...)
- auto transformColMajorToRowMajor() const -> Tensor
- Transform a colMajor-layout tensor to rowMajor-layout.
- auto transformRowMajorToColMajor() const -> Tensor
- Transform a rowMajor-layout tensor to colMajor-layout.
Function documentation
template<typename S>
void eckit:: linalg:: Tensor<S>:: resize(const std:: vector<Size>& shape)
Resize tensor to given a shape Invalidates data if shapes don't match, otherwise keeps data and simply reshapes
template<typename S>
Size eckit:: linalg:: Tensor<S>:: size() const
Returns | flatten size (= product of shape vector) |
---|
template<typename S>
std:: vector<Size> eckit:: linalg:: Tensor<S>:: shape() const
Returns | shape |
---|
template<typename S>
S* eckit:: linalg:: Tensor<S>:: data()
Returns | modifiable view of the data |
---|
template<typename S>
const S* eckit:: linalg:: Tensor<S>:: data() const
Returns | read-only view of the data |
---|
template<typename S>
S* eckit:: linalg:: Tensor<S>:: begin()
Returns | iterator to beginning of the data |
---|
template<typename S>
const S* eckit:: linalg:: Tensor<S>:: begin() const
Returns | const iterator to beginning of the data |
---|
template<typename S>
S* eckit:: linalg:: Tensor<S>:: end()
Returns | iterator to end of the data |
---|
template<typename S>
const S* eckit:: linalg:: Tensor<S>:: end() const
Returns | const iterator to end of the data |
---|
template<typename S>
template<typename... Idx>
S& eckit:: linalg:: Tensor<S>:: operator()(Idx... idx)
Multidimensional index operator A(i,j,k,...)
template<typename S>
template<typename... Idx>
const S& eckit:: linalg:: Tensor<S>:: operator()(Idx... idx) const
Multidimensional index operator A(i,j,k,...)