12#ifndef BELFEM_CL_BZ_VECTOR_HPP
13#define BELFEM_CL_BZ_VECTOR_HPP
17#pragma warning disable 3058
23#include <blaze/Blaze.h>
27#include <blaze/math/Column.h>
39 template<
typename T >
46 typedef blaze::DynamicVector<T, blaze::columnVector>
VectorType;
64 mVector( aNumRows ) {}
68 Vector(
const size_t aNumRows,
const T & aValue ) :
69 mVector( aNumRows, aValue ) {}
73 Vector( std::initializer_list<T> aInitList )
75 if( aInitList.size() == 1 )
78 mVector.resize( 1,
false );
79 mVector[ 0 ] = *aInitList.begin();
84 mVector.resize( aInitList.size(),
false );
86 for(
const T & val : aInitList )
96 mVector( aExpression ) {}
102 mVector.resize( aCell.
size(),
false );
103 std::copy( aCell.
begin(), aCell.
end(), mVector.begin() );
108 Vector(
const std::vector< T > & aVector )
110 mVector.resize( aVector.size(),
false );
111 std::copy( aVector.begin(), aVector.end(), mVector.begin() );
120 template<
typename VT >
121 Vector(
const blaze::DenseVector<VT, false> & aExpression )
122 : mVector( static_cast< const VT& >( aExpression ) ) {}
127 template<
typename VT >
128 Vector(
const blaze::DenseVector<VT, true> & aExpression )
130 const VT & tRow =
static_cast< const VT&
>( aExpression );
131 mVector.resize( tRow.size(),
false );
132 for(
size_t k = 0; k < tRow.size(); ++k )
134 mVector[ k ] = tRow[ k ];
143 Vector(
const blaze::Columns<blaze::DynamicMatrix<T, true>,
true,
true,
false> & aColumn )
146 std::size_t tLength = aColumn.rows();
150 "aColumn must be a single column, but has %lu columns.",
151 (
long unsigned int ) aColumn.columns() );
154 mVector.resize( tLength ,
false );
156 std::copy( aColumn.data(), aColumn.data() + tLength, mVector.data() );
164 Vector(
const blaze::Rows<blaze::DynamicMatrix<T, true>,
false,
true,
false> & aRow )
167 std::size_t tLength = aRow.columns();
171 "aColumn must be a single row, but has %lu rows.",
172 (
long unsigned int ) aRow.rows());
175 mVector.resize( tLength,
false );
178 T * tTarget = mVector.data();
181 for ( std::size_t k = 0; k < tLength; ++k )
183 tTarget[ k ] = aRow.at( 0, k );
193 mVector( aVector.mVector )
200 mVector( std::move( aVector.mVector ) )
219 return mVector.data();
227 return mVector.data();
273 mVector.resize( aNumRows,
false );
279 set_size(
const size_t aNumRows,
const T & aValue )
282 this->
fill( aValue );
293 return mVector.size();
306 if (
this != & aVector )
308 mVector = std::move( aVector.mVector );
319 if (
this != &aVector )
321 mVector = aVector.mVector;
331 "Index %lu out of bounds, which must be smaller than %lu.",
332 (
long unsigned int ) aIndex,
333 (
long unsigned int ) this->
length());
335 return mVector[ aIndex ];
344 "Index %lu out of bounds, which must be smaller than %lu.",
345 (
long unsigned int ) aIndex,
346 (
long unsigned int ) this->
length());
348 return mVector[ aIndex ];
358 return mVector.data();
364 return mVector.data() + this->
length();
370 return mVector.data();
376 return mVector.data() + this->
length();
387 this->
fill( aValue );
396 if( aInitList.size() == 1 )
399 this->
set_size( 1, *aInitList.begin() );
406 for(
const T & val : aInitList )
408 mVector[ i++ ] = val;
416 template <
typename ET >
420 mVector = aExpression;
431 std::for_each( mVector.data(), mVector.data() + this->length(),
432 [ aValue ]( T & tVal )
433 { tVal += aValue; } );
468 template <
typename ET >
470 operator+=(
const blaze::DMatScalarMultExpr< ET, T, false> & aExpression )
472 mVector += blaze::column( aExpression, 0UL );
483 std::for_each( mVector.data(), mVector.data() + this->length(),
484 [ aValue ]( T & tVal )
485 { tVal -= aValue; } );
519 template <
typename ET >
521 operator-=(
const blaze::DMatScalarMultExpr< ET, T, false> & aExpression )
523 mVector -= blaze::column( aExpression, 0UL );
552 mVector *= aExpression;
561 size_t tN = this->
length();
564 "Vector sizes do not match ( %lu and %lu ).",
565 (
long unsigned int ) tN,
566 (
long unsigned int ) aVector.
length() );
568 for(
size_t k=0; k<tN; ++k )
570 mVector[ k ] *= aVector( k );
577 template <
typename ET >
581 mVector *= aExpression;
601 print(
const std::string aLabel=
"Vector" )
const;
608#pragma GCC diagnostic push
609#pragma GCC diagnostic ignored "-Wformat"
612 template <
typename T >
void
615 FILE * tOutFile = stdout;
617 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
624 for(
uint i=0; i< tLength; ++i )
627 fprintf( tOutFile,
"%d; ", (
int ) tThis( i ) );
632 fprintf( tOutFile,
"...\n" );
636 fprintf( tOutFile,
"];\n" );
647 FILE * tOutFile = stdout;
649 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
655 for(
uint i=0; i< tLength; ++i )
658 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
663 fprintf( tOutFile,
"...\n" );
667 fprintf( tOutFile,
"];\n" );
673#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_BZ_Vector.hpp:279
void print(const std::string aLabel="Vector") const
Vector< T > & operator+=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:450
Vector(const std::vector< T > &aVector)
Definition cl_BZ_Vector.hpp:108
void fill(const T &aValue)
write value into all entries of the vector
Definition cl_BZ_Vector.hpp:260
T & operator()(const size_t aIndex)
Definition cl_BZ_Vector.hpp:328
T * data()
Returns a borrowed raw buffer under the layout contract stated in cl_Vector.hpp; may be nullptr when ...
Definition cl_BZ_Vector.hpp:217
Vector< T > & operator=(const T &aValue)
Definition cl_BZ_Vector.hpp:385
const T * begin() const
Definition cl_BZ_Vector.hpp:368
Vector< T > & operator*=(const VectorType &aExpression)
Definition cl_BZ_Vector.hpp:550
Vector(const blaze::DenseVector< VT, true > &aExpression)
Constructor from row vector expression (TF=true), transposes to column.
Definition cl_BZ_Vector.hpp:128
Vector< T > & operator*=(const ET &aExpression)
Definition cl_BZ_Vector.hpp:579
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_BZ_Vector.hpp:271
Vector< T > & operator=(Vector< T > &&aVector) noexcept
move assignment operator
Definition cl_BZ_Vector.hpp:304
Vector(const size_t aNumRows)
Definition cl_BZ_Vector.hpp:63
Vector< T > & operator=(const ET &aExpression)
Definition cl_BZ_Vector.hpp:418
arma::Mat< T > VectorType
Definition cl_AR_Vector.hpp:38
Vector< T > & operator+=(const blaze::DMatScalarMultExpr< ET, T, false > &aExpression)
Definition cl_BZ_Vector.hpp:470
Vector(const blaze::Columns< blaze::DynamicMatrix< T, true >, true, true, false > &aColumn)
Constructor from column.
Definition cl_BZ_Vector.hpp:143
size_t length() const
get the length of the vector
Definition cl_BZ_Vector.hpp:291
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition cl_BZ_Vector.hpp:236
const T & operator()(const size_t aIndex) const
Definition cl_BZ_Vector.hpp:341
Vector< T > & operator/=(const T &aValue)
Definition cl_BZ_Vector.hpp:590
auto end() const
Definition cl_BZ_Vector.hpp:374
Vector< T > & operator%=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:559
T * begin()
Definition cl_BZ_Vector.hpp:356
Vector< T > & operator-=(const T &aValue)
Definition cl_BZ_Vector.hpp:481
Vector(const size_t aNumRows, const T &aValue)
Definition cl_BZ_Vector.hpp:68
Vector< T > & operator-=(const blaze::DMatScalarMultExpr< ET, T, false > &aExpression)
Definition cl_BZ_Vector.hpp:521
Vector(Vector< T > &&aVector) noexcept
move constructor
Definition cl_BZ_Vector.hpp:199
const VectorType & vector_data() const
expose the underlying matrix implementation ( const version )
Definition cl_BZ_Vector.hpp:247
Vector< T > & operator=(const Vector< T > &aVector)
copy assignment operator
Definition cl_BZ_Vector.hpp:317
Vector(const blaze::DenseVector< VT, false > &aExpression)
Constructor from column vector expression (TF=false).
Definition cl_BZ_Vector.hpp:121
virtual ~Vector()=default
empty destructor
Vector< T > & operator+=(const T &aValue)
Definition cl_BZ_Vector.hpp:429
Vector(const blaze::Rows< blaze::DynamicMatrix< T, true >, false, true, false > &aRow)
Constructor from row.
Definition cl_BZ_Vector.hpp:164
Vector< T > & operator*=(const T &aValue)
Definition cl_BZ_Vector.hpp:532
Vector< T > & operator-=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:492
const T * data() const
Definition cl_BZ_Vector.hpp:225
Vector< T > & operator*=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:541
Vector(const Cell< T > &aCell)
Definition cl_BZ_Vector.hpp:100
Vector(const VectorType &aExpression)
Definition cl_BZ_Vector.hpp:95
Vector(std::initializer_list< T > aInitList)
Definition cl_BZ_Vector.hpp:73
T * end()
Definition cl_BZ_Vector.hpp:362
Vector(const Vector< T > &aVector)
copy constructor
Definition cl_BZ_Vector.hpp:192
Vector< T > & operator=(std::initializer_list< T > aInitList)
Definition cl_BZ_Vector.hpp:394
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30