39 template<
class L,
class R>
struct Field 51 template<
class C> C gettype();
59 template<
class C>
struct Clean<const C>
64 template<
class C>
struct Clean<const C&>
69 template<
class C>
struct Clean<C&>
74 template<
class L,
class R>
struct CField 84 template<class L, class R, int F = CField<L,R>::is>
struct AddType {
typedef decltype (gettype<L>()+gettype<R>()) type;};
85 template<class L, class R, int F = CField<L,R>::is>
struct SubtractType {
typedef decltype (gettype<L>()-gettype<R>()) type;};
86 template<class L, class R, int F = CField<L,R>::is>
struct MultiplyType {
typedef decltype (gettype<L>()*gettype<R>()) type;};
87 template<class L, class R, int F = CField<L,R>::is>
struct DivideType {
typedef decltype (gettype<L>()/gettype<R>()) type;};
97 template<
class A,
class B,
class C>
static A op(
const B& b,
const C& c){
return b+c;}
101 template<
class A,
class B,
class C>
static A op(
const B& b,
const C& c){
return b-c;}
105 template<
class A,
class B,
class C>
static A op(
const B& b,
const C& c){
return b*c;}
109 template<
class A,
class B,
class C>
static A op(
const B& b,
const C& c){
return b/c;}
127 template<
typename Op,
128 int S1,
typename P1,
typename B1,
129 int S2,
typename P2,
typename B2>
132 template <
int S,
typename P,
typename A>
136 template<
typename Op,
137 int S1,
typename P1,
typename B1,
138 int S2,
typename P2,
typename B2>
139 struct Operator<Internal::VPairwise<Op, S1, P1, B1, S2, P2, B2> > {
145 template<
int S0,
typename P0,
typename Ba0>
148 for(
int i=0; i < res.size(); ++i)
149 res[i] = Op::template op<P0,P1, P2>(lhs[i],rhs[i]);
151 int size()
const {
return lhs.size();}
155 template<
int S1,
int S2,
typename P1,
typename P2,
typename B1,
typename B2>
164 template<
int S1,
int S2,
typename P1,
typename P2,
typename B1,
typename B2>
172 template <
int S1,
int S2,
typename P1,
typename P2,
typename B1,
typename B2>
179 template<
int S,
typename P,
typename A>
184 template<
int S0,
typename P0,
typename A0>
189 int size()
const {
return input.size(); }
193 template <
int S,
typename P,
typename A>
199 template<
int Size1,
typename Precision1,
typename Base1,
int Size2,
typename Precision2,
typename Base2>
202 const int s=v1.size();
204 for(
int i=0; i<s; i++){
210 template <
typename P1,
typename P2,
typename B1,
typename B2>
217 result[0] = v1[1]*v2[2] - v1[2]*v2[1];
218 result[1] = v1[2]*v2[0] - v1[0]*v2[2];
219 result[2] = v1[0]*v2[1] - v1[1]*v2[0];
232 template<
typename Op,
233 int R1,
int C1,
typename P1,
typename B1,
234 int R2,
int C2,
typename P2,
typename B2>
237 template<
int R1,
int C1,
typename P1,
typename B1,
238 int R2,
int C2,
typename P2,
typename B2>
241 template<
int R,
int C,
typename P,
typename A>
245 template<
typename Op,
246 int R1,
int C1,
typename P1,
typename B1,
247 int R2,
int C2,
typename P2,
typename B2>
248 struct Operator<Internal::MPairwise<Op, R1, C1, P1, B1, R2, C2, P2, B2> > {
254 template<
int R0,
int C0,
typename P0,
typename Ba0>
257 for(
int r=0; r < res.num_rows(); ++r){
258 for(
int c=0; c < res.num_cols(); ++c){
259 res(r,c) = Op::template op<P0,P1, P2>(lhs(r,c),rhs(r,c));
263 int num_rows()
const {
return lhs.num_rows();}
264 int num_cols()
const {
return lhs.num_cols();}
268 template<
int R1,
int R2,
int C1,
int C2,
typename P1,
typename P2,
typename B1,
typename B2>
278 template<
int R1,
int R2,
int C1,
int C2,
typename P1,
typename P2,
typename B1,
typename B2>
287 template<
int R,
int C,
typename P,
typename A>
292 template<
int R0,
int C0,
typename P0,
typename A0>
297 int num_rows()
const {
return input.num_rows(); }
298 int num_cols()
const {
return input.num_cols(); }
302 template <
int R,
int C,
typename P,
typename A>
307 template<
int R1,
int C1,
typename P1,
typename B1,
308 int R2,
int C2,
typename P2,
typename B2>
309 struct Operator<Internal::MatrixMultiply<R1, C1, P1, B1, R2, C2, P2, B2> > {
315 template<
int R0,
int C0,
typename P0,
typename Ba0>
319 for(
int r=0; r < res.num_rows(); ++r) {
320 for(
int c=0; c < res.num_cols(); ++c) {
321 res(r,c) = lhs[r] * (rhs.T()[c]);
325 int num_rows()
const {
return lhs.num_rows();}
326 int num_cols()
const {
return rhs.num_cols();}
334 template<
int R1,
int C1,
int R2,
int C2,
typename P1,
typename P2,
typename B1,
typename B2>
335 Matrix<R1, C2, typename Internal::MultiplyType<P1, P2>::type> operator*(
const Matrix<R1, C1, P1, B1>& m1,
const Matrix<R2, C2, P2, B2>& m2)
348 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
352 template<
int Size,
typename P1,
typename B1,
int R,
int C,
typename P2,
typename B2>
356 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
360 template<
int Size,
typename P1,
typename B1,
int R,
int C,
typename P2,
typename B2>
366 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
367 struct Operator<Internal::MatrixVectorMultiply<R,C,P1,B1,Size,P2,B2> > {
373 int size()
const {
return lhs.num_rows();}
375 template<
int Sout,
typename Pout,
typename Bout>
377 for(
int i=0; i < res.size(); ++i){
378 res[i] = lhs[i] * rhs;
383 template<
int R,
int C,
int Size,
typename P1,
typename P2,
typename B1,
typename B2>
391 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
392 struct Operator<Internal::VectorMatrixMultiply<Size,P1,B1,R,C,P2,B2> > {
398 int size()
const {
return rhs.num_cols();}
400 template<
int Sout,
typename Pout,
typename Bout>
402 for(
int i=0; i < res.size(); ++i){
403 res[i] = lhs * rhs.T()[i];
408 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
418 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
419 struct Operator<Internal::MatrixVectorDiagMultiply<R,C,P1,B1,Size,P2,B2> > {
425 int num_rows()
const {
return lhs.num_rows();}
426 int num_cols()
const {
return lhs.num_cols();}
428 template<
int Rout,
int Cout,
typename Pout,
typename Bout>
430 for(
int c=0; c < res.num_cols(); ++c) {
432 for(
int r=0; r < res.num_rows(); ++r) {
433 res(r,c) = lhs(r,c)*temp;
439 template<
int R,
int C,
int Size,
typename P1,
typename P2,
typename B1,
typename B2>
447 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
448 struct Operator<Internal::VectorMatrixDiagMultiply<Size,P1,B1,R,C,P2,B2> > {
454 int num_rows()
const {
return rhs.num_rows();}
455 int num_cols()
const {
return rhs.num_cols();}
457 template<
int Rout,
int Cout,
typename Pout,
typename Bout>
459 for(
int r=0; r < res.num_rows(); ++r){
460 const P1 temp = lhs[r];
461 for(
int c=0; c<res.num_cols(); ++c){
462 res(r,c) = temp * rhs(r,c);
468 template<
int R,
int C,
typename P1,
typename B1,
int Size,
typename P2,
typename B2>
487 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
490 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
493 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
496 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
500 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
501 struct Operator<Internal::ApplyScalarV<Size,P1,B1,P2,Op> > {
507 template<
int S0,
typename P0,
typename Ba0>
509 for(
int i=0; i<v.size(); i++){
510 v[i]= Op::template op<P0,P1,P2> (lhs[i],rhs);
519 template <
int Size,
typename P1,
typename B1,
typename P2>
523 template <
int Size,
typename P1,
typename B1,
typename P2>
528 template<
int Size,
typename P1,
typename B1,
typename P2,
typename Op>
529 struct Operator<Internal::ApplyScalarVL<Size,P1,B1,P2,Op> > {
535 template<
int S0,
typename P0,
typename Ba0>
537 for(
int i=0; i<v.size(); i++){
538 v[i]= Op::template op<P0,P2,P1> (lhs,rhs[i]);
546 template <
int Size,
typename P1,
typename B1,
typename P2>
555 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
556 struct Operator<Internal::ApplyScalarM<R,C,P1,B1,P2,Op> > {
562 template<
int R0,
int C0,
typename P0,
typename Ba0>
564 for(
int r=0; r<m.num_rows(); r++){
565 for(
int c=0; c<m.num_cols(); c++){
566 m(r,c)= Op::template op<P0,P1,P2> (lhs(r,c),rhs);
571 int num_rows()
const {
572 return lhs.num_rows();
574 int num_cols()
const {
575 return lhs.num_cols();
579 template <
int R,
int C,
typename P1,
typename B1,
typename P2>
583 template <
int R,
int C,
typename P1,
typename B1,
typename P2>
588 template<
int R,
int C,
typename P1,
typename B1,
typename P2,
typename Op>
589 struct Operator<Internal::ApplyScalarML<R,C,P1,B1,P2,Op> > {
595 template<
int R0,
int C0,
typename P0,
typename Ba0>
597 for(
int r=0; r<m.num_rows(); r++){
598 for(
int c=0; c<m.num_cols(); c++){
599 m(r,c)= Op::template op<P0,P1,P2> (lhs,rhs(r,c));
604 int num_rows()
const {
605 return rhs.num_rows();
607 int num_cols()
const {
608 return rhs.num_cols();
612 template <
int R,
int C,
typename P1,
typename B1,
typename P2>
621 template <
int Size,
typename P1,
typename B1,
typename Op>
626 template <
int Size,
typename P1,
typename B1,
typename Op>
631 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
636 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
644 template <
int Size,
typename P1,
typename B1,
typename Op>
646 return op.rsubtract(v);
649 template <
int Size,
typename P1,
typename B1,
typename Op>
651 return op.lsubtract(v);
654 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
656 return op.rsubtract(m);
659 template <
int Rows,
int Cols,
typename P1,
typename B1,
typename Op>
661 return op.lsubtract(m);
669 template <
int Size,
typename Precision,
typename Base>
670 inline std::ostream& operator<< (std::ostream& os, const Vector<Size,Precision,Base>& v){
671 std::streamsize fw = os.width();
672 for(
int i=0; i<v.size(); i++){
680 template <
int Size,
typename Precision,
typename Base>
682 for (
int i=0; i<v.size(); i++){
688 template<
int Rows,
int Cols,
typename Precision,
class Base>
689 inline std::ostream& operator<< (std::ostream& os, const Matrix<Rows, Cols, Precision, Base>& m){
690 std::streamsize fw = os.width();
691 for(
int i=0; i < m.num_rows(); i++)
693 for(
int j=0; j < m.num_cols(); j++)
706 template <
int Rows,
int Cols,
typename Precision,
typename Base>
708 for(
int r=0; r<m.num_rows(); r++){
709 for(
int c=0; c < m.num_cols(); c++){
720 TOON_CREATE_METHOD_DETECTOR(swap);
721 template<class V1, class V2, bool has_swap = Has_swap_Method<V1>::Has>
724 static void swap(V1& v1, V2& v2)
728 for(
int i=0; i < v1.size(); i++)
736 static void swap(V& v1, V& v2)
745 template<
int S1,
class P1,
class B1,
int S2,
class P2,
class B2>
752 template<
int S1,
class P1,
class B1>
Definition: operators.hh:96
Definition: operators.hh:497
Definition: operators.hh:130
Definition: operators.hh:242
Definition: operators.hh:357
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
Is a number a field? i.e., +, -, *, / defined.
Definition: TooN.h:113
Definition: operators.hh:110
Definition: operators.hh:361
Definition: operators.hh:119
Definition: operators.hh:102
Definition: operators.hh:86
Definition: operators.hh:85
Definition: operators.hh:98
Determine if two classes are in the same field.
Definition: operators.hh:39
Definition: operators.hh:106
Definition: operators.hh:87
Definition: operators.hh:108
Definition: operators.hh:74
Definition: operators.hh:104
Definition: operators.hh:54
Definition: operators.hh:353
Definition: operators.hh:349
Definition: size_mismatch.hh:103
Definition: operators.hh:239
Definition: operators.hh:100
Definition: operators.hh:84
Definition: operators.hh:491
Definition: operators.hh:133
Definition: operators.hh:494
Definition: operators.hh:488
Definition: operators.hh:235
Definition: operators.hh:722
static const int is
<Set to 1 if the two classes are in the same field.
Definition: operators.hh:42