Stratax 0.3.1
Loading...
Searching...
No Matches
stratax::container::Vector< T > Class Template Reference

One-dimensional owning array of numeric values. More...

#include <Vector.hpp>

Inheritance diagram for stratax::container::Vector< T >:
Collaboration diagram for stratax::container::Vector< T >:

Public Types

using value_type = typename core::ArrayBase< T >::value_type
 Stored element type inherited from ArrayBase.
 
using size_type = typename core::ArrayBase< T >::size_type
 Unsigned type used for element counts and indices.
 
using difference_type = typename core::ArrayBase< T >::difference_type
 Signed type used for checked indices and iterator distances.
 
using reference = typename core::ArrayBase< T >::reference
 Mutable element reference type.
 
using const_reference = typename core::ArrayBase< T >::const_reference
 Read-only element reference type.
 
using pointer = typename core::ArrayBase< T >::pointer
 Mutable element pointer type.
 
using const_pointer = typename core::ArrayBase< T >::const_pointer
 Read-only element pointer type.
 
using iterator = typename core::ArrayBase< T >::iterator
 Mutable contiguous random-access iterator type.
 
using const_iterator = typename core::ArrayBase< T >::const_iterator
 Read-only contiguous random-access iterator type.
 
using reverse_iterator = typename core::ArrayBase< T >::reverse_iterator
 Mutable reverse iterator type.
 
using const_reverse_iterator = typename core::ArrayBase< T >::const_reverse_iterator
 Read-only reverse iterator type.
 
- Public Types inherited from stratax::core::ArrayBase< T >
using value_type = typename Buffer< T >::value_type
 Stored element type.
 
using size_type = typename Buffer< value_type >::size_type
 Unsigned type used for element counts and indices.
 
using difference_type = typename Buffer< value_type >::difference_type
 Signed type used for checked indices and iterator distances.
 
using reference = typename Buffer< value_type >::reference
 Mutable element reference type.
 
using const_reference = typename Buffer< value_type >::const_reference
 Read-only element reference type.
 
using pointer = typename Buffer< value_type >::pointer
 Mutable element pointer type.
 
using const_pointer = typename Buffer< value_type >::const_pointer
 Read-only element pointer type.
 
using iterator = typename Buffer< value_type >::iterator
 Mutable contiguous random-access iterator type.
 
using const_iterator = typename Buffer< value_type >::const_iterator
 Read-only contiguous random-access iterator type.
 
using reverse_iterator = typename Buffer< value_type >::reverse_iterator
 Mutable reverse iterator type.
 
using const_reverse_iterator = typename Buffer< value_type >::const_reverse_iterator
 Read-only reverse iterator type.
 

Public Member Functions

 Vector (size_type size)
 Constructs a value-initialized vector with size elements.
 
 Vector (const core::Shape &shape)
 Constructs a value-initialized vector from a rank-one shape.
 
 Vector (size_type size, const_reference value)
 Constructs a vector containing size copies of value.
 
 Vector (std::initializer_list< value_type > list)
 Constructs a vector by copying an initializer list.
 
 Vector ()
 Constructs an empty rank-one vector.
 
void swap (Vector &other) noexcept
 Exchanges storage and layout metadata with other.
 
- Public Member Functions inherited from stratax::core::ArrayBase< T >
size_type size () const noexcept
 Returns the number of stored elements.
 
bool empty () const noexcept
 Reports whether no elements are stored.
 
size_type rank () const noexcept
 Returns the number of logical dimensions.
 
const Shapeshape () const noexcept
 Returns the logical shape metadata.
 
const Shapestrides () const noexcept
 Returns the row-major stride metadata.
 
pointer data () noexcept
 Returns a pointer to contiguous mutable element storage.
 
const_pointer data () const noexcept
 Returns a pointer to contiguous read-only element storage.
 
reference front ()
 Returns the first element.
 
const_reference front () const
 Returns the first element.
 
reference back ()
 Returns the final element.
 
const_reference back () const
 Returns the final element.
 
reference operator[] (size_type index) noexcept
 Returns an element without bounds checking.
 
