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;
70 mVector( aNumRows ) {}
77 Vector(
const size_t aNumRows,
const T & aValue ) :
78 mVector( aNumRows, aValue ) {}
85 Vector( std::initializer_list<T> aInitList )
87 if( aInitList.size() == 1 )
90 mVector.resize( 1,
false );
91 mVector[ 0 ] = *aInitList.begin();
96 mVector.resize( aInitList.size(),
false );
98 for(
const T & val : aInitList )
100 mVector[ i++ ] = val;
111 mVector( aExpression ) {}
117 mVector.resize( aCell.
size(),
false );
118 std::copy( aCell.
begin(), aCell.
end(), mVector.begin() );
123 Vector(
const std::vector< T > & aVector )
125 mVector.resize( aVector.size(),
false );
126 std::copy( aVector.begin(), aVector.end(), mVector.begin() );
135 template<
typename VT >
136 Vector(
const blaze::DenseVector<VT, false> & aExpression )
137 : mVector( static_cast< const VT& >( aExpression ) ) {}
142 template<
typename VT >
143 Vector(
const blaze::DenseVector<VT, true> & aExpression )
145 const VT & tRow =
static_cast< const VT&
>( aExpression );
146 mVector.resize( tRow.size(),
false );
147 for(
size_t k = 0; k < tRow.size(); ++k )
149 mVector[ k ] = tRow[ k ];
158 Vector(
const blaze::Columns<blaze::DynamicMatrix<T, true>,
true,
true,
false> & aColumn )
161 std::size_t tLength = aColumn.rows();
165 "aColumn must be a single column, but has %lu columns.",
166 (
long unsigned int ) aColumn.columns() );
169 mVector.resize( tLength ,
false );
171 std::copy( aColumn.data(), aColumn.data() + tLength, mVector.data() );
179 Vector(
const blaze::Rows<blaze::DynamicMatrix<T, true>,
false,
true,
false> & aRow )
182 std::size_t tLength = aRow.columns();
186 "aColumn must be a single row, but has %lu rows.",
187 (
long unsigned int ) aRow.rows());
190 mVector.resize( tLength,
false );
193 T * tTarget = mVector.data();
196 for ( std::size_t k = 0; k < tLength; ++k )
198 tTarget[ k ] = aRow.at( 0, k );
208 mVector( aVector.mVector )
215 mVector( std::move( aVector.mVector ) )
235 return mVector.data();
246 return mVector.data();
292 mVector.resize( aNumRows,
false );
298 set_size(
const size_t aNumRows,
const T & aValue )
301 this->
fill( aValue );
312 return mVector.size();
325 if (
this != & aVector )
327 mVector = std::move( aVector.mVector );
338 if (
this != &aVector )
340 mVector = aVector.mVector;
350 "Index %lu out of bounds, which must be smaller than %lu.",
351 (
long unsigned int ) aIndex,
352 (
long unsigned int ) this->
length());
354 return mVector[ aIndex ];
363 "Index %lu out of bounds, which must be smaller than %lu.",
364 (
long unsigned int ) aIndex,
365 (
long unsigned int ) this->
length());
367 return mVector[ aIndex ];
377 return mVector.data();
383 return mVector.data() + this->
length();
389 return mVector.data();
395 return mVector.data() + this->
length();
406 this->
fill( aValue );
415 if( aInitList.size() == 1 )
418 this->
set_size( 1, *aInitList.begin() );
425 for(
const T & val : aInitList )
427 mVector[ i++ ] = val;
435 template <
typename ET >
439 mVector = aExpression;
450 std::for_each( mVector.data(), mVector.data() + this->length(),
451 [ aValue ]( T & tVal )
452 { tVal += aValue; } );
487 template <
typename ET >
489 operator+=(
const blaze::DMatScalarMultExpr< ET, T, false> & aExpression )
491 mVector += blaze::column( aExpression, 0UL );
502 std::for_each( mVector.data(), mVector.data() + this->length(),
503 [ aValue ]( T & tVal )
504 { tVal -= aValue; } );
538 template <
typename ET >
540 operator-=(
const blaze::DMatScalarMultExpr< ET, T, false> & aExpression )
542 mVector -= blaze::column( aExpression, 0UL );
571 mVector *= aExpression;
580 size_t tN = this->
length();
583 "Vector sizes do not match ( %lu and %lu ).",
584 (
long unsigned int ) tN,
585 (
long unsigned int ) aVector.
length() );
587 for(
size_t k=0; k<tN; ++k )
589 mVector[ k ] *= aVector( k );
596 template <
typename ET >
600 mVector *= aExpression;
620 print(
const std::string aLabel=
"Vector" )
const;
627#pragma GCC diagnostic push
628#pragma GCC diagnostic ignored "-Wformat"
631 template <
typename T >
void
634 FILE * tOutFile = stdout;
636 fprintf( tOutFile,
"\n%s = [ ... \n", aLabel.c_str() );
643 for(
uint i=0; i< tLength; ++i )
646 fprintf( tOutFile,
"%d; ", (
int ) tThis( i ) );
651 fprintf( tOutFile,
"...\n" );
655 fprintf( tOutFile,
"];\n" );
666 FILE * tOutFile = stdout;
668 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
674 for(
uint i=0; i< tLength; ++i )
677 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i ) );
682 fprintf( tOutFile,
"...\n" );
686 fprintf( tOutFile,
"];\n" );
692#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_BZ_Vector.hpp:298
void print(const std::string aLabel="Vector") const
Vector< T > & operator+=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:469
Vector(const std::vector< T > &aVector)
Definition cl_BZ_Vector.hpp:123
void fill(const T &aValue)
write value into all entries of the vector
Definition cl_BZ_Vector.hpp:279
T & operator()(const size_t aIndex)
Definition cl_BZ_Vector.hpp:347
T * data()
expose the underlying raw pointer ( writable version )
Definition cl_BZ_Vector.hpp:233
Vector< T > & operator=(const T &aValue)
Definition cl_BZ_Vector.hpp:404
const T * begin() const
Definition cl_BZ_Vector.hpp:387
Vector< T > & operator*=(const VectorType &aExpression)
Definition cl_BZ_Vector.hpp:569
Vector(const blaze::DenseVector< VT, true > &aExpression)
Constructor from row vector expression (TF=true), transposes to column.
Definition cl_BZ_Vector.hpp:143
Vector< T > & operator*=(const ET &aExpression)
Definition cl_BZ_Vector.hpp:598
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_BZ_Vector.hpp:290
Vector< T > & operator=(Vector< T > &&aVector) noexcept
move assignment operator
Definition cl_BZ_Vector.hpp:323
Vector(const size_t aNumRows)
Constructor without fill value.
Definition cl_BZ_Vector.hpp:69
Vector< T > & operator=(const ET &aExpression)
Definition cl_BZ_Vector.hpp:437
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:489
Vector(const blaze::Columns< blaze::DynamicMatrix< T, true >, true, true, false > &aColumn)
Constructor from column.
Definition cl_BZ_Vector.hpp:158
size_t length() const
get the length of the vector
Definition cl_BZ_Vector.hpp:310
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition cl_BZ_Vector.hpp:255
const T & operator()(const size_t aIndex) const
Definition cl_BZ_Vector.hpp:360
Vector< T > & operator/=(const T &aValue)
Definition cl_BZ_Vector.hpp:609
auto end() const
Definition cl_BZ_Vector.hpp:393
Vector< T > & operator%=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:578
T * begin()
Definition cl_BZ_Vector.hpp:375
Vector< T > & operator-=(const T &aValue)
Definition cl_BZ_Vector.hpp:500
Vector(const size_t aNumRows, const T &aValue)
Constructor with fill value.
Definition cl_BZ_Vector.hpp:77
Vector< T > & operator-=(const blaze::DMatScalarMultExpr< ET, T, false > &aExpression)
Definition cl_BZ_Vector.hpp:540
Vector()=default
empty constructor
Vector(Vector< T > &&aVector) noexcept
move constructor
Definition cl_BZ_Vector.hpp:214
const VectorType & vector_data() const
expose the underlying matrix implementation ( const version )
Definition cl_BZ_Vector.hpp:266
Vector< T > & operator=(const Vector< T > &aVector)
copy assignment operator
Definition cl_BZ_Vector.hpp:336
Vector(const blaze::DenseVector< VT, false > &aExpression)
Constructor from column vector expression (TF=false).
Definition cl_BZ_Vector.hpp:136
virtual ~Vector()=default
empty destructor
Vector< T > & operator+=(const T &aValue)
Definition cl_BZ_Vector.hpp:448
Vector(const blaze::Rows< blaze::DynamicMatrix< T, true >, false, true, false > &aRow)
Constructor from row.
Definition cl_BZ_Vector.hpp:179
Vector< T > & operator*=(const T &aValue)
Definition cl_BZ_Vector.hpp:551
Vector< T > & operator-=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:511
const T * data() const
expose the underlying raw pointer ( const version )
Definition cl_BZ_Vector.hpp:244
Vector< T > & operator*=(const Vector< T > &aVector)
Definition cl_BZ_Vector.hpp:560
Vector(const Cell< T > &aCell)
Definition cl_BZ_Vector.hpp:115
Vector(const VectorType &aExpression)
Constructor from expression.
Definition cl_BZ_Vector.hpp:110
Vector(std::initializer_list< T > aInitList)
Constructor with initializer list.
Definition cl_BZ_Vector.hpp:85
T * end()
Definition cl_BZ_Vector.hpp:381
Vector(const Vector< T > &aVector)
copy constructor
Definition cl_BZ_Vector.hpp:207
Vector< T > & operator=(std::initializer_list< T > aInitList)
Definition cl_BZ_Vector.hpp:413
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30