SG++-Doxygen-Documentation
Loading...
Searching...
No Matches
sgpp::base::DataVectorSP Class Reference

A class to store one-dimensional data. More...

#include <DataVectorSP.hpp>

Inheritance diagram for sgpp::base::DataVectorSP:

Public Member Functions

void abs ()
 Sets all elements to their absolute value.
 
void accumulate (const DataVectorSP &vec)
 
void add (const DataVectorSP &vec)
 Adds the values from another DataVectorSP to the current values.
 
size_t append ()
 Appends a new element and returns index of it.
 
size_t append (float value)
 Appends a new element and returns index of new element.
 
void axpy (float a, DataVectorSP &x)
 Adds a*x to current vector.
 
void componentwise_div (const DataVectorSP &vec)
 Divides the current DataVectorSP component-wise by another DataVectorSP.
 
void componentwise_mult (const DataVectorSP &vec)
 Multiplies the current DataVectorSP component-wise with another DataVectorSP.
 
void copyFrom (const DataVectorSP &vec)
 Copies the data from another DataVectorSP vec.
 
 DataVectorSP ()
 Create an empty DataVectorSP.
 
 DataVectorSP (const DataVectorSP &)=default
 Copy constructor.
 
 DataVectorSP (DataVectorSP &&)=default
 Move constructor.
 
 DataVectorSP (float *input, size_t size)
 Create a new DataVectorSP from a float array with size elements.
 
 DataVectorSP (size_t size)
 Create a DataVectorSP with size elements (uninitialized values).
 
 DataVectorSP (size_t size, float value)
 Create a DataVectorSP with size elements and initializes all elements with the same value.
 
 DataVectorSP (std::initializer_list< float > input)
 Create a new DataVector from a std::initializer_list<float>.
 
 DataVectorSP (std::vector< float > input)
 Create a new DataVectorSP from a std::vector<float>.
 
 DataVectorSP (std::vector< int > input)
 Create a new DataVectorSP from a std::vector<int>.
 
float dotProduct (const DataVectorSP &vec) const
 Returns the dot product of the two vectors.
 
float get (size_t i) const
 Returns the i-th element.
 
size_t getNumberNonZero () const
 Determines the number of non-zero elements in the vector.
 
float * getPointer ()
 gets a pointer to the data array
 
const float * getPointer () const
 gets a const pointer to the data array
 
size_t getSize () const
 gets the elements stored in the vector
 
void insert (size_t index, float value)
 Inserts a new element at the given index.
 
float l2Norm () const
 Returns the vector's \(l^2\)-norm, i.e., \(\sqrt{ \sum_i x_i^2 }\).
 
float max () const
 Returns the maximum over all entries.
 
float maxNorm () const
 calculates the vector's max norm
 
float min () const
 Returns the minimum over all entries.
 
void minmax (float *min, float *max) const
 Determines minimum and maximum over all entries.
 
void mult (float scalar)
 multiplies all elements by a constant factor
 
void normalize ()
 Normalizes vector entries to [0,1].
 
void normalize (float border)
 Normalizes vector entries to [border, 1-border].
 
DataVectorSPoperator= (const DataVectorSP &)=default
 Copy assignment operator.
 
DataVectorSPoperator= (DataVectorSP &&)=default
 Move assignment operator.
 
void partitionClasses (float threshold)
 Partitions vector into two classes using a choosen border.
 
void remove (std::vector< size_t > &indexesToRemove)
 Removes indexes form the vector.
 
void resizeZero (size_t nrows)
 Resizes the DataVectorSP to size elements.
 
void restructure (std::vector< size_t > &remainingIndex)
 Resizes the DataVectorSP by removing entries.
 
float RMSNorm () const
 Returns the vector's root mean square (RMS)-norm, i.e., \(\sqrt{ 1/N \sum_{i=1}^N x_i^2 }\).
 
void set (size_t i, float value)
 Sets the element at index i to value.
 
void setAll (float value)
 Sets all values of DataVectorSP to value.
 
void sqr ()
 Squares all elements of the DataVectorSP.
 
void sqrt ()
 Takes the square root of all elements of the DataVectorSP.
 
