ARTS  2.5.0 (git: 260355e1)
Vector Class Reference

The Vector class. More...

#include <matpackI.h>

Inheritance diagram for Vector:
VectorView ConstVectorView

Public Member Functions

 Vector ()=default
 
 Vector (std::initializer_list< Numeric > init)
 Initialization list constructor. More...
 
 Vector (const Eigen::VectorXd &init)
 Initialization from an Eigen vector. 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...
 
 Vector (Vector &&v) noexcept
 
 Vector (const std::vector< Numeric > &)
 Converting constructor from std::vector<Numeric>. More...
 
 Vector (Numeric *d, const Range &r0) ARTS_NOEXCEPT
 
Vectoroperator= (const Vector &v)
 Assignment from another Vector. More...
 
Vectoroperator= (Vector &&v) noexcept
 Move assignment from another Vector. More...
 
Vectoroperator= (std::initializer_list< Numeric > v)
 Assignment from an initializatoin list. More...
 
Vectoroperator= (const Array< Numeric > &x)
 Assignment operator from Array<Numeric>. More...
 
Vectoroperator= (Numeric x)
 Assignment operator from scalar. More...
 
void resize (Index n)
 Resize function. More...
 
virtual ~Vector ()
 Destructor for Vector. More...
 
- Public Member Functions inherited from VectorView
constexpr VectorView (const VectorView &)=default
 
 VectorView (const Vector &)
 Bail out immediately if somebody tries to create a VectorView from a const Vector. More...
 
 VectorView (Vector &v) ARTS_NOEXCEPT
 Create VectorView from a Vector. More...
 
Numericoperator[] (Index n) ARTS_NOEXCEPT
 Plain Index operator. More...
 
Numericget (Index n) ARTS_NOEXCEPT
 Get element implementation without assertions. More...
 
VectorView operator[] (const Range &r) ARTS_NOEXCEPT
 Index operator for subrange. More...
 
Iterator1D begin () ARTS_NOEXCEPT
 Return iterator to first element. More...
 
Iterator1D end () ARTS_NOEXCEPT
 Return iterator behind last element. More...
 
VectorViewoperator= (const ConstVectorView &v)
 Assignment operator. More...
 
VectorViewoperator= (const VectorView &v)
 Assignment from VectorView to VectorView. More...
 
VectorViewoperator= (const Vector &v)
 Assignment from Vector. More...
 
VectorViewoperator= (const Array< Numeric > &v)
 Assignment operator from Array<Numeric>. More...
 
VectorViewoperator= (Numeric x)
 Assigning a scalar to a VectorView will set all elements to this value. More...
 
VectorView operator*= (Numeric x) ARTS_NOEXCEPT
 Multiplication by scalar. More...
 
VectorView operator/= (Numeric x) ARTS_NOEXCEPT
 Division by scalar. More...
 
VectorView operator+= (Numeric x) ARTS_NOEXCEPT
 Addition of scalar. More...
 
VectorView operator-= (Numeric x) ARTS_NOEXCEPT
 Subtraction of scalar. More...
 
VectorView operator*= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise multiplication by another vector. More...
 
VectorView operator/= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise division by another vector. More...
 
VectorView operator+= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise addition of another vector. More...
 
VectorView operator-= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise subtraction of another vector. More...
 
 operator MatrixView () ARTS_NOEXCEPT
 Conversion to 1 column matrix. More...
 
const Numericget_c_array () const ARTS_NOEXCEPT
 Conversion to plain C-array, const-version. More...
 
Numericget_c_array () ARTS_NOEXCEPT
 Conversion to plain C-array, non-const version. More...
 
virtual ~VectorView ()=default
 Destructor. More...
 
 VectorView (Numeric &a) ARTS_NOEXCEPT
 A special constructor, which allows to make a VectorView from a scalar. More...
 
ConstIterator1D begin () const ARTS_NOEXCEPT
 Return const iterator to first element. More...
 
ConstIterator1D end () const ARTS_NOEXCEPT
 Return const iterator behind last element. More...
 
Numeric get (Index n) const ARTS_NOEXCEPT
 Get element implementation without assertions. More...
 
- Public Member Functions inherited from ConstVectorView
constexpr ConstVectorView (const ConstVectorView &)=default
 
constexpr ConstVectorView (ConstVectorView &&)=default
 
ConstVectorViewoperator= (const ConstVectorView &)=default
 
ConstVectorViewoperator= (ConstVectorView &&)=default
 
bool empty () const ARTS_NOEXCEPT
 Returns true if variable size is zero. More...
 
