12#ifndef BELFEM_CL_AR_VECTOR_HPP
13#define BELFEM_CL_AR_VECTOR_HPP
31 template <
typename T >
62 mVector( aNumRows, 1 ) {}
69 Vector(
const size_t aNumRows,
const T & aValue ) :
70 mVector( aNumRows, 1 )
80 Vector( std::initializer_list<T> aInitList )
82 if( aInitList.size() == 1 )
85 mVector.set_size( 1, 1 );
86 mVector( 0 ) = *aInitList.begin();
91 mVector.set_size( aInitList.size(), 1 );
93 for(
const T & val : aInitList )
103 mVector.set_size( aCell.
size(), 1 );
104 std::copy( aCell.
begin(), aCell.
end(), mVector.begin() );
109 Vector(
const std::vector< T > & aVector )
111 mVector.set_size( aVector.size(), 1 );
112 std::copy( aVector.begin(), aVector.end(), mVector.begin() );
121 mVector( aExpression )
129 template <
typename ET,
typename OP>
130 Vector(
const arma::Op<ET,OP> & aExpression )
131 : mVector( aExpression ) {}
138 Vector(
const arma::subview_col< T > & aCol ) :
147 Vector(
const arma::subview_row< T > & aRow ) :
148 mVector( arma::
trans( aRow ) )
157 mVector( aVector.mVector )
164 mVector( std::move( aVector.mVector ) )
184 return mVector.memptr();
195 return mVector.memptr();
228 mVector.fill( aValue );
239 mVector.set_size( aNumRows, 1 );
245 set_size(
const size_t aNumRows,
const T & aValue )
248 this->
fill( aValue );
259 return mVector.n_rows;
272 if (
this != & aVector )
274 mVector = std::move( aVector.mVector );
285 if (
this != &aVector )
287 mVector = aVector.mVector;
298 "Index %lu out of bounds, which must be smaller than %lu.",
299 (
long unsigned int ) aIndex,
300 (
long unsigned int ) this->
length());
302 return mVector( aIndex );
311 "Index %lu out of bounds, which must be smaller than %lu.",
312 (
long unsigned int ) aIndex,
313 (
long unsigned int ) this->
length());
315 return mVector( aIndex );
323 begin() ->
decltype( mVector.begin() )
325 return mVector.begin();
329 end() ->
decltype( mVector.end() )
331 return mVector.end();
337 return mVector.begin();
343 return mVector.end();
353 this->
fill( aValue );
362 if( aInitList.size() == 1 )
365 this->
set_size( 1, *aInitList.begin() );
372 for(
const T & val : aInitList )
374 mVector( i++ ) = val;
382 template <
typename ET >
386 mVector = aExpression;
406 mVector += aVector.vector_data();
415 mVector += aExpression;
421 template <
typename ET >
425 mVector += aExpression;
445 mVector -= aVector.vector_data();
454 mVector -= aExpression;
460 template <
typename ET >
464 mVector -= aExpression;
484 mVector *= aVector.vector_data();
493 mVector *= aExpression;
503 "Vector sizes do not match ( %lu and %lu ).",
504 (
long unsigned int ) this->length(),
505 (
long unsigned int ) aVector.length() );
507 mVector %= aVector.vector_data();
513 template <
typename ET >
517 mVector *= aExpression;
537 print(
const std::string aLabel=
"Vector" )
const;
544#pragma GCC diagnostic push
545#pragma GCC diagnostic ignored "-Wformat"
548 template <
typename T >
void
551 FILE * tOutFile = stdout;
553 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
558 uint tLength = tThis.length();
560 for(
uint i=0; i< tLength; ++i )
563 fprintf( tOutFile,
"%d; ",
564 (
int ) tThis( i ) );
569 fprintf( tOutFile,
"...\n" );
573 fprintf( tOutFile,
"];\n" );
584 FILE * tOutFile = stdout;
586 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
592 for(
uint i=0; i< tLength; ++i )
595 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
600 fprintf( tOutFile,
"...\n" );
604 fprintf( tOutFile,
"];\n" );
610#pragma GCC diagnostic pop
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
size_t size() const
return the size of the Cell
Definition cl_Cell.hpp:181
auto begin() -> decltype(mCell.begin())
Definition cl_Cell.hpp:205
auto end() -> decltype(mCell.end())
Definition cl_Cell.hpp:213
Column vector.
Definition cl_BZ_Vector.hpp:41
void set_size(const size_t aNumRows, const T &aValue)
Definition cl_AR_Vector.hpp:245
void print(const std::string aLabel="Vector") const
Definition cl_AR_Vector.hpp:549
Vector< T > & operator+=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:404
Vector(const std::vector< T > &aVector)
Definition cl_AR_Vector.hpp:109
void fill(const T &aValue)
write value into all entries of the vector
Definition cl_AR_Vector.hpp:226
Vector< T > & operator-=(const ET &aExpression)
Definition cl_AR_Vector.hpp:462
auto end() -> decltype(mVector.end())
Definition cl_AR_Vector.hpp:329
auto begin() const -> decltype(mVector.begin())
Definition cl_AR_Vector.hpp:335
T & operator()(const size_t aIndex)
Definition cl_AR_Vector.hpp:295
T * data()
expose the underlying raw pointer ( writable version )
Definition cl_AR_Vector.hpp:182
Vector< T > & operator=(const T &aValue)
Definition cl_AR_Vector.hpp:351
Vector< T > & operator+=(const ET &aExpression)
Definition cl_AR_Vector.hpp:423
Vector< T > & operator*=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:491
Vector< T > & operator*=(const ET &aExpression)
Definition cl_AR_Vector.hpp:515
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:237
Vector< T > & operator=(Vector< T > &&aVector) noexcept
move assignment operator
Definition cl_AR_Vector.hpp:270
Vector(const size_t aNumRows)
Constructor without fill value.
Definition cl_AR_Vector.hpp:61
Vector< T > & operator=(const ET &aExpression)
Definition cl_AR_Vector.hpp:384
arma::Mat< T > VectorType
Definition cl_AR_Vector.hpp:38
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition cl_AR_Vector.hpp:204
Vector(const arma::subview_col< T > &aCol)
Constructor from column.
Definition cl_AR_Vector.hpp:138
const T & operator()(const size_t aIndex) const
Definition cl_AR_Vector.hpp:308
Vector< T > & operator/=(const T &aValue)
Definition cl_AR_Vector.hpp:526
Vector< T > & operator%=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:500
Vector< T > & operator-=(const T &aValue)
Definition cl_AR_Vector.hpp:434
auto end() const -> decltype(mVector.end())
Definition cl_AR_Vector.hpp:341
Vector(const size_t aNumRows, const T &aValue)
Constructor with fill value.
Definition cl_AR_Vector.hpp:69
Vector()=default
empty constructor
Vector(Vector< T > &&aVector) noexcept
move constructor
Definition cl_AR_Vector.hpp:163
const VectorType & vector_data() const
Definition cl_AR_Vector.hpp:213
Vector< T > & operator=(const Vector< T > &aVector)
copy assignment operator
Definition cl_AR_Vector.hpp:283
virtual ~Vector()=default
empty destructor
Vector< T > & operator+=(const T &aValue)
Definition cl_AR_Vector.hpp:395
Vector< T > & operator-=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:452
Vector< T > & operator*=(const T &aValue)
Definition cl_AR_Vector.hpp:473
Vector< T > & operator-=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:443
const T * data() const
expose the underlying raw pointer ( const version )
Definition cl_AR_Vector.hpp:193
Vector< T > & operator*=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:482
Vector(const Cell< T > &aCell)
Definition cl_AR_Vector.hpp:101
Vector(const VectorType &aExpression)
Constructor from expression.
Definition cl_AR_Vector.hpp:120
Vector(const arma::subview_row< T > &aRow)
Constructor from row.
Definition cl_AR_Vector.hpp:147
Vector(std::initializer_list< T > aInitList)
Constructor with initializer list.
Definition cl_AR_Vector.hpp:80
auto begin() -> decltype(mVector.begin())
Definition cl_AR_Vector.hpp:323
Vector(const arma::Op< ET, OP > &aExpression)
Constructor from expression.
Definition cl_AR_Vector.hpp:130
Vector(const Vector< T > &aVector)
copy constructor
Definition cl_AR_Vector.hpp:156
Vector< T > & operator=(std::initializer_list< T > aInitList)
Definition cl_AR_Vector.hpp:360
Vector< T > & operator+=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:413
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
auto trans(Matrix< T > &aMatrix) -> decltype(trans(aMatrix.matrix_data()))
Definition fn_trans.hpp:74