Is D a good choice for embedding python/octave/julia

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 13 14:36:53 PDT 2016


On Sunday, 13 March 2016 at 18:42:59 UTC, Bastien wrote:
> The sticking point is unless I commit the rest of my life to 
> maintaining this software, I can't write it all in D. The 
> algorithms change/are improved yearly; the output format from 
> the instrument changes once in a while and therefore these need 
> to be easily scripted/modified by other (non-programming) 
> scientists and the community that only really know python and 
> octave.

It's pretty easy to use D from python and python from D.  The 
documentation for PyD isn't so great, but once you have figured 
it out, it's easy.  Start with something very small (the examples 
and tests in the PyD repo are the best documentation) and work up 
from there.

You can even embed D in a Jupyter/iPython notebook, and write 
some cells in D and some in python and have them call each other. 
  See PydMagic by John Colvin.
https://github.com/DlangScience/PydMagic

D can talk to Julia via C linkage already.  Just extern(C) when 
you declare your D function, and I guess use C style arrays.

I started porting julia.h to D, but didn't get have time to 
finish.  Ilya Yaroshenko, who created the ndslice library in 
std.experimental, will be working on julia integration in coming 
months.

By the way, you can also embed R in D and call D from R - see 
work by bachmeier on bitbucket.  That's very important because of 
the huge numbers of R libraries.  Although R is slow, there 
apparently shouldn't be so much overhead in calling a C library 
written for R from D.
> I guess my resilience to using D for the algorithms is because 
> with python, I have access to numpy and matplotlib. There do 
> seem to be some ongoing developments though:
> http://forum.dlang.org/post/mailman.4923.1434903477.7663.digitalmars-d@puremagic.com

You already have access to matplotlib from D - see here (and 
scroll down or search for matplotlib):
https://d.readthedocs.org/en/latest/examples.html


And you can call numpy from D, but there is some overhead, and I 
wouldn't want to do it inside a tight loop.

 From PyD unit tests:

InterpContext context = new InterpContext();

     context.py_stmts(outdent("
         import numpy
         a = numpy.eye(2, dtype='complex128')
     "));

     context.a.to_d!(Complex!double[][] )();





More information about the Digitalmars-d-learn mailing list