Index nelem () const ARTS_NOEXCEPT
 Returns the number of elements. More...
 
Index size () const ARTS_NOEXCEPT
 
Numeric sum () const ARTS_NOEXCEPT
 The sum of all elements of a Vector. More...
 
Numeric operator[] (Index n) const ARTS_NOEXCEPT
 Plain const index operator. More...
 
Numeric get (Index n) const ARTS_NOEXCEPT
 Get element implementation without assertions. More...
 
ConstVectorView operator[] (const Range &r) const ARTS_NOEXCEPT
 Const index operator for subrange. More...
 
ConstIterator1D begin () const ARTS_NOEXCEPT
 Return const iterator to first element. More...
 
ConstIterator1D end () const ARTS_NOEXCEPT
 Return const iterator behind last element. More...
 
 operator ConstMatrixView () const
 Conversion to const 1 column matrix. More...
 
virtual ~ConstVectorView ()=default
 Destructor. More...
 
 ConstVectorView (const Numeric &a) ARTS_NOEXCEPT
 A special constructor, which allows to make a ConstVectorView from a scalar. More...
 

Friends

void swap (Vector &v1, Vector &v2)
 Swaps two objects. More...
 

Additional Inherited Members

- Public Types inherited from VectorView
typedef Iterator1D iterator
 
- Public Types inherited from ConstVectorView
typedef ConstIterator1D const_iterator
 
- Protected Member Functions inherited from VectorView
 VectorView ()=default
 
 VectorView (Numeric *data, const Range &range) ARTS_NOEXCEPT
 Explicit constructor. More...
 
 VectorView (Numeric *data, const Range &p, const Range &n) ARTS_NOEXCEPT
 Recursive constructor. More...
 
- Protected Member Functions inherited from ConstVectorView
 ConstVectorView ()=default
 
 ConstVectorView (Numeric *data, const Range &range) ARTS_NOEXCEPT
 Explicit constructor. More...
 
 ConstVectorView (Numeric *data, const Range &p, const Range &n) ARTS_NOEXCEPT
 Recursive constructor. More...
 
- Protected Attributes inherited from ConstVectorView
Range mrange {0, 0}
 The range of mdata that is actually used. More...
 
Numericmdata {nullptr}
 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
  3. Assignment operator from scalar.
  4. Resize function.

Definition at line 868 of file matpackI.h.

Constructor & Destructor Documentation

◆ Vector() [1/11]

Vector::Vector ( )
default

◆ Vector() [2/11]

Vector::Vector ( std::initializer_list< Numeric init)

Initialization list constructor.

Definition at line 320 of file matpackI.cc.

References VectorView::begin(), copy(), and ARTS::Continua::init().

◆ Vector() [3/11]

Vector::Vector ( const Eigen::VectorXd &  init)

Initialization from an Eigen vector.

Definition at line 325 of file matpackI.cc.

References ARTS::Continua::init(), and ConstVectorView::size().

◆ Vector() [4/11]

Vector::Vector ( Index  n)
explicit

Constructor setting size.

Definition at line 332 of file matpackI.cc.

◆ Vector() [5/11]

Vector::Vector ( Index  n,
Numeric  fill 
)

Constructor setting size and filling with constant value.

Definition at line 336 of file matpackI.cc.

References ConstVectorView::mdata.

◆ Vector() [6/11]

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

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 343 of file matpackI.cc.

References VectorView::begin(), Zeeman::start(), and ARTS::Var::x().

◆ Vector() [7/11]

Vector::Vector ( const ConstVectorView v)

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 355 of file matpackI.cc.

References VectorView::begin(), copy(), and v.

◆ Vector() [8/11]

Vector::Vector ( const Vector v)

Copy constructor from Vector.

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

Definition at line 360 of file matpackI.cc.

References ConstVectorView::mdata, ConstVectorView::nelem(), and v.

◆ Vector() [9/11]

Vector::Vector ( Vector &&  v)
inlinenoexcept

Definition at line 904 of file matpackI.h.

References v.

◆ Vector() [10/11]

Vector::Vector ( const std::vector< Numeric > &  v)

Converting constructor from std::vector<Numeric>.

Definition at line 365 of file matpackI.cc.

References VectorView::begin(), and v.

◆ Vector() [11/11]

Vector::Vector ( Numeric d,
const Range r0 
)
inline

Construct from known data

Note that this will call delete on the pointer if it is still valid at the end of the lifetime of this variable

Parameters
[in]d- A pointer to some raw data
[in]r0- The Range along the first dimension

Definition at line 919 of file matpackI.h.

References ARTS_ASSERT, and IGRF::r0.

