12#ifndef BELFEM_CL_AR_VECTOR_HPP
13#define BELFEM_CL_AR_VECTOR_HPP
32 template <
typename T >
58 template <
typename ET >
59 struct IsTransposeOp {
static constexpr bool value =
false; };
61 template <
typename T1 >
62 struct IsTransposeOp< arma::Op< T1, arma::op_htrans > > {
static constexpr bool value =
true; };
64 template <
typename T1 >
65 struct IsTransposeOp< arma::Op< T1, arma::op_strans > > {
static constexpr bool value =
true; };
67 template <
typename ET >
68 struct IsOrientedOperand
70 static constexpr bool value =
71 arma::is_eOp< ET >::value || arma::is_eGlue< ET >::value ||
72 arma::is_mtOp< ET >::value || arma::is_mtGlue< ET >::value ||
73 IsTransposeOp< ET >::value ;
76 template <
typename ET >
77 typename std::enable_if< ! IsOrientedOperand< ET >::value,
void >::type
78 assign_oriented(
const ET & aExpression )
80 mVector = aExpression;
82 "Vector: a %lu x %lu result was assigned; products and raw views are not transposed",
83 (
unsigned long ) mVector.n_rows, (
unsigned long ) mVector.n_cols );
86 template <
typename ET >
87 typename std::enable_if< IsOrientedOperand< ET >::value,
void >::type
88 assign_oriented(
const ET & aExpression )
90 const arma::Proxy< ET > tP( aExpression );
91 if ( tP.get_n_rows() == 1 && tP.get_n_cols() > 1 )
93 mVector = arma::strans( aExpression );
97 mVector = aExpression;
101 template <
typename ET >
102 typename std::enable_if< ! IsOrientedOperand< ET >::value,
void >::type
103 plus_oriented(
const ET & aExpression ) { mVector += aExpression; }
105 template <
typename ET >
106 typename std::enable_if< IsOrientedOperand< ET >::value,
void >::type
107 plus_oriented(
const ET & aExpression )
109 const arma::Proxy< ET > tP( aExpression );
110 if ( tP.get_n_rows() == 1 && tP.get_n_cols() > 1 )
112 mVector += arma::strans( aExpression );
116 mVector += aExpression;
120 template <
typename ET >
121 typename std::enable_if< ! IsOrientedOperand< ET >::value,
void >::type
122 minus_oriented(
const ET & aExpression ) { mVector -= aExpression; }
124 template <
typename ET >
125 typename std::enable_if< IsOrientedOperand< ET >::value,
void >::type
126 minus_oriented(
const ET & aExpression )
128 const arma::Proxy< ET > tP( aExpression );
129 if ( tP.get_n_rows() == 1 && tP.get_n_cols() > 1 )
131 mVector -= arma::strans( aExpression );
135 mVector -= aExpression;
148 mVector( aNumRows, 1 ) {}
152 Vector(
const size_t aNumRows,
const T & aValue ) :
153 mVector( aNumRows, 1 )
155 this->
fill( aValue );
160 Vector( std::initializer_list<T> aInitList )
162 if( aInitList.size() == 1 )
165 mVector.set_size( 1, 1 );
166 mVector( 0 ) = *aInitList.begin();
171 mVector.set_size( aInitList.size(), 1 );
173 for(
const T & val : aInitList )
175 mVector( i++ ) = val;
183 mVector.set_size( aCell.
size(), 1 );
184 std::copy( aCell.
begin(), aCell.
end(), mVector.begin() );
189 Vector(
const std::vector< T > & aVector )
191 mVector.set_size( aVector.size(), 1 );
192 std::copy( aVector.begin(), aVector.end(), mVector.begin() );
198 mVector( aExpression )
206 Vector(
const arma::subview_col< T > & aCol ) :
215 Vector(
const arma::subview_row< T > & aRow ) :
216 mVector( arma::strans( aRow ) )
225 template<
typename ET >
226 Vector(
const arma::Base< T, ET > & aExpression )
228 this->assign_oriented( aExpression.get_ref() );
237 mVector( aVector.mVector )
244 mVector( std::move( aVector.mVector ) )
263 return mVector.memptr();
271 return mVector.memptr();
304 mVector.fill( aValue );
315 mVector.set_size( aNumRows, 1 );
321 set_size(
const size_t aNumRows,
const T & aValue )
324 this->
fill( aValue );
335 return mVector.n_rows;
348 if (
this != & aVector )
350 mVector = std::move( aVector.mVector );
361 if (
this != &aVector )
363 mVector = aVector.mVector;
374 "Index %lu out of bounds, which must be smaller than %lu.",
375 (
long unsigned int ) aIndex,
376 (
long unsigned int ) this->
length());
378 return mVector( aIndex );
387 "Index %lu out of bounds, which must be smaller than %lu.",
388 (
long unsigned int ) aIndex,
389 (
long unsigned int ) this->
length());
391 return mVector( aIndex );
399 begin() ->
decltype( mVector.begin() )
401 return mVector.begin();
405 end() ->
decltype( mVector.end() )
407 return mVector.end();
413 return mVector.begin();
419 return mVector.end();
429 this->
fill( aValue );
438 if( aInitList.size() == 1 )
441 this->
set_size( 1, *aInitList.begin() );
448 for(
const T & val : aInitList )
450 mVector( i++ ) = val;
458 template <
typename ET,
459 typename =
typename std::enable_if< arma::is_arma_type< ET >::value >::type >
463 this->assign_oriented( aExpression );
472 mVector = arma::strans( aRow );
492 mVector += aVector.vector_data();
501 mVector += aExpression;
514 mVector += arma::strans( aRow );
520 template <
typename ET,
521 typename =
typename std::enable_if< arma::is_arma_type< ET >::value >::type >
525 this->plus_oriented( aExpression );
545 mVector -= aVector.vector_data();
554 mVector -= aExpression;
563 mVector -= arma::strans( aRow );
569 template <
typename ET,
570 typename =
typename std::enable_if< arma::is_arma_type< ET >::value >::type >
574 this->minus_oriented( aExpression );
594 mVector *= aVector.vector_data();
603 mVector *= aExpression;
613 "Vector sizes do not match ( %lu and %lu ).",
614 (
long unsigned int ) this->length(),
615 (
long unsigned int ) aVector.length() );
617 mVector %= aVector.vector_data();
623 template <
typename ET >
627 mVector *= aExpression;
647 print(
const std::string aLabel=
"Vector" )
const;
654#pragma GCC diagnostic push
655#pragma GCC diagnostic ignored "-Wformat"
658 template <
typename T >
void
661 FILE * tOutFile = stdout;
663 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
668 uint tLength = tThis.length();
670 for(
uint i=0; i< tLength; ++i )
673 fprintf( tOutFile,
"%d; ",
674 (
int ) tThis( i ) );
679 fprintf( tOutFile,
"...\n" );
683 fprintf( tOutFile,
"];\n" );
694 FILE * tOutFile = stdout;
696 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
702 for(
uint i=0; i< tLength; ++i )
705 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
710 fprintf( tOutFile,
"...\n" );
714 fprintf( tOutFile,
"];\n" );
720#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:42
void set_size(const size_t aNumRows, const T &aValue)
Definition cl_AR_Vector.hpp:321
void print(const std::string aLabel="Vector") const
Definition cl_AR_Vector.hpp:659
Vector< T > & operator+=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:490
Vector(const arma::Base< T, ET > &aExpression)
constructor from any Armadillo expression; a 1 x n result is a row and is transposed into the column,...
Definition cl_AR_Vector.hpp:226
Vector(const std::vector< T > &aVector)
Definition cl_AR_Vector.hpp:189
void fill(const T &aValue)
write value into all entries of the vector
Definition cl_AR_Vector.hpp:302
auto end() -> decltype(mVector.end())
Definition cl_AR_Vector.hpp:405
auto begin() const -> decltype(mVector.begin())
Definition cl_AR_Vector.hpp:411
T & operator()(const size_t aIndex)
Definition cl_AR_Vector.hpp:371
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:261
Vector< T > & operator=(const T &aValue)
Definition cl_AR_Vector.hpp:427
Vector< T > & operator=(const ET &aExpression)
Definition cl_AR_Vector.hpp:461
Vector< T > & operator*=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:601
Vector< T > & operator*=(const ET &aExpression)
Definition cl_AR_Vector.hpp:625
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:313
Vector< T > & operator=(Vector< T > &&aVector) noexcept
move assignment operator
Definition cl_AR_Vector.hpp:346
Vector(const size_t aNumRows)
Definition cl_AR_Vector.hpp:147
arma::Mat< T > VectorType
Definition cl_AR_Vector.hpp:39
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:333
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition cl_AR_Vector.hpp:280
Vector(const arma::subview_col< T > &aCol)
Constructor from column.
Definition cl_AR_Vector.hpp:206
const T & operator()(const size_t aIndex) const
Definition cl_AR_Vector.hpp:384
Vector< T > & operator/=(const T &aValue)
Definition cl_AR_Vector.hpp:636
Vector< T > & operator%=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:610
Vector< T > & operator-=(const T &aValue)
Definition cl_AR_Vector.hpp:534
auto end() const -> decltype(mVector.end())
Definition cl_AR_Vector.hpp:417
Vector(const size_t aNumRows, const T &aValue)
Definition cl_AR_Vector.hpp:152
~Vector()=default
empty destructor
Vector(Vector< T > &&aVector) noexcept
move constructor
Definition cl_AR_Vector.hpp:243
Vector< T > & operator+=(const arma::subview_row< T > &aRow)
a row view is transposed into the column; strans, so complex entries are not conjugated ( the same or...
Definition cl_AR_Vector.hpp:512
const VectorType & vector_data() const
Definition cl_AR_Vector.hpp:289
Vector< T > & operator=(const Vector< T > &aVector)
copy assignment operator
Definition cl_AR_Vector.hpp:359
Vector< T > & operator+=(const T &aValue)
Definition cl_AR_Vector.hpp:481
Vector< T > & operator-=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:552
Vector< T > & operator-=(const ET &aExpression)
Definition cl_AR_Vector.hpp:572
Vector< T > & operator*=(const T &aValue)
Definition cl_AR_Vector.hpp:583
Vector< T > & operator-=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:543
const T * data() const
Definition cl_AR_Vector.hpp:269
Vector< T > & operator*=(const Vector< T > &aVector)
Definition cl_AR_Vector.hpp:592
Vector< T > & operator+=(const ET &aExpression)
Definition cl_AR_Vector.hpp:523
Vector(const Cell< T > &aCell)
Definition cl_AR_Vector.hpp:181
Vector(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:197
Vector(const arma::subview_row< T > &aRow)
Constructor from row.
Definition cl_AR_Vector.hpp:215
Vector(std::initializer_list< T > aInitList)
Definition cl_AR_Vector.hpp:160
auto begin() -> decltype(mVector.begin())
Definition cl_AR_Vector.hpp:399
Vector< T > & operator-=(const arma::subview_row< T > &aRow)
Definition cl_AR_Vector.hpp:561
Vector< T > & operator=(const arma::subview_row< T > &aRow)
Definition cl_AR_Vector.hpp:470
Vector(const Vector< T > &aVector)
copy constructor
Definition cl_AR_Vector.hpp:236
Vector< T > & operator=(std::initializer_list< T > aInitList)
Definition cl_AR_Vector.hpp:436
Vector< T > & operator+=(const VectorType &aExpression)
Definition cl_AR_Vector.hpp:499
USER GUIDES:
Definition cl_Capacitor.cpp:16
std::pair< real, unit > value
Definition typedefs.hpp:73
unsigned int uint
Definition typedefs.hpp:30