ARTS  1.0.222
Public Member Functions | List of all members
Vector Class Reference

The Vector class. More...

#include <matpackI.h>

Inheritance diagram for Vector:
VectorView ConstVectorView MakeVector

Public Member Functions

 Vector ()
 Default constructor. More...
 
 Vector (Index n)
 Constructor setting size. More...
 
 Vector (Index n, Numeric fill)
 Constructor setting size and filling with constant value. More...
 
 Vector (Numeric start, Index extent, Numeric stride)
 Constructor filling with values. More...
 
 Vector (const ConstVectorView &v)
 Copy constructor from VectorView. More...
 
 Vector (const Vector &v)
 Copy constructor from Vector. More...
 
Vectoroperator= (const Vector &v)
 Assignment from another Vector. More...
 
Vectoroperator= (const Array< Numeric > &v)
 Assignment operator from Array<Numeric>. More...
 
Vectoroperator= (Numeric x)
 Assignment operator from scalar. More...
 
void resize (Index n)
 Resize function. More...
 
 ~Vector ()
 Destructor for Vector. More...
 
- Public Member Functions inherited from VectorView
Numeric operator[] (Index n) const
 Plain const index operator. More...
 
ConstVectorView operator[] (const Range &r) const
 Const index operator for subrange. More...
 
Numericoperator[] (Index n)
 Plain Index operator. More...
 
VectorView operator[] (const Range &r)
 Index operator for subrange. More...
 
ConstIterator1D begin () const
 Return const iterator to first element. More...
 
ConstIterator1D end () const
 Return const iterator behind last element. More...
 
Iterator1D begin ()
 Return iterator to first element. More...
 
Iterator1D end ()
 Return iterator behind last element. More...
 
VectorView operator= (const ConstVectorView &v)
 Assignment operator. More...
 
VectorView operator= (const VectorView &v)
 Assignment from VectorView to VectorView. More...
 
VectorView operator= (const Vector &v)
 Assignment from Vector. More...
 
VectorView operator= (const Array< Numeric > &v)
 Assignment operator from Array<Numeric>. More...
 
VectorView operator= (Numeric x)
 Assigning a scalar to a VectorView will set all elements to this value. More...
 
VectorView operator*= (Numeric x)
 Multiplication by scalar. More...
 
VectorView operator/= (Numeric x)
 Division by scalar. More...
 
VectorView operator+= (Numeric x)
 Addition of scalar. More...
 
VectorView operator-= (Numeric x)
 Subtraction of scalar. More...
 
VectorView operator*= (const ConstVectorView &x)
 Element-vise multiplication by another vector. More...
 
VectorView operator/= (const ConstVectorView &x)
 Element-vise division by another vector. More...
 
VectorView operator+= (const ConstVectorView &x)
 Element-vise addition of another vector. More...
 
VectorView operator-= (const ConstVectorView &x)
 Element-vise subtraction of another vector. More...
 
 operator MatrixView ()
 Conversion to 1 column matrix. More...
 
- Public Member Functions inherited from ConstVectorView
Index nelem () const
 Returns the number of elements. More...
 
Numeric sum () const
 The sum of all elements of a Vector. More...
 
Numeric operator[] (Index n) const
 Plain const index operator. More...
 
ConstVectorView operator[] (const Range &r) const
 Const index operator for subrange. More...
 
ConstIterator1D begin () const
 Return const iterator to first element. More...
 
ConstIterator1D end () const
 Return const iterator behind last element. More...
 
 operator ConstMatrixView () const
 Conversion to const 1 column matrix. More...
 

Additional Inherited Members

- Protected Member Functions inherited from VectorView
 VectorView ()
 Default constructor. More...
 
 VectorView (Numeric *data, const Range &range)
 Explicit constructor. More...
 
 VectorView (Numeric *data, const Range &p, const Range &n)
 Recursive constructor. More...
 
