toon-members
[Top][All Lists]
Advanced

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

[Toon-members] stacking two matrices with slices.


From: Damian Eads
Subject: [Toon-members] stacking two matrices with slices.
Date: Wed, 8 Jul 2009 18:56:35 -0600

Hi,

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;
    }
  };

  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,

bash-3.2$ g++ acd.cpp -I/usr/local/include -c -o acd.o
acd.hpp: In static member function ‘static TooN::Matrix<(Size * 2),
Size, PixelType, TooN::RowMajor> ACD::MatrixPrimitives<Size,
PixelType>::negI_I(int)’:
acd.hpp:28: error: expected primary-expression before ‘)’ token
acd.hpp:29: error: expected primary-expression before ‘)’ token
acd.hpp: In static member function ‘static TooN::Matrix<-0x000000001,
-0x000000001, PixelType, TooN::RowMajor>
ACD::MatrixPrimitives<-0x000000001, PixelType>::negI_I(int)’:
acd.hpp:38: error: expected primary-expression before ‘>’ token
acd.hpp:39: error: expected primary-expression before ‘>’ token
bash-3.2$

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$

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.

#include <TooN/TooN.h>

using namespace TooN;

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

bash-3.2$ g++ prog2.cpp -I/usr/local/include -c -o prog2.o
prog2.cpp: In function ‘int main()’:
prog2.cpp:8: error: no matching function for call to
‘TooN::Matrix<-0x000000001, -0x000000001, float,
TooN::RowMajor>::slice(int, int, int&, int&)’
prog2.cpp:10: error: no matching function for call to
‘TooN::Matrix<-0x000000001, -0x000000001, double,
TooN::RowMajor>::slice(int, int, int&, int&)’
prog2.cpp:12: error: no matching function for call to
‘TooN::Matrix<-0x000000001, -0x000000001, int,
TooN::RowMajor>::slice(int, int, int&, int&)’
bash-3.2$

Any ideas on what I'm doing wrong?

Thanks in advance,

Damian

-----------------------------------------------------
Damian Eads                           Ph.D. Candidate
University of California             Computer Science
1156 High Street         Machine Learning Lab, E2-489
Santa Cruz, CA 95064    http://www.soe.ucsc.edu/~eads




reply via email to

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