26__pragma (warning (push))
27__pragma (warning (disable : 4324))
35template <
class ElementType,
class StorageType,
size_t extent,
class StorageInfoType = StorageInfo<StorageType>>
41 using value_type = std::remove_cv_t<ElementType>;
55 static consteval size_t getExtent (
size_t amountToShrink = 0)
57 return extent == std::dynamic_extent ? std::dynamic_extent : (extent - amountToShrink);
61 [[nodiscard]]
constexpr size_t size() const noexcept requires (extent == std::dynamic_extent) {
return storage.size(); }
64 static constexpr size_t size() noexcept requires (extent != std::dynamic_extent) {
return extent; }
67 [[nodiscard]]
constexpr bool empty() const noexcept {
return storage.empty(); }
73 [[nodiscard]]
constexpr size_t sizeInBytes() const noexcept requires (extent == std::dynamic_extent) {
return size() *
sizeof (value_type); }
79 [[nodiscard]]
static constexpr size_t sizeInBytes() noexcept requires (extent != std::dynamic_extent) {
return size() *
sizeof (value_type); }
85 [[nodiscard]]
constexpr size_t backIdx() const noexcept requires (extent == std::dynamic_extent) {
return size() - 1; }
91 static constexpr size_t backIdx() noexcept requires (extent != std::dynamic_extent) {
return size() - 1; }
97 constexpr auto&
operator[] (
size_t i) { VCTR_ASSERT (i <
size());
return storage[i]; }
100 constexpr auto&
operator[] (
size_t i)
const { VCTR_ASSERT (i <
size());
return storage[i]; }
103 constexpr auto&
at (
size_t i) { throwIfOutOfRange (i);
return storage[i]; }
106 constexpr auto&
at (
size_t i)
const { throwIfOutOfRange (i);
return storage[i]; }
111 constexpr auto&&
front() {
return storage.front(); }
114 constexpr auto&&
front()
const {
return storage.front(); }
123 VCTR_FORCEDINLINE
constexpr auto*
data()
126 return assumeAlignedToMaxSIMDRegisterSize (storage.data());
128 return storage.data();
132 VCTR_FORCEDINLINE
constexpr auto*
data()
const
135 return assumeAlignedToMaxSIMDRegisterSize (storage.data());
137 return storage.data();
141 constexpr auto begin() {
return storage.begin(); }
144 constexpr auto begin()
const {
return storage.begin(); }
153 constexpr auto rbegin() {
return std::reverse_iterator (
end()); }
156 constexpr auto rbegin()
const {
return std::reverse_iterator (
end()); }
159 constexpr auto rend() {
return std::reverse_iterator (
begin()); }
162 constexpr auto rend()
const {
return std::reverse_iterator (
begin()); }
172 template <
size_t startIdx>
175 assertIsInRangeIncludingEnd<startIdx>();
176 return constCorrectSpan<getExtent (startIdx)> (
data() + startIdx,
size() - startIdx);
184 template <
size_t startIdx>
187 assertIsInRangeIncludingEnd<startIdx>();
188 return constCorrectSpan<getExtent (startIdx)> (
data() + startIdx,
size() - startIdx);
197 VCTR_ASSERT (startIdx <=
size());
198 return constCorrectSpan<std::dynamic_extent> (
data() + startIdx,
size() - startIdx);
205 constexpr auto subSpan (
size_t startIdx)
const
207 VCTR_ASSERT (startIdx <=
size());
208 return constCorrectSpan<std::dynamic_extent> (
data() + startIdx,
size() - startIdx);
215 template <
size_t startIdx,
size_t numElements>
218 VCTR_ASSERT (startIdx + numElements <=
size());
219 return constCorrectSpan<numElements> (
data() + startIdx, numElements);
226 template <
size_t startIdx,
size_t numElements>
229 VCTR_ASSERT (startIdx + numElements <=
size());
230 return constCorrectSpan<numElements> (
data() + startIdx, numElements);
237 constexpr auto subSpan (
size_t startIdx,
size_t numElements)
239 VCTR_ASSERT (startIdx + numElements <=
size());
240 return constCorrectSpan<std::dynamic_extent> (
data() + startIdx, numElements);
247 constexpr auto subSpan (
size_t startIdx,
size_t numElements)
const
249 VCTR_ASSERT (startIdx <
size());
250 VCTR_ASSERT (startIdx + numElements <=
size());
251 return constCorrectSpan<std::dynamic_extent> (
data() + startIdx, numElements);
263 constexpr void assign (std::initializer_list<ElementType> elements)
267 storage.resize (elements.size());
271 VCTR_ASSERT (elements.size() ==
size());
274 std::copy (elements.begin(), elements.end(),
begin());
282 constexpr void copyFrom (
const ElementType* otherData,
size_t otherSize)
285 resizeOrAssertSizeMatches (otherSize);
289 if (! std::is_constant_evaluated())
291 std::memcpy (
data(), otherData,
sizeof (ElementType) * otherSize);
296 std::copy_n (otherData, otherSize,
begin());
300 constexpr void fill (
const value_type& value) { std::fill (
begin(),
end(), value); }
317 constexpr void fillLinspace (ElementType start, ElementType stop,
bool includeEnd =
true)
318 requires is::realNumber<ElementType>
320 const auto num =
size();
322 VCTR_ASSERT (num > 0);
323 VCTR_ASSERT (! includeEnd || num != 1);
325 const auto increment = (stop - start) /
double (num -
size_t (includeEnd));
328 [[maybe_unused]]
const auto isIntegerIncrement = increment - gcem::floor (increment) == ElementType (0);
330 [[maybe_unused]]
const auto isIntegerIncrement = increment - std::floor (increment) == ElementType (0);
332 VCTR_ASSERT (std::is_floating_point_v<ElementType> || isIntegerIncrement);
334 auto value = double (start);
336 for (
int i = 0; i < num; ++i)
338 storage[i] = ElementType (value);
350 template <is::functionWithSignatureOrImplicitlyConvertible<
void (value_type&)> Fn>
353 for (
auto& e : *
this)
361 template <is::functionWithSignatureOrImplicitlyConvertible<
void (const value_type&)> Fn>
364 for (
const auto& e : *
this)
372 template <is::functionWithSignatureOrImplicitlyConvertible<value_type (const value_type&)> Fn>
375 for (
auto& e : *
this)
383 template <is::functionWithSignatureOrImplicitlyConvertible<
void (value_type&,
size_t)> Fn>
386 const auto s =
size();
387 for (
size_t i = 0; i < s; ++i)
395 template <is::functionWithSignatureOrImplicitlyConvertible<
void (const value_type&,
size_t)> Fn>
398 const auto s =
size();
399 for (
size_t i = 0; i < s; ++i)
407 template <is::functionWithSignatureOrImplicitlyConvertible<value_type (const value_type&,
size_t)> Fn>
410 const auto s =
size();
411 for (
size_t i = 0; i < s; ++i)
412 storage[i] = fn (storage[i], i);
420 constexpr void forEach (Fn&& fn, Args&&... fnArgs)
422 for (
auto& e : *
this)
423 fn (e, std::forward<Args> (fnArgs)...);
431 constexpr void forEach (Fn&& fn, Args&&... fnArgs)
const
433 for (
const auto& e : *
this)
434 fn (e, std::forward<Args> (fnArgs)...);
442 constexpr void forEach (Fn&& fn, Args&&... fnArgs)
444 for (
auto& e : *
this)
445 e = fn (e, std::forward<Args> (fnArgs)...);
452 template <std::equality_comparable_with<ElementType> T>
453 constexpr auto find (
const T& valueToLookFor)
455 return std::find (
begin(),
end(), valueToLookFor);
459 template <std::equality_comparable_with<ElementType> T>
460 constexpr auto find (
const T& valueToLookFor)
const
462 return std::find (
begin(),
end(), valueToLookFor);
466 template <std::equality_comparable_with<ElementType> T>
469 return std::find (
rbegin(),
rend(), valueToLookFor);
473 template <std::equality_comparable_with<ElementType> T>
476 return std::find (
rbegin(),
rend(), valueToLookFor);
480 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
483 return std::find_if (
begin(),
end(), std::forward<Fn> (predicate));
487 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
488 constexpr auto findIf (Fn&& predicate)
const
490 return std::find_if (
begin(),
end(), std::forward<Fn> (predicate));
494 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
497 return std::find_if (
rbegin(),
rend(), std::forward<Fn> (predicate));
501 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
504 return std::find_if (
rbegin(),
rend(), std::forward<Fn> (predicate));
508 constexpr size_t count (
const ElementType& valueToLookFor)
const
510 return std::count (
begin(),
end(), valueToLookFor);
514 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
515 constexpr size_t countIf (Fn&& predicate)
const
517 return std::count_if (
begin(),
end(), std::forward<Fn> (predicate));
521 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
522 constexpr bool all (Fn&& predicate)
const
524 return std::all_of (
begin(),
end(), std::forward<Fn> (predicate));
528 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
529 constexpr bool any (Fn&& predicate)
const
531 return std::any_of (
begin(),
end(), std::forward<Fn> (predicate));
535 template <std::equality_comparable_with<ElementType> T>
538 return all ([&] (
const auto& e) {
return e == value; });
543 requires std::equality_comparable<ElementType>
548 return std::all_of (
begin() + 1,
end(), [&v = storage[0]] (
const auto& e) {
return v == e; });
552 template <std::equality_comparable_with<ElementType> T>
562 template <is::contiguousIteratorWithValueTypeSameAs<ElementType> It>
565 const auto* address = std::to_address (it);
566 const auto* first = std::to_address (
begin());
567 const auto* last = std::to_address (
end() - 1);
569 return address >= first && address <= last;
573 template <std::equality_comparable_with<ElementType> T>
574 constexpr std::optional<size_t>
indexOf (
const T& value)
const
576 auto it =
find (value);
577 return it ==
end() ? std::nullopt : std::optional<size_t> (std::distance (
begin(), it));
581 template <std::equality_comparable_with<ElementType> T>
585 return it ==
rend() ? std::nullopt : std::optional<size_t> (std::distance (it,
rend()) - 1);
589 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
590 constexpr std::optional<size_t>
indexIf (Fn&& predicate)
const
592 auto it =
findIf (predicate);
593 return it ==
end() ? std::nullopt : std::optional<size_t> (std::distance (
begin(), it));
597 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const ElementType&)> Fn>
601 return it ==
rend() ? std::nullopt : std::optional<size_t> (std::distance (it,
rend()) - 1);
610 requires std::totally_ordered<value_type>
612 return std::max_element (
begin(),
end());
621 requires std::totally_ordered<value_type>
623 return std::max_element (
begin(),
end());
632 requires std::totally_ordered<value_type>
634 return std::min_element (
begin(),
end());
643 requires std::totally_ordered<value_type>
645 return std::min_element (
begin(),
end());
650 requires std::totally_ordered<value_type>
657 requires std::totally_ordered<value_type>
668 requires std::totally_ordered<value_type>
671 auto it = std::lower_bound (
begin(),
end(), valueToLookFor);
672 return it ==
end() ? std::nullopt : std::optional<value_type> (*it);
681 requires std::totally_ordered<value_type>
684 auto it = std::upper_bound (
begin(),
end(), valueToLookFor);
685 return it ==
end() ? std::nullopt : std::optional<value_type> (*it);
700 constexpr void rotate (
size_t newFirstElementIdx)
702 VCTR_ASSERT (newFirstElementIdx <
size());
713 void shiftLeft (
size_t n,
bool clearFreeSpaceAfterShiftedRegion)
714 requires std::is_trivially_copyable_v<ElementType>
718 if (clearFreeSpaceAfterShiftedRegion)
724 VCTR_ASSERT (n <
size());
726 auto numElementsToMove =
size() - n;
727 memMove (
data() + n,
data(), numElementsToMove);
729 if (clearFreeSpaceAfterShiftedRegion)
730 clear (
data() + numElementsToMove, n);
740 void shiftRight (
size_t n,
bool clearFreeSpaceBeforeShiftedRegion)
741 requires std::is_trivially_copyable_v<ElementType>
745 if (clearFreeSpaceBeforeShiftedRegion)
751 VCTR_ASSERT (n <
size());
753 const auto numElementsToMove =
size() - n;
754 memMove (
data(),
data() + n, numElementsToMove);
756 if (clearFreeSpaceBeforeShiftedRegion)
762 requires std::totally_ordered<value_type>
771 template <is::functionWithSignatureOrImplicitlyConvertible<
bool (const value_type&, const value_type&)> ComparatorFn>
772 constexpr void sort (ComparatorFn&& compare)
774 std::sort (
begin(),
end(), compare);
779 requires std::totally_ordered<value_type>
781 return std::is_sorted (
begin(),
end());
787 void prepareNeonEvaluation()
const {}
792 VCTR_ASSERT (i %
NeonRegister<std::remove_const_t<ElementType>>::numElements == 0);
796 void prepareAVXEvaluation()
const {}
799 AVXRegister<std::remove_const_t<ElementType>> getAVX (
size_t i) const
800 requires archX64 && is::realNumber<ElementType>
802 VCTR_ASSERT (i % AVXRegister<std::remove_const_t<ElementType>>::numElements == 0);
803 if (StorageInfoType::dataIsSIMDAligned)
804 return AVXRegister<std::remove_const_t<ElementType>>::loadAligned (
data() + i);
806 return AVXRegister<std::remove_const_t<ElementType>>::loadUnaligned (
data() + i);
809 void prepareSSEEvaluation()
const {}
811 VCTR_TARGET (
"sse4.1")
812 SSERegister<std::remove_const_t<ElementType>> getSSE (
size_t i) const
813 requires archX64 && is::realNumber<ElementType>
815 VCTR_ASSERT (i % SSERegister<std::remove_const_t<ElementType>>::numElements == 0);
816 if (StorageInfoType::dataIsSIMDAligned)
817 return SSERegister<std::remove_const_t<ElementType>>::loadAligned (
data() + i);
819 return SSERegister<std::remove_const_t<ElementType>>::loadUnaligned (
data() + i);
828 template <is::expressionChainBuilder ExpressionChain>
829 void evalInPlace (
const ExpressionChain& expression)
831 assignExpressionTemplate (expression << *
this);
834 constexpr bool isNotAliased (
const void*)
const {
return true; }
836 VCTR_FORCEDINLINE
const ElementType* evalNextVectorOpInExpressionChain (
void*)
const {
return data(); }
838 constexpr const StorageInfoType& getStorageInfo()
const {
return *
this; }
844 template <is::anyVctrOrExpression V>
851 template <is::anyVctrOrExpression V>
876 template <is::anyVctrOrExpression V>
883 template <is::anyVctrOrExpression V>
893 constexpr ElementType
min() const requires std::totally_ordered<ElementType>;
896 constexpr ElementType
minAbs() const requires is::number<ElementType>;
899 constexpr ElementType
max() const requires std::totally_ordered<ElementType>;
902 constexpr ElementType
maxAbs() const requires is::number<ElementType>;
905 constexpr ElementType
mean() const requires is::number<ElementType>;
908 constexpr ElementType
meanSquare() const requires is::number<ElementType>;
911 constexpr ElementType
rms() const requires is::number<ElementType>;
914 constexpr ElementType
sum() const requires has::operatorPlusEquals<std::remove_cv_t<ElementType>>;
936 requires is::stdPair<value_type> && (! is::view<StorageType>)
938 return std::map<typename value_type::first_type, typename value_type::second_type> { std::make_move_iterator (
begin()), std::make_move_iterator (
end()) };
943 requires is::stdPair<value_type>
945 return std::map<typename value_type::first_type, typename value_type::second_type> {
begin(),
end() };
953 StorageInfoType::init (storage.data(), storage.size());
956 constexpr VctrBase (StorageType&& s)
957 : storage (std::move (s))
959 if constexpr (has::init<StorageInfoType>)
960 StorageInfoType::init (storage.data(), storage.size());
963 template <is::storageInfo OtherStorageInfoType>
964 constexpr VctrBase (StorageType&& s,
const OtherStorageInfoType& otherInfo)
966 storage (std::move (s))
971 constexpr void resizeOrAssertSizeMatches (
size_t desiredSize)
972 requires has::resize<StorageType>
974 storage.resize (desiredSize);
978 constexpr void resizeOrAssertSizeMatches ([[maybe_unused]]
size_t desiredSize)
const
980 VCTR_ASSERT (
size() == desiredSize);
985 constexpr void assertIsInRange() const
986 requires (extent == std::dynamic_extent)
988 VCTR_ASSERT (i <
size());
993 constexpr void assertIsInRange() const
994 requires (extent != std::dynamic_extent)
996 static_assert (i < extent);
1001 constexpr void assertIsInRangeIncludingEnd() const
1002 requires (extent == std::dynamic_extent)
1004 VCTR_ASSERT (i <=
size());
1009 constexpr void assertIsInRangeIncludingEnd() const
1010 requires (extent != std::dynamic_extent)
1012 static_assert (i <= extent);
1016 void throwIfOutOfRange (
size_t i)
const
1020 VCTR_ASSERT (
false);
1021 throw std::out_of_range (
"Vctr of size " + std::to_string (
size()) +
": Element " + std::to_string (i) +
" is out of range.");
1026 template <is::expression Expression>
1027 VCTR_FORCEDINLINE
constexpr void assignExpressionTemplate (
const Expression& e)
1029 if (! std::is_constant_evaluated())
1031 if constexpr (has::evalNextVectorOpInExpressionChain<Expression, ElementType>)
1033 if (e.isNotAliased (
data()))
1035 e.evalNextVectorOpInExpressionChain (
data());
1040 if constexpr (has::getNeon<Expression>)
1042 assignExpressionTemplateNeon (e);
1046 if constexpr (has::getAVX<Expression>)
1048 if constexpr (is::realFloatNumber<ElementType>)
1050 if (supportedCPUInstructionSets.fma)
1052 assignExpressionTemplateFMA (e);
1058 if (supportedCPUInstructionSets.avx2)
1060 assignExpressionTemplateAVX2 (e);
1066 if constexpr (has::getSSE<Expression>)
1068 if (supportedCPUInstructionSets.sse4_1)
1070 assignExpressionTemplateSSE4_1 (e);
1076 const auto n =
size();
1078 for (
size_t i = 0; i < n; ++i)
1083 template <
class OtherContainer>
1084 static constexpr bool shouldMoveFromOtherContainer = has::begin<OtherContainer> &&
1085 has::end<OtherContainer> &&
1086 (! is::view<OtherContainer>) &&
1087 (! std::is_reference_v<OtherContainer>) &&
1088 (! std::is_trivially_copyable_v<ElementType>);
1091 alignas (StorageInfoType::memberAlignment) StorageType storage = StorageType {};
1095 template <
class Expression>
1096 void assignExpressionTemplateNeon (
const Expression& e)
1099 constexpr auto inc = NeonRegister<ElementType>::numElements;
1100 const bool hasExtendedSIMDStorage = e.getStorageInfo().hasSIMDExtendedStorage && StorageInfoType::hasSIMDExtendedStorage;
1101 const auto n = storage.size();
1102 const auto nSIMD = hasExtendedSIMDStorage ? detail::nextMultipleOf<inc> (n) : detail::previousMultipleOf<inc> (n);
1104 e.prepareNeonEvaluation();
1108 for (; i < nSIMD; i += inc, d += inc)
1109 e.getNeon (i).store (d);
1111 for (; i < n; ++i, ++d)
1115 template <
class Expression>
1116 VCTR_TARGET (
"avx2")
1117 void assignExpressionTemplateAVX2 (const Expression& e)
1120 constexpr auto inc = AVXRegister<ElementType>::numElements;
1121 const bool hasExtendedSIMDStorage = e.getStorageInfo().hasSIMDExtendedStorage && StorageInfoType::hasSIMDExtendedStorage;
1122 const auto n = storage.size();
1123 const auto nSIMD = hasExtendedSIMDStorage ? detail::nextMultipleOf<inc> (n) : detail::previousMultipleOf<inc> (n);
1125 e.prepareAVXEvaluation();
1128 if (StorageInfoType::dataIsSIMDAligned)
1131 for (; i < nSIMD; i += inc, d += inc)
1132 e.getAVX (i).storeAligned (d);
1134 for (; i < n; ++i, ++d)
1140 for (; i < nSIMD; i += inc, d += inc)
1141 e.getAVX (i).storeUnaligned (d);
1143 for (; i < n; ++i, ++d)
1148 template <
class Expression>
1150 void assignExpressionTemplateFMA (const Expression& e)
1153 constexpr auto inc = AVXRegister<ElementType>::numElements;
1154 const bool hasExtendedSIMDStorage = e.getStorageInfo().hasSIMDExtendedStorage && StorageInfoType::hasSIMDExtendedStorage;
1155 const auto n = storage.size();
1156 const auto nSIMD = hasExtendedSIMDStorage ? detail::nextMultipleOf<inc> (n) : detail::previousMultipleOf<inc> (n);
1158 e.prepareAVXEvaluation();
1161 if (StorageInfoType::dataIsSIMDAligned)
1164 for (; i < nSIMD; i += inc, d += inc)
1165 e.getAVX (i).storeAligned (d);
1167 for (; i < n; ++i, ++d)
1173 for (; i < nSIMD; i += inc, d += inc)
1174 e.getAVX (i).storeUnaligned (d);
1176 for (; i < n; ++i, ++d)
1181 template <
class Expression>
1182 VCTR_TARGET (
"sse4.1")
1183 void assignExpressionTemplateSSE4_1 (const Expression& e)
1186 constexpr auto inc = SSERegister<ElementType>::numElements;
1187 const bool hasExtendedSIMDStorage = e.getStorageInfo().hasSIMDExtendedStorage && StorageInfoType::hasSIMDExtendedStorage;
1188 const auto n = storage.size();
1189 const auto nSIMD = hasExtendedSIMDStorage ? detail::nextMultipleOf<inc> (n) : detail::previousMultipleOf<inc> (n);
1191 e.prepareSSEEvaluation();
1194 if (StorageInfoType::dataIsSIMDAligned)
1197 for (; i < nSIMD; i += inc, d += inc)
1198 e.getSSE (i).storeAligned (d);
1200 for (; i < n; ++i, ++d)
1206 for (; i < nSIMD; i += inc, d += inc)
1207 e.getSSE (i).storeUnaligned (d);
1209 for (; i < n; ++i, ++d)
1215 template <
size_t spanExtent>
1216 constexpr auto constCorrectSpan (ElementType*
data,
size_t spanSize);
1218 template <
size_t spanExtent>
1219 constexpr auto constCorrectSpan (
const ElementType*
data,
size_t spanSize)
const
1220 requires (! is::stdSpan<StorageType>);
1222 template <
size_t spanExtent>
1223 constexpr auto constCorrectSpan (ElementType*
data,
size_t spanSize)
const
1224 requires is::stdSpan<StorageType>;
1228 static void clear (ElementType* ptr,
size_t numElements)
1230 std::memset (ptr, 0, numElements *
sizeof (ElementType));
1234 static void memMove (
const ElementType* src, ElementType* dst,
size_t numElements)
1235 requires std::is_trivially_copyable_v<ElementType>
1237 std::memmove (dst, src, numElements *
sizeof (ElementType));
1242 VCTR_FORCEDINLINE
constexpr static T* assumeAlignedToMaxSIMDRegisterSize (T* ptr)
1244 if (std::is_constant_evaluated())
1247 #if __cpp_lib_assume_aligned
1248 return std::assume_aligned<maxSIMDRegisterSize> (ptr);
1250 return static_cast<T*
> (__builtin_assume_aligned (ptr, maxSIMDRegisterSize));
1262template <is::anyVctr Lhs, is::anyVctr Rhs>
1263requires std::same_as<ValueType<Lhs>, ValueType<Rhs>>
1266 return std::equal (lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1272__pragma (warning (pop))
The base class to all one dimensional containers and views in the VCTR project.
Definition: VctrBase.h:38
void shiftRight(size_t n, bool clearFreeSpaceBeforeShiftedRegion)
Shifts all elements to the right by n.
Definition: VctrBase.h:740
auto findMaxElement() const
Returns an iterator to the first greatest element.
Definition: VctrBase.h:620
constexpr size_t count(const ElementType &valueToLookFor) const
Returns the number of elements that are equal to valueToLookFor.
Definition: VctrBase.h:508
auto findMaxElement()
Returns an iterator to the first greatest element.
Definition: VctrBase.h:609
constexpr bool contains(It it) const
Returns true if the iterator refers to an element inside this container or span.
Definition: VctrBase.h:563
constexpr void sort(ComparatorFn &&compare)
Sorts all elements in this vector according to the compare function.
Definition: VctrBase.h:772
static consteval size_t getExtent(size_t amountToShrink=0)
Returns the extent of this instance, optionally shrank by a certain amount.
Definition: VctrBase.h:55
constexpr size_t size() const noexcept
Returns the number of elements.
Definition: VctrBase.h:61
constexpr auto findReverse(const T &valueToLookFor)
Returns a reverse iterator to the last element in this vector that equals valueToLookFor or rend() if...
Definition: VctrBase.h:467
constexpr std::optional< size_t > indexIfReverse(Fn &&predicate) const
Returns the index of the last element that satisfies the predicate or std::nullopt if none is found.
Definition: VctrBase.h:598
constexpr void fillLinspace(ElementType start, ElementType stop, bool includeEnd=true)
Fills the vector with evenly spaced numbers between start and stop.
Definition: VctrBase.h:317
constexpr void rotate(size_t newFirstElementIdx)
Rotates the elements so that the element with the index newFirstElementIdx becomes the first element ...
Definition: VctrBase.h:700
constexpr void forEach(Fn &&fn) const
Calls a function on each element.
Definition: VctrBase.h:362
constexpr auto subSpan() const
Returns a Span that views a portion of this instance, starting at startIdx with a length of numElemen...
Definition: VctrBase.h:227
auto findMinElement()
Returns an iterator to the first smallest element.
Definition: VctrBase.h:631
constexpr auto subSpan()
Returns a Span that views a portion of this instance, starting at startIdx with a length of size() - ...
Definition: VctrBase.h:173
constexpr auto subSpan(size_t startIdx) const
Returns a Span that views a portion of this instance, starting at startIdx with a length of size() - ...
Definition: VctrBase.h:205
VCTR_FORCEDINLINE constexpr auto * data() const
Returns a raw pointer to the underlying storage.
Definition: VctrBase.h:132
constexpr void operator-=(const V &v)
Subtracts a vector or expression from this in place.
constexpr void operator+=(const V &v)
Adds a vector or expression to this in place.
constexpr ElementType min() const
Returns the minimal value of all elements.
constexpr auto find(const T &valueToLookFor)
Returns an iterator to the first element that equals valueToLookFor or end() if none was found.
Definition: VctrBase.h:453
constexpr void operator/=(const V &v)
Divides this by a vector or expression in place.
constexpr auto find(const T &valueToLookFor) const
Returns a const iterator to the first element that equals valueToLookFor or end() if none was found.
Definition: VctrBase.h:460
static constexpr size_t sizeInBytes() noexcept
Returns the container size in bytes.
Definition: VctrBase.h:79
constexpr auto toStdMap() const &
If value_type is std::pair, this converts the content into a std::map with pair::first_type being the...
Definition: VctrBase.h:942
constexpr bool all(Fn &&predicate) const
Returns true if all elements satisfy the predicate or if the container is empty.
Definition: VctrBase.h:522
constexpr auto begin()
Returns an iterator to the begin of the storage.
Definition: VctrBase.h:141
constexpr std::optional< size_t > indexOfReverse(const T &value) const
Returns the index of the last element that compares true to value or std::nullopt if none is found.
Definition: VctrBase.h:582
constexpr auto subSpan(size_t startIdx, size_t numElements) const
Returns a Span that views a portion of this instance, starting at startIdx with a length of numElemen...
Definition: VctrBase.h:247
constexpr void assign(std::initializer_list< ElementType > elements)
Assigns elements from the initializer list to this instance.
Definition: VctrBase.h:263
size_t indexOfMinElement() const
Returns the index of the first smallest element (aka argMin).
Definition: VctrBase.h:656
constexpr ElementType maxAbs() const
Returns the maximum absolute value of all elements.
constexpr size_t countIf(Fn &&predicate) const
Returns the number of elements that satisfy predicate.
Definition: VctrBase.h:515
constexpr auto subSpan(size_t startIdx, size_t numElements)
Returns a Span that views a portion of this instance, starting at startIdx with a length of numElemen...
Definition: VctrBase.h:237
constexpr void sort()
Sorts all elements in an ascending order using operator <=>.
Definition: VctrBase.h:761
constexpr void forEach(Fn &&fn, Args &&... fnArgs)
Calls a function on each element and forwards fnArgs to the function after the value.
Definition: VctrBase.h:420
constexpr size_t sizeInBytes() const noexcept
Returns the container size in bytes.
Definition: VctrBase.h:73
constexpr auto findReverse(const T &valueToLookFor) const
Returns a const reverse iterator to the last element in this vector that equals valueToLookFor or ren...
Definition: VctrBase.h:474
constexpr void copyFrom(const ElementType *otherData, size_t otherSize)
Copies the content from otherData to this instance.
Definition: VctrBase.h:282
VCTR_FORCEDINLINE constexpr auto * data()
Returns a raw pointer to the underlying storage.
Definition: VctrBase.h:123
constexpr bool anyElementIsNaN()
Returns true if any element is NaN.
static constexpr size_t backIdx() noexcept
Returns the index referring to the last element in the vector.
Definition: VctrBase.h:91
constexpr auto subSpan()
Returns a Span that views a portion of this instance, starting at startIdx with a length of numElemen...
Definition: VctrBase.h:216
NeonRegister< std::remove_const_t< ElementType > > getNeon(size_t i) const &&is
Evaluates a certain expression in place on this vector, e.g.
Definition: VctrBase.h:789
constexpr void forEach(Fn &&fn)
Calls a function on each element.
Definition: VctrBase.h:351
constexpr std::optional< size_t > indexOf(const T &value) const
Returns the index of the first element that compares true to value or std::nullopt if none is found.
Definition: VctrBase.h:574
constexpr auto findIf(Fn &&predicate)
Returns an iterator to the first element in this vector for which predicate returns true or end() if ...
Definition: VctrBase.h:481
constexpr auto subSpan() const
Returns a Span that views a portion of this instance, starting at startIdx with a length of size() - ...
Definition: VctrBase.h:185
constexpr auto end() const
Returns a const iterator to the first element behind the storage.
Definition: VctrBase.h:150
constexpr auto subSpan(size_t startIdx)
Returns a Span that views a portion of this instance, starting at startIdx with a length of size() - ...
Definition: VctrBase.h:195
constexpr auto & at(size_t i) const
Returns a reference to element i.
Definition: VctrBase.h:106
constexpr auto findIfReverse(Fn &&predicate) const
Returns a const reverse iterator to the last element in this vector for which predicate returns true ...
Definition: VctrBase.h:502
constexpr auto && front() const
Returns a reference to the first element.
Definition: VctrBase.h:114
constexpr ElementType rms() const
Returns the square root of the mean value across all squared elements.
constexpr auto findIfReverse(Fn &&predicate)
Returns a reverse iterator to the last element in this vector for which predicate returns true or ren...
Definition: VctrBase.h:495
constexpr void reverse()
Reverses the order of all elements.
Definition: VctrBase.h:692
constexpr bool allElementsEqual() const
Returns true if all elements are equal to themselves.
Definition: VctrBase.h:542
constexpr std::optional< value_type > firstValueGreaterThan(const value_type &valueToLookFor) const
Returns a std::optional holding a copy of the first element value which is greater than valueToLookFo...
Definition: VctrBase.h:680
constexpr auto && front()
Returns a reference to the first element.
Definition: VctrBase.h:111
constexpr bool allElementsAreFinite()
Returns true if all elements are finite.
constexpr auto rend() const
Returns a const reverse iterator to the element before the first element in the storage.
Definition: VctrBase.h:162
constexpr auto & operator[](size_t i)
Returns a reference to element i.
Definition: VctrBase.h:97
constexpr auto && back()
Returns a reference to the last element.
Definition: VctrBase.h:117
constexpr bool allElementsEqual(const T &value) const
Returns true if all elements are equal to value or if the container is empty.
Definition: VctrBase.h:536
constexpr bool elementsAreSorted() const
Returns true if all elements are sorted.
Definition: VctrBase.h:778
constexpr size_t backIdx() const noexcept
Returns the index referring to the last element in the vector.
Definition: VctrBase.h:85
constexpr std::optional< value_type > firstValueGreaterThanOrEqualTo(const value_type &valueToLookFor) const
Returns a std::optional holding a copy of the first element value which is greater or equal to valueT...
Definition: VctrBase.h:667
size_t indexOfMaxElement() const
Returns the index of the first greatest element (aka argMax).
Definition: VctrBase.h:649
constexpr ElementType minAbs() const
Returns the minimal absolute value of all elements.
constexpr ElementType max() const
Returns the maximum value of all elements.
constexpr auto findIf(Fn &&predicate) const
Returns a const iterator to the first element in this vector for which predicate returns true or end(...
Definition: VctrBase.h:488
constexpr void forEach(Fn &&fn, Args &&... fnArgs) const
Calls a function on each element and forwards fnArgs to the function after the value.
Definition: VctrBase.h:431
constexpr auto rend()
Returns a reverse iterator to the element before the first element in the storage.
Definition: VctrBase.h:159
constexpr auto & at(size_t i)
Returns a reference to element i.
Definition: VctrBase.h:103
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: VctrBase.h:67
constexpr void fill(const value_type &value)
Fills the container with the given value.
Definition: VctrBase.h:300
constexpr ElementType mean() const
Returns the mean value across all elements.
constexpr bool any(Fn &&predicate) const
Returns true if one or more elements satisfy the predicate.
Definition: VctrBase.h:529
constexpr ElementType sum() const
Returns the sum of all elements.
auto findMinElement() const
Returns an iterator to the first smallest element.
Definition: VctrBase.h:642
constexpr auto && back() const
Returns a reference to the last element.
Definition: VctrBase.h:120
constexpr auto begin() const
Returns a const iterator to the begin of the storage.
Definition: VctrBase.h:144
constexpr auto end()
Returns an iterator to the first element behind the storage.
Definition: VctrBase.h:147
constexpr ElementType meanSquare() const
Returns the mean value across all squared elements.
static constexpr size_t size() noexcept
Returns the number of elements.
Definition: VctrBase.h:64
constexpr bool contains(const T &value) const
Returns true if at least one element is equal to value.
Definition: VctrBase.h:553
constexpr std::optional< size_t > indexIf(Fn &&predicate) const
Returns the index of the first element that satisfies the predicate or std::nullopt if none is found.
Definition: VctrBase.h:590
void shiftLeft(size_t n, bool clearFreeSpaceAfterShiftedRegion)
Shifts all elements to the left by n.
Definition: VctrBase.h:713
constexpr auto rbegin() const
Returns a const reverse iterator to the last element in the storage.
Definition: VctrBase.h:156
constexpr auto toStdMap() &&
If value_type is std::pair, this converts the content into a std::map with pair::first_type being the...
Definition: VctrBase.h:935
constexpr void operator*=(const V &v)
Multiplies this by a vector or expression in place.
constexpr auto rbegin()
Returns a reverse iterator to the last element in the storage.
Definition: VctrBase.h:153
Constrains the type to have a member function init that takes a void pointer and a size_t.
Definition: GenericConcepts.h:32
Constrains a type to have a function resize (size_t).
Definition: ContainerAndExpressionConcepts.h:164
Constrains Fn to be a function with the specified function signature or some signature with implicitl...
Definition: FunctionConcepts.h:89
Constrains a type to be non const.
Definition: GenericConcepts.h:82
Constrains a type to represent a real valued number.
Definition: NumericTypeConcepts.h:79
Constrains a type to be any instance of std::array.
Definition: ContainerAndExpressionConcepts.h:234
Constrains a type to be trivially copyable.
Definition: GenericConcepts.h:78
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::StorageInfoType< std::remove_cvref_t< T > >::Type StorageInfoType
If t is a type derived from VctrBase, this will equal the return value of T::getStorageInfo,...
Definition: Traits.h:227
constexpr bool operator==(const Lhs &lhs, const Rhs &rhs)
Compares lhs and rhs for equality.
Definition: VctrBase.h:1264
Definition: NeonRegister.h:28
A helper struct intended to check if a value is a constexpr.
Definition: Traits.h:300