Vector.h¶
-
template<typename
T
, size_tDIM
>
classCubism::Core
::
Vector
¶ Vector class with support for common operations.
Wraps around
std::array
. The data typeT
must follow the rules of aggregate initialization. The vector dimensionDIM
should be low-dimensional when used for automatic variables on the stack.- Template Parameters
T
: Data typeDIM
: Dimension
Public Functions
-
inline
Vector
()¶ Default constructor.
All elements are initialized to
0
.
-
inline
Vector
(const ArrayType &ary)¶ Copy constructor.
Initialize data from
std::array
of same type
-
inline
Vector
(ArrayType &&ary) noexcept¶ Move constructor.
Initialize data from
std::array
of same type (linear complexity)
-
template<typename
U
, size_tDIMU
>
inlineVector
(const Vector<U, DIMU> &c)¶ Constructor for arbitrary Vector types.
The type
U
must define a cast toDataType
.- Template Parameters
U
: Scalar typeDIMU
: Vector dimension
- Parameters
c
: Initial values
-
template<typename
U
>
inline explicitVector
(const U scalar)¶ Constructor for any scalar type
U
.The type
U
must define a cast toDataType
.- Template Parameters
U
: Scalar type
- Parameters
scalar
: Initialization value
-
template<typename
U
>
inlineVector
(std::initializer_list<U> ilist)¶ Constructor for arbitrary list initialization.
The type
U
must define a cast toDataType
.- Template Parameters
U
: Scalar type
- Parameters
ilist
: Initializer list
-
template<typename
U
>
inlineVector
(const std::vector<U> &vec)¶ Constructor to initialize data from
std::vector
The type
U
must define a cast toDataType
.- Template Parameters
U
: Scalar type
- Parameters
vec
: Initializer vector
-
template<typename
U
, size_tDIMU
>
inlineVector
(const std::array<U, DIMU> &ary)¶ Constructor to initialize data from arbitrary
std::array
The type
U
must define a cast toDataType
. IfDIMU > DIM
only the firstDIM
elements will be copied. IfDIMU < DIM
the missing elements will be initialized to zero.- Template Parameters
U
: Scalar typeDIMU
: Array dimension
- Parameters
ary
: Initializer array
-
template<typename
U
>
inline explicitVector
(const U *ptr, size_t n)¶ Constructor to initialize data from arbitrary pointer.
The type
U
must define a cast toDataType
. Ifn > DIM
only the firstDIM
elements will be copied. Ifn < DIM
the missing elements will be initialized to zero.- Template Parameters
U
: Scalar type
- Parameters
ptr
: Pointer to first elementn
: Number of elements to copy
-
~Vector
() = default¶ Default destructor.
-
template<typename
U
, size_tDIMU
>
inline Vector &operator=
(const Vector<U, DIMU> &c)¶ Copy assignment operator for any other Vector type.
The type
U
must define a cast toDataType
. IfDIMU > DIM
only the firstDIM
elements will be copied. IfDIMU < DIM
the missing elements in this vector will not be modified.- Template Parameters
U
: Scalar typeDIMU
: Vector dimension
- Parameters
c
: Source vector
-
inline size_t
size
() const¶ Size of vector.
- Return
Size of vector (static)
-
inline DataType *
data
()¶ Get pointer to raw data.
- Return
Pointer to first element
-
inline const DataType *
data
() const¶ Get pointer to raw data.
- Return
const
pointer to first element
-
inline ArrayType &
getArray
()¶ Get underlying array.
- Return
std::array
-
inline const ArrayType &
getArray
() const¶ Get underlying array.
- Return
const std::array
-
inline DataType &
operator[]
(const size_t i)¶ Data access interface.
- Return
Reference to element
- Parameters
i
: Vector element
-
inline const DataType &
operator[]
(const size_t i) const¶ Data access interface.
- Return
const
reference to element- Parameters
i
: Vector element
-
inline explicit
operator ArrayType
() const¶ Cast operator.
Cast to
std::array
-
inline explicit
operator DataType*
()¶ Cast operator.
Cast to pointer pointing to the first array element
-
inline bool
operator==
(const Vector &other) const¶ Equality operator.
A Vector is equal to another if they are equal component-wise.
-
inline bool
operator<
(const Vector &other) const¶ Less than operator.
A Vector is smaller than another if all components are less than the corresponding components of the other Vector.
-
inline bool
operator>
(const Vector &other) const¶ Greater than operator.
A Vector is larger than another if all components are greater than the corresponding components of the other Vector.
-
inline bool
operator<=
(const Vector &other) const¶ Less-equal than operator.
A Vector is smaller or equal than another if all components are less or equal than the corresponding components of the other Vector.
-
inline bool
operator>=
(const Vector &other) const¶ Greater-equal than operator.
A Vector is larger or equal than another if all components are greater or equal than the corresponding components of the other Vector.
-
inline DataType
normsq
() const¶ Squared Euclidean vector norm.
-
inline DataType
norm
() const¶ Euclidean vector norm (L2)
-
inline DataType
normL2
() const¶ Vector L2 norm (alias for
norm()
)
-
inline DataType
normL1
() const¶ Vector L1 norm.
-
inline DataType
normLinf
() const¶ Vector maximum norm.
-
inline DataType
sum
() const¶ Sum of vector components.
-
inline DataType
prod
() const¶ Product of vector components.
-
inline DataType
min
() const¶ Minimum vector component.
-
inline DataType
max
() const¶ Maximum vector component.
-
inline size_t
argmin
() const¶ Index of minimum component.
-
inline size_t
argmax
() const¶ Index of maximum component.