Logo ROOT  
Reference Guide
RTensor.hxx
Go to the documentation of this file.
1#ifndef TMVA_RTENSOR
2#define TMVA_RTENSOR
3
4#include <vector>
5#include <cstddef> // std::size_t
6#include <stdexcept> // std::runtime_error
7#include <sstream> // std::stringstream
8#include <memory> // std::shared_ptr
9#include <type_traits> // std::is_convertible
10#include <algorithm> // std::reverse
11#include <iterator> // std::random_access_iterator_tag
12
13namespace TMVA {
14namespace Experimental {
15
16/// Memory layout type
17enum class MemoryLayout : uint8_t {
18 RowMajor = 0x01,
19 ColumnMajor = 0x02
20};
21
22namespace Internal {
23
24/// \brief Get size of tensor from shape vector
25/// \param[in] shape Shape vector
26/// \return Size of contiguous memory
27template <typename T>
28inline std::size_t GetSizeFromShape(const T &shape)
29{
30 if (shape.size() == 0)
31 return 0;
32 std::size_t size = 1;
33 for (auto &s : shape)
34 size *= s;
35 return size;
36}
37
38/// \brief Compute strides from shape vector.
39/// \param[in] shape Shape vector
40/// \param[in] layout Memory layout
41/// \return Size of contiguous memory
42///
43/// This information is needed for the multi-dimensional indexing. See here:
44/// https://en.wikipedia.org/wiki/Row-_and_column-major_order
45/// https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.strides.html
46template <typename T>
47inline std::vector<std::size_t> ComputeStridesFromShape(const T &shape, MemoryLayout layout)
48{
49 const auto size = shape.size();
50 T strides(size);
51 if (layout == MemoryLayout::RowMajor) {
52 for (std::size_t i = 0; i < size; i++) {
53 if (i == 0) {
54 strides[size - 1 - i] = 1;
55 } else {
56 strides[size - 1 - i] = strides[size - 1 - i + 1] * shape[size - 1 - i + 1];
57 }
58 }
59 } else if (layout == MemoryLayout::ColumnMajor) {
60 for (std::size_t i = 0; i < size; i++) {
61 if (i == 0) {
62 strides[i] = 1;
63 } else {
64 strides[i] = strides[i - 1] * shape[i - 1];
65 }
66 }
67 } else {
68 std::stringstream ss;
69 ss << "Memory layout type is not valid for calculating strides.";
70 throw std::runtime_error(ss.str());
71 }
72 return strides;
73}
74
75/// \brief Compute indices from global index
76/// \param[in] shape Shape vector
77/// \param[in] idx Global index
78/// \param[in] layout Memory layout
79/// \return Indice vector
80template <typename T>
81inline T ComputeIndicesFromGlobalIndex(const T& shape, MemoryLayout layout, const typename T::value_type idx)
82{
83 const auto size = shape.size();
84 auto strides = ComputeStridesFromShape(shape, layout);
85 T indices(size);
86 auto r = idx;
87 for (std::size_t i = 0; i < size; i++) {
88 indices[i] = int(r / strides[i]);
89 r = r % strides[i];
90 }
91 return indices;
92}
93
94/// \brief Compute global index from indices
95/// \param[in] strides Strides vector
96/// \param[in] idx Indice vector
97/// \return Global index
98template <typename U, typename V>
99inline std::size_t ComputeGlobalIndex(const U& strides, const V& idx)
100{
101 std::size_t globalIndex = 0;
102 const auto size = idx.size();
103 for (std::size_t i = 0; i < size; i++) {
104 globalIndex += strides[size - 1 - i] * idx[size - 1 - i];
105 }
106 return globalIndex;
107}
108
109/// \brief Type checking for all types of a parameter pack, e.g., used in combination with std::is_convertible
110template <class... Ts>
111struct and_types : std::true_type {
112};
113
114template <class T0, class... Ts>
115struct and_types<T0, Ts...> : std::integral_constant<bool, T0() && and_types<Ts...>()> {
116};
117
118/// \brief Copy slice of a tensor recursively from here to there
119/// \param[in] here Source tensor
120/// \param[in] there Target tensor (slice of source tensor)
121/// \param[in] mins Minimum of indices for each dimension
122/// \param[in] maxs Maximum of indices for each dimension
123/// \param[in] idx Current indices
124/// \param[in] active Active index needed to stop the recursion
125///
126/// Copy the content of a slice of a tensor from source to target. This is done
127/// by recursively iterating over the ranges of the slice for each dimension.
128template <typename T>
129void RecursiveCopy(const T &here, T &there,
130 const std::vector<std::size_t> &mins, const std::vector<std::size_t> &maxs,
131 std::vector<std::size_t> idx, std::size_t active)
132{
133 const auto size = idx.size();
134 for (std::size_t i = mins[active]; i < maxs[active]; i++) {
135 idx[active] = i;
136 if (active == size - 1) {
137 auto idxThere = idx;
138 for (std::size_t j = 0; j < size; j++) {
139 idxThere[j] -= mins[j];
140 }
141 there(idxThere) = here(idx);
142 } else {
143 Internal::RecursiveCopy(here, there, mins, maxs, idx, active + 1);
144 }
145 }
146}
147
148} // namespace TMVA::Experimental::Internal
149
150/// \class TMVA::Experimental::RTensor
151/// \brief RTensor is a container with contiguous memory and shape information.
152/// \tparam T Data-type of the tensor
153///
154/// An RTensor is a vector-like container, which has additional shape information.
155/// The elements of the multi-dimensional container can be accessed by their
156/// indices in a coherent way without taking care about the one-dimensional memory
157/// layout of the contiguous storage. This also allows to manipulate the shape
158/// of the container without moving the actual elements in memory. Another feature
159/// is that an RTensor can own the underlying contiguous memory but can also represent
160/// only a view on existing data without owning it.
161template <typename V, typename C = std::vector<V>>
162class RTensor {
163public:
164 // Typedefs
165 using Value_t = V;
166 using Shape_t = std::vector<std::size_t>;
168 using Slice_t = std::vector<Shape_t>;
169 using Container_t = C;
170
171private:
174 std::size_t fSize;
177 std::shared_ptr<Container_t> fContainer;
178
179protected:
180 void ReshapeInplace(const Shape_t &shape);
181
182public:
183 // Constructors
184
185 /// \brief Construct a tensor as view on data
186 /// \param[in] data Pointer to data contiguous in memory
187 /// \param[in] shape Shape vector
188 /// \param[in] layout Memory layout
190 : fShape(shape), fLayout(layout), fData(data), fContainer(NULL)
191 {
194 }
195
196 /// \brief Construct a tensor as view on data
197 /// \param[in] data Pointer to data contiguous in memory
198 /// \param[in] shape Shape vector
199 /// \param[in] strides Strides vector
200 /// \param[in] layout Memory layout
202 : fShape(shape), fStrides(strides), fLayout(layout), fData(data), fContainer(NULL)
203 {
205 }
206
207 /// \brief Construct a tensor owning externally provided data
208 /// \param[in] container Shared pointer to data container
209 /// \param[in] shape Shape vector
210 /// \param[in] layout Memory layout
211 RTensor(std::shared_ptr<Container_t> container, Shape_t shape,
213 : fShape(shape), fLayout(layout), fContainer(container)
214 {
217 fData = &(*container->begin());
218 }
219
220 /// \brief Construct a tensor owning data initialized with new container
221 /// \param[in] shape Shape vector
222 /// \param[in] layout Memory layout
224 : fShape(shape), fLayout(layout)
225 {
226 // TODO: Document how data pointer is determined using STL iterator interface.
227 // TODO: Sanitize given container type with type traits
230 fContainer = std::make_shared<Container_t>(fSize);
231 fData = &(*fContainer->begin());
232 }
233
234 // Access elements
236 const Value_t &operator() (const Index_t &idx) const;
237 template <typename... Idx> Value_t &operator()(Idx... idx);
238 template <typename... Idx> const Value_t &operator() (Idx... idx) const;
239
240 // Access properties
241 std::size_t GetSize() const { return fSize; }
242 const Shape_t &GetShape() const { return fShape; }
243 const Shape_t &GetStrides() const { return fStrides; }
244 Value_t *GetData() { return fData; }
245 const Value_t *GetData() const { return fData; }
246 std::shared_ptr<Container_t> GetContainer() { return fContainer; }
247 const std::shared_ptr<Container_t> GetContainer() const { return fContainer; }
249 bool IsView() const { return fContainer == NULL; }
250 bool IsOwner() const { return !IsView(); }
251
252 // Copy
254
255 // Transformations
261
262 // Iterator class
263 class Iterator : public std::iterator<std::random_access_iterator_tag, Value_t> {
264 private:
266 Index_t::value_type fGlobalIndex;
267 public:
268 using difference_type = typename std::iterator<std::random_access_iterator_tag, Value_t>::difference_type;
269
270 Iterator(RTensor<Value_t, Container_t>& x, typename Index_t::value_type idx) : fTensor(x), fGlobalIndex(idx) {}
271 Iterator& operator++() { fGlobalIndex++; return *this; }
272 Iterator operator++(int) { auto tmp = *this; operator++(); return tmp; }
273 Iterator& operator--() { fGlobalIndex--; return *this; }
274 Iterator operator--(int) { auto tmp = *this; operator--(); return tmp; }
278 Iterator& operator+=(difference_type rhs) { fGlobalIndex += rhs; return *this; }
279 Iterator& operator-=(difference_type rhs) { fGlobalIndex -= rhs; return *this; }
281 {
282 auto idx = Internal::ComputeIndicesFromGlobalIndex(fTensor.GetShape(), fTensor.GetMemoryLayout(), fGlobalIndex);
283 return fTensor(idx);
284 }
285 bool operator==(const Iterator& rhs) const
286 {
287 if (fGlobalIndex == rhs.GetGlobalIndex()) return true;
288 return false;
289 }
290 bool operator!=(const Iterator& rhs) const { return !operator==(rhs); };
291 bool operator>(const Iterator& rhs) const { return fGlobalIndex > rhs.GetGlobalIndex(); }
292 bool operator<(const Iterator& rhs) const { return fGlobalIndex < rhs.GetGlobalIndex(); }
293 bool operator>=(const Iterator& rhs) const { return fGlobalIndex >= rhs.GetGlobalIndex(); }
294 bool operator<=(const Iterator& rhs) const { return fGlobalIndex <= rhs.GetGlobalIndex(); }
295 typename Index_t::value_type GetGlobalIndex() const { return fGlobalIndex; };
296 };
297
298 // Iterator interface
299 // TODO: Document that the iterator always iterates following the physical memory layout.
300 Iterator begin() noexcept {
301 return Iterator(*this, 0);
302 }
303 Iterator end() noexcept {
304 return Iterator(*this, fSize);
305 }
306};
307
308/// \brief Reshape tensor in place
309/// \param[in] shape Shape vector
310/// Reshape tensor without changing the overall size
311template <typename Value_t, typename Container_t>
313{
314 const auto size = Internal::GetSizeFromShape(shape);
315 if (size != fSize) {
316 std::stringstream ss;
317 ss << "Cannot reshape tensor with size " << fSize << " into shape { ";
318 for (std::size_t i = 0; i < shape.size(); i++) {
319 if (i != shape.size() - 1) {
320 ss << shape[i] << ", ";
321 } else {
322 ss << shape[i] << " }.";
323 }
324 }
325 throw std::runtime_error(ss.str());
326 }
327
328 // Compute new strides from shape
329 auto strides = Internal::ComputeStridesFromShape(shape, fLayout);
330 fShape = shape;
331 fStrides = strides;
332}
333
334
335/// \brief Access elements
336/// \param[in] idx Index vector
337/// \return Reference to element
338template <typename Value_t, typename Container_t>
340{
341 const auto globalIndex = Internal::ComputeGlobalIndex(fStrides, idx);
342 return fData[globalIndex];
343}
344
345/// \brief Access elements
346/// \param[in] idx Index vector
347/// \return Reference to element
348template <typename Value_t, typename Container_t>
350{
351 const auto globalIndex = Internal::ComputeGlobalIndex(fStrides, idx);
352 return fData[globalIndex];
353}
354
355/// \brief Access elements
356/// \param[in] idx Indices
357/// \return Reference to element
358template <typename Value_t, typename Container_t>
359template <typename... Idx>
361{
362 static_assert(Internal::and_types<std::is_convertible<Idx, std::size_t>...>{},
363 "Indices are not convertible to std::size_t.");
364 return operator()({static_cast<std::size_t>(idx)...});
365}
366
367/// \brief Access elements
368/// \param[in] idx Indices
369/// \return Reference to element
370template <typename Value_t, typename Container_t>
371template <typename... Idx>
373{
374 static_assert(Internal::and_types<std::is_convertible<Idx, std::size_t>...>{},
375 "Indices are not convertible to std::size_t.");
376 return operator()({static_cast<std::size_t>(idx)...});
377}
378
379/// \brief Transpose
380/// \returns New RTensor
381/// The tensor is transposed by inverting the associated memory layout from row-
382/// major to column-major and vice versa. Therefore, the underlying data is not
383/// touched.
384template <typename Value_t, typename Container_t>
386{
387 MemoryLayout layout;
388 // Transpose by inverting memory layout
389 if (fLayout == MemoryLayout::RowMajor) {
391 } else if (fLayout == MemoryLayout::ColumnMajor) {
392 layout = MemoryLayout::RowMajor;
393 } else {
394 throw std::runtime_error("Memory layout is not known.");
395 }
396
397 // Create copy of container
398 RTensor<Value_t, Container_t> x(fData, fShape, fStrides, layout);
399
400 // Reverse shape
401 std::reverse(x.fShape.begin(), x.fShape.end());
402
403 // Reverse strides
404 std::reverse(x.fStrides.begin(), x.fStrides.end());
405
406 return x;
407}
408
409/// \brief Squeeze dimensions
410/// \returns New RTensor
411/// Squeeze removes the dimensions of size one from the shape.
412template <typename Value_t, typename Container_t>
414{
415 // Remove dimensions of one and associated strides
416 Shape_t shape;
417 Shape_t strides;
418 for (std::size_t i = 0; i < fShape.size(); i++) {
419 if (fShape[i] != 1) {
420 shape.emplace_back(fShape[i]);
421 strides.emplace_back(fStrides[i]);
422 }
423 }
424
425 // If all dimensions are 1, we need to keep one.
426 // This does not apply if the inital shape is already empty. Then, return
427 // the empty shape.
428 if (shape.size() == 0 && fShape.size() != 0) {
429 shape.emplace_back(1);
430 strides.emplace_back(1);
431 }
432
433 // Create copy, attach new shape and strides and return
435 x.fShape = shape;
436 x.fStrides = strides;
437 return x;
438}
439
440/// \brief Expand dimensions
441/// \param[in] idx Index in shape vector where dimension is added
442/// \returns New RTensor
443/// Inserts a dimension of one into the shape.
444template <typename Value_t, typename Container_t>
446{
447 // Compose shape vector with additional dimensions and adjust strides
448 const int len = fShape.size();
449 auto shape = fShape;
450 auto strides = fStrides;
451 if (idx < 0) {
452 if (len + idx + 1 < 0) {
453 throw std::runtime_error("Given negative index is invalid.");
454 }
455 shape.insert(shape.end() + 1 + idx, 1);
456 strides.insert(strides.begin() + 1 + idx, 1);
457 } else {
458 if (idx > len) {
459 throw std::runtime_error("Given index is invalid.");
460 }
461 shape.insert(shape.begin() + idx, 1);
462 strides.insert(strides.begin() + idx, 1);
463 }
464
465 // Create copy, attach new shape and strides and return
467 x.fShape = shape;
468 x.fStrides = strides;
469 return x;
470}
471
472/// \brief Reshape tensor
473/// \param[in] shape Shape vector
474/// \returns New RTensor
475/// Reshape tensor without changing the overall size
476template <typename Value_t, typename Container_t>
478{
479 // Create copy, replace and return
481 x.ReshapeInplace(shape);
482 return x;
483}
484
485/// \brief Create a slice of the tensor
486/// \param[in] slice Slice vector
487/// \returns New RTensor
488/// A slice is a subset of the tensor defined by a vector of pairs of indices.
489template <typename Value_t, typename Container_t>
491{
492 // Sanitize size of slice
493 const auto sliceSize = slice.size();
494 const auto shapeSize = fShape.size();
495 if (sliceSize != shapeSize) {
496 std::stringstream ss;
497 ss << "Size of slice (" << sliceSize << ") is unequal number of dimensions (" << shapeSize << ").";
498 throw std::runtime_error(ss.str());
499 }
500
501 // Sanitize slice indices
502 // TODO: Sanitize slice indices
503 /*
504 for (std::size_t i = 0; i < sliceSize; i++) {
505 }
506 */
507
508 // Convert -1 in slice to proper pair of indices
509 // TODO
510
511 // Recompute shape and size
512 Shape_t shape(sliceSize);
513 for (std::size_t i = 0; i < sliceSize; i++) {
514 shape[i] = slice[i][1] - slice[i][0];
515 }
516 auto size = Internal::GetSizeFromShape(shape);
517
518 // Determine first element contributing to the slice and get the data pointer
519 Value_t *data;
520 Shape_t idx(sliceSize);
521 for (std::size_t i = 0; i < sliceSize; i++) {
522 idx[i] = slice[i][0];
523 }
524 data = &operator()(idx);
525
526 // Create copy and modify properties
528 x.fData = data;
529 x.fShape = shape;
530 x.fSize = size;
531
532 // Squeeze tensor and return
533 return x.Squeeze();
534}
535
536/// Copy RTensor to new object
537/// \param[in] layout Memory layout of the new RTensor
538/// \returns New RTensor
539/// The operation copies all elements of the current RTensor to a new RTensor
540/// with the given layout contiguous in memory. Note that this copies by default
541/// to a row major memory layout.
542template <typename Value_t, typename Container_t>
544{
545 // Create new tensor with zeros owning the memory
546 RTensor<Value_t, Container_t> r(fShape, layout);
547
548 // Copy over the elements from this tensor
549 const auto mins = Shape_t(fShape.size());
550 const auto maxs = fShape;
551 auto idx = mins;
552 Internal::RecursiveCopy(*this, r, mins, maxs, idx, 0);
553
554 return r;
555}
556
557/// \brief Pretty printing
558/// \param[in] os Output stream
559/// \param[in] x RTensor
560/// \return Modified output stream
561template <typename T>
562std::ostream &operator<<(std::ostream &os, RTensor<T> &x)
563{
564 const auto shapeSize = x.GetShape().size();
565 if (shapeSize == 1) {
566 os << "{ ";
567 const auto size = x.GetSize();
568 for (std::size_t i = 0; i < size; i++) {
569 os << x({i});
570 if (i != size - 1)
571 os << ", ";
572 }
573 os << " }";
574 } else if (shapeSize == 2) {
575 os << "{";
576 const auto shape = x.GetShape();
577 for (std::size_t i = 0; i < shape[0]; i++) {
578 os << " { ";
579 for (std::size_t j = 0; j < shape[1]; j++) {
580 os << x({i, j});
581 if (j < shape[1] - 1) {
582 os << ", ";
583 } else {
584 os << " ";
585 }
586 }
587 os << "}";
588 }
589 os << " }";
590 } else {
591 os << "{ printing not yet implemented for this rank }";
592 }
593 return os;
594}
595
596} // namespace TMVA::Experimental
597} // namespace TMVA
598
599namespace cling {
600template <typename T>
601std::string printValue(TMVA::Experimental::RTensor<T> *x)
602{
603 std::stringstream ss;
604 ss << *x;
605 return ss.str();
606}
607} // namespace cling
608
609#endif // TMVA_RTENSOR
uint8_t
Definition: Converters.cxx:876
size_t fSize
ROOT::R::TRInterface & r
Definition: Object.C:4
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
TRObject operator()(const T1 &t1) const
Iterator & operator-=(difference_type rhs)
Definition: RTensor.hxx:279
bool operator>=(const Iterator &rhs) const
Definition: RTensor.hxx:293
bool operator==(const Iterator &rhs) const
Definition: RTensor.hxx:285
Iterator & operator+=(difference_type rhs)
Definition: RTensor.hxx:278
Iterator(RTensor< Value_t, Container_t > &x, typename Index_t::value_type idx)
Definition: RTensor.hxx:270
bool operator!=(const Iterator &rhs) const
Definition: RTensor.hxx:290
difference_type operator-(const Iterator &rhs)
Definition: RTensor.hxx:277
Iterator operator+(difference_type rhs) const
Definition: RTensor.hxx:275
bool operator<(const Iterator &rhs) const
Definition: RTensor.hxx:292
Index_t::value_type fGlobalIndex
Definition: RTensor.hxx:266
typename std::iterator< std::random_access_iterator_tag, Value_t >::difference_type difference_type
Definition: RTensor.hxx:268
RTensor< Value_t, Container_t > & fTensor
Definition: RTensor.hxx:265
bool operator>(const Iterator &rhs) const
Definition: RTensor.hxx:291
Iterator operator-(difference_type rhs) const
Definition: RTensor.hxx:276
Index_t::value_type GetGlobalIndex() const
Definition: RTensor.hxx:295
bool operator<=(const Iterator &rhs) const
Definition: RTensor.hxx:294
RTensor is a container with contiguous memory and shape information.
Definition: RTensor.hxx:162
void ReshapeInplace(const Shape_t &shape)
Reshape tensor in place.
Definition: RTensor.hxx:312
RTensor< Value_t, Container_t > Squeeze() const
Squeeze dimensions.
Definition: RTensor.hxx:413
Value_t & operator()(const Index_t &idx)
Access elements.
Definition: RTensor.hxx:339
RTensor(Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
Construct a tensor owning data initialized with new container.
Definition: RTensor.hxx:223
const Shape_t & GetStrides() const
Definition: RTensor.hxx:243
MemoryLayout GetMemoryLayout() const
Definition: RTensor.hxx:248
const Value_t * GetData() const
Definition: RTensor.hxx:245
const std::shared_ptr< Container_t > GetContainer() const
Definition: RTensor.hxx:247
Iterator end() noexcept
Definition: RTensor.hxx:303
std::shared_ptr< Container_t > GetContainer()
Definition: RTensor.hxx:246
std::vector< Shape_t > Slice_t
Definition: RTensor.hxx:168
RTensor(Value_t *data, Shape_t shape, Shape_t strides, MemoryLayout layout=MemoryLayout::RowMajor)
Construct a tensor as view on data.
Definition: RTensor.hxx:201
RTensor< Value_t, Container_t > ExpandDims(int idx) const
Expand dimensions.
Definition: RTensor.hxx:445
RTensor< Value_t, Container_t > Transpose() const
Transpose.
Definition: RTensor.hxx:385
Value_t & operator()(Idx... idx)
Access elements.
Definition: RTensor.hxx:360
std::shared_ptr< Container_t > fContainer
Definition: RTensor.hxx:177
RTensor(std::shared_ptr< Container_t > container, Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
Construct a tensor owning externally provided data.
Definition: RTensor.hxx:211
RTensor< Value_t, Container_t > Copy(MemoryLayout layout=MemoryLayout::RowMajor) const
Copy RTensor to new object.
Definition: RTensor.hxx:543
std::size_t GetSize() const
Definition: RTensor.hxx:241
RTensor< Value_t, Container_t > Reshape(const Shape_t &shape) const
Reshape tensor.
Definition: RTensor.hxx:477
RTensor(Value_t *data, Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
Construct a tensor as view on data.
Definition: RTensor.hxx:189
RTensor< Value_t, Container_t > Slice(const Slice_t &slice)
Create a slice of the tensor.
Definition: RTensor.hxx:490
Iterator begin() noexcept
Definition: RTensor.hxx:300
std::vector< std::size_t > Shape_t
Definition: RTensor.hxx:166
const Shape_t & GetShape() const
Definition: RTensor.hxx:242
Double_t x[n]
Definition: legend1.C:17
static double C[]
double T(double x)
Definition: ChebyshevPol.h:34
static constexpr double s
void RecursiveCopy(const T &here, T &there, const std::vector< std::size_t > &mins, const std::vector< std::size_t > &maxs, std::vector< std::size_t > idx, std::size_t active)
Copy slice of a tensor recursively from here to there.
Definition: RTensor.hxx:129
T ComputeIndicesFromGlobalIndex(const T &shape, MemoryLayout layout, const typename T::value_type idx)
Compute indices from global index.
Definition: RTensor.hxx:81
std::vector< std::size_t > ComputeStridesFromShape(const T &shape, MemoryLayout layout)
Compute strides from shape vector.
Definition: RTensor.hxx:47
std::size_t GetSizeFromShape(const T &shape)
Get size of tensor from shape vector.
Definition: RTensor.hxx:28
std::size_t ComputeGlobalIndex(const U &strides, const V &idx)
Compute global index from indices.
Definition: RTensor.hxx:99
MemoryLayout
Memory layout type (copy from RTensor.hxx)
Definition: CudaTensor.h:47
std::ostream & operator<<(std::ostream &os, RTensor< T > &x)
Pretty printing.
Definition: RTensor.hxx:562
create variable transformations
Type checking for all types of a parameter pack, e.g., used in combination with std::is_convertible.
Definition: RTensor.hxx:111