toon-members
[Top][All Lists]
Advanced

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

Re: [Toon-members] stacking two matrices with slices.


From: E. Rosten
Subject: Re: [Toon-members] stacking two matrices with slices.
Date: Thu, 9 Jul 2009 10:51:37 +0100 (BST)

On Wed, 8 Jul 2009, Damian Eads wrote:

Hi,

There were a number of bugs (now fixes). In addition:


I would like to stack two matrices, -1*identity and the identity
matrix using TooN slices. I've tried to do this with the following
code:

 template <int Size, typename PixelType=float>
 struct MatrixPrimitives {
   static Matrix <Size*2, Size, PixelType> negI_I(int size=Size) {
     Matrix <Size*2, Size, PixelType> X;
     X.slice<0,     0,     Size, Size>() = -1.0 * Identity;  // error
     X.slice<Size,  0,     Size, Size>() = Identity;         // error
     return X;
   }
 };


This is a C++-ism. Because the type X is not fully determined when the struct is written, it doesn't know that slice is a template. So, you have to be explicit:

   X.template slice<0, 0, Size, Size>() = ...



 template <typename PixelType>
 struct MatrixPrimitives<-1, PixelType> {
   static Matrix <Dynamic, Dynamic, PixelType> negI_I(int size) {
     Matrix <Dynamic, Dynamic, PixelType> X(2*size, size);
     X.slice<>(0,     0,     size, size) = -1.0 * Identity(size); // error
     X.slice<>(size,  0,     size, size) = Identity(size);   // error
     return X;
   }
 };

but I get a compiler error before instantiating MatrixPrimitives,

That was a documentation bug (now fixed). Dynamic slices don't take template arguments:

      X.slice(size,  0,     size, size) = Identity(size);   // error

To gain some insights, in a separate program (prog3.cpp), I tried
instantiating Matrix with resolved constants (e.g. 6 and 3) for the
template arguments then did slicing,

#include <TooN/TooN.h>

using namespace TooN;

int main() {
 Matrix <6, 3, float> Xf;
 Xf.slice<0, 0, 3, 3>() = Identity(3);
 Matrix <6, 3, double> Xd;
 Xd.slice<0, 0, 3, 3>() = Identity(3);
 Matrix <6, 3, int> Xi;
 Xi.slice<0, 0, 3, 3>() = Identity(3);
}

and the program compiles with a benign precision warning,

bash-3.2$ g++ prog1.cpp -I/usr/local/include -c -o prog1.o
/usr/local/include/TooN/internal/objects.h: In member function ?void
TooN::Operator<TooN::Internal::ScaledIdentity<Pr>
::eval(TooN::Matrix<Rows2, Cols2, Precision2, Base2>&) const [with
int R = 3, int C = 3, P = int, B = TooN::Internal::Slice<3, 1>, Pr =
double]?:
/usr/local/include/TooN/internal/matrix.hh:111:   instantiated from
?TooN::Matrix<Rows, Cols, Precision, Base>& TooN::Matrix<Rows, Cols,
Precision, Base>::operator=(const TooN::Operator<Op>&) [with Op =
TooN::Internal::SizedIdentity<double>, int Rows = 3, int Cols = 3,
Precision = int, Layout = TooN::Internal::Slice<3, 1>]?
prog1.cpp:11:   instantiated from here
/usr/local/include/TooN/internal/objects.h:195: warning: converting to
?int? from ?const double?
bash-3.2$

This is another bug (now fixed). Idendity used to hold a double and then assign it where required. This causes a warning when assigning it to an int. This has now been replaced with a generic One type which can be assigned efficiently to anything with no warnings.

By the way, in the static sized case, you don't need to provide a size to Identity, eg:

Xd.slice<0, 0, 3, 3>() = Identity;

In fact, if you do provide a size (even an incorrect one) it will be silently ignored.


It looks like the compiler wants the template arguments to be resolved
before instantiation. How do I get around this?

Also unexpected, if I use non-constant *function* (not template!)
arguments when calling slice, I get a compiler error.

Same doc bug as before. If you remove the empty template brackes <> for slice, then it will compile.

Thanks in advance,

Thanks for the bug report!

-Ed

--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
    d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage




reply via email to

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