FLAMES 0.1.0
Matrix-Empowered HLS Library
Loading...
Searching...
No Matches
tensor.hpp
Go to the documentation of this file.
1
12#ifndef _FLAMES_TENSOR_HPP_
13#define _FLAMES_TENSOR_HPP_
14
15#ifndef _FLAMES_CORE_HPP_
16# include "core.hpp"
17#endif
18
19#ifndef FLAMES_TENSOR_PARTITION_COMPLETE
20# ifdef FLAMES_MAT_PARTITION_COMPLETE
21# define FLAMES_TENSOR_PARTITION_COMPLETE
22# endif
23#endif
24
25namespace flames {
26template <typename T, size_t n_rows, size_t n_cols, size_t n_slices, MatType type>
27class Tensor {
28 public:
29 using element_type = T;
30 using value_type = T;
32
34#ifdef FLAMES_TENSOR_PARTITION_COMPLETE
35 FLAMES_PRAGMA(ARRAY_PARTITION variable = _data type = complete)
36#else
37 FLAMES_PRAGMA(ARRAY_PARTITION variable = _data type = block factor = FLAMES_MAT_PARTITION_FACTOR)
38#endif
39 }
40
41 inline static constexpr size_t matSize() noexcept {
42 return type == MatType::NORMAL ? n_rows * n_cols
43 : type == MatType::DIAGONAL ? n_rows
44 : type == MatType::SCALAR ? 1
45 : type == MatType::SUPPER ? (n_rows - 1) * n_rows / 2
46 : type == MatType::SLOWER ? (n_rows - 1) * n_rows / 2
47 : type == MatType::ASYM ? (n_rows - 1) * n_rows / 2
48 : (1 + n_rows) * n_rows / 2;
49 }
50
51 inline static constexpr size_t size() noexcept { return n_slices * size(); }
52
53 inline View slice(size_t index) const {
54 assert(index < n_slices && "Index should be within in range for MatView::slice(index).");
55 return const_cast<T*>(_data + index * matSize());
56 }
57
58 inline View slice(size_t index) {
59 assert(index < n_slices && "Index should be within in range for MatView::slice(index).");
60 return const_cast<T*>(_data + index * matSize());
61 }
62
63 inline View operator[](size_t index) const { return slice(index); }
64
65 inline View operator[](size_t index) { return slice(index); }
66
67 private:
68 T _data[type == MatType::NORMAL ? n_slices * n_rows * n_cols
69 : type == MatType::DIAGONAL ? n_slices * n_rows
70 : type == MatType::SCALAR ? n_slices * 1
71 : type == MatType::SUPPER ? n_slices * (n_rows - 1) * n_rows / 2
72 : type == MatType::SLOWER ? n_slices * (n_rows - 1) * n_rows / 2
73 : type == MatType::ASYM ? n_slices * (n_rows - 1) * n_rows / 2
74 : n_slices * (1 + n_rows) * n_rows / 2];
75};
76
77} // namespace flames
78
79#endif
Read only view version of a matrix.
Definition core.hpp:7057
Tensor.
Definition tensor.hpp:27
T element_type
Definition tensor.hpp:29
Tensor()
Definition tensor.hpp:33
View operator[](size_t index)
Definition tensor.hpp:65
View operator[](size_t index) const
Definition tensor.hpp:63
View slice(size_t index) const
Definition tensor.hpp:53
static constexpr size_t size() noexcept
Definition tensor.hpp:51
static constexpr size_t matSize() noexcept
Definition tensor.hpp:41
View slice(size_t index)
Definition tensor.hpp:58
T _data[type==MatType::NORMAL ? n_slices *n_rows *n_cols :type==MatType::DIAGONAL ? n_slices *n_rows :type==MatType::SCALAR ? n_slices *1 :type==MatType::SUPPER ? n_slices *(n_rows - 1) *n_rows/2 :type==MatType::SLOWER ? n_slices *(n_rows - 1) *n_rows/2 :type==MatType::ASYM ? n_slices *(n_rows - 1) *n_rows/2 :n_slices *(1+n_rows) *n_rows/2]
Definition tensor.hpp:74
T value_type
Definition tensor.hpp:30
Core Utilities for FLAMES.
#define FLAMES_PRAGMA(x)
Definition core.hpp:50
#define FLAMES_MAT_PARTITION_FACTOR
Definition core.hpp:143
Namespace for the FLAMES library.
Definition core.hpp:166
MatType
Matrix type for storage.
Definition core.hpp:172
@ SCALAR
Definition core.hpp:175
@ SLOWER
Definition core.hpp:179
@ DIAGONAL
Definition core.hpp:174
@ NORMAL
Definition core.hpp:173
@ ASYM
Definition core.hpp:181
@ SUPPER
Definition core.hpp:178