23 #ifndef FTL_TENSOR_DYNAMIC_CPU_HPP
24 #define FTL_TENSOR_DYNAMIC_CPU_HPP
31 #include <initializer_list>
43 template <
typename Traits>
47 template <
typename DT>
51 template <
typename DT>
53 TensorTraits<DT, CPU>> {
103 template <
typename Expression,
typename Traits>
126 inline size_t size(
const int dim)
const {
return dim < _rank ? _dim_sizes[dim] : 0; }
145 void initialize(
const data_type min,
const data_type max);
170 template <
typename IF,
typename... IR>
171 DT& operator()(IF index_dim_one, IR... index_dim_other);
182 template <
typename IF,
typename... IR>
183 DT operator()(IF index_dim_one, IR... index_dim_other)
const;
185 data_container _data;
186 dim_container _dim_sizes;
194 template <
typename DT>
196 : _data(std::accumulate(dim_sizes.begin(), dim_sizes.end(), 1, std::multiplies<
size_type>())),
197 _rank(dim_sizes.size())
199 for (
auto& element : dim_sizes) _dim_sizes.push_back(element);
202 template <
typename DT>
204 : _data(data), _rank(dim_sizes.size()), _dim_sizes(dim_sizes)
211 template <
typename DT>
213 : _data(data), _rank(dim_sizes.size()), _dim_sizes(dim_sizes)
220 template <
typename DT>
template <
typename E,
typename T>
222 : _data(expression.size()), _dim_sizes(expression.dim_sizes()), _rank(expression.rank())
224 for (
size_type i = 0; i != size(); ++i) _data[i] = expression[i];
227 template <
typename DT>
230 std::random_device rand_device;
231 std::mt19937 gen(rand_device());
232 std::uniform_real_distribution<> dist(min, max);
233 for (
auto& element : _data) element =
static_cast<data_type>(dist(gen));
236 template <
typename DT>
template <
typename IF,
typename... IR>
242 template <
typename DT>
template <
typename IF,
typename... IR>
249 #endif // FTL_TENSOR_DYNAMIC_CPU_HPP
size_type size() const
Gets the size (total number of elements) of the tensor.
Definition: tensor_dynamic_cpu.hpp:116
size_t size(const int dim) const
Gets the size of a specific dimension of the tensor, if the requested dimension is invalid then 0 is ...
Definition: tensor_dynamic_cpu.hpp:126
typename traits::data_type data_type
Definition: tensor_dynamic_cpu.hpp:60
typename traits::data_container data_container
Definition: tensor_dynamic_cpu.hpp:58
Definition: tensor_dynamic_cpu.hpp:44
const dim_container & dim_sizes() const
Gets a vector holding the size of each dimension of the tensor.
Definition: tensor_dynamic_cpu.hpp:132
typename traits::dim_container dim_container
Definition: tensor_dynamic_cpu.hpp:59
TensorInterface(size_type rank)
Default constructor - sets the data to have no elements, the rank to the specified rank...
Definition: tensor_dynamic_cpu.hpp:67
typename traits::container_type container_type
Definition: tensor_dynamic_cpu.hpp:57
Definition: mapper.hpp:37
static size_t indices_to_index(const Container &dim_sizes, IF index_first, IR...indices_rest)
Definition: mapper.hpp:144
Defines a general tensor expression so that opertions on tensor expressions can be defined the syntax...
Definition: tensor_expression_interface.hpp:49
typename traits::size_type size_type
Definition: tensor_dynamic_cpu.hpp:61
data_type & operator[](size_type i)
Gets the element at position i in the tensor's data vector, by refernce.
Definition: tensor_dynamic_cpu.hpp:152
const data_container & data() const
Gets the tensor data.
Definition: tensor_dynamic_cpu.hpp:138
size_type rank() const
Gets the rank (number of dimensions) of the tensor.
Definition: tensor_dynamic_cpu.hpp:110
const data_type & operator[](size_type i) const
Gets the element at position i in the tensor's data vector, by value.
Definition: tensor_dynamic_cpu.hpp:159
Traits class which specifies parameters for a tensor, such as what type of container it uses and what...
Definition: tensor_traits.hpp:48