SG++-Doxygen-Documentation
sgpp::base::DataVectorSP Class Reference

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

#include <DataVectorSP.hpp>

Public Member Functions

void abs ()
 Sets all elements to their absolute value. More...
 
void add (const DataVectorSP &vec)
 Adds the values from another DataVectorSP to the current values. More...
 
void addSize (size_t inc_elems)
 Add add potentially new elements to the DataVectorSP. More...
 
size_t append ()
 Appends a new element and returns index of it. More...
 
size_t append (float value)
 Appends a new element and returns index of new element. More...
 
void axpy (float a, DataVectorSP &x)
 Adds a*x to current vector. More...
 
void componentwise_div (const DataVectorSP &vec)
 Divides the current DataVectorSP component-wise by another DataVectorSP. More...
 
void componentwise_mult (const DataVectorSP &vec)
 Multiplies the current DataVectorSP component-wise with another DataVectorSP. More...
 
void copyFrom (const DataVectorSP &vec)
 Copies the data from another DataVectorSP vec. More...
 
 DataVectorSP (size_t size)
 Create a DataVectorSP with size elements (uninitialized values). More...
 
 DataVectorSP (size_t size, float value)
 Create a DataVectorSP with size elements and initializes all elements with the same value. More...
 
 DataVectorSP (const DataVectorSP &vec)
 Create a new DataVectorSP that is a copy of vec. More...
 
 DataVectorSP (float *input, size_t size)
 Create a new DataVectorSP from a float array with size elements. More...
 
 DataVectorSP (std::vector< float > input)
 Create a new DataVectorSP from a std::vector<float>. More...
 
 DataVectorSP (std::vector< int > input)
 Create a new DataVectorSP from a std::vector<int>. More...
 
float dotProduct (const DataVectorSP &vec) const
 Returns the dot product of the two vectors. More...
 
float get (size_t i) const
 Returns the i-th element. More...
 
size_t getInc () const
 Get the current number of elements by which the DataVectorSP is extended, if append() or insert() is called and no unused rows are left. More...
 
size_t getNumberNonZero () const
 Determines the number of non-zero elements in the vector. More...
 
float * getPointer ()
 gets a pointer to the data array More...
 
const float * getPointer () const
 gets a const pointer to the data array More...
 
size_t getSize () const
 gets the elements stored in the vector More...
 
size_t getUnused () const
 Returns the number of unused elements. More...
 
void insert (size_t index, float value)
 Inserts a new element at the given index. More...
 
float l2Norm () const
 Returns the vector's \(l^2\)-norm, i.e., \(\sqrt{ \sum_i x_i^2 }\). More...
 
float max () const
 Returns the maximum over all entries. More...
 
float maxNorm () const
 calculates the vector's max norm More...
 
float min () const
 Returns the minimum over all entries. More...
 
void minmax (float *min, float *max) const
 Determines minimum and maximum over all entries. More...
 
void mult (float scalar)
 multiplies all elements by a constant factor More...
 
void normalize ()
 Normalizes vector entries to [0,1]. More...
 
void normalize (float border)
 Normalizes vector entries to [border, 1-border]. More...
 
DataVectorSPoperator= (const DataVectorSP &vec)
 Copies the data from another DataVectorSP. More...
 
float & operator[] (size_t i)
 Returns a reference to the i-th element. More...
 
const float & operator[] (size_t i) const
 Returns a constant reference to the i-th element. More...
 
void partitionClasses (float threshold)
 Partitions vector into two classes using a choosen border. More...
 
void resize (size_t size)
 Resizes the DataVectorSP to size elements. More...
 
void resizeZero (size_t nrows)
 Resizes the DataVectorSP to size elements. More...
 
void restructure (std::vector< size_t > &remainingIndex)
 Resizes the DataVectorSP by removing entries. More...
 
float RMSNorm () const
 Returns the vector's root mean square (RMS)-norm, i.e., \(\sqrt{ 1/N \sum_{i=1}^N x_i^2 }\). More...
 
void set (size_t i, float value)
 Sets the element at index i to value. More...
 
void setAll (float value)
 Sets all values of DataVectorSP to value. More...
 
void setInc (size_t inc_elems)
 Sets the current number of elements by which the DataVectorSP is extended, if append() or insert() is called and no unused elements are left. More...
 
void sqr ()
 Squares all elements of the DataVectorSP. More...
 
void sqrt ()
 Takes the square root of all elements of the DataVectorSP. More...
 
void sub (const DataVectorSP &vec)
 Subtracts the values from another DataVectorSP of the current values. More...
 
float sum () const
 Returns the sum of all elements. More...
 
void toString (std::string &text) const
 Writes the data stored in the DataVectorSP into a string. More...
 
std::string toString () const
 Returns a description of the DataVectorSP as a string. More...
 
virtual ~DataVectorSP ()
 Destructor. More...
 

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/6]

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

Create a DataVectorSP with size elements (uninitialized values).

Parameters
sizeNumber of elements

◆ DataVectorSP() [2/6]

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

References setAll().

◆ DataVectorSP() [3/6]

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

Create a new DataVectorSP that is a copy of vec.

Parameters
vecReference to another instance of DataVectorSP

◆ DataVectorSP() [4/6]

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() [5/6]

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() [6/6]

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

◆ ~DataVectorSP()

sgpp::base::DataVectorSP::~DataVectorSP ( )
virtual

Destructor.

Referenced by setInc().

Member Function Documentation

◆ abs()

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

Sets all elements to their absolute value.

References python.statsfileInfo::i.

Referenced by get().

◆ 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

References python.statsfileInfo::i.

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

◆ addSize()

