[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN internal/operators.hh test/scalars.cc
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN internal/operators.hh test/scalars.cc |
Date: |
Sun, 26 Apr 2009 11:21:23 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/04/26 11:21:22
Modified files:
internal : operators.hh
Added files:
test : scalars.cc
Log message:
Added scalar addition for matrices.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/operators.hh?cvsroot=toon&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/TooN/test/scalars.cc?cvsroot=toon&rev=1.1
Patches:
Index: internal/operators.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/operators.hh,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- internal/operators.hh 24 Apr 2009 20:24:02 -0000 1.36
+++ internal/operators.hh 26 Apr 2009 11:21:19 -0000 1.37
@@ -592,6 +592,7 @@
//
namespace Internal{
template<int S, class P, class B, class Ps> class ScalarsVector;
+ template<int R, int C, class P, class B, class Ps> class ScalarsMatrix;
template<class P> class Scalars;
}
@@ -614,15 +615,37 @@
for(int i=0; i < v.size(); i++)
vv[i] = s + v[i];
}
-};
+ int size() const
+ {
+ return v.size();
+ }
+};
-/*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)
+template<int R, int C, class P, class B, class Precision> struct
Operator<Internal::ScalarsMatrix<R,C,P,B,Precision> >
{
- return Operators<Internal::ScalarsVector<S,P,B,typename
Operator<Op>::Precision> >(op.s, v);
-}*/
+ const Precision s;
+ const Matrix<R,C,P,B>& m;
+ Operator(Precision s_, const Matrix<R,C,P,B>& m_)
+ :s(s_),m(m_){}
+ template<int R1, int C1, class P1, class B1>
+ void eval(Matrix<R1,C1,P1,B1>& mm) const{
+ for(int r=0; r < m.num_rows(); r++)
+ for(int c=0; c < m.num_cols(); c++)
+ mm[r][c] = s + m[r][c];
+ }
+
+ int num_rows() const
+ {
+ return m.num_rows();
+ }
+ int num_cols() const
+ {
+ return m.num_cols();
+ }
+};
+// Vectors
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);
@@ -632,6 +655,17 @@
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);
}
+
+//Matrices
+template <int Rows, int Cols, typename P1, typename B1, typename P2>
+Matrix<Rows, Cols, typename Internal::Add::Return<P1,P2>::Type>
operator+(const Matrix<Rows, Cols, P1, B1>& m, const
Operator<Internal::Scalars<P2> >& s){
+ return Operator<Internal::ScalarsMatrix<Rows, Cols,P1,B1,P2> >(s.s, m);
+}
+
+template <int Rows, int Cols, typename P1, typename B1, typename P2>
+Matrix<Rows, Cols, typename Internal::Add::Return<P1,P2>::Type>
operator+(const Operator<Internal::Scalars<P2> >& s, const Matrix<Rows, Cols,
P1, B1>& m){
+ return Operator<Internal::ScalarsMatrix<Rows, Cols,P1,B1,P2> >(s.s, m);
+}
////////////////////////////////////////////////////////////////////////////////
//
// Stream I/O operators
Index: test/scalars.cc
===================================================================
RCS file: test/scalars.cc
diff -N test/scalars.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/scalars.cc 26 Apr 2009 11:21:22 -0000 1.1
@@ -0,0 +1,16 @@
+#include <TooN/TooN.h>
+#include <TooN/helpers.h>
+using namespace TooN;
+using namespace std;
+int main()
+{
+ Vector<5> v = makeVector(1,2,3,4,5);
+
+ cout << v + Scalars(3) << endl;
+ cout << v.slice(2,3) + Scalars(3) << endl;
+
+ Matrix<> m = Identity(4);
+
+ cout << m + Scalars(1) << endl;
+ cout << m.slice<0,0,2,3>() + Scalars(2) << endl;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN internal/operators.hh test/scalars.cc,
Edward Rosten <=