Vector¶
-
template<Number ElemType, DataLocation Location, template<typename, typename> typename Storage>
class Vector : public HighFM::MatrixBase<Vector<ElemType, Location, Storage>>, public Storage<ElemType, Location>¶ An object representing a vector in Linear Algebra. Depending on the
Storage
parameter, this object will be referred to either asVectorMap
(whenStorage
is set to DataMap) or as justVector
(whenStorage
is set to Array).Creating a new object:
using namespace HighFM; Vector<int> vec1; // Creates an empty column vector Vector<double> vec2(10); // Creates a column vector with 10 doubles initialized at 0 Vector<double> vec3(10, 3.4); // Creates a row vector with 10 doubles initialized at 3.4 Vector<double> vec4 = vec2; // Creates a copy of the vec2 VectorMap<double> vec_map1(vec4.mat_data()); // Creates a data map to vec4 VectorMap<double> vec_map2({.buffer = vec4.data(), .size = vec4.size()}); // Creates a data map to vec4 (is equivalent to the above)
Accessing the elements:
Vector<double> vec(10); vec(1) = 10; // Access element at position (1) vec[2] = 20; // Access element at position (1) and (2) vec({1, 6}) = 5; // Creates a slice (entries: 1 → 6) from the vector
- Template Parameters:
Constructor
-
template<ResizableContainer S = storage>
Vector(index_t size, ElemType val = ElemType(0))¶ Creates a Vector and fills with
val
.Warning
This constructor is only available when using Array as
Storage
.- Parameters:
size – [in] vector size
val – [in] value to initialize the
Vector
with.
-
Vector(VectorData<ElemType> data)¶
Maps the Vector to an external container when using DataMap as
Storage
. Otherwise, creates a new Vector and then copies the data from the external container.- Parameters:
data – [in] struct containing the information about the container
-
template<DataLocation OtherLoc, template<typename, typename> typename OtherStorage>
Vector(const Vector<ElemType, OtherLoc, OtherStorage> &other)¶ Creates a Vector from an
other
Vector. When using DataMap asStorage
, this will just duplicate the map without copying the data.- Parameters:
other – [in] another Vector to use as the data source.
-
template<template<typename, typename> typename OtherStorage, ResizableContainer S = storage>
Vector(const SparseVector<ElemType, Location, OtherStorage> &sparse_vec)¶ Creates a new Vector from a SparseVector.
Warning
This constructor is only available when using Array as
Storage
.- Parameters:
sparse_vec – [in] another Vector to use as the data source
- Returns:
*this
.
Destructor
-
virtual ~Vector() = default¶
Default destructor.
Assignment
-
template<Number T>
Vector &operator=(T scalar)¶ Sets all elements in the container to
scalar
.- Parameters:
scalar – [in] scalar to use as the data source
- Returns:
*this
.
-
template<DataLocation OtherLoc, template<typename, typename> typename OtherStorage>
Vector &operator=(const Vector<ElemType, OtherLoc, OtherStorage> &other)¶ Copies the content from an
other
Vector to this container.- Parameters:
other – [in] another Vector to use as the data source
- Returns:
*this
.
-
template<template<typename, typename> typename OtherStorage>
Vector &operator=(const SparseVector<ElemType, Location, OtherStorage> &sparse_vec)¶ Copies the content from an
other
Vector to this container.- Parameters:
sparse_vec – [in] another Vector to use as the data source
- Returns:
*this
.
Element Access
-
ElemType &operator()(index_t idx)¶
Accesses element at
idx
position.- Parameters:
idx – [in] position of the element to return
- Returns:
A reference to requested element
Capacity
Modifiers
-
internal::ConjugateOp<Vector> conj() const¶
- Returns:
An abstract expression representing the conjugate of the Vector. If the matrix is real, this is a noop.
-
void swap(Vector &other) noexcept¶
Swaps the Vector content with an
other
Vector, including any memory allocation (if applicable).- Parameters:
other – [in] another Vector to exchange content with.
-
template<RemappableContainer S = storage>
void map_to(VectorData<ElemType> data)¶ Replaces the managed container.
Note
This routine is only available when using DataMap as
Storage
.- Parameters:
data – [in] a struct containing the pointer and size of the container
-
template<template<typename, typename> typename OtherStorage, RemappableContainer S = storage>
void map_to(const Vector<ElemType, Location, OtherStorage> &other)¶ Replaces the managed container.
Note
This routine is only available when using DataMap as
Storage
.- Parameters:
other – [in] another Vector
-
VectorData<ElemType> mat_data() const¶
- Returns:
a simple struct with a pointer to the container and its dimensions.
-
template<typename T>
struct VectorData¶ A simple struct storing the data of a dense vector.