void sub (const DataVectorSP &vec)
 Subtracts the values from another DataVectorSP of the current values.
 
float sum () const
 Returns the sum of all elements.
 
void toFile (const std::string &fileName) const
 
std::string toString () const
 Returns a description of the DataVectorSP as a string.
 
void toString (std::string &text) const
 Writes the data stored in the DataVectorSP into a string.
 
 ~DataVectorSP ()=default
 Destructor.
 

Static Public Member Functions

static DataVectorSP fromFile (const std::string &fileName)
 
static DataVectorSP fromString (const std::string &serializedVector)
 

Detailed Description

A class to store one-dimensional data.

Typically, an object of type DataVectorSP will contain an array of (hierarchical) coefficients (or surplusses), or the coordinates of a data point at which a sparse grid function should be evaluated.

This is an re-implementation of the standard DataVector for single precision floating point numbers in order to increase support for GPUs.

Constructor & Destructor Documentation

◆ DataVectorSP() [1/9]

sgpp::base::DataVectorSP::DataVectorSP ( )

Create an empty DataVectorSP.

◆ DataVectorSP() [2/9]

sgpp::base::DataVectorSP::DataVectorSP ( const DataVectorSP )
default

Copy constructor.

◆ DataVectorSP() [3/9]

sgpp::base::DataVectorSP::DataVectorSP ( DataVectorSP &&  )
default

Move constructor.

◆ ~DataVectorSP()

sgpp::base::DataVectorSP::~DataVectorSP ( )
default

Destructor.

◆ DataVectorSP() [4/9]

sgpp::base::DataVectorSP::DataVectorSP ( size_t  size)
explicit

Create a DataVectorSP with size elements (uninitialized values).

Parameters
sizeNumber of elements

◆ DataVectorSP() [5/9]

sgpp::base::DataVectorSP::DataVectorSP ( size_t  size,
float  value 
)

Create a DataVectorSP with size elements and initializes all elements with the same value.

Parameters
sizeNumber of elements
valueValue for all entries

◆ DataVectorSP() [6/9]

sgpp::base::DataVectorSP::DataVectorSP ( float *  input,
size_t  size 
)

Create a new DataVectorSP from a float array with size elements.

Parameters
inputfloat array that contains the data
sizenumber of elements

◆ DataVectorSP() [7/9]

sgpp::base::DataVectorSP::DataVectorSP ( std::vector< float >  input)
explicit

Create a new DataVectorSP from a std::vector<float>.

Parameters
inputstd::vector<float> that contains the data

◆ DataVectorSP() [8/9]

sgpp::base::DataVectorSP::DataVectorSP ( std::initializer_list< float >  input)
explicit

Create a new DataVector from a std::initializer_list<float>.

Parameters
inputstd::initializer_list<float> that contains the data

◆ DataVectorSP() [9/9]

sgpp::base::DataVectorSP::DataVectorSP ( std::vector< int >  input)
explicit

Create a new DataVectorSP from a std::vector<int>.

Parameters
inputstd::vector<int> that contains the data

Member Function Documentation

◆ abs()

void sgpp::base::DataVectorSP::abs ( )

Sets all elements to their absolute value.

◆ accumulate()

void sgpp::base::DataVectorSP::accumulate ( const DataVectorSP vec)

◆ add()

void sgpp::base::DataVectorSP::add ( const DataVectorSP vec)

Adds the values from another DataVectorSP to the current values.

Modifies the current values.

Parameters
vecThe DataVectorSP which is added to the current values

Referenced by sgpp::solver::ConjugateGradientsSP::solve().

◆ append() [1/2]

size_t sgpp::base::DataVectorSP::append ( )

Appends a new element and returns index of it.

Returns
Index of new element

References append().

Referenced by append(), sgpp::base::DataMatrixSP::fromString(), and fromString().

◆ append() [2/2]

size_t sgpp::base::DataVectorSP::append ( float  value)

Appends a new element and returns index of new element.

Parameters
valueValue of new element
Returns
Index of new element

◆ axpy()

void sgpp::base::DataVectorSP::axpy ( float  a,
DataVectorSP x 
)

Adds a*x to current vector.

