toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] TooN TooN.h internal/vbase.hh internal/diagmatr...


From: Tom Drummond
Subject: [Toon-members] TooN TooN.h internal/vbase.hh internal/diagmatr...
Date: Sat, 25 Apr 2009 14:53:33 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Tom Drummond <twd20>    09/04/25 14:53:33

Modified files:
        .              : TooN.h 
        internal       : vbase.hh 
Added files:
        internal       : diagmatrix.hh 

Log message:
        diagonal matrix added

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/diagmatrix.hh?cvsroot=toon&rev=1.1

Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- TooN.h      20 Apr 2009 17:51:54 -0000      1.33
+++ TooN.h      25 Apr 2009 14:53:32 -0000      1.34
@@ -71,6 +71,7 @@
 
        template<int Size, class Precision, class Base> struct Vector;
        template<int Rows, int Cols, class Precision, class Base> struct Matrix;
+       template<int Size, class Precision, class Base> struct DiagonalMatrix;
        template<typename T> class Operator;
 
        static const int Dynamic = -1;
@@ -90,6 +91,8 @@
        #include <TooN/internal/matrix.hh>
        #include <TooN/internal/reference.hh>
 
+    #include <TooN/internal/diagmatrix.hh>
+
        #include <TooN/internal/make_vector.hh>
        #include <TooN/internal/operators.hh>
 }

Index: internal/vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- internal/vbase.hh   16 Apr 2009 17:54:10 -0000      1.26
+++ internal/vbase.hh   25 Apr 2009 14:53:32 -0000      1.27
@@ -161,6 +161,13 @@
        Vector<Size, Precision, SliceVBase<Stride> > as_slice(){
                return Vector<Size, Precision, SliceVBase<Stride> >(my_data, 
size(), stride(), Slicing());
        }
+
+       typedef Vector<Size, Precision, SliceVBase<Stride> > as_slice_type;
+
+       DiagonalMatrix<Size,Precision, SliceVBase<Stride> > as_diagonal() {
+               return DiagonalMatrix<Size, Precision, SliceVBase<Stride> > 
(my_data, size(), stride(), Slicing());
+       }
+
 };
 
 }

Index: internal/diagmatrix.hh
===================================================================
RCS file: internal/diagmatrix.hh
diff -N internal/diagmatrix.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ internal/diagmatrix.hh      25 Apr 2009 14:53:32 -0000      1.1
@@ -0,0 +1,69 @@
+//-*- c++ -*-
+//
+// Copyright (C) 2009 Tom Drummond (address@hidden),
+// Ed Rosten (address@hidden)
+//
+// This file is part of the TooN Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+template<int Size=-1, typename Precision=DefaultPrecision, typename 
Base=Internal::VBase>
+class DiagonalMatrix {
+public:
+       inline DiagonalMatrix() {}
+       inline DiagonalMatrix(int size_in) : my_vector(size_in) {}
+       inline DiagonalMatrix(Precision* data) : my_vector(data) {}
+       inline DiagonalMatrix(Precision* data, int size_in) : 
my_vector(data,size_in) {}
+       inline DiagonalMatrix(Precision* data_in, int size_in, int stride_in, 
Internal::Slicing)
+               : my_vector(data_in, size_in, stride_in, Internal::Slicing() ) 
{}
+
+
+       // constructors to allow return value optimisations
+       // construction from 0-ary operator
+       template <class Op>
+       inline DiagonalMatrix(const Operator<Op>& op)
+               : my_vector (op)
+       {
+               op.eval(*this);
+       }
+
+       // constructor from arbitrary vector
+       template<int Size2, typename Precision2, typename Base2>
+       inline DiagonalMatrix(const Vector<Size2,Precision2,Base2>& from)
+               : my_vector(from.size())
+       {
+               my_vector=from;
+       }
+
+
+       Precision& operator[](int i){return my_vector[i];}
+       const Precision& operator[](int i) const {return my_vector[i];}
+
+       typename Vector<Size, Precision, Base>::as_slice_type diagonal_slice() {
+               return my_vector.as_slice();
+       }
+
+
+       Vector<Size,Precision,Base> my_vector;
+};




reply via email to

[Prev in Thread] Current Thread [Next in Thread]