[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN helpers.h internal/matrix.hh internal/oper...
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN helpers.h internal/matrix.hh internal/oper... |
Date: |
Fri, 24 Apr 2009 20:24:03 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/04/24 20:24:03
Modified files:
. : helpers.h
internal : matrix.hh operators.hh vector.hh
test : test2.cc
Log message:
Removed obnoxious vector + scalar operators.
Use more explicit Vector + Scalars(3.456); instead.
+=, and Matrix not yet implemented.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/matrix.hh?cvsroot=toon&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/operators.hh?cvsroot=toon&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vector.hh?cvsroot=toon&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/TooN/test/test2.cc?cvsroot=toon&r1=1.5&r2=1.6
Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- helpers.h 22 Apr 2009 09:59:12 -0000 1.52
+++ helpers.h 24 Apr 2009 20:24:01 -0000 1.53
@@ -381,5 +381,10 @@
}
}
}
+
+ template<class P> Operator<Internal::Scalars<P> > Scalars(const P& s)
+ {
+ return Operator<Internal::Scalars<P> > (s);
+ }
}
#endif
Index: internal/matrix.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/matrix.hh,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- internal/matrix.hh 20 Apr 2009 17:54:37 -0000 1.29
+++ internal/matrix.hh 24 Apr 2009 20:24:02 -0000 1.30
@@ -124,24 +124,6 @@
return *this;
}
- Matrix& operator+=(const Precision& rhs)
- {
- for(int r=0; r < num_rows(); r++)
- for(int c=0; c < num_cols(); c++)
- (*this)[r][c] += rhs;
-
- return *this;
- }
-
- Matrix& operator-=(const Precision& rhs)
- {
- for(int r=0; r < num_rows(); r++)
- for(int c=0; c < num_cols(); c++)
- (*this)[r][c] -= rhs;
-
- return *this;
- }
-
Matrix& operator*=(const Precision& rhs)
{
for(int r=0; r < num_rows(); r++)
Index: internal/operators.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/operators.hh,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- internal/operators.hh 23 Apr 2009 22:24:56 -0000 1.35
+++ internal/operators.hh 24 Apr 2009 20:24:02 -0000 1.36
@@ -489,14 +489,6 @@
};
template <int Size, typename P1, typename B1, typename P2>
-Vector<Size, typename Internal::Add::Return<P1,P2>::Type> operator+(const
Vector<Size, P1, B1>& v, const P2& s){
- return Operator<Internal::ApplyScalarV<Size,P1,B1,P2,Internal::Add> >
(v,s);
-}
-template <int Size, typename P1, typename B1, typename P2>
-Vector<Size, typename Internal::Subtract::Return<P1,P2>::Type> operator-(const
Vector<Size, P1, B1>& v, const P2& s){
- return
Operator<Internal::ApplyScalarV<Size,P1,B1,P2,Internal::Subtract> > (v,s);
-}
-template <int Size, typename P1, typename B1, typename P2>
Vector<Size, typename Internal::Multiply::Return<P1,P2>::Type> operator*(const
Vector<Size, P1, B1>& v, const P2& s){
return
Operator<Internal::ApplyScalarV<Size,P1,B1,P2,Internal::Multiply> > (v,s);
}
@@ -523,24 +515,11 @@
return rhs.size();
}
};
-
-template <int Size, typename P1, typename B1, typename P2>
-Vector<Size, typename Internal::Add::Return<P2,P1>::Type> operator+(const P2&
s, const Vector<Size, P1, B1>& v){
- return Operator<Internal::ApplyScalarVL<Size,P1,B1,P2,Internal::Add> >
(s,v);
-}
-template <int Size, typename P1, typename B1, typename P2>
-Vector<Size, typename Internal::Subtract::Return<P2,P1>::Type> operator-(const
P2& s, const Vector<Size, P1, B1>& v){
- return
Operator<Internal::ApplyScalarVL<Size,P1,B1,P2,Internal::Subtract> > (s,v);
-}
template <int Size, typename P1, typename B1, typename P2>
Vector<Size, typename Internal::Multiply::Return<P2,P1>::Type> operator*(const
P2& s, const Vector<Size, P1, B1>& v){
return
Operator<Internal::ApplyScalarVL<Size,P1,B1,P2,Internal::Multiply> > (s,v);
}
// no left division
-// template <int Size, typename P1, typename B1, typename P2>
-// Vector<Size, typename Internal::Divide::Return<P2,P1>::Type>
operator/(const P2& s, const Vector<Size, P1, B1>& v){
-// return Operator<Internal::ApplyScalarVL<Size,P1,B1,P2,Internal::Divide>
> (s,v);
-// }
/////// Matrix scalar operators
@@ -570,14 +549,6 @@
};
template <int R, int C, typename P1, typename B1, typename P2>
-Matrix<R,C, typename Internal::Add::Return<P1,P2>::Type> operator+(const
Matrix<R,C, P1, B1>& m, const P2& s){
- return Operator<Internal::ApplyScalarM<R,C,P1,B1,P2,Internal::Add> >
(m,s);
-}
-template <int R, int C, typename P1, typename B1, typename P2>
-Matrix<R,C, typename Internal::Subtract::Return<P1,P2>::Type> operator-(const
Matrix<R,C, P1, B1>& m, const P2& s){
- return Operator<Internal::ApplyScalarM<R,C,P1,B1,P2,Internal::Subtract>
> (m,s);
-}
-template <int R, int C, typename P1, typename B1, typename P2>
Matrix<R,C, typename Internal::Multiply::Return<P1,P2>::Type> operator*(const
Matrix<R,C, P1, B1>& m, const P2& s){
return Operator<Internal::ApplyScalarM<R,C,P1,B1,P2,Internal::Multiply>
> (m,s);
}
@@ -611,26 +582,56 @@
};
template <int R, int C, typename P1, typename B1, typename P2>
-Matrix<R,C, typename Internal::Add::Return<P2,P1>::Type> operator+(const P2&
s, const Matrix<R,C, P1, B1>& m){
- return Operator<Internal::ApplyScalarML<R,C,P1,B1,P2,Internal::Add> >
(s,m);
-}
-template <int R, int C, typename P1, typename B1, typename P2>
-Matrix<R,C, typename Internal::Subtract::Return<P2,P1>::Type> operator-(const
P2& s, const Matrix<R,C, P1, B1>& m){
- return
Operator<Internal::ApplyScalarML<R,C,P1,B1,P2,Internal::Subtract> > (s,m);
-}
-template <int R, int C, typename P1, typename B1, typename P2>
Matrix<R,C, typename Internal::Multiply::Return<P2,P1>::Type> operator*(const
P2& s, const Matrix<R,C, P1, B1>& m){
return
Operator<Internal::ApplyScalarML<R,C,P1,B1,P2,Internal::Multiply> > (s,m);
}
-// template <int R, int C, typename P1, typename B1, typename P2>
-// Matrix<R,C, typename Internal::Divide::Return<P2,P1>::Type> operator/(const
P2& s, const Matrix<R,C, P1, B1>& m){
-// return Operator<Internal::ApplyScalarML<R,C,P1,B1,P2,Internal::Divide>
> (s,m);
-// }
+////////////////////////////////////////////////////////////////////////////////
+//
+// Addition of scalars
+//
+namespace Internal{
+ template<int S, class P, class B, class Ps> class ScalarsVector;
+ template<class P> class Scalars;
+}
+template<class Precision> struct Operator<Internal::Scalars<Precision> >
+{
+ const Precision s;
+ Operator(Precision s_)
+ :s(s_){}
+};
+
+template<int S, class P, class B, class Precision> struct
Operator<Internal::ScalarsVector<S,P,B,Precision> >
+{
+ const Precision s;
+ const Vector<S,P,B>& v;
+ Operator(Precision s_, const Vector<S,P,B>& v_)
+ :s(s_),v(v_){}
+
+ template<int S1, class P1, class B1>
+ void eval(Vector<S1,P1,B1>& vv) const{
+ for(int i=0; i < v.size(); i++)
+ vv[i] = s + v[i];
+ }
+};
+/*template<int S, class P, class B, class P2>
+Vector<S, typename Internal:AddType<P, P2>::type > operator+(const
Vector<S,P,B>& v, const Operators<Scalar<P2> >& op)
+{
+ return Operators<Internal::ScalarsVector<S,P,B,typename
Operator<Op>::Precision> >(op.s, v);
+}*/
+template <int Size, typename P1, typename B1, typename P2>
+Vector<Size, typename Internal::Add::Return<P1,P2>::Type> operator+(const
Vector<Size, P1, B1>& v, const Operator<Internal::Scalars<P2> >& s){
+ return Operator<Internal::ScalarsVector<Size,P1,B1,P2> >(s.s, v);
+}
+
+template <int Size, typename P1, typename B1, typename P2>
+Vector<Size, typename Internal::Add::Return<P1,P2>::Type> operator+(const
Operator<Internal::Scalars<P2> >& s, const Vector<Size, P1, B1>& v){
+ return Operator<Internal::ScalarsVector<Size,P1,B1,P2> >(s.s, v);
+}
////////////////////////////////////////////////////////////////////////////////
//
// Stream I/O operators
Index: internal/vector.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vector.hh,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- internal/vector.hh 20 Apr 2009 17:54:06 -0000 1.39
+++ internal/vector.hh 24 Apr 2009 20:24:02 -0000 1.40
@@ -98,20 +98,6 @@
return *this;
}
-
- Vector& operator+=(const Precision& rhs) {
- for(int i=0; i<size(); i++)
- (*this)[i]+=rhs;
- return *this;
- }
-
-
- Vector& operator-=(const Precision& rhs) {
- for(int i=0; i<size(); i++)
- (*this)[i]-=rhs;
- return *this;
- }
-
Vector& operator/=(const Precision& rhs) {
for(int i=0; i<size(); i++)
(*this)[i]/=rhs;
Index: test/test2.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/test2.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- test/test2.cc 18 Feb 2009 16:46:29 -0000 1.5
+++ test/test2.cc 24 Apr 2009 20:24:03 -0000 1.6
@@ -1,4 +1,5 @@
#include <TooN/TooN.h>
+#include <TooN/helpers.h>
using namespace std;
using namespace TooN;
@@ -22,7 +23,7 @@
make_a_copy_constructor_happen(v1);
- cout << 1+(v1 + v2)+2 << endl;
+ cout << Scalars(1) + (v1 + v2)+Scalars(2) << endl;
v1.slice<0, 2>() /= 2;
cout << v1 << endl;
- [Toon-members] TooN helpers.h internal/matrix.hh internal/oper...,
Edward Rosten <=