BLAS Level 1 (elementary vector operations) operation: axpy.

Parameters
aA scalar
xReference to the DataVectorSP

Referenced by sgpp::solver::BiCGStabSP::solve().

◆ componentwise_div()

void sgpp::base::DataVectorSP::componentwise_div ( const DataVectorSP vec)

Divides the current DataVectorSP component-wise by another DataVectorSP.

Modifies the current values. Performs

for i from 1 to this.getSize()
this[i] /= vec[i]
size_t getSize() const
gets the elements stored in the vector
Definition DataVectorSP.hpp:362

Note: No check for division by zero!

Parameters
vecthe DataVectorSP which the current DataVectorSP is divided by

◆ componentwise_mult()

void sgpp::base::DataVectorSP::componentwise_mult ( const DataVectorSP vec)

Multiplies the current DataVectorSP component-wise with another DataVectorSP.

Modifies the current values. Performs

for i from 1 to this.getSize()
this[i] *= vec[i]
Parameters
vecthe DataVectorSP which is multiplied to current DataVectorSP

Referenced by l2Norm().

◆ copyFrom()

void sgpp::base::DataVectorSP::copyFrom ( const DataVectorSP vec)

Copies the data from another DataVectorSP vec.

Disregards the number of entries set for the two vectors, i.e., just copies the data entry by entry. If the size matches, the current DataVectorSP is an exact copy of vec. If not, as many elements as possible are copied, and everything else is left untouched.

Parameters
vecThe source DataVectorSP containing the data

◆ dotProduct()

float sgpp::base::DataVectorSP::dotProduct ( const DataVectorSP vec) const

Returns the dot product of the two vectors.

Parameters
vecReference to another vector
Returns
The dot-product

References sum().

Referenced by sgpp::solver::BiCGStabSP::solve(), and sgpp::solver::ConjugateGradientsSP::solve().

◆ fromFile()

DataVectorSP sgpp::base::DataVectorSP::fromFile ( const std::string &  fileName)
static

References f, fileName, and fromString().

◆ fromString()

DataVectorSP sgpp::base::DataVectorSP::fromString ( const std::string &  serializedVector)
static

References append().

Referenced by fromFile().

◆ get()

float sgpp::base::DataVectorSP::get ( size_t  i) const
inline

◆ getNumberNonZero()

size_t sgpp::base::DataVectorSP::getNumberNonZero ( ) const

Determines the number of non-zero elements in the vector.

Returns
The number of non-zero elements

◆ getPointer() [1/2]

float * sgpp::base::DataVectorSP::getPointer ( )

gets a pointer to the data array

Returns
pointer to the data array

◆ getPointer() [2/2]

const float * sgpp::base::DataVectorSP::getPointer ( ) const

gets a const pointer to the data array

Returns
const pointer to the data array

◆ getSize()

◆ insert()

void sgpp::base::DataVectorSP::insert ( size_t  index,
float  value 
)

Inserts a new element at the given index.

Parameters
indexIndex of new element
valueValue of new element

References insert().

Referenced by insert().

◆ l2Norm()

float sgpp::base::DataVectorSP::l2Norm ( ) const

Returns the vector's \(l^2\)-norm, i.e., \(\sqrt{ \sum_i x_i^2 }\).

Returns
The vector's \(l^2\)-norm.

References componentwise_mult(), l2Norm(), and sum().

Referenced by l2Norm().

◆ max()

float sgpp::base::DataVectorSP::max ( ) const

Returns the maximum over all entries.

Returns
global maximum

References max().

Referenced by max(), maxNorm(), and normalize().

◆ maxNorm()

float sgpp::base::DataVectorSP::maxNorm ( ) const

calculates the vector's max norm

Returns
the vector's max norm

References max().

◆ min()

float sgpp::base::DataVectorSP::min ( ) const

Returns the minimum over all entries.

Returns
Minimal value

References min().

Referenced by min(), and normalize().

◆ minmax()

void sgpp::base::DataVectorSP::minmax ( float *  min,
float *  max 
) const

Determines minimum and maximum over all entries.

Parameters
minReference variable for the minimum
maxReference variable for the maximum

Referenced by normalize().

