IMHO its better to go with the first option. You essentially want to add a 
single new method to matrices, it'll be easier to write and maintain to not 
have to dig through a layer of Python->C++ indirection. 

The linbox code of course uses the LinBox C++ matrix class. Then there is 
always some song and dance about getting the matrix data to linbox and back 
into Sage. If you think its confusing then that is precisely why you should 
go with A) to avoid it. Hint: At the end of the day, all dense matrices are 
in C storage order in memory.



On Wednesday, July 9, 2014 10:52:19 AM UTC-4, David Mödinger wrote:
>
>
>
> Am Mittwoch, 9. Juli 2014 16:18:03 UTC+2 schrieb Volker Braun:
>>
>> Python/Cython classes are not C++ classes, so you can't call Py/Cy 
>> methods from C++ code directly. It can of course be done using the CPython 
>> C API or Boost.Python, but a Python object is never a straight C++ object. 
>> For starters it doesn't have a C++ vtable, methods can be added dynamically 
>> in Python...
>>
>> The two basic patterns for Cython code are
>>
>> A) Write your implementation in Python first. Then switch py->pyx Cython. 
>> Then identify the slow parts and cdef variables & methods as appropriate, 
>> so that Cython can generate fast C code instead of having to call the 
>> CPython API always.
>>
>> B) Write your implementation in C++ first, or use an existing code. Wrap 
>> the C++ objects in Cython objects (
>> http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html). In this 
>> case you'd want to pass the raw matrix data as a pointer.
>>
>>
> Thank you for your response.
>
> I am trying to go with option B, that is one of the reasons I looked at 
> linbox code.
> One of the main points of my project is, that there are already wrappers 
> for the objects I want to use (NTLs ZZ_pEX and GF2EX are already wrapped, 
> see sage.rings.polynomial.
> polynomial_zz_pex.Polynomial_ZZ_pEX), and there are matrix types defined 
> and wrapped. When I looked at linbox code (example used: echelon-form) I 
> found the following code:
> int rowReducedEchelon(Matrix &E, const Matrix& A)
> They use references for Matrices throughout the file.
> These functions are specified in echelon-form.pxd
> cdef extern from "linbox/algorithms/echelon-form.h":
>     cdef cppclass EchelonFormDomainDouble 
> "LinBox::EchelonFormDomain<LinBox::Modular<double> 
> >":
>         EchelonFormDomainDouble(ModDoubleField)
>         int rowReducedEchelon(BlasMatrixDouble, BlasMatrixDouble)
>
> The objects I want to use are most likely already wrapped somewhere in 
> sage (NTL for example is a c++ library, the matrix representation I do not 
> know at all, that is one of the problems).
> So it shouldn't be necessary to build my own objects and wrap them, or at 
> least I thought so. And if I have to build my own wrappers, I'd have to 
> make them compatible with sage internal objects, but I think that would be 
> easier, as both are defined in cython.
>
> Regards,
> David
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to