const_reference operator[] (size_type index) const noexcept
 Returns an element without bounds checking.
 
reference at (difference_type index)
 Returns an element using checked, Python-style flat indexing.
 
const_reference at (difference_type index) const
 Returns an element using checked, Python-style flat indexing.
 
iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
const_iterator begin () const noexcept
 Returns a const iterator to the first element.
 
const_iterator cbegin () const noexcept
 Returns a const iterator to the first element.
 
iterator end () noexcept
 Returns a mutable iterator past the final element.
 
const_iterator end () const noexcept
 Returns a const iterator past the final element.
 
const_iterator cend () const noexcept
 Returns a const iterator past the final element.
 
reverse_iterator rbegin () noexcept
 Returns a mutable reverse iterator to the final element.
 
const_reverse_iterator rbegin () const noexcept
 Returns a const reverse iterator to the final element.
 
const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator to the final element.
 
reverse_iterator rend () noexcept
 Returns the past-the-end mutable reverse iterator.
 
const_reverse_iterator rend () const noexcept
 Returns the past-the-end const reverse iterator.
 
const_reverse_iterator crend () const noexcept
 Returns the past-the-end const reverse iterator.
 
void fill (const_reference value)
 Assigns value to every stored element.
 
void swap (ArrayBase &other) noexcept
 Exchanges storage and layout metadata with other.
 

Friends

void swap (Vector &lhs, Vector &rhs) noexcept
 Exchanges two vectors using argument-dependent lookup.
 

Additional Inherited Members

- Static Public Member Functions inherited from stratax::core::ArrayBase< T >
static constexpr std::string_view dtype () noexcept
 Returns the canonical name of the stored element dtype.
 
- Protected Member Functions inherited from stratax::core::ArrayBase< T >
 ArrayBase (const Shape &shape)
 Constructs value-initialized storage for shape.
 
 ArrayBase (const Shape &shape, const_reference value)
 Constructs storage filled with value for shape.
 
 ArrayBase (const Shape &shape, Buffer< value_type > &&buffer)
 Adopts an existing buffer for shape.
 
template<typename IndexContainer >
size_type normalized_flat_offset (const IndexContainer &raw_indices) const
 Converts checked signed multidimensional indices to a flat offset.
 

Detailed Description

template<typename T>
requires DType<T>
class stratax::container::Vector< T >

One-dimensional owning array of numeric values.

Forward declaration of the rank-one dtype array container.

Vector specializes core::ArrayBase for rank-one data. Elements are stored contiguously, while the inherited shape and strides describe a row-major layout whose sole stride is one. The class inherits flat checked and unchecked access, iteration, metadata access, and modifiers from ArrayBase.

Template Parameters
TElement type satisfying the DType concept.
Invariants
Example
stratax::container::Vector<double> values{1.0, 2.0, 3.0};
values[0] = 4.0; // unchecked access
values.at(-1); // 3.0; negative indices count from the end
values.fill(2.0);
One-dimensional owning array of numeric values.
Definition Vector.hpp:44
reference at(difference_type index)
Returns an element using checked, Python-style flat indexing.
See also
core::ArrayBase
core::Shape

Definition at line 43 of file Vector.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using stratax::container::Vector< T >::const_iterator = typename core::ArrayBase<T>::const_iterator

Read-only contiguous random-access iterator type.

Definition at line 63 of file Vector.hpp.

◆ const_pointer

template<typename T >
using stratax::container::Vector< T >::const_pointer = typename core::ArrayBase<T>::const_pointer

Read-only element pointer type.

Definition at line 59 of file Vector.hpp.

◆ const_reference

template<typename T >
using stratax::container::Vector< T >::const_reference = typename core::ArrayBase<T>::const_reference

Read-only element reference type.

Definition at line 55 of file Vector.hpp.

◆ const_reverse_iterator

template<typename T >
using stratax::container::Vector< T >::const_reverse_iterator = typename core::ArrayBase<T>::const_reverse_iterator

Read-only reverse iterator type.

Definition at line 67 of file Vector.hpp.

◆ difference_type

template<typename T >
using stratax::container::Vector< T >::difference_type = typename core::ArrayBase<T>::difference_type

