12#ifndef BELFEM_CL_AR_VECTOR_HPP
13#define BELFEM_CL_AR_VECTOR_HPP
31 template <
typename T >
56 mVector( aNumRows, 1 ) {}
60 Vector(
const size_t aNumRows,
const T & aValue ) :
61 mVector( aNumRows, 1 )
68 Vector( std::initializer_list<T> aInitList )
70 if( aInitList.size() == 1 )
73 mVector.set_size( 1, 1 );
74 mVector( 0 ) = *aInitList.begin();
79 mVector.set_size( aInitList.size(), 1 );
81 for(
const T & val : aInitList )
91 mVector.set_size( aCell.
size(), 1 );
92 std::copy( aCell.
begin(), aCell.
end(), mVector.begin() );
97 Vector(
const std::vector< T > & aVector )
99 mVector.set_size( aVector.size(), 1 );
100 std::copy( aVector.begin(), aVector.end(), mVector.begin() );
106 mVector( aExpression )
111 template <
typename ET,
typename OP>
112 Vector(
const arma::Op<ET,OP> & aExpression )
113 : mVector( aExpression ) {}
120 Vector(
const arma::subview_col< T > & aCol ) :
129 Vector(
const arma::subview_row< T > & aRow ) :
130 mVector( arma::
trans( aRow ) )
139 mVector( aVector.mVector )
146 mVector( std::move( aVector.mVector ) )
165 return mVector.memptr();
173 return mVector.memptr();
206 mVector.fill( aValue );
217 mVector.set_size( aNumRows, 1 );
223 set_size(
const size_t aNumRows,
const T & aValue )
226 this->
fill( aValue );
237 return mVector.n_rows;
250 if (
this != & aVector )
252 mVector = std::move( aVector.mVector );
263 if (
this != &aVector )
265 mVector = aVector.mVector;
276 "Index %lu out of bounds, which must be smaller than %lu.",
277 (
long unsigned int ) aIndex,
278 (
long unsigned int ) this->
length());
280 return mVector( aIndex );
289 "Index %lu out of bounds, which must be smaller than %lu.",
290 (
long unsigned int ) aIndex,
291 (
long unsigned int ) this->
length());
293 return mVector( aIndex );
301 begin() ->
decltype( mVector.begin() )
303 return mVector.begin();
307 end() ->
decltype( mVector.end() )
309 return mVector.end();
315 return mVector.begin();
321 return mVector.end();
331 this->
fill( aValue );
340 if( aInitList.size() == 1 )
343 this->
set_size( 1, *aInitList.begin() );
350 for(
const T & val : aInitList )
352 mVector( i++ ) = val;
360 template <
typename ET >
364 mVector = aExpression;
384 mVector += aVector.vector_data();
393 mVector += aExpression;
399 template <
typename ET >
403 mVector += aExpression;
423 mVector -= aVector.vector_data();
432 mVector -= aExpression;
438 template <
typename ET >
442 mVector -= aExpression;
462 mVector *= aVector.vector_data();
471 mVector *= aExpression;
481 "Vector sizes do not match ( %lu and %lu ).",
482 (
long unsigned int ) this->length(),
483 (
long unsigned int ) aVector.length() );
485 mVector %= aVector.vector_data();
491 template <
typename ET >
495 mVector *= aExpression;
515 print(
const std::string aLabel=
"Vector" )
const;
522#pragma GCC diagnostic push
523#pragma GCC diagnostic ignored "-Wformat"
526 template <
typename T >
void
529 FILE * tOutFile = stdout;
531 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
536 uint tLength = tThis.length();
538 for(
uint i=0; i< tLength; ++i )
541 fprintf( tOutFile,
"%d; ",
542 (
int ) tThis( i ) );
547 fprintf( tOutFile,
"...\n" );
551 fprintf( tOutFile,
"];\n" );
562 FILE * tOutFile = stdout;
564 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
570 for(
uint i=0; i< tLength; ++i )
573 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
578 fprintf( tOutFile,
"...\n" );
582 fprintf( tOutFile,
"];\n" );
588#pragma GCC diagnostic pop
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
A bounds-checked wrapper around std::vector.
Definition cl_Cell.hpp:45
size_t size() const
Definition cl_Cell.hpp:189
auto begin() -> decltype(mCell.begin())
Definition cl_Cell.hpp:215
auto end() -> decltype(mCell.end())
Definition cl_Cell.hpp:223
Column vector.
Definition cl_BZ_Vector.hpp:41
void set_size(const size_t aNumRows, const T &aValue)
Definition cl_AR_Vector.hpp:223
void print(const std::string aLabel="Vector") const
Definition cl_AR_Vector.hpp:527
Vector< T > & operator+=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:382
Vector(const std::vector< T > &aVector)
Definition cl_AR_Vector.hpp:97
void fill(const T &aValue)
write value into all entries of the vector
Definition cl_AR_Vector.hpp:204
Vector< T > & operator-=(const ET &aExpression)
Definition cl_AR_Vector.hpp:440
auto end() -> decltype(mVector.end())
Definition cl_AR_Vector.hpp:307
auto begin() const -> decltype(mVector.begin())
Definition cl_AR_Vector.hpp:313
T & operator()(const size_t aIndex)
Definition cl_AR_Vector.hpp:273
T * data()
Returns a borrowed raw buffer under the layout contract stated in cl_Vector.hpp; may be nullptr when ...
Definition cl_AR_Vector.hpp:163
Vector< T > & operator=(const T &aValue)
Definition cl_AR_Vector.hpp:329
Vector< T > & operator+=(const ET &aExpression)
Definition cl_AR_Vector.hpp:401
Vector< T > & operator*=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:469
Vector< T > & operator*=(const ET &aExpression)
Definition cl_AR_Vector.hpp:493
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:215
Vector< T > & operator=(Vector< T > &&aVector) noexcept
move assignment operator
Definition cl_AR_Vector.hpp:248
Vector(const size_t aNumRows)
Definition cl_AR_Vector.hpp:55
Vector< T > & operator=(const ET &aExpression)
Definition cl_AR_Vector.hpp:362
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:235
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition cl_AR_Vector.hpp:182
Vector(const arma::subview_col< T > &aCol)
Constructor from column.
Definition cl_AR_Vector.hpp:120
const T & operator()(const size_t aIndex) const
Definition cl_AR_Vector.hpp:286
Vector< T > & operator/=(const T &aValue)
Definition cl_AR_Vector.hpp:504
Vector< T > & operator%=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:478
Vector< T > & operator-=(const T &aValue)
Definition cl_AR_Vector.hpp:412
auto end() const -> decltype(mVector.end())
Definition cl_AR_Vector.hpp:319
Vector(const size_t aNumRows, const T &aValue)
Definition cl_AR_Vector.hpp:60
Vector(Vector< T > &&aVector) noexcept
move constructor
Definition cl_AR_Vector.hpp:145
const VectorType & vector_data() const
Definition cl_AR_Vector.hpp:191
Vector< T > & operator=(const Vector< T > &aVector)
copy assignment operator
Definition cl_AR_Vector.hpp:261
virtual ~Vector()=default
empty destructor
Vector< T > & operator+=(const T &aValue)
Definition cl_AR_Vector.hpp:373
Vector< T > & operator-=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:430
Vector< T > & operator*=(const T &aValue)
Definition cl_AR_Vector.hpp:451
Vector< T > & operator-=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:421
const T * data() const
Definition cl_AR_Vector.hpp:171
Vector< T > & operator*=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:460
Vector(const Cell< T > &aCell)
Definition cl_AR_Vector.hpp:89
Vector(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:105
Vector(const arma::subview_row< T > &aRow)
Constructor from row.
Definition cl_AR_Vector.hpp:129
Vector(std::initializer_list< T > aInitList)
Definition cl_AR_Vector.hpp:68
auto begin() -> decltype(mVector.begin())
Definition cl_AR_Vector.hpp:301
Vector(const arma::Op< ET, OP > &aExpression)
Definition cl_AR_Vector.hpp:112
Vector(const Vector< T > &aVector)
copy constructor
Definition cl_AR_Vector.hpp:138
Vector< T > & operator=(std::initializer_list< T > aInitList)
Definition cl_AR_Vector.hpp:338
Vector< T > & operator+=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:391
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