37#ifndef STK_ARRAY2D_FUNCTORS_H
38#define STK_ARRAY2D_FUNCTORS_H
40#define BINARY_RETURN_TYPE(Lhs,Rhs) \
41typename hidden::BinaryReturnArray2DType< typename hidden::Promote< typename hidden::Traits<Lhs>::Type \
42 , typename hidden::Traits<Rhs>::Type >::result_type \
43 , hidden::Traits<Lhs>::structure_ \
44 , hidden::Traits<Rhs>::structure_ \
51template<
typename>
class Array2D;
52template<
typename>
class Array2DSquare;
53template<
typename>
class Array2DUpperTriangular;
54template<
typename>
class Array2DLowerTriangular;
55template<
typename>
class Array2DDiagonal;
56template<
typename>
class Array2DPoint;
57template<
typename>
class Array2DVector;
58template<
typename>
class Array2DNumber;
222template<
typename Lhs,
typename Rhs>
232 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
269template<
typename Lhs,
typename Rhs>
279 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
316template<
typename Lhs,
typename Rhs>
326 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
356template<
typename Lhs,
typename Rhs>
366 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
394template<
typename Lhs,
typename Rhs>
404 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
414 for (
int j=
res_.beginCols();
j<
res_.endCols();
j++)
417 for (
int i=
res_.rangeRowsInCol(
j).begin();
i<end;
i++)
422 template<
typename Weights>
427 for (
int j=
res_.beginCols();
j<
res_.endCols();
j++)
430 for (
int i=
res_.rangeRowsInCol(
j).begin();
i<end;
i++)
448template<
typename Lhs,
typename Rhs>
458 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
467 for (
int j=
res_.beginCols();
j<
res_.endCols();
j++)
470 for (
int i=
res_.rangeRowsInCol(
j).begin();
i<end;
i++)
475 template<
typename Weights>
479 for (
int j=
rhs_.beginCols();
j<
rhs_.endCols();
j++)
482 for (
int i=
res_.rangeRowsInCol(
j).begin();
i<end;
i++)
500template<
typename Lhs,
typename Rhs>
510 :
lhs_(lhs.asDerived()),
rhs_(rhs.asDerived())
519 for (
int j=
res_.beginCols();
j<
res_.endCols();
j++)
522 for (
int i=
res_.rangeRowsInCol(
j).begin();
i<end;
i++)
527 template<
typename Weights>
531 for (
int j=
res_.beginCols();
j<
res_.endCols();
j++)
534 for (
int i=
res_.rangeRowsInCol(
j).begin();
i<end;
i++)
552template<
typename Lhs,
typename Rhs>
559template<
typename Lhs,
typename Rhs>
566template<
typename Lhs,
typename Rhs>
573template<
typename Lhs,
typename Rhs>
580template<
typename Lhs,
typename Rhs>
587template<
typename Lhs,
typename Rhs,
typename Weights>
594template<
typename Lhs,
typename Rhs>
601template<
typename Lhs,
typename Rhs,
typename Weights>
608template<
typename Lhs,
typename Rhs>
615template<
typename Lhs,
typename Rhs,
typename Weights>
632template<
class Container1D1,
class Container1D2>
636 const int first = std::max(x.begin(),
y.begin()) , end = std::min(x.end(),
y.end());
639 for (
int i = first;
i<end; ++
i)
sum += x[
i] *
y[
i];
656template<
class Container1D1,
class Container1D2,
class Container1D3>
663 const int first = std::max(x.begin(),
y.begin()) ,
last = std::min(x.lastIdx(),
y.lastIdx());
691template<
class Container1D1,
class Container1D2>
695 const int first = std::max(x.begin(),
y.begin()) ,
last = std::min(x.lastIdx(),
y.lastIdx());
698 for (
int i = first;
i<=
last;
i++)
699 scale = std::max(scale, std::abs(x[
i] -
y[
i]));
704 for (
int i = first;
i<=
last;
i++)
711 return (
Real(sqrt(
double(norm2)))*scale);
728template<
class Container1D1,
class Container1D2,
class Container1D3>
735 const int first = std::max(x.begin(),
y.begin()) ,
last = std::min(x.lastIdx(),
y.lastIdx());
739 "Range(first,last) not include in w.range()");
742 Real scale = 0., norm2= 0.;
743 for (
int i = first;
i<=
last;
i++)
744 scale = std::max(scale, std::abs(
w[
i]*(x[
i] -
y[
i])));
748 for (
int i = first;
i<=
last;
i++)
755 return (
Real(sqrt(
double(norm2)))*scale);
765template<
typename Derived>
768 typedef typename Derived::Type Type;
770 for (
int i=
A.beginCols();
i<=
A.lastIdxCols();
i++)
773 for (
int k =
A.beginRows(); k<
A.endRows(); k++)
res(
i,
i) +=
A(k,
i) *
A(k,
i);
775 for (
int j=
A.beginCols();
j<
i;
j++)
777 for (
int k =
A.beginRows(); k<
A.endRows(); k++)
792template<
typename Derived>
795 typedef typename Derived::Type Type;
797 for (
int i=
A.beginRows();
i<=
A.lastIdxRows();
i++)
800 for (
int k =
A.beginCols(); k<
A.endCols(); k++)
803 for (
int j=
A.beginRows();
j<
i;
j++)
805 for (
int k =
A.beginCols(); k<
A.endCols(); k++)
821template<
typename Derived,
typename Weights>
822Array2DSquare<typename Derived::Type>
825 typedef typename Derived::Type Type;
827 for (
int i=
A.beginCols();
i<=
A.lastIdxCols();
i++)
830 for (
int k =
A.beginRows(); k<
A.endRows(); k++)
833 for (
int j=
A.beginCols();
j<
i;
j++)
835 for (
int k =
A.beginRows(); k<
A.endRows(); k++)
851template<
typename Derived,
typename Weights>
852Array2DSquare<typename Derived::Type>
855 typedef typename Derived::Type Type;
857 for (
int i=
A.beginRows();
i<=
A.lastIdxRows();
i++)
860 for (
int k =
A.beginCols(); k<
A.endCols(); k++)
863 for (
int j=
A.beginRows();
j<
i;
j++)
865 for (
int k =
A.beginCols(); k<
A.endCols(); k++)
876#undef BINARY_RETURN_TYPE
#define BINARY_RETURN_TYPE(Lhs, Rhs)
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
int begin() const
get the first index of the TRange.
Index sub-vector region: Specialization when the size is unknown.
int end() const
get the ending index of the TRange.
Runtime errors represent problems outside the scope of a program; they cannot be easily predicted and...
Real weightedDist(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y, ExprBase< Container1D3 > const &w)
Compute the weighted distance between two vectors.
Arrays::DivOp< Lhs, Rhs >::result_type div(Lhs const &lhs, Rhs const &rhs)
convenience function for the division element by element of two arrays
Real weightedDot(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y, ExprBase< Container1D3 > const &w)
Compute the dot product.
Arrays::Product< Lhs, Rhs >::result_type product(Lhs const &lhs, Rhs const &rhs)
convenience function for the product element by element of two arrays
Array2DSquare< typename Derived::Type > weightedMultRightTranspose(ExprBase< Derived > const &A, ExprBase< Weights > const &weights)
weighted Array multiplication by its transpose
Array2DSquare< typename Derived::Type > weightedMultLeftTranspose(ExprBase< Derived > const &A, ExprBase< Weights > const &weights)
Weighted matrix multiplication by its transpose.
Arrays::MultOp< Lhs, Rhs >::result_type wmult(Lhs const &lhs, Rhs const &rhs, Weights const &weights)
convenience function for the multiplication of two matrices
Arrays::MultOp< Lhs, Rhs >::result_type mult(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices
Arrays::MultLeftTransposeOp< Lhs, Rhs >::result_type wmultLeftTranspose(Lhs const &lhs, Rhs const &rhs, Weights const &weights)
convenience function for the multiplication of two matrices
Real dist(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y)
Compute the distance between two vectors.
Real dot(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y)
Compute the dot product.
Arrays::MultLeftTransposeOp< Lhs, Rhs >::result_type multLeftTranspose(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices
Arrays::DifferenceOp< Lhs, Rhs >::result_type difference(Lhs const &lhs, Rhs const &rhs)
convenience function for differencing two arrays
Arrays::MultRightTransposeOp< Lhs, Rhs >::result_type multRightTranspose(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices
Arrays::MultRightTransposeOp< Lhs, Rhs >::result_type wmultRightTranspose(Lhs const &lhs, Rhs const &rhs, Weights const &weights)
convenience function for the multiplication of two matrices
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
@ array2D_
general matrix/array/expression
@ point_
row oriented vector/array/expression
@ lower_triangular_
lower triangular matrix/array/expression
@ upper_triangular_
upper triangular matrix/array/expression
@ diagonal_
diagonal matrix/array/expression
@ vector_
column oriented vector/array/expression
@ square_
square matrix/array/expression
Range inf(TRange< SizeI_ > const &I, TRange< SizeJ_ > const &J)
compute inf(I,J).
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range
Array difference (by coefficient) Perform the matrix difference coefficient by coefficient of the Arr...
hidden::BinaryReturnArray2DType< typenamehidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type, hidden::Traits< Lhs >::structure_, hidden::Traits< Rhs >::structure_ >::result_type result_type
DifferenceOp(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
hidden::BinaryReturnArray2DType< typenamehidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type, hidden::Traits< Lhs >::structure_, hidden::Traits< Rhs >::structure_ >::result_type result_type
DivOp(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
Array multiplication Perform the matrix product of the transposed Array lhs by the Array rhs.
result_type operator()(ExprBase< Weights > const &weights)
MultLeftTransposeOp(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
hidden::ProductArray2DReturnType< Type, Lhs::structure_, Rhs::structure_ >::result_type result_type
Array multiplication Perform the matrix product of the Array lhs by the Array rhs.
result_type operator()(ExprBase< Weights > const &weights)
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
hidden::ProductArray2DReturnType< Type, Lhs::structure_, Rhs::structure_ >::result_type result_type
MultOp(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
Array multiplication Perform the matrix product of the Array lhs by the transposed Array rhs.
hidden::ProductArray2DReturnType< Type, Lhs::structure_, Rhs::structure_ >::result_type result_type
MultRightTransposeOp(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
result_type operator()(ExprBase< Weights > const &weights)
Array product (by coefficient) Perform the matrix product coefficient by coefficient of the Array lhs...
Product(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
hidden::BinaryReturnArray2DType< typenamehidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type, hidden::Traits< Lhs >::structure_, hidden::Traits< Rhs >::structure_ >::result_type result_type
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
Array sum (by coefficient) Perform the matrix sum coefficient by coefficient of the Array lhs by the ...
hidden::BinaryReturnArray2DType< typenamehidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type, hidden::Traits< Lhs >::structure_, hidden::Traits< Rhs >::structure_ >::result_type result_type
hidden::Promote< typenamehidden::Traits< Lhs >::Type, typenamehidden::Traits< Rhs >::Type >::result_type Type
SumOp(ExprBase< Lhs > const &lhs, ExprBase< Rhs > const &rhs)
Array2D< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2DDiagonal< Type > result_type
Array2DLowerTriangular< Type > result_type
Array2DSquare< Type > result_type
Array2DUpperTriangular< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2DLowerTriangular< Type > result_type
Array2D< Type > result_type
Array2DLowerTriangular< Type > result_type
Array2D< Type > result_type
Array2DSquare< Type > result_type
Array2D< Type > result_type
Array2DSquare< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2DUpperTriangular< Type > result_type
Array2D< Type > result_type
Array2DUpperTriangular< Type > result_type
Helper class to get the correct returned Structure of Functors.
Array2DVector< Type > result_type
Array2D< Type > result_type
Array2D< Type > result_type
Array2DDiagonal< Type > result_type
Array2DLowerTriangular< Type > result_type
Array2DSquare< Type > result_type
Array2DUpperTriangular< Type > result_type
Array2DVector< Type > result_type
Array2DLowerTriangular< Type > result_type
Array2DVector< Type > result_type
Array2D< Type > result_type
Array2DLowerTriangular< Type > result_type
Array2DPoint< Type > result_type
Array2DPoint< Type > result_type
Array2DPoint< Type > result_type
Array2DPoint< Type > result_type
Array2DPoint< Type > result_type
Array2DNumber< Type > result_type
Array2D< Type > result_type
Array2DSquare< Type > result_type
Array2D< Type > result_type
Array2DSquare< Type > result_type
Array2D< Type > result_type
Array2DVector< Type > result_type
Array2DUpperTriangular< Type > result_type
Array2DVector< Type > result_type
Array2D< Type > result_type
Array2DUpperTriangular< Type > result_type
Array2D< Type > result_type
Helper class to get the correct returned Type for Array2D* classes when a product is performed betwee...