Skip to content

Class Vector

ClassList > Vector

Represents a vector.

  • #include <Vector.hpp>

Public Attributes

Type Name
Comm & comm

Public Functions

Type Name
Vector (Comm & comm, unsigned int blocks, unsigned int block_size, std::string row_or_col, bool global_sizes=false, bool SOTI_ordering=true)
Constructor for the Vector class.
Vector (Vector & vec, bool deep_copy)
Copy constructor for the Vector class.
Vector (Vector & vec)
Copy constructor for the Vector class.
Vector (Vector && vec) noexcept
Move constructor for the Vector class.
Vector add_scalar (double scalar)
Adds a scalar to each element of this vector.
void add_scalar_inplace (double scalar)
Performs an in-place scalar addition (x_i = x_i + scalar).
void axpby (double alpha, double beta, Vector & x)
Computes the operation y = alpha * x + beta * y.
void axpy (double alpha, Vector & x)
Computes the operation y = alpha * x + y.
void copy_to (Vector & x)
Copies a vector to another vector.
double dot (Vector & x)
Computes the dot product of the vector with another vector.
Vector elementwise_abs ()
Computes the element-wise absolute value of this vector.
void elementwise_abs_inplace ()
Performs an in-place element-wise absolute value operation.
Vector elementwise_divide (Vector & other)
Computes the element-wise division of this vector by another.
void elementwise_divide_inplace (Vector & other)
Performs an in-place element-wise division by another vector.
Vector elementwise_inverse ()
Computes the element-wise inverse (1.0 / x_i) of this vector.
void elementwise_inverse_inplace ()
Performs an in-place element-wise inversion (x_i = 1.0 / x_i).
Vector elementwise_max (Vector & other)
Computes the element-wise maximum of this vector and another.
void elementwise_max_inplace (Vector & other)
Performs an in-place element-wise maximum with another vector.
Vector elementwise_min (Vector & other)
Computes the element-wise minimum of this vector and another.
void elementwise_min_inplace (Vector & other)
Performs an in-place element-wise minimum with another vector.
Vector elementwise_multiply (Vector & other)
Computes the element-wise product of this vector and another.
Vector elementwise_multiply_add (Vector & y, Vector & z)
Computes the fused element-wise multiply-add: this_i * y_i + z_i.
void elementwise_multiply_add_inplace (Vector & y, Vector & z)
Performs an in-place fused element-wise multiply-add: this_i = this_i * y_i + z_i.
void elementwise_multiply_inplace (Vector & other)
Performs an in-place element-wise multiplication with another vector.
Vector elementwise_sign ()
Computes the element-wise sign of this vector.
void elementwise_sign_inplace ()
Performs an in-place element-wise sign operation.
Vector extend (int new_block_size)
Extends the vector to a new block size.
void extend (Vector & out)
Extends the vector to a new block size.
unsigned int get_block_size ()
Gets the size of each block without padding.
int get_checksum ()
double * get_d_vec ()
Gets the pointer to the vector data.
unsigned int get_glob_num_blocks ()
Gets the global number of blocks.
unsigned int get_num_blocks ()
Gets the number of blocks.
unsigned int get_padded_size ()
Gets the size of each block with padding.
std::string get_row_or_col ()
Gets the row or column descriptor.
double global_max ()
Computes the global maximum element across the distributed vector.
double global_min ()
Computes the global minimum element across the distributed vector.
void init_vec ()
Initializes the vector.
void init_vec_consecutive ()
Initializes the vector with consecutive integers.
void init_vec_doubles ()
Initializes the vector with double precision floating point numbers (used for precision testing).
void init_vec_from_file (std::string filename, int checksum=0, bool QoI=false)
Initializes the vector from a file.
void init_vec_ones ()
Initializes the vector with all ones.
void init_vec_zeros ()
Initializes the vector with all zeros.
bool is_SOTI_ordered ()
Checks if the vector is using SOTI ordering.
bool is_initialized ()
Checks if the vector data is initialized.
Vector max_scalar (double scalar)
Computes the element-wise maximum of this vector and a scalar.
void max_scalar_inplace (double scalar)
Performs an in-place element-wise maximum with a scalar.
Vector min_scalar (double scalar)
Computes the element-wise minimum of this vector and a scalar.
void min_scalar_inplace (double scalar)
Performs an in-place element-wise minimum with a scalar.
double norm (int order=2, std::string name="")
Computes the norm of the vector.
bool on_grid ()
Checks if the calling process has the vector data.
Vector operator* (double alpha)
Scalar multiplication operator for the Vector class.
Vector operator* (Vector & other)
Element-wise multiplication operator for the Vector class.
Vector operator* (Vector && other)
R-value overload to allow chaining (e.g., y * (1.0 / x))
Vector & operator*= (double alpha)
Scalar Multiplicative assignment operator for the Vector class.
Vector & operator*= (Vector & other)
Element-wise multiplicative assignment operator for the Vector class.
Vector operator+ (Vector & x)
Addition operator for the Vector class.
Vector operator+ (double scalar)
Scalar addition operator ( Vector + scalar).
Vector & operator+= (Vector & x)
Additive assignment operator for the Vector class.
Vector & operator+= (double scalar)
In-place scalar addition operator ( Vector += scalar).
Vector operator- (Vector & x)
Subtraction operator for the Vector class.
Vector operator- (double scalar)
Scalar subtraction operator ( Vector - scalar).
Vector & operator-= (Vector & x)
Subtractive assignment operator for the Vector class.
Vector & operator-= (double scalar)
In-place scalar subtraction operator ( Vector -= scalar).
Vector operator/ (double alpha)
Scalar division operator for the Vector class.
Vector operator/ (Vector & other)
Element-wise division operator for the Vector class.
Vector operator/ (Vector && other)
R-value overload to allow chaining (e.g., y / (1.0 / x))
Vector & operator/= (double alpha)
Scalar Division assignment operator for the Vector class.
Vector & operator/= (Vector & other)
Element-wise division assignment operator for the Vector class.
Vector & operator= (Vector & vec)
Copy assignment operator for the Vector class.
Vector & operator= (Vector && vec)
Move assignment operator for the Vector class.
Vector pow (double exponent)
Computes the element-wise power (x_i ^ p) of this vector.
void pow_inplace (double exponent)
Performs an in-place element-wise power operation (x_i = x_i ^ p).
void print (std::string name="")
Prints the vector.
Vector resize (int new_block_size)
Resizes the vector to a new block size.
void resize (Vector & out)
Resizes the vector to a new block size.
void save (std::string filename, bool QoI=false)
Saves the vector to a file (HDF5 format).
void scale (double alpha)
Scales the vector by a constant (in-place).
void set_checksum (int checksum)
void set_d_vec (double * vec)
Sets the pointer to the vector data.
Vector shrink (int new_block_size)
Shrinks the vector to a new block size.
void shrink (Vector & out)
Shrinks the vector to a new block size.
Vector waxpby (double alpha, double beta, Vector & x)
Computes the operation w = alpha * x + beta * y.
Vector waxpy (double alpha, Vector & x)
Computes the operation w = alpha * x + y.
Vector wscale (double alpha)
Scales the vector by a constant (out-of-place).
~Vector ()
Destructor for the Vector class. Frees the memory allocated for the vector data.

