[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN doc/documentation.h internal/config.hh int...
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN doc/documentation.h internal/config.hh int... |
Date: |
Mon, 24 Aug 2009 13:00:19 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/08/24 13:00:18
Modified files:
doc : documentation.h
internal : config.hh slice_error.hh vbase.hh
test : test2.cc test3.cc
Log message:
General purpose slicing of Vectors. Syntax is eg:
vector.slice<Dynamic, 4>(1,4);
As usual, the static argument is used where possible. Optional
debugging checks
to make sure that the static and dynamic sizes are the same (unless the
static
size is -1). Disable with -D TOON_NDEBUG_MISMATCH
Also, fixed some test programs.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/doc/documentation.h?cvsroot=toon&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/config.hh?cvsroot=toon&rev=1.13
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/slice_error.hh?cvsroot=toon&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/TooN/test/test2.cc?cvsroot=toon&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/TooN/test/test3.cc?cvsroot=toon&r1=1.6&r2=1.7
Patches:
Index: doc/documentation.h
===================================================================
RCS file: /cvsroot/toon/TooN/doc/documentation.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- doc/documentation.h 18 Aug 2009 14:15:39 -0000 1.33
+++ doc/documentation.h 24 Aug 2009 13:00:14 -0000 1.34
@@ -309,9 +309,13 @@
is checked at run-time in the dynamic case (with some additions).
Checks can
be disabled with various macros. Note that the optimizer will usually
remove run-time checks on static objects if the test passes.
+ - Static/Dynamic mismatch
+ - Statically determined functions accept and ignore dynamically
specified
+ sizes. Nevertheless, it is an error if they do not match.
+ - Disable with \c TOON_NDEBUG_MISMATCH
- Slices
- Disable with \c TOON_NDEBUG_SLICE
- - Sizes
+ - Size checks (for assignment)
- Disable with \c TOON_NDEBUG_SIZE
- overfilling using Fill
- Disable with \c TOON_NDEBUG_FILL
Index: internal/config.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/config.hh,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- internal/config.hh 27 Jul 2009 16:39:43 -0000 1.12
+++ internal/config.hh 24 Aug 2009 13:00:15 -0000 1.13
@@ -1 +0,0 @@
-
Index: internal/slice_error.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/slice_error.hh,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- internal/slice_error.hh 10 Jul 2009 14:05:56 -0000 1.9
+++ internal/slice_error.hh 24 Aug 2009 13:00:15 -0000 1.10
@@ -35,7 +35,7 @@
struct BadSlice;
///@internal
- ///A static slice is OK.
+ ///@brief A static slice is OK.
///This class is used after it has been determined that a slice is OK.
///It does nothing except provide a callable function. By contrast,
///if the slice is not OK, then the class is not specified and the
function
@@ -46,6 +46,97 @@
static void check(){} ///<This function does nothing: it merely
exists.
};
+ ///@internal
+ ///@brief Check if a slice is OK.
+ ///This class is used to see if a slice is OK. It provides a
+ ///callable function which checks the run-time slice information.
+ ///If the compile time information is bad, then it will not compile
+ ///at all. Otherwise, the sizes are checked at run-time. The check
+ ///will be optimized away if the sizes are known statically.
+ ///@ingroup gInternal
+ template<int Size, int Start, int Length>
+ struct CheckSlice
+ {
+
+ ///@internal
+ ///@brief choose a number statically or dynamically.
+ template<int Num> struct N
+ {
+ static int n(int num)
+ {
+ return Num==Dynamic?num:Num;
+ }
+ };
+
+ ///@internal
+ ///@brief Check the slice.
+ ///This is full static checking, which is stricter than
+ ///mixed chacking. For instance, none of the slice parameters.
This
+ ///should be used in addition to the other check function.
+ ///are allowed to be -1 (Dynamic).
+ static void check()
+ {
+ //Sanity check all basic static sizes
+ BadSlice<!(Size== Dynamic || Size > 0)>::check();
+ BadSlice<!(Start >= 0)>::check();
+ BadSlice<!(Length > 0)>::check();
+ BadSlice<(Size != Dynamic && (Start + Length >
Size))>::check();
+ }
+
+ ///@internal
+ ///@brief Check the slice.
+ ///The policy is that static sized where present are used.
+ ///However, for extra debugging one can test to see if the
+ ///static and dynamic sizes are mismatched.
+ ///any sense whatsoever.
+ ///@param size Vector size
+ ///@param start Start position of the slice
+ ///@param length Length of the slice.
+ static void check(int size, int start, int length)
+ {
+ //Sanity check all basic static sizes
+ BadSlice<!(Size == Dynamic || Size > 0)>::check();
+ BadSlice<!(Start == Dynamic || Start >= 0)>::check();
+ BadSlice<!(Length == Dynamic || Length > 0)>::check();
+
+ //We can make sure Length <= Size, even if Start is
unknown
+ BadSlice<(Size!=Dynamic && Length != Dynamic && Length
> Size)>::check();
+
+ //We can make sure Start < Size even if Length is
unknown
+ BadSlice<(Start != Dynamic && Size != Dynamic && Start
>= Size)>::check();
+
+ BadSlice<(Size != Dynamic && Start != Dynamic && Length
!= Dynamic && Start + Length > Size)>::check();
+ #ifndef TOON_NDEBUG_MISMATCH
+ if(Start != Dynamic && Start != start)
+ {
+ std::cerr << "TooN slice: mismatch
between static and dynamic start.\n";
+ std::abort();
+ }
+ if(Length != Dynamic && Length != length)
+ {
+ std::cerr << "TooN slice: mismatch
between static and dynamic length.\n";
+ std::abort();
+ }
+ if(Size != Dynamic && Size != size)
+ {
+ std::cerr << "TooN slice: mismatch
between static and dynamic size.\n";
+ std::abort();
+ }
+ #endif
+ if( N<Start>::n(start) + N<Length>::n(length) >
N<Size>::n(size) ||
+ N<Start>::n(start) < 0 ||
+ N<Length>::n(length) < 0)
+ {
+ #ifdef TOON_TEST_INTERNALS
+ throw Internal::SliceError();
+ #elif !defined TOON_NDEBUG_SLICE
+ std::cerr << "TooN slice out of range"
<< std::endl;
+ std::abort();
+ #endif
+ }
+ }
+ };
+
template<int Size, int Start, int Length>
struct CheckStaticSlice
{
Index: internal/vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- internal/vbase.hh 29 Apr 2009 21:57:30 -0000 1.28
+++ internal/vbase.hh 24 Aug 2009 13:00:15 -0000 1.29
@@ -120,29 +120,39 @@
return my_data[i * stride()];
}
-
+ //Completely generic Vector slice operations below:
template<int Start, int Length>
- Vector<Length, Precision, SliceVBase<Stride> > slice(){
- Internal::CheckStaticSlice<Size, Start, Length>::check(size());
- return Vector<Length, Precision, SliceVBase<Stride> >(my_data +
stride()*Start, Length, stride(), Slicing());
+ Vector<Length, Precision, SliceVBase<Stride> > slice(int start, int
length){
+ Internal::CheckSlice<Size, Start, Length>::check(size(), start,
length);
+ return Vector<Length, Precision, SliceVBase<Stride> >(my_data +
stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length,
stride(), Slicing());
}
template<int Start, int Length>
- const Vector<Length, Precision, SliceVBase<Stride> > slice() const {
- Internal::CheckStaticSlice<Size, Start, Length>::check(size());
- return Vector<Length, Precision, SliceVBase<Stride>
>(const_cast<Precision*>(my_data + stride()*Start), Length, stride(),
Slicing());
+ const Vector<Length, Precision, SliceVBase<Stride> > slice(int start,
int length) const{
+ Internal::CheckSlice<Size, Start, Length>::check(size(), start,
length);
+ return Vector<Length, Precision, SliceVBase<Stride> >(my_data +
stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length,
stride(), Slicing());
+ }
+
+ //Special case slice operations
+ template<int Start, int Length> Vector<Length, Precision,
SliceVBase<Stride> > slice(){
+ Internal::CheckSlice<Size, Start, Length>::check();
+ return slice<Start, Length>(Start, Length);
+ }
+
+ template<int Start, int Length> const Vector<Length, Precision,
SliceVBase<Stride> > slice() const {
+ Internal::CheckSlice<Size, Start, Length>::check();
+ return slice<Start, Length>(Start, Length);
}
- Vector<-1, Precision, SliceVBase<Stride> > slice(int start, int length){
- Internal::CheckDynamicSlice::check(size(), start, length);
- return Vector<-1, Precision, SliceVBase<Stride> >(my_data +
stride()*start, length, stride(), Slicing());
+ Vector<Dynamic, Precision, SliceVBase<Stride> > slice(int start, int
length){
+ return slice<Dynamic, Dynamic>(start, length);
}
- const Vector<-1, Precision, SliceVBase<Stride> > slice(int start, int
length) const {
- Internal::CheckDynamicSlice::check(size(), start, length);
- return Vector<-1, Precision, SliceVBase<Stride>
>(const_cast<Precision*>(my_data + stride()*start), length, stride(),
Slicing());
+ const Vector<Dynamic, Precision, SliceVBase<Stride> > slice(int start,
int length) const{
+ return slice<Dynamic, Dynamic>(start, length);
}
+ //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*>(my_data), 1, size(), 1, stride(), Slicing());
}
Index: test/test2.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/test2.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- test/test2.cc 24 Apr 2009 20:24:03 -0000 1.6
+++ test/test2.cc 24 Aug 2009 13:00:16 -0000 1.7
@@ -23,7 +23,7 @@
make_a_copy_constructor_happen(v1);
- cout << Scalars(1) + (v1 + v2)+Scalars(2) << endl;
+ cout << Ones + (v1 + v2)+2*Ones << endl;
v1.slice<0, 2>() /= 2;
cout << v1 << endl;
Index: test/test3.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/test3.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- test/test3.cc 30 Mar 2009 20:01:32 -0000 1.6
+++ test/test3.cc 24 Aug 2009 13:00:16 -0000 1.7
@@ -11,8 +11,8 @@
int main()
{
- Matrix<3> m1(Zero);
- Matrix<3> m2(Zero);
+ Matrix<3> m1(Zeros);
+ Matrix<3> m2(Zeros);
m1.slice<0,0,2,2>()+=3;
m2.slice<1,1,2,2>()+=2;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN doc/documentation.h internal/config.hh int...,
Edward Rosten <=