void sgpp::base::DataVectorSP::addSize ( size_t  inc_elems)

Add add potentially new elements to the DataVectorSP.

The size remains unchanged Reserves memory for potentially inc_elems new elements; the actual number of elements remains unchanged. Corresponds to a resize to size+inc_elems new elements while leaving the current vector's size unchanged.

Parameters
inc_elemsNumber of additional elements for which storage is to be reserved.

References add().

Referenced by append().

◆ append() [1/2]

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

Appends a new element and returns index of it.

If the new element does not fit into the reserved memory, reserves memory for getInc() additional elements.

Returns
Index of new element

References addSize().

Referenced by append(), and insert().

◆ append() [2/2]

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

Appends a new element and returns index of new element.

If the new element does not fit into the reserved memory, reserves memory for getInc() additional elements.

Parameters
valueValue of new element
Returns
Index of new element

References append().

◆ 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

References python.statsfileInfo::i.

Referenced by get(), sgpp::solver::BiCGStabSP::solve(), and sgpp::solver::ConjugateGradientsSP::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]

Note: No check for division by zero!

Parameters
vecthe DataVectorSP which the current DataVectorSP is divided by

References python.statsfileInfo::i.

Referenced by get().

◆ 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

References python.statsfileInfo::i.

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

◆ 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 python.statsfileInfo::i, and sum().

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

◆ get()

◆ getInc()

size_t sgpp::base::DataVectorSP::getInc ( ) const
inline

Get the current number of elements by which the DataVectorSP is extended, if append() or insert() is called and no unused rows are left.

Returns
Increment

◆ 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

References python.statsfileInfo::f, and python.statsfileInfo::i.

Referenced by getUnused().

◆ getPointer() [1/2]

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

gets a pointer to the data array

Returns
pointer to the data array

Referenced by sgpp::base::DataMatrixSP::appendRow(), and get().

◆ 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()

◆ getUnused()

size_t sgpp::base::DataVectorSP::getUnused ( ) const
inline

Returns the number of unused elements.

Returns
number of unused elements

References getNumberNonZero().

◆ insert()

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

Inserts a new element at the given index.

If the new element does not fit into the reserved memory, reserves memory for getInc() additional elements.

Parameters
indexIndex of new element
valueValue of new element

References append().

◆ 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(), and sum().

Referenced by get(), and RMSNorm().

◆ max()

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

Returns the maximum over all entries.

Returns
global maximum

References python.statsfileInfo::i.

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

◆ maxNorm()

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

calculates the vector's max norm

Returns
the vector's max norm

References python.statsfileInfo::i, and max().

Referenced by get().

◆ min()

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

Returns the minimum over all entries.

Returns
Minimal value

References python.statsfileInfo::i.

Referenced by get(), 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

References python.statsfileInfo::i.

Referenced by get(), and normalize().

◆ mult()

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

multiplies all elements by a constant factor

Parameters
scalarthe constant

References python.statsfileInfo::i.

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

◆ normalize() [1/2]

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

Normalizes vector entries to [0,1].

References python.statsfileInfo::f.

Referenced by setInc().

◆ normalize() [2/2]

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

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

Parameters
borderwidth of border

References python.statsfileInfo::i, max(), min(), and minmax().

◆ operator=()

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

Copies the data from another DataVectorSP.

Dimensions have to match.

Parameters
vecthe DataVectorSP containing the data
Returns
*this

◆ operator[]() [1/2]

float& sgpp::base::DataVectorSP::operator[] ( size_t  i)
inline

Returns a reference to the i-th element.

Parameters
iposition of the element
Returns
data[i]

References python.statsfileInfo::i.

◆ operator[]() [2/2]

const float& sgpp::base::DataVectorSP::operator[] ( size_t  i) const
inline

Returns a constant reference to the i-th element.

Parameters
iposition of the element
Returns
data[i]

References python.statsfileInfo::i.

◆ partitionClasses()

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

Partitions vector into two classes using a choosen border.

Parameters
thresholdvalue of the border

References python.statsfileInfo::i.

Referenced by setInc().

◆ resize()

void sgpp::base::DataVectorSP::resize ( size_t  size)

Resizes the DataVectorSP to size elements.

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

Parameters
sizeNew number of elements of the DataVectorSP

◆ 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

References python.statsfileInfo::i.

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

References python.statsfileInfo::i.

◆ 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 componentwise_mult(), getSize(), l2Norm(), and sum().

Referenced by get().

◆ 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

References python.statsfileInfo::i.

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

◆ setAll()

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

◆ setInc()

void sgpp::base::DataVectorSP::setInc ( size_t  inc_elems)
inline

Sets the current number of elements by which the DataVectorSP is extended, if append() or insert() is called and no unused elements are left.

Defaults to 100.

Parameters
inc_elemsIncrement

References normalize(), partitionClasses(), toString(), and ~DataVectorSP().

◆ sqr()

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

Squares all elements of the DataVectorSP.

References python.statsfileInfo::i.

Referenced by get(), and sgpp::datadriven::LearnerBaseSP::getAccuracy().

◆ sqrt()

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

Takes the square root of all elements of the DataVectorSP.

References python.statsfileInfo::i.

Referenced by get().

◆ 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

References python.statsfileInfo::i.

Referenced by get(), and sgpp::datadriven::LearnerBaseSP::getAccuracy().

◆ sum()

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

Returns the sum of all elements.

Returns
The sum of all elements

References python.statsfileInfo::i.

Referenced by dotProduct(), get(), sgpp::datadriven::LearnerBaseSP::getAccuracy(), l2Norm(), and RMSNorm().

◆ toString() [1/2]

◆ toString() [2/2]


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