Public Attributes Documentation

variable comm

Comm& Vector::comm;

Reference to the communication object.


Public Functions Documentation

function Vector [1/4]

Constructor for the Vector class.

Vector::Vector (
    Comm & comm,
    unsigned int blocks,
    unsigned int block_size,
    std::string row_or_col,
    bool global_sizes=false,
    bool SOTI_ordering=true
) 

Parameters:

  • comm The Comm object (passed as reference).
  • blocks The number of blocks (local or global based on value of global_sizes).
  • block_size The size of each block without padding.
  • row_or_col Indicates whether the vector is row or column.
  • global_sizes Flag indicating whether the sizes are global.
  • SOTI_ordering Flag indicating whether to use SOTI ordering.

function Vector [2/4]

Copy constructor for the Vector class.

Vector::Vector (
    Vector & vec,
    bool deep_copy
) 

Parameters:

  • vec The Vector object to be copied.
  • deep_copy Flag indicating whether to perform a deep copy.

function Vector [3/4]

Copy constructor for the Vector class.

inline Vector::Vector (
    Vector & vec
) 

Parameters:

  • vec The Vector object to be copied.

function Vector [4/4]

Move constructor for the Vector class.

inline Vector::Vector (
    Vector && vec
) noexcept

Parameters:

  • vec The Vector object to be moved.

