22 #include "Utilities/PrintHelpers.hpp" 49 #if ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3)) 54 #endif // ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3)) 58 #if ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3)) 63 #endif // ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3)) 108 template <
typename T,
typename VectorType>
111 blaze::defaultTransposeFlag, VectorType> {
113 using value_type = T;
114 using size_type = size_t;
117 blaze::defaultTransposeFlag, VectorType>;
118 static constexpr
bool transpose_flag = blaze::defaultTransposeFlag;
120 using ElementType = T;
123 using iterator =
typename BaseType::Iterator;
124 using const_iterator =
typename BaseType::ConstIterator;
126 using BaseType::operator[];
127 using BaseType::begin;
128 using BaseType::cbegin;
129 using BaseType::cend;
130 using BaseType::data;
132 using BaseType::size;
140 return static_cast<const BaseType&
>(*this);
151 : owned_data_(set_size > 0 ? static_cast<value_type*>(
152 malloc(set_size *
sizeof(value_type)))
155 #if defined(SPECTRE_DEBUG) || defined(SPECTRE_NAN_INIT) 156 std::fill(owned_data_.get(), owned_data_.get() + set_size,
158 #endif // SPECTRE_DEBUG 159 reset_pointer_vector(set_size);
167 : owned_data_(set_size > 0 ? static_cast<value_type*>(
168 malloc(set_size *
sizeof(value_type)))
171 std::fill(owned_data_.get(), owned_data_.get() + set_size, value);
172 reset_pointer_vector(set_size);
177 :
BaseType(start, set_size), owning_(
false) {}
180 template <
class U, Requires<cpp17::is_same_v<U, T>> =
nullptr>
182 : owned_data_(list.size() > 0 ?
static_cast<value_type*
>(malloc(
183 list.size() *
sizeof(value_type)))
187 std::copy(list.begin(), list.end(), owned_data_.get());
188 reset_pointer_vector(list.size());
205 typename VT,
bool VF,
207 VectorImpl(
const blaze::DenseVector<VT, VF>& expression) noexcept;
209 template <
typename VT,
bool VF>
210 VectorImpl& operator=(
const blaze::DenseVector<VT, VF>& expression) noexcept;
223 (~*
this).reset(start, set_size);
233 void pup(PUP::er& p) noexcept;
240 const size_t set_size) noexcept {
241 this->reset(owned_data_.get(), set_size);
245 template <
typename T,
typename VectorType>
249 owned_data_(rhs.size() > 0 ?
static_cast<value_type*
>(
250 malloc(rhs.size() *
sizeof(value_type)))
253 reset_pointer_vector(rhs.size());
254 std::memcpy(data(), rhs.data(), size() *
sizeof(value_type));
257 template <
typename T,
typename VectorType>
262 if (size() != rhs.size()) {
263 owned_data_.reset(rhs.size() > 0 ?
static_cast<value_type*
>(malloc(
264 rhs.size() *
sizeof(value_type)))
267 reset_pointer_vector(rhs.size());
269 ASSERT(rhs.size() == size(),
"Must copy into same size, not " 270 << rhs.size() <<
" into " << size());
272 std::memcpy(data(), rhs.data(), size() *
sizeof(value_type));
277 template <
typename T,
typename VectorType>
280 owned_data_ = std::move(rhs.owned_data_);
282 owning_ = rhs.owning_;
287 template <
typename T,
typename VectorType>
292 owned_data_ = std::move(rhs.owned_data_);
294 owning_ = rhs.owning_;
296 ASSERT(rhs.size() == size(),
"Must copy into same size, not " 297 << rhs.size() <<
" into " << size());
298 std::memcpy(data(), rhs.data(), size() *
sizeof(value_type));
310 template <
typename T,
typename VectorType>
311 template <
typename VT,
bool VF,
314 const blaze::DenseVector<VT, VF>& expression)
316 : owned_data_(static_cast<value_type*>(
317 malloc((~expression).size() *
sizeof(value_type))),
319 static_assert(cpp17::is_same_v<typename VT::ResultType, VectorType>,
320 "You are attempting to assign the result of an expression " 321 "that is not consistent with the VectorImpl type you are " 323 reset_pointer_vector((~expression).size());
327 template <
typename T,
typename VectorType>
328 template <
typename VT,
bool VF>
330 const blaze::DenseVector<VT, VF>& expression) noexcept {
331 static_assert(cpp17::is_same_v<typename VT::ResultType, VectorType>,
332 "You are attempting to assign the result of an expression " 333 "that is not consistent with the VectorImpl type you are " 335 if (owning_ and (~expression).size() != size()) {
336 owned_data_.reset(static_cast<value_type*>(
337 malloc((~expression).size() *
sizeof(value_type))));
338 reset_pointer_vector((~expression).size());
339 }
else if (not owning_) {
340 ASSERT((~expression).size() == size(),
"Must copy into same size, not " 341 << (~expression).size()
342 <<
" into " << size());
353 template <
typename T,
typename VectorType>
355 const T& rhs) noexcept {
360 template <
typename T,
typename VectorType>
362 auto my_size = size();
365 if (p.isUnpacking()) {
367 owned_data_.reset(my_size > 0 ? static_cast<value_type*>(
368 malloc(my_size *
sizeof(value_type)))
370 reset_pointer_vector(my_size);
372 PUParray(p, data(), size());
377 template <
typename T,
typename VectorType>
397 #define BLAZE_TRAIT_SPECIALIZE_BINARY_TRAIT(VECTOR_TYPE, BLAZE_MATH_TRAIT) \ 399 struct BLAZE_MATH_TRAIT<VECTOR_TYPE, VECTOR_TYPE> { \ 400 using Type = VECTOR_TYPE; \ 403 struct BLAZE_MATH_TRAIT<VECTOR_TYPE, VECTOR_TYPE::value_type> { \ 404 using Type = VECTOR_TYPE; \ 407 struct BLAZE_MATH_TRAIT<VECTOR_TYPE::value_type, VECTOR_TYPE> { \ 408 using Type = VECTOR_TYPE; \ 426 #define BLAZE_TRAIT_SPECIALIZE_COMPATIBLE_BINARY_TRAIT( \ 427 VECTOR_TYPE, COMPATIBLE, BLAZE_MATH_TRAIT) \ 429 struct BLAZE_MATH_TRAIT<VECTOR_TYPE, COMPATIBLE> { \ 430 using Type = VECTOR_TYPE; \ 433 struct BLAZE_MATH_TRAIT<COMPATIBLE, VECTOR_TYPE> { \ 434 using Type = VECTOR_TYPE; \ 450 #define VECTOR_BLAZE_TRAIT_SPECIALIZE_ARITHMETIC_TRAITS(VECTOR_TYPE) \ 452 struct IsVector<VECTOR_TYPE> : std::true_type {}; \ 454 struct TransposeFlag<VECTOR_TYPE> \ 455 : BoolConstant<VECTOR_TYPE::transpose_flag> {}; \ 456 BLAZE_TRAIT_SPECIALIZE_BINARY_TRAIT(VECTOR_TYPE, AddTrait); \ 457 BLAZE_TRAIT_SPECIALIZE_BINARY_TRAIT(VECTOR_TYPE, SubTrait); \ 458 BLAZE_TRAIT_SPECIALIZE_BINARY_TRAIT(VECTOR_TYPE, MultTrait); \ 459 BLAZE_TRAIT_SPECIALIZE_BINARY_TRAIT(VECTOR_TYPE, DivTrait) 475 #if ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3)) 476 #define VECTOR_BLAZE_TRAIT_SPECIALIZE_ALL_MAP_TRAITS(VECTOR_TYPE) \ 477 template <typename Operator> \ 478 struct UnaryMapTrait<VECTOR_TYPE, Operator> { \ 479 using Type = VECTOR_TYPE; \ 481 template <typename Operator> \ 482 struct BinaryMapTrait<VECTOR_TYPE, VECTOR_TYPE, Operator> { \ 483 using Type = VECTOR_TYPE; \ 486 #define VECTOR_BLAZE_TRAIT_SPECIALIZE_ALL_MAP_TRAITS(VECTOR_TYPE) \ 487 template <typename Operator> \ 488 struct MapTrait<VECTOR_TYPE, Operator> { \ 489 using Type = VECTOR_TYPE; \ 491 template <typename Operator> \ 492 struct MapTrait<VECTOR_TYPE, VECTOR_TYPE, Operator> { \ 493 using Type = VECTOR_TYPE; \ 495 #endif // ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3)) 504 #define MAKE_STD_ARRAY_VECTOR_BINOPS(VECTOR_TYPE) \ 505 DEFINE_STD_ARRAY_BINOP(VECTOR_TYPE, VECTOR_TYPE::value_type, \ 506 VECTOR_TYPE, operator+, std::plus<>()) \ 507 DEFINE_STD_ARRAY_BINOP(VECTOR_TYPE, VECTOR_TYPE, \ 508 VECTOR_TYPE::value_type, operator+, std::plus<>()) \ 509 DEFINE_STD_ARRAY_BINOP(VECTOR_TYPE, VECTOR_TYPE, VECTOR_TYPE, operator+, \ 512 DEFINE_STD_ARRAY_BINOP(VECTOR_TYPE, VECTOR_TYPE::value_type, \ 513 VECTOR_TYPE, operator-, std::minus<>()) \ 514 DEFINE_STD_ARRAY_BINOP(VECTOR_TYPE, VECTOR_TYPE, \ 515 VECTOR_TYPE::value_type, operator-, std::minus<>()) \ 516 DEFINE_STD_ARRAY_BINOP(VECTOR_TYPE, VECTOR_TYPE, VECTOR_TYPE, operator-, \ 519 DEFINE_STD_ARRAY_INPLACE_BINOP(VECTOR_TYPE, VECTOR_TYPE, operator-=, \ 521 DEFINE_STD_ARRAY_INPLACE_BINOP( \ 522 VECTOR_TYPE, VECTOR_TYPE::value_type, operator-=, std::minus<>()) \ 523 DEFINE_STD_ARRAY_INPLACE_BINOP(VECTOR_TYPE, VECTOR_TYPE, operator+=, \ 525 DEFINE_STD_ARRAY_INPLACE_BINOP( \ 526 VECTOR_TYPE, VECTOR_TYPE::value_type, operator+=, std::plus<>()) 535 #define MAKE_MATH_ASSIGN_EXPRESSION_ARITHMETIC(VECTOR_TYPE) \ 536 MAKE_MATH_ASSIGN_EXPRESSION_POINTERVECTOR(+=, VECTOR_TYPE) \ 537 MAKE_MATH_ASSIGN_EXPRESSION_POINTERVECTOR(-=, VECTOR_TYPE) \ 538 MAKE_MATH_ASSIGN_EXPRESSION_POINTERVECTOR(*=, VECTOR_TYPE) \ 539 MAKE_MATH_ASSIGN_EXPRESSION_POINTERVECTOR(/=, VECTOR_TYPE) 552 #define MAKE_WITH_VALUE_IMPL_DEFINITION_FOR(VECTOR_TYPE) \ 553 namespace MakeWithValueImpls { \ 555 struct MakeWithValueImpl<VECTOR_TYPE, VECTOR_TYPE> { \ 556 static SPECTRE_ALWAYS_INLINE VECTOR_TYPE \ 557 apply(const VECTOR_TYPE& input, \ 558 const VECTOR_TYPE::value_type value) noexcept { \ 559 return VECTOR_TYPE(input.size(), value); \ 563 struct MakeWithValueImpl<VECTOR_TYPE, size_t> { \ 564 static SPECTRE_ALWAYS_INLINE VECTOR_TYPE \ 565 apply(const size_t& size, const VECTOR_TYPE::value_type value) noexcept { \ 566 return VECTOR_TYPE(size, value); \ 569 } // namespace MakeWithValueImpls 588 template <
typename T,
589 bool =
static_cast<bool>(tt::is_complex_of_fundamental_v<T> or
590 cpp17::is_fundamental_v<T>)>
592 template <
typename T>
596 template <
typename T>
600 template <
typename T>
603 typename T::ResultType::ElementType>::type;
605 template <
typename T>
609 template <
typename T>
613 template <
typename T,
size_t S>
619 template <
typename T>
623 template <
typename... VectorImplTemplateArgs>
634 template <
typename T>
636 decltype(detail::is_derived_of_vector_impl_impl(std::declval<T*>()));
638 template <
typename T>
639 constexpr
bool is_derived_of_vector_impl_v =
void set_data_ref(gsl::not_null< VectorType *> rhs) noexcept
Set the VectorImpl to be a reference to another VectorImpl object.
Definition: VectorImpl.hpp:217
VectorImpl(std::initializer_list< U > list) noexcept
Create from an initializer list of T.
Definition: VectorImpl.hpp:181
T signaling_NaN(T... args)
void pup(PUP::er &p) noexcept
Serialization for Charm++.
Definition: VectorImpl.hpp:361
Base class template for various DataVector and related types.
Definition: VectorImpl.hpp:109
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
Defines class PointerVector.
const BaseType & operator~() const noexcept
Upcast to BaseType
Definition: VectorImpl.hpp:139
Defines the type alias Requires.
VectorImpl(size_t set_size) noexcept
Create with the given size. In debug mode, the vector is initialized to 'NaN' by default. If not initialized to 'NaN', the memory is allocated but not initialized.
Definition: VectorImpl.hpp:150
VectorImpl(T *start, size_t set_size) noexcept
Create a non-owning VectorImpl that points to start
Definition: VectorImpl.hpp:176
Definition: Determinant.hpp:11
Definition: VectorImpl.hpp:593
Definition: VectorImpl.hpp:601
decltype(detail::is_derived_of_vector_impl_impl(std::declval< T * >())) is_derived_of_vector_impl
This is std::true_type if the provided type possesses an implicit conversion to any VectorImpl...
Definition: VectorImpl.hpp:636
VectorImpl()=default
Empty VectorImpl.
VectorImpl(size_t set_size, T value) noexcept
Create with the given size and value.
Definition: VectorImpl.hpp:166
#define SPECTRE_ALWAYS_INLINE
Always inline a function. Only use this if you benchmarked the code.
Definition: ForceInline.hpp:20
Definition: VectorImpl.hpp:597
bool is_owning() const noexcept
Returns true if the class owns the data.
Definition: VectorImpl.hpp:229
void sequence_print_helper(std::ostream &out, ForwardIt &&begin, ForwardIt &&end, Func f) noexcept
Applies the function f(out, it) to each item from begin to end, separated by commas and surrounded by...
Definition: PrintHelpers.hpp:18
Defines macro to always inline a function.
A raw pointer endowed with expression template support via the Blaze library.
Definition: PointerVector.hpp:496
Helper struct to determine the element type of a VectorImpl or container of VectorImpl.
Definition: VectorImpl.hpp:591
void set_data_ref(T *const start, const size_t set_size) noexcept
Set the VectorImpl to be a reference to another VectorImpl object.
Definition: VectorImpl.hpp:221
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t ...
Definition: Requires.hpp:67
BaseType & operator~() noexcept
Upcast to BaseType
Definition: VectorImpl.hpp:142
Defines arithmetic operators for std::array and other helpful functions.
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12