[Cython] aritmetic with arrays in Cython

Sturla Molden sturla.molden at gmail.com
Tue Aug 12 17:18:12 CEST 2014


But using Eigen will taint the output with Eigen's license, since the Eigen
library is statically linked. OTOH, Cilkplus is just a compiler extension
for C and C++. 

AFAIK, it is currently available for Intel C++ and Clang (also by Intel)
and GCC 4.9. On MSVC I believe it requires Intel Parallel Studio. The main
obstacle to its adoption today is MSVC and GCC 4.8. Cilkplus is also being
evaluated for becoming parts of the future C and C++ standards.

Another thing to observe is that Eigen depends on the C++ compiler to elide
temporary arrays. Currently it only/mostly happens for fixed size arrays.
Clikplus arrays does not suffer from this. You just index pointers like
typed memory views (though the indexing syntax is slightly different), and
it compiles to efficient machine code just like Fortran 90 array code. 

Sturla

Stefan Behnel <stefan_ml at behnel.de> wrote:
> Ian Henriksen schrieb am 12.08.2014 um 04:34:
>> On Sun, Aug 10, 2014 at 12:41 PM, Sturla Molden wrote:
>>> Ian Henriksen wrote:
>>>> Maybe I should clarify a little about why eigen is a good place to start.
>>>> According to <a
>>>> href="http://eigen.tuxfamily.org/dox/TopicLazyEvaluation.html">
>>> http://eigen.tuxfamily.org/dox/TopicLazyEvaluation.html</a>
>>>> it
>>>> already takes care of things like the elimination of temporary variables
>>>> and common subexpression reduction at compile time. This should make it
>>>> possible to compile array expressions in Cython without having to
>>>> re-implement those sorts of optimizations. Ideally we would just have to
>>>> map memory view operations to corresponding equivalents from eigen. It's
>>>> not yet clear to me how to do things with arbitrary-dimensional arrays or
>>>> broadcasting, but, given some more time, a solution may present itself.
>>>> -Ian
>>> 
>>> cilkplus is what you want, not Eigen.
>>> 
>>> But if you are serious about number crunching, learn Fortran 95.
>> 
>> Cilk Plus would also work really nicely for this. Thanks for the suggestion.
>> Fortran is a really great language for this sort of thing, but I don't
>> think I'm ready to tackle the difficulties of using it as a backend for
>> array arithmetic in Cython. It would be a really great feature to have
>> later on though.
> 
> That clarifies a bit of the design then: The syntax support should be
> somewhat generic, with specialised (sets of) node implementations as
> backends that generate code for different libraries/compilers/languages.
> 
> It's ok to start only with Eigen, though. We have working example code for
> it and everything else has either a much higher entry level for the
> implementation or a much lower general availability of the required tools.
> 
> For the syntax/type support, a look at the array expressions branch might
> also be helpful, although I doubt that there really is all that much to do
> on that front.
> 
> Stefan



More information about the cython-devel mailing list