- Protected Member Functions inherited from ConstVectorView
 ConstVectorView ()
 Default constructor. More...
 
 ConstVectorView (Numeric *data, const Range &range)
 Explicit constructor. More...
 
 ConstVectorView (Numeric *data, const Range &p, const Range &n)
 Recursive constructor. More...
 
- Protected Attributes inherited from ConstVectorView
Range mrange
 The range of mdata that is actually used. More...
 
Numericmdata
 Pointer to the plain C array that holds the data. More...
 

Detailed Description

The Vector class.

This is a subvector that also allocates storage automatically, and deallocates it when it is destroyed. We take all the functionality from VectorView. Additionally defined in this class are:

  1. Constructors and destructors (allocating memory).
  2. Assignment operator from scalar.
  3. Resize function.

It seems that we need no assignment operator from VectorView or Vector, because the one of VectorView is used.

Definition at line 389 of file matpackI.h.

Constructor & Destructor Documentation

◆ Vector() [1/6]

Vector::Vector ( )
inline

Default constructor.

Definition at line 1341 of file matpackI.h.

◆ Vector() [2/6]

Vector::Vector ( Index  n)
inlineexplicit

Constructor setting size.

Definition at line 1347 of file matpackI.h.

◆ Vector() [3/6]

Vector::Vector ( Index  n,
Numeric  fill 
)
inline

Constructor setting size and filling with constant value.

Definition at line 1355 of file matpackI.h.

◆ Vector() [4/6]

Vector::Vector ( Numeric  start,
Index  extent,
Numeric  stride 
)
inline

Constructor filling with values.

Examples:

Vector v(1,5,1); // 1, 2, 3, 4, 5 Vector v(1,5,.5); // 1, 1.5, 2, 2.5, 3 Vector v(5,5,-1); // 5, 4, 3, 2, 1

Definition at line 1373 of file matpackI.h.

◆ Vector() [5/6]

Vector::Vector ( const ConstVectorView v)
inline

Copy constructor from VectorView.

This automatically sets the size and copies the data. The vector created will have start zero and stride 1, independent on how these parameters are set for the original. So, what is copied is the data, not the shape of the selection.

Definition at line 1393 of file matpackI.h.

◆ Vector() [6/6]

Vector::Vector ( const Vector v)
inline

Copy constructor from Vector.

This is important to override the automatically generated shallow constructor. We want deep copies!

Definition at line 1402 of file matpackI.h.

◆ ~Vector()

Vector::~Vector ( )
inline

Destructor for Vector.

This is important, since Vector uses new to allocate storage.

Definition at line 1481 of file matpackI.h.

Member Function Documentation

◆ operator=() [1/3]

Vector & Vector::operator= ( const Array< Numeric > &  x)
inline

Assignment operator from Array<Numeric>.

This copies the data from a Array<Numeric> to this VectorView. Dimensions must agree! Resizing would destroy the selection that we might have done in this VectorView by setting its range.

Array<Numeric> can be useful to collect things in, because there is a .push_back method for it. Then, after collecting we usually have to transfer the content to a Vector. With this assignment operator that's easy.

Assignment operators are not inherited, so we have to make an explicit call to:

VectorView VectorView::operator=(const Array<Numeric>& v)

here.

Definition at line 1439 of file matpackI.h.

◆ operator=() [2/3]

Vector & Vector::operator= ( const Vector v)
inline

Assignment from another Vector.

Important to avoid segmentation fault for x = Vector(n);

Definition at line 1413 of file matpackI.h.

◆ operator=() [3/3]

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

Assignment operator from scalar.

Assignment operators are not inherited.

Definition at line 1447 of file matpackI.h.

◆ resize()

void Vector::resize ( Index  n)
inline

Resize function.

If the size is already correct this function does nothing. All data is lost after resizing! The new Vector is not initialized, so it will contain random values.

Definition at line 1467 of file matpackI.h.


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