function add_scalar

Adds a scalar to each element of this vector.

Vector Vector::add_scalar (
    double scalar
) 

Parameters:

  • scalar The scalar value to add.

Returns:

A new vector containing the shifted elements.


function add_scalar_inplace

Performs an in-place scalar addition (x_i = x_i + scalar).

void Vector::add_scalar_inplace (
    double scalar
) 

Parameters:

  • scalar The scalar value to add.

function axpby

Computes the operation y = alpha * x + beta * y.

void Vector::axpby (
    double alpha,
    double beta,
    Vector & x
) 

Parameters:

  • alpha The constant by which to scale the vector x.
  • beta The constant by which to scale the vector y.
  • x The vector to be added.

function axpy

Computes the operation y = alpha * x + y.

void Vector::axpy (
    double alpha,
    Vector & x
) 

Parameters:

  • alpha The constant by which to scale the vector x.
  • x The vector to be added.

function copy_to

Copies a vector to another vector.

void Vector::copy_to (
    Vector & x
) 

Parameters:

  • x The vector to be copied to.

function dot

Computes the dot product of the vector with another vector.

double Vector::dot (
    Vector & x
) 

Parameters:

  • x The vector with which to compute the dot product.

Returns:

The dot product of the two vectors. All ranks have the global dot product.


function elementwise_abs

Computes the element-wise absolute value of this vector.

Vector Vector::elementwise_abs () 

Returns:

A new vector containing |x_i|.


function elementwise_abs_inplace

Performs an in-place element-wise absolute value operation.

void Vector::elementwise_abs_inplace () 


function elementwise_divide

Computes the element-wise division of this vector by another.

Vector Vector::elementwise_divide (
    Vector & other
) 

Parameters:

  • other The vector to divide by.

Returns:

A new vector containing the element-wise quotient.


function elementwise_divide_inplace

Performs an in-place element-wise division by another vector.

void Vector::elementwise_divide_inplace (
    Vector & other
) 

Parameters:

  • other The vector to divide by.

function elementwise_inverse

Computes the element-wise inverse (1.0 / x_i) of this vector.

Vector Vector::elementwise_inverse () 

Returns:

A new vector containing the inverted elements.


function elementwise_inverse_inplace

Performs an in-place element-wise inversion (x_i = 1.0 / x_i).

void Vector::elementwise_inverse_inplace () 


function elementwise_max

Computes the element-wise maximum of this vector and another.

Vector Vector::elementwise_max (
    Vector & other
) 

Parameters:

  • other The vector to compare against.

Returns:

A new vector containing max(x_i, y_i).


function elementwise_max_inplace

Performs an in-place element-wise maximum with another vector.

void Vector::elementwise_max_inplace (
    Vector & other
) 

Parameters:

  • other The vector to compare against.

function elementwise_min

Computes the element-wise minimum of this vector and another.

Vector Vector::elementwise_min (
    Vector & other
) 

Parameters:

  • other The vector to compare against.

Returns:

A new vector containing min(x_i, y_i).


function elementwise_min_inplace

Performs an in-place element-wise minimum with another vector.

void Vector::elementwise_min_inplace (
    Vector & other
) 

Parameters:

  • other The vector to compare against.

function elementwise_multiply

Computes the element-wise product of this vector and another.

Vector Vector::elementwise_multiply (
    Vector & other
) 

Parameters:

  • other The vector to multiply with.

Returns:

A new vector containing the element-wise product.


function elementwise_multiply_add

Computes the fused element-wise multiply-add: this_i * y_i + z_i.

Vector Vector::elementwise_multiply_add (
    Vector & y,
    Vector & z
) 

Parameters:

  • y The vector to multiply with.
  • z The vector to add.

Returns:

A new vector containing the result.


function elementwise_multiply_add_inplace

Performs an in-place fused element-wise multiply-add: this_i = this_i * y_i + z_i.

