49 template<
class L,
class R>
struct Field
60 template<class L, class R, int F = Field<L,R>::is>
struct AddType {
typedef TOON_TYPEOF(gettype<L>()+gettype<R>()) type;};
61 template<class L, class R, int F = Field<L,R>::is>
struct SubtractType {
typedef TOON_TYPEOF(gettype<L>()-gettype<R>()) type;};
62 template<class L, class R, int F = Field<L,R>::is>
struct MultiplyType {
typedef TOON_TYPEOF(gettype<L>()*gettype<R>()) type;};
63 template<class L, class R, int F = Field<L,R>::is>
struct DivideType {
typedef TOON_TYPEOF(gettype<L>()/gettype<R>()) type;};
73 template<
class A,
class B,
class C>
static A
op(
const B& b,
const C& c){
return b+c;}
77 template<
class A,
class B,
class C>
static A
op(
const B& b,
const C& c){
return b-c;}
81 template<
class A,
class B,
class C>
static A
op(
const B& b,
const C& c){
return b*c;}
85 template<
class A,
class B,
class C>
static A
op(
const B& b,
const C& c){
return b/c;}
103 template<
typename Op,
104 int S1,
typename P1,
typename B1,
105 int S2,
typename P2,
typename B2>
108 template <
int S,
typename P,
typename A>
112 template<
typename Op,
113 int S1,
typename P1,
typename B1,
114 int S2,
typename P2,
typename B2>
115 struct Operator<Internal::VPairwise<Op, S1, P1, B1, S2, P2, B2> > {
121 template<
int S0,
typename P0,
typename Ba0>
124 for(
int i=0; i < res.size(); ++i)
125 res[i] = Op::template op<P0,P1, P2>(lhs[i],rhs[i]);
127 int size()
const {
return lhs.size();}
131 template<
int S1,
int S2,
typename P1,
typename P2,
typename B1,
typename B2>
132 Vector<Internal::Sizer<S1,S2>::size,
typename Internal::AddType<P1, P2>::type>
140 template<
int S1,
int S2,
typename P1,
typename P2,
typename B1,
typename B2>
148 template <
int S1,
int S2,
typename P1,
typename P2,
typename B1,
typename B2>
155 template<
int S,
typename P,
typename A>
160 template<
int S0,
typename P0,
typename A0>
165 int size()
const {
return input.size(); }
169 template <
int S,
typename P,
typename A>
175 template<
int Size1,
typename Precision1,
typename Base1,
int Size2,
typename Precision2,
typename Base2>
178 const int s=v1.size();
180 for(
int i=0; i<s; i++){
186 template <
typename P1,
typename P2,
typename B1,
typename B2>
193 result[0] = v1[1]*v2[2] - v1[2]*v2[1];
194 result[1] = v1[2]*v2[0] - v1[0]*v2[2];
195 result[2] = v1[0]*v2[1] - v1[1]*v2[0];
208 template<
typename Op,
209 int R1,
int C1,
typename P1,
typename B1,
210 int R2,
int C2,
typename P2,
typename B2>
213 template<
int R1,
int C1,
typename P1,
typename B1,
214 int R2,
int C2,
typename P2,
typename B2>
217 template<
int R,
int C,
typename P,
typename A>
221 template<
typename Op,
222 int R1,
int C1,
typename P1,
typename B1,
223 int R2,
int C2,
typename P2,
typename B2>
224 struct Operator<Internal::MPairwise<Op, R1, C1, P1, B1, R2, C2, P2, B2> > {
230 template<
int R0,
int C0,
typename P0,
typename Ba0>
233 for(
int r=0; r < res.num_rows(); ++r){
234 for(
int c=0; c < res.num_cols(); ++c){
235 res(r,c) = Op::template op<P0,P1, P2>(lhs(r,c),rhs(r,c));
244 template<
int R1,
int R2,
int C1,
int C2,
typename P1,
typename P2,
typename B1,
typename B2>
245 Matrix<Internal::Sizer<R1,R2>::size, Internal::Sizer<C1,C2>::size,
typename Internal::AddType<P1, P2>::type>
254 template<
int R1,
int R2,
int C1,
int C2,
typename P1,
typename P2,
typename B1,
typename B2>
255 Matrix<Internal::Sizer<R1,R2>::size, Internal::Sizer<C1,C2>::size,
typename Internal::SubtractType<P1, P2>::type>
263 template<
int R,
int C,
typename P,
typename A>
268 template<
int R0,
int C0,
typename P0,
typename A0>
278 template <
int R,
int C,
typename P,
typename A>
283 template<
int R1,
int C1,
typename P1,
typename B1,
284 int R2,
int C2,
typename P2,
typename B2>
285 struct Operator<Internal::MatrixMultiply<R1, C1, P1, B1, R2, C2, P2, B2> > {
291 template<
int R0,
int C0,
typename P0,
typename Ba0>
295 for(
int r=0; r < res.num_rows(); ++r) {
296 for(
int c=0; c < res.num_cols(); ++c) {
297 res(r,c) = lhs[r] * (rhs.T()[c]);
310 template<
int R1,
int C1,
int R2,
int C2,
typename P1,
typename P2,
typename B1,
typename B2>
311 Matrix<R1, C2, typename Internal::MultiplyType<P1, P2>::type>
operator*(
const Matrix<R1, C1, P1, B1>& m1,
const Matrix<R2, C2, P2, B2>& m2)
324 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
328 template<
int Size,
typename P1,
typename B1,
int R,
int C,
typename P2,
typename B2>
332 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
336 template<
int Size,
typename P1,
typename B1,
int R,
int C,
typename P2,
typename B2>
342 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
343 struct Operator<Internal::MatrixVectorMultiply<R,C,P1,B1,Size,P2,B2> > {
349 int size()
const {
return lhs.num_rows();}
351 template<
int Sout,
typename Pout,
typename Bout>
353 for(
int i=0; i < res.size(); ++i){
354 res[i] = lhs[i] * rhs;
359 template<
int R,
int C,
int Size,
typename P1,
typename P2,
typename B1,
typename B2>
367 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
368 struct Operator<Internal::VectorMatrixMultiply<Size,P1,B1,R,C,P2,B2> > {
374 int size()
const {
return rhs.num_cols();}
376 template<
int Sout,
typename Pout,
typename Bout>
378 for(
int i=0; i < res.size(); ++i){
379 res[i] = lhs * rhs.T()[i];
384 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
394 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
395 struct Operator<Internal::MatrixVectorDiagMultiply<R,C,P1,B1,Size,P2,B2> > {
404 template<
int Rout,
int Cout,
typename Pout,
typename Bout>
406 for(
int c=0; c < res.num_cols(); ++c) {
408 for(
int r=0; r < res.num_rows(); ++r) {
409 res(r,c) = lhs(r,c)*temp;
415 template<
int R,
int C,
int Size,
typename P1,
typename P2,
typename B1,
typename B2>
423 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
424 struct Operator<Internal::VectorMatrixDiagMultiply<Size,P1,B1,R,C,P2,B2> > {
433 template<
int Rout,
int Cout,
typename Pout,
typename Bout>
435 for(
int r=0; r < res.num_rows(); ++r){
436 const P1 temp = lhs[r];
437 for(
int c=0; c<res.num_cols(); ++c){
438 res(r,c) = temp * rhs(r,c);
444 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
463 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
466 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
469 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
472 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
476 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
477 struct Operator<Internal::ApplyScalarV<Size,P1,B1,P2,Op> > {
483 template<
int S0,
typename P0,
typename Ba0>
485 for(
int i=0; i<v.size(); i++){
486 v[i]= Op::template op<P0,P1,P2> (lhs[i],rhs);
495 template <
int Size,
typename P1,
typename B1,
typename P2>
499 template <
int Size,
typename P1,
typename B1,
typename P2>
504 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
505 struct Operator<Internal::ApplyScalarVL<Size,P1,B1,P2,Op> > {
511 template<
int S0,
typename P0,
typename Ba0>
513 for(
int i=0; i<v.size(); i++){
514 v[i]= Op::template op<P0,P2,P1> (lhs,rhs[i]);
522 template <
int Size,
typename P1,
typename B1,
typename P2>
531 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
532 struct Operator<Internal::ApplyScalarM<R,C,P1,B1,P2,Op> > {
538 template<
int R0,
int C0,
typename P0,
typename Ba0>
540 for(
int r=0; r<m.num_rows(); r++){
541 for(
int c=0; c<m.num_cols(); c++){
542 m(r,c)= Op::template op<P0,P1,P2> (lhs(r,c),rhs);
548 return lhs.num_rows();
551 return lhs.num_cols();
555 template <
int R,
int C,
typename P1,
typename B1,
typename P2>
559 template <
int R,
int C,
typename P1,
typename B1,
typename P2>
564 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
565 struct Operator<Internal::ApplyScalarML<R,C,P1,B1,P2,Op> > {
571 template<
int R0,
int C0,
typename P0,
typename Ba0>
573 for(
int r=0; r<m.num_rows(); r++){
574 for(
int c=0; c<m.num_cols(); c++){
575 m(r,c)= Op::template op<P0,P1,P2> (lhs,rhs(r,c));
581 return rhs.num_rows();
584 return rhs.num_cols();
588 template <
int R,
int C,
typename P1,
typename B1,
typename P2>
597 template <
int Size,
typename P1,
typename B1,
typename Op>
602 template <
int Size,
typename P1,
typename B1,
typename Op>
607 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
612 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
620 template <
int Size,
typename P1,
typename B1,
typename Op>
622 return op.rsubtract(v);
625 template <
int Size,
typename P1,
typename B1,
typename Op>
627 return op.lsubtract(v);
630 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
632 return op.rsubtract(m);
635 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
637 return op.lsubtract(m);
645 template <
int Size,
typename Precision,
typename Base>
646 inline std::ostream& operator<< (std::ostream& os, const Vector<Size,Precision,Base>& v){
647 std::streamsize fw = os.width();
648 for(
int i=0; i<v.size(); i++){
656 template <
int Size,
typename Precision,
typename Base>
658 for (
int i=0; i<v.size(); i++){
664 template<
int Rows,
int Cols,
typename Precision,
class Base>
665 inline std::ostream& operator<< (std::ostream& os, const Matrix<Rows, Cols, Precision, Base>& m){
666 std::streamsize fw = os.width();
667 for(
int i=0; i < m.num_rows(); i++)
669 for(
int j=0; j < m.num_cols(); j++)
682 template <
int Rows,
int Cols,
typename Precision,
typename Base>
684 for(
int r=0; r<m.num_rows(); r++){
685 for(
int c=0; c < m.num_cols(); c++){
const Vector< Size, P1, B1 > & lhs
Operator(const Vector< Size, P1, B1 > &lhs_in, const Matrix< R, C, P2, B2 > &rhs_in)
static const int is
Operator(const Vector< S, P, A > &in)
Operator< Op< typename Internal::DivideType< Pl, Pr >::type > > operator/(const Operator< Op< Pl > > &l, const Pr &r)
These_Types_Do_Not_Form_A_Field< L, R > type
void eval(Matrix< Rout, Cout, Pout, Bout > &res) const
void eval(Vector< Sout, Pout, Bout > &res) const
const Vector< S1, P1, B1 > & lhs
void eval(Matrix< R0, C0, P0, Ba0 > &res) const
void eval(Vector< S0, P0, Ba0 > &res) const
These_Types_Do_Not_Form_A_Field< L, R > type
static A op(const B &b, const C &c)
void eval(Vector< S0, P0, A0 > &res) const
static A op(const B &b, const C &c)
void eval(Vector< S0, P0, Ba0 > &v) const
Vector< Internal::Sizer< S1, S2 >::size, typename Internal::AddType< P1, P2 >::type > operator+(const Vector< S1, P1, B1 > &v1, const Vector< S2, P2, B2 > &v2)
Everything lives inside this namespace.
Operator(const Matrix< R1, C1, P1, B1 > &lhs_in, const Matrix< R2, C2, P2, B2 > &rhs_in)
const Matrix< R1, C1, P1, B1 > & lhs
static void test(int s1, int s2)
SubtractType< P1, P2 >::type Type
DivideType< P1, P2 >::type Type
Operator(const Vector< S1, P1, B1 > &lhs_in, const Vector< S2, P2, B2 > &rhs_in)
Vector< 3, typename Internal::MultiplyType< P1, P2 >::type > operator^(const Vector< 3, P1, B1 > &v1, const Vector< 3, P2, B2 > &v2)
const Vector< Size, P1, B1 > & rhs
void eval(Vector< S0, P0, Ba0 > &v) const
Operator(const Matrix< R, C, P1, B1 > &m, const P2 &s)
const Vector< S2, P2, B2 > & rhs
void eval(Matrix< R0, C0, P0, Ba0 > &res) const
void eval(Matrix< R0, C0, P0, A0 > &res) const
typedef TOON_TYPEOF(gettype< L >()-gettype< R >()) type
const Matrix< R, C, P, A > & input
These_Types_Do_Not_Form_A_Field< L, R > type
const Matrix< R, C, P1, B1 > & rhs
void eval(Matrix< R0, C0, P0, Ba0 > &m) const
const Vector< Size, P2, B2 > & rhs
typedef TOON_TYPEOF(gettype< L >()*gettype< R >()) type
void eval(Vector< Sout, Pout, Bout > &res) const
Operator< Op > operator-(const Operator< Op > &o)
Operator(const Vector< Size, P1, B1 > &lhs_in, const Matrix< R, C, P2, B2 > &rhs_in)
void eval(Matrix< Rout, Cout, Pout, Bout > &res) const
static A op(const B &b, const C &c)
const Vector< S, P, A > & input
const Matrix< R, C, P1, B1 > & lhs
const Vector< Size, P1, B1 > & lhs
const Vector< Size, P1, B1 > & lhs
const Vector< Size, P2, B2 > & rhs
const Matrix< R2, C2, P2, B2 > & rhs
const Matrix< R, C, P2, B2 > & rhs
Operator(const Matrix< R, C, P, A > &in)
Operator(const P2 &s, const Vector< Size, P1, B1 > &v)
void eval(Matrix< R0, C0, P0, Ba0 > &m) const
Operator(const Matrix< R, C, P1, B1 > &lhs_in, const Vector< Size, P2, B2 > &rhs_in)
AddType< P1, P2 >::type Type
const Matrix< R, C, P1, B1 > & lhs
Operator(const Vector< Size, P1, B1 > &v, const P2 &s)
const Matrix< R2, C2, P2, B2 > & rhs
std::istream & operator>>(std::istream &is, Vector< Size, Precision, Base > &v)
Operator(const P2 &s, const Matrix< R, C, P1, B1 > &m)
Operator(const Matrix< R1, C1, P1, B1 > &lhs_in, const Matrix< R2, C2, P2, B2 > &rhs_in)
Vector< Internal::Sizer< S1, S2 >::size, typename Internal::MultiplyType< P1, P2 >::type > operator*(const DiagonalMatrix< S1, P1, B1 > &d, const Vector< S2, P2, B2 > &v)
const Matrix< R, C, P1, B1 > & lhs
typedef TOON_TYPEOF(gettype< L >()+gettype< R >()) type
MultiplyType< P1, P2 >::type Type
Vector< Internal::Sizer< S1, S2 >::size, typename Internal::MultiplyType< P1, P2 >::type > diagmult(const Vector< S1, P1, B1 > &v1, const Vector< S2, P2, B2 > &v2)
typedef TOON_TYPEOF(gettype< L >()/gettype< R >()) type
const Matrix< R1, C1, P1, B1 > & lhs
const Matrix< R, C, P2, B2 > & rhs
Operator(const Matrix< R, C, P1, B1 > &lhs_in, const Vector< Size, P2, B2 > &rhs_in)
These_Types_Do_Not_Form_A_Field< L, R > type
static A op(const B &b, const C &c)