◆ mult()

void sgpp::base::DataVectorSP::mult ( float  scalar)

multiplies all elements by a constant factor

Parameters
scalarthe constant

Referenced by sgpp::solver::ConjugateGradientsSP::solve().

◆ normalize() [1/2]

void sgpp::base::DataVectorSP::normalize ( )

Normalizes vector entries to [0,1].

References normalize().

Referenced by normalize().

◆ normalize() [2/2]

void sgpp::base::DataVectorSP::normalize ( float  border)

Normalizes vector entries to [border, 1-border].

Parameters
borderwidth of border

References max(), min(), and minmax().

◆ operator=() [1/2]

DataVectorSP & sgpp::base::DataVectorSP::operator= ( const DataVectorSP )
default

Copy assignment operator.

◆ operator=() [2/2]

DataVectorSP & sgpp::base::DataVectorSP::operator= ( DataVectorSP &&  )
default

Move assignment operator.

◆ partitionClasses()

void sgpp::base::DataVectorSP::partitionClasses ( float  threshold)

Partitions vector into two classes using a choosen border.

Parameters
thresholdvalue of the border

◆ remove()

void sgpp::base::DataVectorSP::remove ( std::vector< size_t > &  indexesToRemove)

Removes indexes form the vector.

Throws an exception if the boundaries are violated

Parameters
indexesToRemovea vector if indexes that will be removed from the vector

Referenced by python.uq.uq_setting.UQSetting.UQSetting::cleanUp().

◆ resizeZero()

void sgpp::base::DataVectorSP::resizeZero ( size_t  nrows)

Resizes the DataVectorSP to size elements.

All new additional entries are set to zero. If nrows is smaller than the current number of rows, all superfluous entries are removed.

Parameters
nrowsNew number of rows of the DataVectorSP

Referenced by sgpp::datadriven::LearnerBaseSP::train().

◆ restructure()

void sgpp::base::DataVectorSP::restructure ( std::vector< size_t > &  remainingIndex)

Resizes the DataVectorSP by removing entries.

Throws an exception if boundaries a violated.

Parameters
remainingIndexvector that contains the remaining indices of the DataVectorSP

◆ RMSNorm()

float sgpp::base::DataVectorSP::RMSNorm ( ) const

Returns the vector's root mean square (RMS)-norm, i.e., \(\sqrt{ 1/N \sum_{i=1}^N x_i^2 }\).

If the vector's entries correspond to function values on a full grid, this is the discrete \(L^2\)-norm of the corresponding function.

Returns
The vector's root mean square-norm.

References getSize(), sqr(), and sum().

◆ set()

void sgpp::base::DataVectorSP::set ( size_t  i,
float  value 
)

Sets the element at index i to value.

Parameters
iIndex
valueNew value for element

Referenced by sgpp::base::DataMatrixSP::addReduce(), and sgpp::base::DataMatrixSP::addReduce().

◆ setAll()

void sgpp::base::DataVectorSP::setAll ( float  value)

Sets all values of DataVectorSP to value.

Parameters
valueNew value for all entries

Referenced by sgpp::datadriven::LearnerBaseSP::InitializeGrid(), and sgpp::solver::ConjugateGradientsSP::solve().

◆ sqr()

void sgpp::base::DataVectorSP::sqr ( )

Squares all elements of the DataVectorSP.

Referenced by RMSNorm().

◆ sqrt()

void sgpp::base::DataVectorSP::sqrt ( )

Takes the square root of all elements of the DataVectorSP.

◆ sub()

void sgpp::base::DataVectorSP::sub ( const DataVectorSP vec)

Subtracts the values from another DataVectorSP of the current values.

Modifies the current values.

Parameters
vecThe DataVectorSP which is subtracted from the current values

◆ sum()

float sgpp::base::DataVectorSP::sum ( ) const

Returns the sum of all elements.

Returns
The sum of all elements

Referenced by dotProduct(), l2Norm(), and RMSNorm().

◆ toFile()

void sgpp::base::DataVectorSP::toFile ( const std::string &  fileName) const

References f, fileName, and toString().

◆ toString() [1/2]

◆ toString() [2/2]


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