tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
Operations.h
Go to the documentation of this file.
1#pragma once
2
3#include "config.h"
6
7// ===============================
8// Operation Tags
9// ===============================
10
11template <typename T, my_size_t Bits, typename Arch = DefaultArch>
12struct Add
13{
15 using type = typename microkernel::VecType; // alias for easier usage
16
17 FORCE_INLINE static type apply(type a, type b) noexcept
18 {
19 // print the types of a and b
20 return microkernel::add(a, b);
21 }
22
23 template <typename Vec = type>
24 requires(!is_same_v<Vec, T>)
25 FORCE_INLINE static Vec apply(Vec a, T scalar) noexcept
26 {
27 return microkernel::add(a, scalar);
28 }
29};
30
31template <typename T, my_size_t Bits, typename Arch = DefaultArch>
32struct Fma // a*b + c
33{
35 using type = typename microkernel::VecType;
36
37 FORCE_INLINE static type apply(type a, type b, type c) noexcept
38 {
39 return microkernel::fmadd(a, b, c);
40 }
41
42 template <typename Vec = type>
43 requires(!is_same_v<Vec, T>)
44 FORCE_INLINE static Vec apply(Vec a, T b, Vec c) noexcept
45 {
46 return microkernel::fmadd(a, b, c);
47 }
48};
49
50template <typename T, my_size_t Bits, typename Arch = DefaultArch>
51struct Fms // a*b - c
52{
54 using type = typename microkernel::VecType;
55
56 FORCE_INLINE static type apply(type a, type b, type c) noexcept
57 {
58 return microkernel::fmsub(a, b, c);
59 }
60
61 template <typename Vec = type>
62 requires(!is_same_v<Vec, T>)
63 FORCE_INLINE static Vec apply(Vec a, T b, Vec c) noexcept
64 {
65 return microkernel::fmsub(a, b, c);
66 }
67};
68
69template <typename T, my_size_t Bits, typename Arch = DefaultArch>
70struct Fnma // -(a*b) + c
71{
73 using type = typename microkernel::VecType;
74
75 FORCE_INLINE static type apply(type a, type b, type c) noexcept
76 {
77 return microkernel::fnmadd(a, b, c);
78 }
79
80 template <typename Vec = type>
81 requires(!is_same_v<Vec, T>)
82 FORCE_INLINE static Vec apply(Vec a, T b, Vec c) noexcept
83 {
84 return microkernel::fnmadd(a, b, c);
85 }
86};
87
88template <typename T, my_size_t Bits, typename Arch = DefaultArch>
89struct Fnms // -(a*b) - c
90{
92 using type = typename microkernel::VecType;
93
94 FORCE_INLINE static type apply(type a, type b, type c) noexcept
95 {
96 return microkernel::fnmsub(a, b, c);
97 }
98
99 template <typename Vec = type>
100 requires(!is_same_v<Vec, T>)
101 FORCE_INLINE static Vec apply(Vec a, T b, Vec c) noexcept
102 {
103 return microkernel::fnmsub(a, b, c);
104 }
105};
106
107template <typename T, my_size_t Bits, typename Arch = DefaultArch>
108struct Sub
109{
111 using type = typename microkernel::VecType; // alias for easier usage
112
113 FORCE_INLINE static type apply(type a, type b) noexcept
114 {
115 return microkernel::sub(a, b);
116 }
117
118 template <typename Vec = type>
119 requires(!is_same_v<Vec, T>)
120 FORCE_INLINE static Vec apply(Vec a, T scalar) noexcept
121 {
122 return microkernel::sub(a, scalar);
123 }
124
125 template <typename Vec = type>
126 requires(!is_same_v<Vec, T>)
127 FORCE_INLINE static Vec apply(T scalar, Vec a) noexcept
128 {
129 return microkernel::sub(scalar, a);
130 }
131};
132
133template <typename T, my_size_t Bits, typename Arch = DefaultArch>
134struct Mul
135{
137 using type = typename microkernel::VecType; // alias for easier usage
138
139 FORCE_INLINE static type apply(type a, type b) noexcept
140 {
141 return microkernel::mul(a, b);
142 }
143
144 template <typename Vec = type>
145 requires(!is_same_v<Vec, T>)
146 FORCE_INLINE static Vec apply(Vec a, T scalar) noexcept
147 {
148 return microkernel::mul(a, scalar);
149 }
150};
151
152template <typename T, my_size_t Bits, typename Arch = DefaultArch>
153struct Div
154{
156 using type = typename microkernel::VecType; // alias for easier usage
157
158 FORCE_INLINE static type apply(type a, type b) noexcept
159 {
160 return microkernel::div(a, b);
161 }
162
163 template <typename Vec = type>
164 requires(!is_same_v<Vec, T>)
165 FORCE_INLINE static Vec apply(Vec a, T scalar) noexcept
166 {
167 return microkernel::div(a, scalar);
168 }
169
170 template <typename Vec = type>
171 requires(!is_same_v<Vec, T>)
172 FORCE_INLINE static Vec apply(T scalar, Vec a) noexcept
173 {
174 return microkernel::div(scalar, a);
175 }
176};
177
178template <typename T, my_size_t Bits, typename Arch = DefaultArch>
179struct Min
180{
182 using type = typename microkernel::VecType;
183
184 FORCE_INLINE static type apply(type a, type b) noexcept
185 {
186 return microkernel::min(a, b);
187 }
188
189 template <typename Vec = type>
190 requires(!is_same_v<Vec, T>)
191 FORCE_INLINE static Vec apply(Vec a, T scalar) noexcept
192 {
193 return microkernel::min(a, scalar);
194 }
195
196 // commutative — no need for scalar-vec variant
197};
198
199template <typename T, my_size_t Bits, typename Arch = DefaultArch>
200struct Max
201{
203 using type = typename microkernel::VecType;
204
205 FORCE_INLINE static type apply(type a, type b) noexcept
206 {
207 return microkernel::max(a, b);
208 }
209
210 template <typename Vec = type>
211 requires(!is_same_v<Vec, T>)
212 FORCE_INLINE static Vec apply(Vec a, T scalar) noexcept
213 {
214 return microkernel::max(a, scalar);
215 }
216
217 // commutative — no need for scalar-vec variant
218};
Global configuration for the tesseract tensor library.
#define FORCE_INLINE
Hint the compiler to always inline a function.
Definition config.h:26
Definition Operations.h:13
static FORCE_INLINE Vec apply(Vec a, T scalar) noexcept
Definition Operations.h:25
typename microkernel::VecType type
Definition Operations.h:15
static FORCE_INLINE type apply(type a, type b) noexcept
Definition Operations.h:17
Definition Operations.h:154
static FORCE_INLINE type apply(type a, type b) noexcept
Definition Operations.h:158
typename microkernel::VecType type
Definition Operations.h:156
static FORCE_INLINE Vec apply(Vec a, T scalar) noexcept
Definition Operations.h:165
static FORCE_INLINE Vec apply(T scalar, Vec a) noexcept
Definition Operations.h:172
Definition Operations.h:33
static FORCE_INLINE type apply(type a, type b, type c) noexcept
Definition Operations.h:37
typename microkernel::VecType type
Definition Operations.h:35
static FORCE_INLINE Vec apply(Vec a, T b, Vec c) noexcept
Definition Operations.h:44
Definition Operations.h:52
typename microkernel::VecType type
Definition Operations.h:54
static FORCE_INLINE type apply(type a, type b, type c) noexcept
Definition Operations.h:56
static FORCE_INLINE Vec apply(Vec a, T b, Vec c) noexcept
Definition Operations.h:63
Definition Operations.h:71
static FORCE_INLINE Vec apply(Vec a, T b, Vec c) noexcept
Definition Operations.h:82
typename microkernel::VecType type
Definition Operations.h:73
static FORCE_INLINE type apply(type a, type b, type c) noexcept
Definition Operations.h:75
Definition Operations.h:90
static FORCE_INLINE Vec apply(Vec a, T b, Vec c) noexcept
Definition Operations.h:101
static FORCE_INLINE type apply(type a, type b, type c) noexcept
Definition Operations.h:94
typename microkernel::VecType type
Definition Operations.h:92
Definition Operations.h:201
static FORCE_INLINE Vec apply(Vec a, T scalar) noexcept
Definition Operations.h:212
typename microkernel::VecType type
Definition Operations.h:203
static FORCE_INLINE type apply(type a, type b) noexcept
Definition Operations.h:205
Definition microkernel_base.h:16
T VecType
Definition microkernel_base.h:18
static FORCE_INLINE VecType mul(VecType a, VecType b) noexcept
static FORCE_INLINE VecType min(VecType a, VecType b) noexcept
static FORCE_INLINE VecType add(VecType a, VecType b) noexcept
static FORCE_INLINE VecType sub(VecType a, VecType b) noexcept
static FORCE_INLINE VecType div(VecType a, VecType b) noexcept
static FORCE_INLINE VecType max(VecType a, VecType b) noexcept
Definition Operations.h:180
static FORCE_INLINE type apply(type a, type b) noexcept
Definition Operations.h:184
typename microkernel::VecType type
Definition Operations.h:182
static FORCE_INLINE Vec apply(Vec a, T scalar) noexcept
Definition Operations.h:191
Definition Operations.h:135
static FORCE_INLINE Vec apply(Vec a, T scalar) noexcept
Definition Operations.h:146
typename microkernel::VecType type
Definition Operations.h:137
static FORCE_INLINE type apply(type a, type b) noexcept
Definition Operations.h:139
Definition Operations.h:109
static FORCE_INLINE type apply(type a, type b) noexcept
Definition Operations.h:113
typename microkernel::VecType type
Definition Operations.h:111
static FORCE_INLINE Vec apply(Vec a, T scalar) noexcept
Definition Operations.h:120
static FORCE_INLINE Vec apply(T scalar, Vec a) noexcept
Definition Operations.h:127