VCTR
Loading...
Searching...
No Matches
ContainerAndExpressionConcepts.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::detail
24{
25
26// clang-format off
27template <class T>
28struct AnyVctr : std::false_type {};
29
30template <class T, template <class> class A>
31struct AnyVctr<Vector<T, A>> : std::true_type {};
32
33template <class T>
34struct AnyVctr<OwnedVector<T>> : std::true_type {};
35
36template <class T, size_t e, size_t s>
37struct AnyVctr<Array<T, e, s>> : std::true_type {};
38
39template <class T, size_t e>
40struct AnyVctr<OwnedArray<T, e>> : std::true_type {};
41
42template <class T, size_t n, class S>
43struct AnyVctr<Span<T, n, S>> : std::true_type {};
44
45template <class E, class S, size_t e, class I>
46struct AnyVctr<VctrBase<E, S, e, I>> : std::true_type {};
47
48template <class T>
49struct IsVector : std::false_type {};
50
51template <class T, template <class> class A>
52struct IsVector<Vector<T, A>> : std::true_type {};
53
54template <class T>
55struct IsSpan : std::false_type {};
56
57template <class T, size_t n, class S>
58struct IsSpan<Span<T, n, S>> : std::true_type {};
59
60template <class T>
61struct IsStdArray : std::false_type {};
62
63template <class T, size_t e>
64struct IsStdArray<std::array<T, e>> : std::true_type {};
65
66template <class T>
67struct IsStdSpan : std::false_type {};
68
69template <class T, size_t e>
70struct IsStdSpan<std::span<T, e>> : std::true_type {};
71
72template <class T>
73struct IsExpressionChainBuilder : std::false_type {};
74
75template <template <size_t, class...> class ExpressionType, class RuntimeArgs, class... AdditionalParameters>
76struct IsExpressionChainBuilder<ExpressionChainBuilderWithRuntimeArgs<ExpressionType, RuntimeArgs, AdditionalParameters...>> : std::true_type {};
77// clang-format on
78
79} // namespace vctr::detail
80
81namespace vctr::has
82{
83
85template <class T>
86concept prepareNeonEvaluation = requires (const T& t) { t.prepareNeonEvaluation(); };
87
89template <class T>
90concept getNeon = requires (const T& t, size_t i) { t.getNeon (i); };
91
93template <class T>
94concept prepareAVXEvaluation = requires (const T& t) { t.prepareAVXEvaluation(); };
95
97template <class T>
98concept getAVX = requires (const T& t, size_t i) { t.getAVX (i); };
99
101template <class T>
102concept prepareSSEEvaluation = requires (const T& t) { t.prepareSSEEvaluation(); };
103
105template <class T>
106concept getSSE = requires (const T& t, size_t i) { t.getSSE (i); };
107
109template <class T>
110concept indexOperator = requires (T& t) { t[size_t()]; };
111
113template <class T>
114concept constIndexOperator = requires (const T& t) { t[size_t()]; };
115
117template <class T, class DstType>
118concept evalNextVectorOpInExpressionChain = requires (const T& t, DstType* d) { t.evalNextVectorOpInExpressionChain (d); } && std::same_as<DstType, typename std::remove_cvref_t<T>::value_type>;
119
121template <class T, class ValueType>
122concept reduceElementWise = requires (const T&t, ValueType& v) { t.reduceElementWise (v, size_t()); };
123
125template <class T, class DstType>
126concept reduceVectorOp = requires (const T& t) { { t.reduceVectorOp() } -> std::same_as<DstType>; };
127
129template <class T, class SrcDstType>
130concept reduceNeonRegisterWise = requires (const T& t, NeonRegister<SrcDstType>& sd, size_t s) { t.reduceNeonRegisterWise (sd, s); };
131
133template <class T, class SrcDstType>
134concept reduceAVXRegisterWise = requires (const T& t, AVXRegister<SrcDstType>& sd, size_t s) { t.reduceAVXRegisterWise (sd, s); };
135
137template <class T, class SrcDstType>
138concept reduceSSERegisterWise = requires (const T& t, SSERegister<SrcDstType>& sd, size_t s) { t.reduceSSERegisterWise (sd, s); };
139
141template <class T>
142concept data = requires (const T& t) { t.data(); };
143
145template <class T, class ElementType>
146concept dataWithElementType = requires (const T& t) { { t.data() } -> std::convertible_to<const ElementType*>; };
147
149template <class T>
150concept size = requires (const T& t, size_t i) { i = t.size(); };
151
153template <class T>
155
157template <class T, class ElementType>
159
161template <class T>
162concept begin = requires (T& t) { *t.begin(); } || requires (const T& t) { *t.begin(); };
163
165template <class T>
166concept end = requires (T& t) { *t.end(); } || requires (const T& t) { *t.begin(); };
167
169template <class T>
170concept resize = requires (T& t, size_t n) { t.resize (n); };
171
173template <class T>
174concept getStorageInfo = requires (const T& t) { t.getStorageInfo(); };
175
177template <class T>
178concept isNotAliased = requires (const T& t, bool r, const void* o) { r = t.isNotAliased (o); };
179
181template <class T, size_t i, class RuntimeArgs>
182concept iterateOverRuntimeArgChain = requires (T& t, const RuntimeArgs& r) { t.template iterateOverRuntimeArgChain<i, RuntimeArgs> (r); };
183
185template <class T, class... Args>
186concept applyRuntimeArgs = requires (T& t, const Args&... args) { t.applyRuntimeArgs (args...); };
187
188} // namespace vctr::has
189
190namespace vctr::detail
191{
200enum PlatformVectorOpPreference
201{
202 dontPreferIfIppAndAccelerateAreAvailable,
203 preferIfIppAndAccelerateAreAvailable
204};
205
236template <PlatformVectorOpPreference pref>
237concept isPreferredVectorOp = (! (Config::hasIPP && Config::platformApple)) || (pref == preferIfIppAndAccelerateAreAvailable);
238} // namespace vctr::detail
239
240namespace vctr::is
241{
242
243// clang-format off
244
246template <class T>
247concept anyVctr = detail::AnyVctr<std::remove_cvref_t<T>>::value;
248
250template <class T, class V>
251concept anyVctrWithValueType = anyVctr<T> && std::same_as<typename std::remove_cvref_t<T>::value_type, V>;
252
254template <class T>
256
258template <class T>
260
262template <class T>
264
266template <class T, class V>
267concept expressionWithValueType = expression<T> && std::same_as<typename std::remove_cvref_t<T>::value_type, V>;
268
270template <class T>
271concept expressionChainBuilder = detail::IsExpressionChainBuilder<std::remove_cvref_t<T>>::value;
272
274template <class T>
276
278template <class T>
279concept stdArray = detail::IsStdArray<T>::value;
280
282template <class T>
283concept stdSpan = detail::IsStdSpan<T>::value;
284
286template <class T>
287concept view = detail::IsSpan<T>::value || detail::IsStdSpan<T>::value;
288
290template <class T>
291concept vctrVector = detail::IsVector<T>::value;
292
293//==============================================================================
295template <class T, class DstType>
297
298//==============================================================================
300template <class DstType, class... Sources>
301concept suitableForAccelerateSSEOp = Config::platformApple && Config::archX64 && std::same_as<float, DstType> && (has::getSSE<Sources> && ...);
302
304template <class DstType, class... Sources>
305concept suitableForAccelerateNeonOp = Config::platformApple && Config::archARM && std::same_as<float, DstType> && (has::getNeon<Sources> && ...);
306
308template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
310
312template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
314
316template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
318
320template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
322
324template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
326
328template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
330
332template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
333concept suitableForAccelerateRealFloatVectorReductionOp = detail::isPreferredVectorOp<pref> && Config::platformApple && has::data<Src> && realFloatNumber<DstType>;
334//==============================================================================
336template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
338
340template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
341concept suitableForIppRealSingedInt32VectorOp = detail::isPreferredVectorOp<pref> && Config::hasIPP && has::evalNextVectorOpInExpressionChain<Src, DstType> && std::same_as<int32_t, DstType>;
342
344template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
346
348template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
350
352template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
354
356template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
357concept suitableForIppRealFloatVectorReductionOp = detail::isPreferredVectorOp<pref> && Config::hasIPP && has::data<Src> && realFloatNumber<DstType>;
358
360template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
362
363//==============================================================================
365template <class SrcA, class SrcB, class DstType>
366concept suitableForBinaryVectorOp = ((expressionWithEvalVectorOp < SrcA, DstType > && anyVctr < SrcB >) ||
367 (anyVctr<SrcA> && expressionWithEvalVectorOp < SrcB, DstType >) ||
369 std::same_as<typename std::remove_cvref_t<SrcA>::value_type, typename std::remove_cvref_t<SrcB>::value_type>;
370
371//==============================================================================
373template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
375
377template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
379
381template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
383
384//==============================================================================
386template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
388
390template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
392
394template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
396
398template <class ValueType>
399concept suitableForVfpOrSvmlSSERegisterFunction = Config::archX64 && ((Config::platformApple && std::same_as<float, ValueType>) || (Config::hasSVML && realFloatNumber<ValueType>));
400
401//==============================================================================
403template <class T>
405
407template <class T>
409
413template <class T, class ElementType>
414concept suitableInitializerForElementType = std::constructible_from<ElementType, std::remove_cvref_t<T>> && ! expression<T>;
415
419template <class T>
420concept suitableInitializerFunction = std::invocable<T, size_t> && ! std::same_as<void, std::invoke_result_t<T, size_t>>;
421
425template <class T, class ElementType>
426concept suitableInitializerFunctionForElementType = suitableInitializerFunction<T> && std::constructible_from<ElementType, std::invoke_result_t<T, size_t>>;
427
429template <class T, class ElementType>
430concept inputIteratorToConstructValuesOfType = std::input_iterator<T> && std::constructible_from<ElementType, std::iter_value_t<T>>;
431
433template <class T, class ElementType>
434concept contiguousIteratorWithValueTypeSameAs = std::contiguous_iterator<T> && std::same_as<ElementType, std::iter_value_t<T>>;
435
440template <class T>
441concept storageInfo = requires (const T& info, size_t a, bool b) { a = T::memberAlignment; b = info.dataIsSIMDAligned; b = info.hasSIMDExtendedStorage; };
442
443template <class T>
444concept reductionExpression = requires (const T& t, typename T::value_type v, size_t i) { v = T::reductionResultInitValue; t.reduceElementWise (v, i); };
445
446// clang-format on
447
448} // namespace vctr::is
449
450namespace vctr::are
451{
452
454template <class... T>
456
457} // namespace vctr::are
458
459namespace vctr
460{
461// Forward declaration, needed by the concept below which is in turn needed by the assignment operators of the VCTR
462// containers. Defined in Containers/SplitComplex.h.
463template <is::anyVctrWithRealFloatValueType ContainerTypeParam>
464class SplitComplexBase;
465} // namespace vctr
466
467namespace vctr::is
468{
469
471template <class T>
472concept derivedFromSplitComplexBase = requires (T& d) { [] <class ContainerType> (const SplitComplexBase<ContainerType>&) {} (d); };
473
474} // namespace vctr::is
A container for complex values that stores the real and imaginary parts in two separate,...
Definition: SplitComplex.h:127
Constrains a pack of types to be no expression templates.
Definition: ContainerAndExpressionConcepts.h:455
Constrains a type to have a function applyRuntimeArgs (const Args&...)
Definition: ContainerAndExpressionConcepts.h:186
Constrains a type to have a member function begin() or begin() const.
Definition: ContainerAndExpressionConcepts.h:162
Constrains a type to have a const operator[] overload taking a size_t argument.
Definition: ContainerAndExpressionConcepts.h:114
Constrains a type to have a member function data() const returning a pointer convertible to const Ele...
Definition: ContainerAndExpressionConcepts.h:146
Constrains a type to have a member function data() const.
Definition: ContainerAndExpressionConcepts.h:142
Constrains a type to have a member function end() or end() const.
Definition: ContainerAndExpressionConcepts.h:166
Constrains a type to have a member function evalNextVectorOpInExpressionChain (value_type*) const.
Definition: ContainerAndExpressionConcepts.h:118
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:98
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:90
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:106
Constrains a type to have a function getStorageInfo() const.
Definition: ContainerAndExpressionConcepts.h:174
Constrains a type to have a non const operator[] overload taking a size_t argument.
Definition: ContainerAndExpressionConcepts.h:110
Constrains a type to have a function isNotAliased (const void*) const.
Definition: ContainerAndExpressionConcepts.h:178
Constrains a type to have a function iterateOverRuntimeArgChain<size_t> (RuntimeArgs)
Definition: ContainerAndExpressionConcepts.h:182
Constrains a type to have a member function prepareAVXEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:94
Constrains a type to have a member function prepareNeonEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:86
Constrains a type to have a member function prepareSSEEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:102
Constrains a type to have a member function reduceAVXRegisterWise (AVXRegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:134
Constrains a type to have a member function reduceElementWise() const that takes a ValueType& and siz...
Definition: ContainerAndExpressionConcepts.h:122
Constrains a type to have a member function reduceNeonRegisterWise (NeonRegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:130
Constrains a type to have a member function reduceSSERegisterWise (SSERegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:138
Constrains a type to have a member function reduceVectorOp() const that returns a DstType value.
Definition: ContainerAndExpressionConcepts.h:126
Constrains a type to have a function resize (size_t).
Definition: ContainerAndExpressionConcepts.h:170
Constrains a type to both, a member function size() const and data() const returning a pointer conver...
Definition: ContainerAndExpressionConcepts.h:158
Constrains a type to both, a member function size() const and data() const.
Definition: ContainerAndExpressionConcepts.h:154
Constrains a type to have a member function size() const.
Definition: ContainerAndExpressionConcepts.h:150
Constrains a type to either be an expression template or any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:275
Constrains a type to be any derived instance of VctrBase with a value_type to represent a complex val...
Definition: ContainerAndExpressionConcepts.h:259
Constrains a type to be any derived instance of VctrBase with a value_type to represent a real valued...
Definition: ContainerAndExpressionConcepts.h:255
Constrains a type to be any derived instance of VctrBase with a certain value_type.
Definition: ContainerAndExpressionConcepts.h:251
Constrains a type to be any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:247
Constrains a type to represent a complex valued floating point number (e.g.
Definition: NumericTypeConcepts.h:91
Constrains the type to be a contiguous iterator with a value type same as ElementType.
Definition: ContainerAndExpressionConcepts.h:434
Evaluates to true if T derives from a specialization of SplitComplexBase.
Definition: ContainerAndExpressionConcepts.h:472
Constrains a type to be an expression chain builder.
Definition: ContainerAndExpressionConcepts.h:271
Constrains a type to be an expression template that defines evalNextVectorOpInExpressionChain for Dst...
Definition: ContainerAndExpressionConcepts.h:296
Constrains a type to be an expression template with a certain value_type.
Definition: ContainerAndExpressionConcepts.h:267
Constrains a type to be an expression template.
Definition: ContainerAndExpressionConcepts.h:263
Constrains the type to be an input iterator with a value type suitable to construct an ElementType.
Definition: ContainerAndExpressionConcepts.h:430
Constrains a type to represent a real valued integer number.
Definition: NumericTypeConcepts.h:57
Constrains a type to supply begin and end functions and to not satisfy triviallyCopyableWithDataAndSi...
Definition: ContainerAndExpressionConcepts.h:408
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:87
Definition: ContainerAndExpressionConcepts.h:444
Constrains a type to be any instance of std::array.
Definition: ContainerAndExpressionConcepts.h:279
Constrains a type to be any instance of std::span.
Definition: ContainerAndExpressionConcepts.h:283
Constrains the type to be a suitable storage info type.
Definition: ContainerAndExpressionConcepts.h:441
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:378
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:313
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector oper...
Definition: ContainerAndExpressionConcepts.h:321
A combined concept to check if Apple Accelerate vpf functions are suitable to work on Neon registers.
Definition: ContainerAndExpressionConcepts.h:305
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:374
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:309
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector redu...
Definition: ContainerAndExpressionConcepts.h:333
A combined concept to check if Apple Accelerate is a suitable option for a vector operation that tran...
Definition: ContainerAndExpressionConcepts.h:329
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:382
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:317
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector oper...
Definition: ContainerAndExpressionConcepts.h:325
A combined concept to check if Apple Accelerate vpf functions are suitable to work on SSE registers.
Definition: ContainerAndExpressionConcepts.h:301
Constrains two source types to be suitable for a an aliasing-free binary vector operation using platf...
Definition: ContainerAndExpressionConcepts.h:366
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point bin...
Definition: ContainerAndExpressionConcepts.h:391
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point vec...
Definition: ContainerAndExpressionConcepts.h:345
A combined concept to check if Intel IPP is a suitable option for a floating point vector operation t...
Definition: ContainerAndExpressionConcepts.h:353
A combined concept to check if Intel IPP is a suitable option for a real valued floating point binary...
Definition: ContainerAndExpressionConcepts.h:387
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:337
A combined concept to check if Intel IPP is a suitable option for a floating point vector reduction o...
Definition: ContainerAndExpressionConcepts.h:357
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:395
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:349
A combined concept to check if Intel IPP is a suitable option for a real or complex floating point ve...
Definition: ContainerAndExpressionConcepts.h:361
A combined concept to check if Intel IPP is a suitable option for a real valued singed int32 vector o...
Definition: ContainerAndExpressionConcepts.h:341
A combined concept if one of the similar named Apple Accelerate VFP or Intel SVML backed member funct...
Definition: ContainerAndExpressionConcepts.h:399
Constrains the type to be suitable for initializing a single element Vctr with a given ElementType,...
Definition: ContainerAndExpressionConcepts.h:414
Constrains the type to be a function suitable for initializing the nth element of a Vctr with a given...
Definition: ContainerAndExpressionConcepts.h:426
Constrains the type to be a function suitable for initializing the nth element of a Vctr,...
Definition: ContainerAndExpressionConcepts.h:420
Constrains a type to supply a data and size function, an index operator and define a trivially copyab...
Definition: ContainerAndExpressionConcepts.h:404
Constrains a type to be trivially copyable.
Definition: GenericConcepts.h:78
Constrains a type to be any instance of vctr::Vector (not std::vector).
Definition: ContainerAndExpressionConcepts.h:291
Constrains a type to be a view rather than an owning container.
Definition: ContainerAndExpressionConcepts.h:287
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201
SplitComplexBase(const Interleaved &) -> SplitComplexBase< typename detail::SplitComplexContainerType< Interleaved >::Type >
Deduces the real storage type from an interleaved complex container.