Signed type used for checked indices and iterator distances.

Definition at line 51 of file Vector.hpp.

◆ iterator

template<typename T >
using stratax::container::Vector< T >::iterator = typename core::ArrayBase<T>::iterator

Mutable contiguous random-access iterator type.

Definition at line 61 of file Vector.hpp.

◆ pointer

template<typename T >
using stratax::container::Vector< T >::pointer = typename core::ArrayBase<T>::pointer

Mutable element pointer type.

Definition at line 57 of file Vector.hpp.

◆ reference

template<typename T >
using stratax::container::Vector< T >::reference = typename core::ArrayBase<T>::reference

Mutable element reference type.

Definition at line 53 of file Vector.hpp.

◆ reverse_iterator

template<typename T >
using stratax::container::Vector< T >::reverse_iterator = typename core::ArrayBase<T>::reverse_iterator

Mutable reverse iterator type.

Definition at line 65 of file Vector.hpp.

◆ size_type

template<typename T >
using stratax::container::Vector< T >::size_type = typename core::ArrayBase<T>::size_type

Unsigned type used for element counts and indices.

Definition at line 49 of file Vector.hpp.

◆ value_type

template<typename T >
using stratax::container::Vector< T >::value_type = typename core::ArrayBase<T>::value_type

Stored element type inherited from ArrayBase.

Definition at line 47 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/5]

template<typename T >
stratax::container::Vector< T >::Vector ( size_type  size)
inlineexplicit

Constructs a value-initialized vector with size elements.

Parameters
sizeNumber of elements to allocate.
Exceptions
std::bad_allocIf storage allocation fails.
Anyexception thrown while value-initializing a value_type.
Complexity
O(size).

Definition at line 76 of file Vector.hpp.

◆ Vector() [2/5]

template<typename T >
stratax::container::Vector< T >::Vector ( const core::Shape shape)
inlineexplicit

Constructs a value-initialized vector from a rank-one shape.

Parameters
shapeShape whose only dimension determines the vector size.
Exceptions
Exceptions::RankErrorIf shape.rank() != 1.
std::bad_allocIf storage allocation fails.
Anyexception thrown while value-initializing a value_type.
Complexity
O(shape.elements()).

Definition at line 88 of file Vector.hpp.

◆ Vector() [3/5]

template<typename T >
stratax::container::Vector< T >::Vector ( size_type  size,
const_reference  value 
)
inline

Constructs a vector containing size copies of value.

Parameters
sizeNumber of elements to allocate.
valueValue copied into each element.
Exceptions
std::bad_allocIf storage allocation fails.
Anyexception thrown by value_type's copy constructor.
Complexity
O(size).

Definition at line 105 of file Vector.hpp.

◆ Vector() [4/5]

template<typename T >
stratax::container::Vector< T >::Vector ( std::initializer_list< value_type list)
inline

Constructs a vector by copying an initializer list.

Parameters
listElements in vector order.
Exceptions
std::bad_allocIf storage allocation fails.
Anyexception thrown by value_type's copy constructor.
Complexity
O(list.size()).

Definition at line 116 of file Vector.hpp.

◆ Vector() [5/5]

template<typename T >
stratax::container::Vector< T >::Vector ( )
inline

Constructs an empty rank-one vector.

The resulting shape is {0} rather than a rank-zero shape.

Complexity
O(1).

Definition at line 127 of file Vector.hpp.

Member Function Documentation

◆ swap()

template<typename T >
void stratax::container::Vector< T >::swap ( Vector< T > &  other)
inlinenoexcept

Exchanges storage and layout metadata with other.

Parameters
otherVector to exchange with this vector.
Complexity
O(1).

Definition at line 134 of file Vector.hpp.

Friends And Related Symbol Documentation

◆ swap

template<typename T >
void swap ( Vector< T > &  lhs,
Vector< T > &  rhs 
)
friend

Exchanges two vectors using argument-dependent lookup.

Parameters
lhsFirst vector.
rhsSecond vector.
Complexity
O(1).

Definition at line 145 of file Vector.hpp.


The documentation for this class was generated from the following file: