Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b4c6ee08 authored by hhakim's avatar hhakim
Browse files

Add move and assignment operator= overload, Vect::operator=.

- Faust::Vect move constructor and move assignment = overload avoid useless copy of r-value.
- new overload of operator-= to directly use the data pointer instead of a Vect.
parent ad8d2fe6
No related branches found
No related tags found
No related merge requests found
......@@ -118,9 +118,10 @@ namespace Faust
// template<typename U>
// Vect(const Vect<U>& v) : dim(v.dim), vec(v.vec){}
template<typename FPP1>
Vect(const Vect<FPP1,Cpu> & v);
Vect(const Vect<FPP,Cpu> & v) : dim(v.dim), vec(v.vec){}
Vect(const Vect<FPP1,Cpu>& v); // copy-convert scalar ctor
Vect(const Vect<FPP,Cpu>& v); //copy ctor
Vect(const faust_unsigned_int dim_, const FPP* data_);
Vect(Vect<FPP,Cpu>&& v); //move ctor
FPP* getData(){return vec.data();}
......@@ -161,8 +162,9 @@ namespace Faust
template<typename FPP1>
void operator=(Vect<FPP1,Cpu> const& y);
void operator=(Vect<FPP,Cpu> const& y);
void operator=(Vect<FPP1,Cpu> const& y); // copy assignment from different scalar type
Vect<FPP,Cpu>& operator=(const Vect<FPP,Cpu>& y); // copy assignment
Vect<FPP,Cpu>& operator=(Vect<FPP,Cpu>&& y); // move assignment
void operator*=(const FPP alpha);
void operator+=(const FPP alpha);
......@@ -170,6 +172,7 @@ namespace Faust
void operator+=(const Vect<FPP,Cpu> & v);
void operator-=(const Vect<FPP,Cpu> & v);
void operator-=(const FPP* v_data);
FPP mean_relative_error(const Vect<FPP,Cpu> & v);
......
......@@ -56,6 +56,23 @@ for (int i=0;i<dim;i++)
vec[i]=v(i);
}
template<typename FPP>
Faust::Vect<FPP,Cpu>::Vect(const Faust::Vect<FPP,Cpu>& v) : dim(v.dim), vec(v.vec)
{
}
template<typename FPP>
Faust::Vect<FPP,Cpu>::Vect(const faust_unsigned_int dim_, const FPP* data_) : dim(dim_), vec(dim_)
{
memcpy(getData(), data_, dim*sizeof(FPP));
}
template<typename FPP>
Faust::Vect<FPP,Cpu>::Vect(Faust::Vect<FPP,Cpu>&& v)
{
vec = std::move(v.vec);
dim = v.dim;
}
template<typename FPP>
bool Faust::Vect<FPP,Cpu>::equality(Faust::Vect<FPP,Cpu> const &x, FPP precision) const
......@@ -98,11 +115,6 @@ bool Faust::Vect<FPP,Cpu>::isReal() const
template<typename FPP>
Faust::Vect<FPP,Cpu>::Vect(const faust_unsigned_int dim_, const FPP* data_) : dim(dim_), vec(dim_)
{
memcpy(getData(), data_, dim*sizeof(FPP));
}
template<typename FPP>
void Faust::Vect<FPP,Cpu>::setOnes()
......@@ -191,14 +203,18 @@ void Faust::Vect<FPP,Cpu>::operator-=(const Faust::Vect<FPP,Cpu>& v)
{
handleError(m_className,"operator-= : dimensions are in conflict");
}
FPP*const ptr_data = getData();
const FPP* v_ptr_data = v.getData();
//#pragma omp parallel for
for (int i=0 ; i<size() ; i++)
ptr_data[i] -= v_ptr_data[i];
return *(this) -= v.getData();
}
template<typename FPP>
void Faust::Vect<FPP,Cpu>::operator-=(const FPP* v_data)
{
FPP*const ptr_data = getData();
#pragma omp parallel for
for (int i=0 ; i<size() ; i++)
ptr_data[i] -= v_data[i];
}
template<typename FPP>
FPP Faust::Vect<FPP,Cpu>::mean_relative_error(const Faust::Vect<FPP,Cpu>& v_ref)
......@@ -233,19 +249,28 @@ void Faust::Vect<FPP,Cpu>::operator=(Faust::Vect<FPP1,Cpu> const& y)
{
resize(y.dim);
//#pragma omp parallel for
for (int i=0;i<dim;i++)
vec[i]=y(i);
}
template<typename FPP>
void Faust::Vect<FPP,Cpu>::operator=(Faust::Vect<FPP,Cpu> const& y)
Faust::Vect<FPP,Cpu>& Faust::Vect<FPP,Cpu>::operator=(const Faust::Vect<FPP,Cpu>& y)
{
vec = y.vec;
dim = y.dim;
if(this->size() != y.size())
this->resize(y.size());
memcpy(this->getData(), y.getData(), y.size()*sizeof(FPP));
return *this;
}
template<typename FPP>
Faust::Vect<FPP,Cpu>& Faust::Vect<FPP,Cpu>::operator=(Faust::Vect<FPP,Cpu>&& y)
{
this->vec = std::move(y.vec);
this->dim = y.dim;
return *this;
}
template <typename FPP>
FPP Faust::Vect<FPP,Cpu>::dot(const Faust::Vect<FPP,Cpu>& v) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment