toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN TooN.h doc/documentation.h internal/mbase....


From: Edward Rosten
Subject: [Toon-members] TooN TooN.h doc/documentation.h internal/mbase....
Date: Mon, 11 Jan 2010 14:59:12 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Edward Rosten <edrosten>        10/01/11 14:59:12

Modified files:
        .              : TooN.h 
        doc            : documentation.h 
        internal       : mbase.hh operators.hh reference.hh vbase.hh 

Log message:
        Fixed const correctness of TooN.
        
        Note, the following code will not work:
        
        template<class B> void foo(const Vector<2, double, B>&);
        void bar(const Vector<3>& v)
        {
            foo.slice<0,2>();
        }
        
        To fix, change foo to:
        template<class P, class B> void foo(const Vector<2, P, B>&);
        
        The old version can be checked out using the tag BEFORE_CONST_FIX.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/TooN/doc/documentation.h?cvsroot=toon&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/mbase.hh?cvsroot=toon&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/operators.hh?cvsroot=toon&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/reference.hh?cvsroot=toon&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.43&r2=1.44

Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- TooN.h      2 Nov 2009 16:26:55 -0000       1.57
+++ TooN.h      11 Jan 2010 14:59:12 -0000      1.58
@@ -88,6 +88,17 @@
                static const int value = numeric_limits<C>::is_specialized; 
///<Is C a field?
        };
        
+       ///Specialized for const types
+       ///@internal
+       ///Internal::Field determines if two classes are in the same field.
+       ///@ingroup gLinAlg
+       template<class C> struct IsField<const C>
+       {
+               static const int value = IsField<C>::value; ///<Is C a field?
+       };
+
+       template<class C, class D> struct These_Types_Do_Not_Form_A_Field;
+       
        ///@internal
        ///@brief The namaespace holding all the internal code.
        namespace Internal

Index: doc/documentation.h
===================================================================
RCS file: /cvsroot/toon/TooN/doc/documentation.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- doc/documentation.h 16 Dec 2009 16:47:01 -0000      1.42
+++ doc/documentation.h 11 Jan 2010 14:59:12 -0000      1.43
@@ -57,6 +57,7 @@
  - \ref sCreateMatrix
  - \ref sFunctionVector
  - \ref sGenericCode
+ - \ref sConst
  - \ref sElemOps
  - \ref sInitialize
  - \ref sScalars
@@ -147,11 +148,76 @@
 
                To write a function taking any type of vector by reference:
                @code
-               template<int Size, typename Base> void func(const Vector<Size, 
double, Base>& v);
+               template<int Size, typename Precision, typename Base> void 
func(const Vector<Size, Precision, Base>& v);
                @endcode
                See also \ref sPrecision, \ref sGenericCode and \ref sNoInplace
 
 
+               Slices are strange types. If you want to write a function which
+               uniformly accepts <code>const</code> whole objects as well as 
slices,
+               you need to template on the precision.
+
+               Note that constness in C++ is tricky (see \ref sConst). If you 
write
+               the function to accept <code> Vector<3, double, B>& </code>, 
then you
+               will not be able to pass it slices from <code> const 
Vector</code>s.
+               If, however you write it to accept <code> Vector<3, const 
double, B>&
+               </code>, then the only way to pass in a <code>Vector<3></code> 
is to
+               use the <code>.as_slice()</code> method.
+
+               See also \ref sGenericCode
+
+       \subsection sConst What is wrong with constness?
+
+               In TooN, the behaviour of a Vector or Matrix is controlled by 
the third
+               template parameter. With one parameter, it owns the data, with 
another
+               parameter, it is a slice. A static sized object uses the 
variable:
+               @code
+                        double my_data[3];
+               @endcode
+               to hold the data. A slice object uses:
+               @code
+                        double* my_data;
+               @endcode
+               When a Vector is made <code>const</code>, C++ inserts 
<code>const</code> in
+               to those types.  The <code>const</code> it inserts it top 
level, so these
+               become (respectively):
+               @code
+                        const double my_data[3];
+                        double * const my_data;
+               @endcode
+               Now the types behave very differently. In the first case
+               <code>my_data[0]</code> is immutable. In the second case,
+               <code>my_data</code> is immutable, but
+               <code>my_data[0]</code> is mutable.
+               
+               Therefore a slice <code>const Vector</code> behaves like an 
immutable
+               pointer to mutable data. TooN attempts to make 
<code>const</code>
+               objects behave as much like pointers to \e immutable data as 
possible.
+
+               The semantics that TooN tries to enforce can be bypassed with 
+               sufficient steps:
+               @code
+                       //Make v look immutable
+                       template<class P, class B> void fake_immutable(const 
Vector<2, P, B>& v)
+                       {
+                               Vector<2, P, B> nonconst_v(v);
+                               nonconst_v[0] = 0; //Effectively mutate v
+                       }
+
+                       void bar()
+                       {
+                               Vector<3> v;
+                               ...
+                               fake_immutable(v.slice<0,2>());
+                               //Now v is mutated
+                       }
+
+               @endcode
+
+               See also \ref sFunctionVector
+
+
+
        \subsection sElemOps What elementary operations are supported?
                
                Assignments are performed using <code>=</code>. See also 
@@ -222,7 +288,12 @@
                Vector.slice(start, length);                           
//Dynamic slice
                Matrix.slice<RowStart, ColStart, NumRows, NumCols>();  //Static 
slice
                Matrix.slice(rowstart, colstart, numrows, numcols);    
//Dynamic slice
+               @endcode
+               
+               Slicing diagonals:
+               @code
                Matrix.diagonal_slice();                               //Get 
the leading diagonal as a vector.
+               Vector.as_diagonal();                                  
//Represent a Vector as a DiagonalMatrix
                @endcode
                
                Like other features of TooN, mixed static/dynamic slicing is 
allowed.
@@ -368,7 +439,7 @@
 
        TooN does not initialize data in a Vector or Matrix.  For debugging 
purposes
        the following macros can be defined:
-       - \c TOON_INITIALIZE_QNAN or TOON_INITIALIZE_NAN Sets every element of 
newly defined Vectors or
+       - \c TOON_INITIALIZE_QNAN or \c TOON_INITIALIZE_NAN Sets every element 
of newly defined Vectors or
          Matrixs to quiet NaN, if it exists, and 0 otherwise. Your code will 
not compile
          if you have made a Vector or Matrix of a type which cannot be 
constructed
          from a number.
@@ -402,6 +473,7 @@
                m[0][0]=6;
        @endcode
 
+       Slices are usually strange types. See \ref sFunctionVector
 
        \subsection sPrecision Can I have a precision other than double?
 
@@ -411,7 +483,17 @@
                Vector<Dynamic, float> v(4); //Dynamic sized vector of floats
        @endcode
 
-       Likewise for matrix.
+       Likewise for matrix. By default, TooN supports all builtin types
+       and std::complex. Using custom types requires some work. If the 
+       custom type understands +,-,*,/ with builtin types, then specialize
+       TooN::IsField on the types.
+
+       If the type only understands +,-,*,/ with itself, then specialize
+       TooN::Field on the type.
+
+       Note that this is required so that TooN can follow the C++ promotion 
+       rules. The result of multiplying a <code>Matrix<double></code> by a 
+       <code>Vector<float></code> is a <code>Vector<double></code>.
 
        \subsection sSolveLinear How do I invert a matrix / solve linear 
equations?
        
@@ -503,6 +585,7 @@
        @endcode
 
        \subsection sWrap I have a pointer to a bunch of data. How do I turn it 
in to a vector/matrix without copying?
+
        To create a vector use:
        @code
        double d[]={1,2,3,4};
@@ -529,6 +612,8 @@
        Matrix<Dynamic, 3, double, Reference::RowMajor> m4(d, 2, 3); // note 
two size arguments are required for semi-dynamic matrices
        @endcode
 
+       See also wrapVector() and wrapMatrix().
+
        \subsection sGenericCode How do I write generic code?
        
        The constructors for TooN objects are very permissive in that they 
@@ -575,6 +660,8 @@
        }
        @endcode
 
+       For issues relating to constness, see \sFunctionVector and \sConst
+
 
 \subsection ssExamples Are there any examples?
 

Index: internal/mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- internal/mbase.hh   26 Aug 2009 11:22:35 -0000      1.34
+++ internal/mbase.hh   11 Jan 2010 14:59:12 -0000      1.35
@@ -157,15 +157,16 @@
 
        // this is the type of vector obtained by [ ]
        typedef Vector<Cols, Precision, SliceVBase<SliceColStride> > Vec;
+       typedef Vector<Cols, const Precision, SliceVBase<SliceColStride> > CVec;
        
        Vec operator[](int r) {
                Internal::check_index(num_rows(), r);
                return Vec(my_data + rowstride()* r, num_cols(), colstride(), 
Slicing());
        }
 
-       const Vec operator[](int r) const {
+       const CVec operator[](int r) const {
                Internal::check_index(num_rows(), r);
-               return Vec(const_cast<Precision*>(my_data + rowstride()* r), 
num_cols(), colstride(), Slicing());
+               return CVec(my_data + rowstride()* r, num_cols(), colstride(), 
Slicing());
        }
 
        
@@ -185,14 +186,14 @@
        }
 
        template<int Rstart, int Cstart, int Rlength, int Clength>
-       const Matrix<Rlength, Clength, Precision, 
Slice<SliceRowStride,SliceColStride> > slice(int rs, int cs, int rl, int cl) 
const{
+       const Matrix<Rlength, Clength, const Precision, 
Slice<SliceRowStride,SliceColStride> > slice(int rs, int cs, int rl, int cl) 
const{
                Internal::CheckSlice<Rows, Rstart, Rlength>::check(num_rows(), 
rs, rl);
                Internal::CheckSlice<Cols, Cstart, Clength>::check(num_cols(), 
cs, cl);
 
                //Always pass the size and stride as a run-time parameter. It 
will be ignored
                //by SliceHolder (above) if it is statically determined.
-               return Matrix<Rlength, Clength, Precision, 
Slice<SliceRowStride,SliceColStride> >(
-                      
const_cast<Precision*>(my_data)+rowstride()*(Rstart==Dynamic?rs:Rstart) + 
colstride()*(Cstart==Dynamic?cs:Cstart), 
+               return Matrix<Rlength, Clength, const Precision, 
Slice<SliceRowStride,SliceColStride> >(
+                      my_data+rowstride()*(Rstart==Dynamic?rs:Rstart) + 
colstride()*(Cstart==Dynamic?cs:Cstart), 
                           Rlength==Dynamic?rl:Rlength, 
                           Clength==Dynamic?cl:Clength, 
                           rowstride(), colstride(), Slicing());
@@ -229,8 +230,8 @@
                return Matrix<Cols, Rows, Precision, 
Slice<SliceColStride,SliceRowStride> >(my_data, num_cols(), num_rows(), 
colstride(), rowstride(), Slicing());
        }
 
-       const Matrix<Cols, Rows, Precision, 
Slice<SliceColStride,SliceRowStride> > T() const{
-               return Matrix<Cols, Rows, Precision, 
Slice<SliceColStride,SliceRowStride> >(const_cast<Precision*>(my_data), 
num_cols(), num_rows(), colstride(), rowstride(), Slicing());
+       const Matrix<Cols, Rows, const Precision, 
Slice<SliceColStride,SliceRowStride> > T() const{
+               return Matrix<Cols, Rows, const Precision, 
Slice<SliceColStride,SliceRowStride> >(my_data, num_cols(), num_rows(), 
colstride(), rowstride(), Slicing());
        }
 
        static const int DiagSize = Internal::DiagSize<Rows, Cols>::size;
@@ -240,6 +241,11 @@
        {
                return Vector<DiagSize, Precision, SliceVBase<DiagStride> 
>(my_data, std::min(num_cols(), num_rows()), rowstride() + colstride(), 
Slicing());
        }
+
+       Vector<DiagSize, const Precision, SliceVBase<DiagStride> > 
diagonal_slice() const 
+       {
+               return Vector<DiagSize, const Precision, SliceVBase<DiagStride> 
>(my_data, std::min(num_cols(), num_rows()), rowstride() + colstride(), 
Slicing());
+       }
 };
 
 }

Index: internal/operators.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/operators.hh,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- internal/operators.hh       27 Aug 2009 17:29:31 -0000      1.45
+++ internal/operators.hh       11 Jan 2010 14:59:12 -0000      1.46
@@ -62,10 +62,10 @@
        template<class L, class R, int F = Field<L,R>::is> struct MultiplyType 
{ typedef TOON_TYPEOF(gettype<L>()*gettype<R>()) type;};
        template<class L, class R, int F = Field<L,R>::is> struct DivideType   
{ typedef TOON_TYPEOF(gettype<L>()/gettype<R>()) type;};
 
-       template<class L, class R> struct AddType<L, R, 0>         { typedef 
void type;};
-       template<class L, class R> struct SubtractType<L, R, 0>    { typedef 
void type;};
-       template<class L, class R> struct MultiplyType<L, R, 0>    { typedef 
void type;};
-       template<class L, class R> struct DivideType<L, R, 0>      { typedef 
void type;};
+       template<class L, class R> struct AddType<L, R, 0>         { typedef 
These_Types_Do_Not_Form_A_Field<L, R> type;};
+       template<class L, class R> struct SubtractType<L, R, 0>    { typedef 
These_Types_Do_Not_Form_A_Field<L, R> type;};
+       template<class L, class R> struct MultiplyType<L, R, 0>    { typedef 
These_Types_Do_Not_Form_A_Field<L, R> type;};
+       template<class L, class R> struct DivideType<L, R, 0>      { typedef 
These_Types_Do_Not_Form_A_Field<L, R> type;};
 
 
        //Mini operators for passing to Pairwise, etc

Index: internal/reference.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/reference.hh,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- internal/reference.hh       27 Jul 2009 16:39:43 -0000      1.8
+++ internal/reference.hh       11 Jan 2010 14:59:12 -0000      1.9
@@ -81,13 +81,13 @@
 
 
                                     inline       Vector<Dynamic, double,    
Reference> wrapVector(double* data, int size)          { return Vector<Dynamic, 
double,    Reference>(data, size); }
-                                    inline const Vector<Dynamic, double,    
Reference> wrapVector(const double* data, int size)    { return Vector<Dynamic, 
double,    Reference>(const_cast<double*>(data), size); }
+                                    inline const Vector<Dynamic, const double, 
   Reference> wrapVector(const double* data, int size)    { return 
Vector<Dynamic, const double,    Reference>(data, size); }
 template<int Size>                  inline       Vector<Size,    double,    
Reference> wrapVector(double* data)                    { return Vector<Size,    
double,    Reference>(data); }
-template<int Size>                  inline const Vector<Size,    double,    
Reference> wrapVector(const double* data)              { return Vector<Size,    
double,    Reference>(const_cast<double*>(data)); }
+template<int Size>                  inline const Vector<Size,    const double, 
   Reference> wrapVector(const double* data)              { return Vector<Size, 
   const double,    Reference>(data); }
 template<class Precision>           inline       Vector<Dynamic, Precision, 
Reference> wrapVector(Precision* data, int size)       { return Vector<Dynamic, 
Precision, Reference>(data, size); }
-template<class Precision>           inline const Vector<Dynamic, Precision, 
Reference> wrapVector(const Precision* data, int size) { return Vector<Dynamic, 
Precision, Reference>(const_cast<Precision*>(data), size); }
+template<class Precision>           inline const Vector<Dynamic, const 
Precision, Reference> wrapVector(const Precision* data, int size) { return 
Vector<Dynamic, const Precision, Reference>(data, size); }
 template<int Size, class Precision> inline       Vector<Size,    Precision, 
Reference> wrapVector(Precision* data)                 { return Vector<Size,    
Precision, Reference>(data); }
-template<int Size, class Precision> inline const Vector<Size,    Precision, 
Reference> wrapVector(const Precision* data)           { return Vector<Size,    
Precision, Reference>(const_cast<Precision*>(data)); }
+template<int Size, class Precision> inline const Vector<Size,    const 
Precision, Reference> wrapVector(const Precision* data)           { return 
Vector<Size,    const Precision, Reference>(data); }
 
 ///Wrap external data as a \link TooN::Matrix Matrix \endlink
 ///As usual, if template sizes are provided, then the run-time size is only
@@ -96,18 +96,18 @@
 ///@{
 //Fully static matrices, ie no size parameters
 template<int Rows, int Cols>                  inline       Matrix<Rows, Cols,  
     double,    Reference::RowMajor> wrapMatrix(double*    data)                
     { return Matrix<Rows, Cols, double, Reference::RowMajor>(data);}
-template<int Rows, int Cols>                  inline const Matrix<Rows, Cols,  
     double,    Reference::RowMajor> wrapMatrix(const double*    data)          
           { return Matrix<Rows, Cols, double, 
Reference::RowMajor>(const_cast<double*>(data));}
+template<int Rows, int Cols>                  inline const Matrix<Rows, Cols,  
     const double,    Reference::RowMajor> wrapMatrix(const double*    data)    
                 { return Matrix<Rows, Cols,       const double,    
Reference::RowMajor>(data);}
 template<int Rows, int Cols, class Precision> inline       Matrix<Rows, Cols,  
     Precision, Reference::RowMajor> wrapMatrix(Precision* data)                
     { return Matrix<Rows, Cols, Precision, Reference::RowMajor>(data);}
-template<int Rows, int Cols, class Precision> inline const Matrix<Rows, Cols,  
     Precision, Reference::RowMajor> wrapMatrix(const Precision* data)          
           { return Matrix<Rows, Cols, Precision, 
Reference::RowMajor>(const_cast<Precision*>(data));}
+template<int Rows, int Cols, class Precision> inline const Matrix<Rows, Cols,  
     const Precision, Reference::RowMajor> wrapMatrix(const Precision* data)    
                 { return Matrix<Rows, Cols,       const Precision, 
Reference::RowMajor>(data);}
 //Static sizes with size parameters (useful for half-dynamic matrices)
 template<int Rows, int Cols>                  inline       Matrix<Rows, Cols,  
     double,    Reference::RowMajor> wrapMatrix(double*    data, int rows, int 
cols) { return Matrix<Rows, Cols, double, Reference::RowMajor>(data, rows, 
cols);}
-template<int Rows, int Cols>                  inline const Matrix<Rows, Cols,  
     double,    Reference::RowMajor> wrapMatrix(const double*    data, int 
rows, int cols) { return Matrix<Rows, Cols, double, 
Reference::RowMajor>(const_cast<double*>(data), rows, cols);}
+template<int Rows, int Cols>                  inline const Matrix<Rows, Cols,  
     const double,    Reference::RowMajor> wrapMatrix(const double*    data, 
int rows, int cols) { return Matrix<Rows, Cols,       const double,    
Reference::RowMajor>(data, rows, cols);}
 template<int Rows, int Cols, class Precision> inline       Matrix<Rows, Cols,  
     Precision, Reference::RowMajor> wrapMatrix(Precision* data, int rows, int 
cols) { return Matrix<Rows, Cols, Precision, Reference::RowMajor>(data, rows, 
cols);}
-template<int Rows, int Cols, class Precision> inline const Matrix<Rows, Cols,  
     Precision, Reference::RowMajor> wrapMatrix(const Precision* data, int 
rows, int cols) { return Matrix<Rows, Cols, Precision, 
Reference::RowMajor>(const_cast<Precision*>(data), rows, cols);}
+template<int Rows, int Cols, class Precision> inline const Matrix<Rows, Cols,  
     const Precision, Reference::RowMajor> wrapMatrix(const Precision* data, 
int rows, int cols) { return Matrix<Rows, Cols,       const Precision, 
Reference::RowMajor>(data, rows, cols);}
 //Fully dynamic
                                               inline       Matrix<Dynamic, 
Dynamic, double,    Reference::RowMajor> wrapMatrix(double*          data, int 
rows, int cols) { return Matrix<Dynamic, Dynamic, double, 
Reference::RowMajor>(data, rows, cols);}
-                                              inline const Matrix<Dynamic, 
Dynamic, double,    Reference::RowMajor> wrapMatrix(const double*    data, int 
rows, int cols) { return Matrix<Dynamic, Dynamic, double, 
Reference::RowMajor>(const_cast<double*>(data), rows, cols);}
+                                              inline const Matrix<Dynamic, 
Dynamic, const double,    Reference::RowMajor> wrapMatrix(const double*    
data, int rows, int cols) { return Matrix<Dynamic, Dynamic, const double,    
Reference::RowMajor>(data, rows, cols);}
 template<class Precision>                     inline       Matrix<Dynamic, 
Dynamic, Precision, Reference::RowMajor> wrapMatrix(Precision* data, int rows, 
int cols) { return Matrix<Dynamic, Dynamic, Precision, 
Reference::RowMajor>(data, rows, cols);}
-template<class Precision>                     inline const Matrix<Dynamic, 
Dynamic, Precision, Reference::RowMajor> wrapMatrix(const Precision* data, int 
rows, int cols) { return Matrix<Dynamic, Dynamic, Precision, 
Reference::RowMajor>(const_cast<Precision*>(data), rows, cols);}
+template<class Precision>                     inline const Matrix<Dynamic, 
Dynamic, const Precision, Reference::RowMajor> wrapMatrix(const Precision* 
data, int rows, int cols) { return Matrix<Dynamic, Dynamic, const Precision, 
Reference::RowMajor>(data, rows, cols);}
 ///@}
 }

Index: internal/vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- internal/vbase.hh   2 Nov 2009 16:26:55 -0000       1.43
+++ internal/vbase.hh   11 Jan 2010 14:59:12 -0000      1.44
@@ -127,9 +127,9 @@
        }
 
        template<int Start, int Length> 
-       const Vector<Length, Precision, SliceVBase<Stride> > slice(int start, 
int length) const{
+       const Vector<Length, const Precision, SliceVBase<Stride> > slice(int 
start, int length) const{
                Internal::CheckSlice<Size, Start, Length>::check(size(), start, 
length);        
-               return Vector<Length, Precision, SliceVBase<Stride> 
>(const_cast<Precision*>(data()) + stride() * (Start==Dynamic?start:Start), 
Length==Dynamic?length:Length, stride(), Slicing());
+               return Vector<Length, const Precision, SliceVBase<Stride> 
>(data() + stride() * (Start==Dynamic?start:Start), 
Length==Dynamic?length:Length, stride(), Slicing());
        }
 
        
@@ -140,7 +140,7 @@
                return slice<Start, Length>(Start, Length);
        }
 
-       template<int Start, int Length> const Vector<Length, Precision, 
SliceVBase<Stride> > slice() const {
+       template<int Start, int Length> const Vector<Length, const Precision, 
SliceVBase<Stride> > slice() const {
                Internal::CheckSlice<Size, Start, Length>::check();
                return slice<Start, Length>(Start, Length);
        }
@@ -154,16 +154,16 @@
        }
                
        //Other slices below
-       const Matrix<1, Size, Precision, Slice<1,Stride> > as_row() const{
-               return Matrix<1, Size, Precision, Slice<1,Stride> 
>(const_cast<Precision*>(data()), 1, size(), 1, stride(), Slicing());
+       const Matrix<1, Size, const Precision, Slice<1,Stride> > as_row() const{
+               return Matrix<1, Size, const Precision, Slice<1,Stride> 
>(data(), 1, size(), 1, stride(), Slicing());
        }
 
        Matrix<1, Size, Precision, Slice<1,Stride> > as_row(){
                return Matrix<1, Size, Precision, Slice<1,Stride> >(data(), 1, 
size(), 1, stride(), Slicing());
        }
 
-       const Matrix<Size, 1, Precision, Slice<Stride,1> > as_col() const{
-               return Matrix<Size, 1, Precision, Slice<Stride,1> 
>(const_cast<Precision*>(data()), size(), 1, stride(), 1, Slicing());
+       const Matrix<Size, 1, const Precision, Slice<Stride,1> > as_col() const{
+               return Matrix<Size, 1, const Precision, Slice<Stride,1> 
>(data(), size(), 1, stride(), 1, Slicing());
        }
 
        Matrix<Size, 1, Precision, Slice<Stride,1> > as_col(){
@@ -176,16 +176,16 @@
                return Vector<Size, Precision, SliceVBase<Stride> >(data(), 
size(), stride(), Slicing());         
        }
 
-       const Vector<Size, Precision, SliceVBase<Stride> > as_slice() const {   
              
-               return Vector<Size, Precision, SliceVBase<Stride> 
>(const_cast<Precision*>(data()), size(), stride(), Slicing());         
+       const Vector<Size, const Precision, SliceVBase<Stride> > as_slice() 
const {                 
+               return Vector<Size, const Precision, SliceVBase<Stride> 
>(data(), size(), stride(), Slicing());         
        }
 
        DiagonalMatrix<Size,Precision, SliceVBase<Stride> > as_diagonal() {
                return DiagonalMatrix<Size, Precision, SliceVBase<Stride> > 
(data(), size(), stride(), Slicing());
        }
 
-       const DiagonalMatrix<Size,Precision, SliceVBase<Stride> > as_diagonal() 
const {
-               return DiagonalMatrix<Size, Precision, SliceVBase<Stride> > 
(const_cast<Precision*>(data()), size(), stride(), Slicing());
+       const DiagonalMatrix<Size,const Precision, SliceVBase<Stride> > 
as_diagonal() const {
+               return DiagonalMatrix<Size, const Precision, SliceVBase<Stride> 
> (data(), size(), stride(), Slicing());
        }
 
 };




reply via email to

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