◆ ~Vector()

Vector::~Vector ( )
virtual

Destructor for Vector.

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

Definition at line 427 of file matpackI.cc.

References ConstVectorView::mdata.

Member Function Documentation

◆ operator=() [1/5]

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

Assignment operator from Array<Numeric>.

This copies the data from an Array<Numeric> to this VectorView. The size is adjusted automatically.

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.

Parameters
[in]xThe array to assign to this.
Returns
This vector, by tradition.
Author
Stefan Buehler
Date
2002-12-19

Definition at line 400 of file matpackI.cc.

References VectorView::operator=(), resize(), and ARTS::Var::x().

◆ operator=() [2/5]

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

Assignment from another Vector.

While dimensions of VectorViews can not be adjusted, dimensions of Vectors can be adjusted. Hence, the behavior of the assignment operator is different.

In this case the size of the target is automatically adjusted. This is important, so that structures containing Vectors are copied correctly.

This is a deviation from the old ARTS paradigm that sizes must match exactly before copying!

Note: It is sufficient to have only this one version of the assignment (Vector = Vector). It implicitly covers the cases Vector=VectorView, etc, because there is a default constructor for Vector from VectorView. (See C++ Primer Plus, page 571ff.)

Parameters
[in]vThe other vector to copy to this one.
Returns
This vector, by tradition.
Author
Stefan Buehler
Date
2002-12-19

Definition at line 381 of file matpackI.cc.

References ConstVectorView::mdata, ConstVectorView::nelem(), resize(), and v.

◆ operator=() [3/5]

Vector & Vector::operator= ( Numeric  x)

Assignment operator from scalar.

Assignment operators are not inherited.

Definition at line 406 of file matpackI.cc.

References ConstVectorView::mdata, ConstVectorView::nelem(), and ARTS::Var::x().

◆ operator=() [4/5]

Vector & Vector::operator= ( std::initializer_list< Numeric v)

Assignment from an initializatoin list.

Definition at line 375 of file matpackI.cc.

References VectorView::begin(), copy(), resize(), and v.

◆ operator=() [5/5]

Vector & Vector::operator= ( Vector &&  v)
noexcept

Move assignment from another Vector.

Definition at line 389 of file matpackI.cc.

References v.

◆ resize()

void Vector::resize ( Index  n)

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 411 of file matpackI.cc.

Referenced by abs_xsec_per_speciesAddCIA(), abs_xsec_per_speciesAddConts(), abs_xsec_per_speciesAddHitranXsec(), GasAbsLookup::Adapt(), AngularGridsSetFluxCalc(), Append(), calcBaselineFit(), cloudbox_checkedCalc(), defocusing_general_sub(), do_gridcell_2d_byltest(), do_gridcell_3d_byltest(), ExtractFromMetaSingleScatSpecies(), fastem(), find_effective_channel_boundaries(), FrequencyFromCGSAngularWavenumber(), FrequencyFromCGSKayserWavenumber(), FrequencyFromWavelength(), geompath_from_r1_to_r2(), get_ppath_atmvars(), iyHybrid(), iyRadarSingleScat(), iyTransmissionStandard(), jacobianAddPointingZa(), jacobianSetFuncTransformation(), linreg(), Sparse::list_elements(), mirror_los(), mixer_matrix(), operator=(), opt_prop_sptFromData(), opt_prop_sptFromScat_data(), ArtsParser::parse_numvector(), ArtsParser::parse_numvector_from_string(), pha_mat_sptFromData(), pha_mat_sptFromScat_data(), propmat_clearskyAddParticles(), psd_cloudice_MH97(), psd_rain_W16(), CIARecord::ReadFromCIA(), Reduce(), GriddedField1::resize(), ScatSpeciesMerge(), sensor_responseGenericAMSU(), sensor_responseSimpleAMSU(), InteractiveWorkspace::set_vector_variable(), set_vmr_from_first_species(), sparse_f_gridFromFrequencyGrid(), TangentPointExtract(), telsemAtlasLookup(), tessem_read_ascii(), test1(), test_and_merge_two_channels(), TestTessem(), tmatrix_random_orientation(), transmittanceFromIy_aux(), VectorAddScalar(), VectorClip(), VectorCrop(), VectorFlip(), VectorInsertGridPoints(), VectorZtanToZa1D(), VectorZtanToZaRefr1D(), xml_parse_from_stream(), and za_gridOpt().

Friends And Related Function Documentation

◆ swap

void swap ( Vector v1,
Vector v2 
)
friend

Swaps two objects.

Definition at line 422 of file matpackI.cc.


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