void Vector::elementwise_multiply_add_inplace (
    Vector & y,
    Vector & z
) 

Parameters:

  • y The vector to multiply with.
  • z The vector to add.

function elementwise_multiply_inplace

Performs an in-place element-wise multiplication with another vector.

void Vector::elementwise_multiply_inplace (
    Vector & other
) 

Parameters:

  • other The vector to multiply with.

function elementwise_sign

Computes the element-wise sign of this vector.

Vector Vector::elementwise_sign () 

Returns:

A new vector containing sign(d_in[i]) in {-1, 0, 1}.


function elementwise_sign_inplace

Performs an in-place element-wise sign operation.

void Vector::elementwise_sign_inplace () 


function extend [1/2]

Extends the vector to a new block size.

Vector Vector::extend (
    int new_block_size
) 

Parameters:

  • new_block_size The new block size.

Returns:

The extended vector.


function extend [2/2]

Extends the vector to a new block size.

void Vector::extend (
    Vector & out
) 

Parameters:

  • out The vector to be extended.

function get_block_size

Gets the size of each block without padding.

inline unsigned int Vector::get_block_size () 

Returns:

The size of each block without padding.


function get_checksum

inline int Vector::get_checksum () 

Returns the checksum for the vector.


function get_d_vec

Gets the pointer to the vector data.

inline double * Vector::get_d_vec () 

Returns:

The pointer to the vector data.


function get_glob_num_blocks

Gets the global number of blocks.

inline unsigned int Vector::get_glob_num_blocks () 

Returns:

The global number of blocks.


function get_num_blocks

Gets the number of blocks.

inline unsigned int Vector::get_num_blocks () 

Returns:

The number of blocks.


function get_padded_size

Gets the size of each block with padding.

inline unsigned int Vector::get_padded_size () 

Returns:

The size of each block with padding.


function get_row_or_col

Gets the row or column descriptor.

inline std::string Vector::get_row_or_col () 

Returns:

The row or column descriptor.


function global_max

Computes the global maximum element across the distributed vector.

double Vector::global_max () 

Returns:

The maximum value over all local and remote elements.


function global_min

Computes the global minimum element across the distributed vector.

double Vector::global_min () 

Returns:

The minimum value over all local and remote elements.


function init_vec

Initializes the vector.

void Vector::init_vec () 


function init_vec_consecutive

Initializes the vector with consecutive integers.

void Vector::init_vec_consecutive () 


function init_vec_doubles

Initializes the vector with double precision floating point numbers (used for precision testing).

void Vector::init_vec_doubles () 


function init_vec_from_file

Initializes the vector from a file.

void Vector::init_vec_from_file (
    std::string filename,
    int checksum=0,
    bool QoI=false
) 

Parameters:

  • filename The name of the file.
  • checksum Checksum for the vector (if applicable).
  • QoI Flag indicating whether the vector is a quantity of interest or regular observation (if applicable).

function init_vec_ones

Initializes the vector with all ones.

void Vector::init_vec_ones () 


function init_vec_zeros

Initializes the vector with all zeros.

void Vector::init_vec_zeros () 


function is_SOTI_ordered

Checks if the vector is using SOTI ordering.

inline bool Vector::is_SOTI_ordered () 

Returns:

True if the vector is using SOTI ordering, false otherwise.


function is_initialized

Checks if the vector data is initialized.

inline bool Vector::is_initialized () 

Returns:

True if the vector data is initialized, false otherwise.


function max_scalar

Computes the element-wise maximum of this vector and a scalar.

Vector Vector::max_scalar (
    double scalar
) 

Parameters:

  • scalar The scalar value broadcast to each element.

Returns:

A new vector containing max(x_i, scalar).


function max_scalar_inplace

Performs an in-place element-wise maximum with a scalar.

void Vector::max_scalar_inplace (
    double scalar
) 

Parameters:

  • scalar The scalar value broadcast to each element.

function min_scalar

Computes the element-wise minimum of this vector and a scalar.

Vector Vector::min_scalar (
    double scalar
) 

Parameters:

  • scalar The scalar value broadcast to each element.

Returns:

A new vector containing min(x_i, scalar).


function min_scalar_inplace

Performs an in-place element-wise minimum with a scalar.

