Discussion:
[Pyublas] Square matrix?
João Luís Silva
2010-08-10 21:33:57 UTC
Permalink
Hello,

I've recently found pyublas and it's being most useful to link python
and C++. However I've found a problem that doesn't make sense to me. I
can pass a non-square matrix from Python to C++, but when the matrix is
square I'll get the error:

Boost.Python.ArgumentError: Python argument types in
numerical_method.cpp_function(matrix)
did not match C++ signature:
cpp_function(pyublas::numpy_matrix<std::complex<double>,
boost::numeric::ublas::basic_row_major<unsigned int, int> >)

In the C++ side I have:

void cpp_function(pyublas::numpy_matrix<std::complex<double>> M)

and in Python:

numerical_method.cpp_function(np.asmatrix(self.M))


The same square matrix that won't work will work fine if reshaped to a
non-square shape. I've looked in the Ublas and pyUblas documentation but
couldn't find a specific type for square matrices.

Regards,
Jo?o Silva
Andreas Kloeckner
2010-08-11 00:12:27 UTC
Permalink
Try with np.asarray. I've never tried numpy's matrix type.

Andreas
Post by João Luís Silva
Hello,
I've recently found pyublas and it's being most useful to link python
and C++. However I've found a problem that doesn't make sense to me. I
can pass a non-square matrix from Python to C++, but when the matrix is
Boost.Python.ArgumentError: Python argument types in
numerical_method.cpp_function(matrix)
cpp_function(pyublas::numpy_matrix<std::complex<double>,
boost::numeric::ublas::basic_row_major<unsigned int, int> >)
void cpp_function(pyublas::numpy_matrix<std::complex<double>> M)
numerical_method.cpp_function(np.asmatrix(self.M))
The same square matrix that won't work will work fine if reshaped to a
non-square shape. I've looked in the Ublas and pyUblas documentation but
couldn't find a specific type for square matrices.
Regards,
Jo?o Silva
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pyublas/attachments/20100810/a68678b4/attachment.pgp>
Loading...