anpcpp 0.1.0
Analytic Network Process computational library
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
anpcpp::Vector Class Reference

One-dimensional array of doubles with element-wise arithmetic. More...

#include <matrix.hpp>

Public Member Functions

 Vector ()=default
 Default-constructs an empty vector.
 
 Vector (std::size_t size, double fill=0.0)
 Constructs a vector of the given length.
 
 Vector (const Vector &)=default
 Copy constructor (deep-copies element storage).
 
 Vector (Vector &&) noexcept=default
 Move constructor.
 
Vectoroperator= (const Vector &)=default
 Copy assignment.
 
Vectoroperator= (Vector &&) noexcept=default
 Move assignment.
 
std::size_t size () const noexcept
 
bool empty () const noexcept
 
double & operator[] (std::size_t i)
 Mutable element access.
 
const double & operator[] (std::size_t i) const
 Const element access.
 
double * data () noexcept
 
const double * data () const noexcept
 
Vector operator+ (const Vector &other) const
 Element-wise addition.
 
Vector operator- (const Vector &other) const
 Element-wise subtraction.
 
Vector operator* (double scalar) const
 Scalar multiplication (each element times scalar).
 
Vectoroperator+= (const Vector &other)
 In-place element-wise addition.
 
Vectoroperator-= (const Vector &other)
 In-place element-wise subtraction.
 
Vectoroperator*= (double scalar)
 In-place scalar multiplication.
 
double sum () const
 
void normalize ()
 Divides each element by sum(); no-op if sum is zero.
 
Vector normalized () const
 
bool is_equal (const Vector &other, double abs_tol=1e-12) const
 Exact equality within absolute tolerance.
 
bool is_near (const Vector &other, double abs_tol=1e-9, double rel_tol=1e-9) const
 Approximate equality (absolute and relative tolerances).
 

Friends

Vector operator* (double scalar, const Vector &v)
 Scalar multiplication from the left (scalar * v).
 

Detailed Description

One-dimensional array of doubles with element-wise arithmetic.

Constructor & Destructor Documentation

◆ Vector()

anpcpp::Vector::Vector ( std::size_t  size,
double  fill = 0.0 
)
explicit

Constructs a vector of the given length.

Parameters
sizeNumber of elements.
fillInitial value for every element (default 0).

Member Function Documentation

◆ data() [1/2]

const double * anpcpp::Vector::data ( ) const
inlinenoexcept
Returns
Pointer to contiguous element storage (const).

◆ data() [2/2]

double * anpcpp::Vector::data ( )
inlinenoexcept
Returns
Pointer to contiguous element storage (mutable).

◆ empty()

bool anpcpp::Vector::empty ( ) const
inlinenoexcept
Returns
True if size() is zero.

◆ is_equal()

bool anpcpp::Vector::is_equal ( const Vector other,
double  abs_tol = 1e-12 
) const

Exact equality within absolute tolerance.

Parameters
otherVector to compare.
abs_tolMaximum absolute difference per element.

◆ is_near()

bool anpcpp::Vector::is_near ( const Vector other,
double  abs_tol = 1e-9,
double  rel_tol = 1e-9 
) const

Approximate equality (absolute and relative tolerances).

Parameters
otherVector to compare.
abs_tolAbsolute tolerance per element.
rel_tolRelative tolerance scaled by element magnitudes.

◆ normalized()

Vector anpcpp::Vector::normalized ( ) const
Returns
A copy of this vector with elements L1-normalized.

◆ operator+()

Vector anpcpp::Vector::operator+ ( const Vector other) const

Element-wise addition.

Exceptions
DimensionErroron size mismatch.

◆ operator+=()

Vector & anpcpp::Vector::operator+= ( const Vector other)

In-place element-wise addition.

Exceptions
DimensionErroron size mismatch.

◆ operator-()

Vector anpcpp::Vector::operator- ( const Vector other) const

Element-wise subtraction.

Exceptions
DimensionErroron size mismatch.

◆ operator-=()

Vector & anpcpp::Vector::operator-= ( const Vector other)

In-place element-wise subtraction.

Exceptions
DimensionErroron size mismatch.

◆ operator[]() [1/2]

double & anpcpp::Vector::operator[] ( std::size_t  i)

Mutable element access.

Parameters
iZero-based index.
Returns
Reference to element i.
Exceptions
DimensionErrorif i is out of range.

◆ operator[]() [2/2]

const double & anpcpp::Vector::operator[] ( std::size_t  i) const

Const element access.

Parameters
iZero-based index.
Returns
Const reference to element i.
Exceptions
DimensionErrorif i is out of range.

◆ size()

std::size_t anpcpp::Vector::size ( ) const
inlinenoexcept
Returns
Number of elements.

◆ sum()

double anpcpp::Vector::sum ( ) const
Returns
Sum of all elements.

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