void Vector::min_scalar_inplace (
    double scalar
) 

Parameters:

  • scalar The scalar value broadcast to each element.

function norm

Computes the norm of the vector.

double Vector::norm (
    int order=2,
    std::string name=""
) 

Parameters:

  • order The order of the norm (e.g., "2" for the 2-norm, "1" for the 1-norm, "-1" for the infinity norm).
  • name The name of the vector. Prints the norm if name is not empty.

Returns:

The norm of the vector. All ranks have the global norm.


function on_grid

Checks if the calling process has the vector data.

inline bool Vector::on_grid () 

Returns:

True if the calling process has the vector data, false otherwise.


function operator*

Scalar multiplication operator for the Vector class.

inline Vector Vector::operator* (
    double alpha
) 

Parameters:

  • alpha The constant by which to scale the vector.

Returns:

The scaled vector.


function operator*

Element-wise multiplication operator for the Vector class.

inline Vector Vector::operator* (
    Vector & other
) 

Parameters:

  • other The Vector object to multiply with.

Returns:

A new vector containing the element-wise product.


function operator*

R-value overload to allow chaining (e.g., y * (1.0 / x))

inline Vector Vector::operator* (
    Vector && other
) 


function operator*=

Scalar Multiplicative assignment operator for the Vector class.

inline Vector & Vector::operator*= (
    double alpha
) 

Parameters:

  • alpha The constant by which to scale the vector.

Returns:

The scaled vector.


function operator*=

Element-wise multiplicative assignment operator for the Vector class.

inline Vector & Vector::operator*= (
    Vector & other
) 

Parameters:

  • other The Vector object to multiply with.

Returns:

The modified vector.


function operator+

Addition operator for the Vector class.

inline Vector Vector::operator+ (
    Vector & x
) 

Parameters:

  • x The Vector object to be added.

Returns:

The sum of the two vectors.


function operator+

Scalar addition operator ( Vector + scalar).

inline Vector Vector::operator+ (
    double scalar
) 


function operator+=

Additive assignment operator for the Vector class.

inline Vector & Vector::operator+= (
    Vector & x
) 

Parameters:

  • x The Vector object to be added.

Returns:

The sum of the two vectors.


function operator+=

In-place scalar addition operator ( Vector += scalar).

inline Vector & Vector::operator+= (
    double scalar
) 


function operator-

Subtraction operator for the Vector class.

inline Vector Vector::operator- (
    Vector & x
) 

Parameters:

  • x The Vector object to be subtracted.

Returns:

The difference of the two vectors.


function operator-

Scalar subtraction operator ( Vector - scalar).

inline Vector Vector::operator- (
    double scalar
) 


function operator-=

Subtractive assignment operator for the Vector class.

inline Vector & Vector::operator-= (
    Vector & x
) 

Parameters:

  • x The Vector object to be subtracted.

Returns:

The difference of the two vectors.


function operator-=

In-place scalar subtraction operator ( Vector -= scalar).

inline Vector & Vector::operator-= (
    double scalar
) 


function operator/

Scalar division operator for the Vector class.

inline Vector Vector::operator/ (
    double alpha
) 

Parameters:

  • alpha The constant by which to divide the vector.

Returns:

The scaled vector.


function operator/

Element-wise division operator for the Vector class.

inline Vector Vector::operator/ (
    Vector & other
) 

Parameters:

  • other The Vector object to divide by.

Returns:

A new vector containing the element-wise quotient.


function operator/

R-value overload to allow chaining (e.g., y / (1.0 / x))

inline Vector Vector::operator/ (
    Vector && other
) 


function operator/=

Scalar Division assignment operator for the Vector class.

inline Vector & Vector::operator/= (
    double alpha
) 

Parameters:

  • alpha The constant by which to divide the vector.

Returns:

The scaled vector.


function operator/=

Element-wise division assignment operator for the Vector class.

inline Vector & Vector::operator/= (
    Vector & other
) 

Parameters:

  • other The Vector object to divide by.

Returns:

The modified vector.


function operator=

Copy assignment operator for the Vector class.

Vector & Vector::operator= (
    Vector & vec
) 

Parameters:

  • vec The Vector object to be copied.

Returns:

The copied Vector object.


function operator=

Move assignment operator for the Vector class.

Vector & Vector::operator= (
    Vector && vec
) 

Parameters:

  • vec The Vector object to be moved.

Returns:

The moved Vector object.


function pow

Computes the element-wise power (x_i ^ p) of this vector.

Vector Vector::pow (
    double exponent
) 

Parameters:

  • exponent The power to raise the elements to.

Returns:

A new vector containing the powered elements.


function pow_inplace

Performs an in-place element-wise power operation (x_i = x_i ^ p).

void Vector::pow_inplace (
    double exponent
) 

Parameters:

  • exponent The power to raise the elements to.

function print

Prints the vector.

void Vector::print (
    std::string name=""
) 

Parameters:

  • name The name of the vector.

function resize [1/2]

Resizes the vector to a new block size.

Vector Vector::resize (
    int new_block_size
) 

Parameters:

  • new_block_size The new block size.

Returns:

The resized vector.


function resize [2/2]

Resizes the vector to a new block size.

void Vector::resize (
    Vector & out
) 

Parameters:

  • out The vector to be resized.

function save

Saves the vector to a file (HDF5 format).

void Vector::save (
    std::string filename,
    bool QoI=false
) 

Parameters:

  • filename The name of the file.
  • QoI Flag indicating whether the vector is a quantity of interest vector.

function scale

Scales the vector by a constant (in-place).

void Vector::scale (
    double alpha
) 

Parameters:

  • alpha The constant by which to scale the vector.

function set_checksum

inline void Vector::set_checksum (
    int checksum
) 

Sets the checksum for the vector.


function set_d_vec

Sets the pointer to the vector data.

void Vector::set_d_vec (
    double * vec
) 

Parameters:

  • vec The pointer to the vector data. Must be allocated on the GPU.

function shrink [1/2]

Shrinks the vector to a new block size.

Vector Vector::shrink (
    int new_block_size
) 

Parameters:

  • new_block_size The new block size.

Returns:

The shrunken vector.


function shrink [2/2]

Shrinks the vector to a new block size.

void Vector::shrink (
    Vector & out
) 

Parameters:

  • out The vector to be shrunken.

function waxpby

Computes the operation w = alpha * x + beta * y.

Vector Vector::waxpby (
    double alpha,
    double beta,
    Vector & x
) 

Parameters:

  • alpha The constant by which to scale the vector x.
  • beta The constant by which to scale the vector y.
  • x The vector to be added.

function waxpy

Computes the operation w = alpha * x + y.

Vector Vector::waxpy (
    double alpha,
    Vector & x
) 

Parameters:

  • alpha The constant by which to scale the vector x.
  • x The vector to be added.

function wscale

Scales the vector by a constant (out-of-place).

Vector Vector::wscale (
    double alpha
) 

Parameters:

  • alpha The constant by which to scale the vector.

Returns:

The scaled vector.


function ~Vector

Destructor for the Vector class. Frees the memory allocated for the vector data.

Vector::~Vector () 


Friends Documentation

friend operator*

inline Vector Vector::operator* (
    double alpha,
    Vector & x
) 

friend operator+

Scalar addition operator (scalar + Vector ).

inline Vector Vector::operator+ (
    double scalar,
    Vector & v
) 


friend operator+

inline Vector Vector::operator+ (
    double scalar,
    Vector && v
) 

friend operator-

Scalar subtraction operator (scalar - Vector ). Calculates: scalar - x_i.

inline Vector Vector::operator- (
    double scalar,
    Vector & v
) 


friend operator-

inline Vector Vector::operator- (
    double scalar,
    Vector && v
) 

friend operator/

R-value overload to allow chaining (e.g., 1.0 / (x * y))

inline Vector Vector::operator/ (
    double numerator,
    Vector && v
) 


friend operator/

Allows the syntax: Vector y = 1.0 / x;.

inline Vector Vector::operator/ (
    double numerator,
    Vector & v
) 

Parameters:

  • numerator The scalar numerator (typically 1.0).
  • v The Vector object to invert.

Returns:

A new vector containing (numerator / v_i).



The documentation for this class was generated from the following file src/Vector.hpp