c# application calling Scipy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dongarbage@hotmail.com

    #1

    c# application calling Scipy

    Hi,

    Novice here. :)

    I'm building a c# application and I want to call functions in SciPy
    from that application.

    What's the best way to call SciPy methods from a C# program?

    Is there a best Python implementation for this? Ironython? Python for
    ..NET? Enthought?

    Thanks in advance,
    Don

  • Robert Kern

    #2
    Re: c# application calling Scipy

    dongarbage@hotm ail.com wrote:
    Hi,
    >
    Novice here. :)
    >
    I'm building a c# application and I want to call functions in SciPy
    from that application.
    >
    What's the best way to call SciPy methods from a C# program?
    >
    Is there a best Python implementation for this? Ironython? Python for
    .NET? Enthought?
    scipy is a package with many C and FORTRAN extensions, so IronPython won't work
    unless someone has figured out a magic way to compile them. The Enthought
    distribution (disclosure: I work for Enthought) is just a bundling of the normal
    python.org distribution of Python with a bunch of packages; it knows nothing
    about C#. I know little about Python for .NET beyond its README, but it does
    seem to be able to embed CPython into a C# application and with some elbow
    grease, that might work for you.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco

    Comment

    • sturlamolden

      #3
      Re: c# application calling Scipy


      dongarbage@hotm ail.com wrote:
      Hi,
      >
      Novice here. :)
      >
      I'm building a c# application and I want to call functions in SciPy
      from that application.
      >
      What's the best way to call SciPy methods from a C# program?
      You need to:

      1. Embed a Python interpreter in your C# app. That is, importing from a
      DLL with a Python interpreter and defining a few structs.

      2. Define a NumPy ndarray as a C# struct.

      Or:

      1. Write a proxy DLL in C and embed Python in that. This is the
      preferred way, as I see it. You are relieved of having to redefine
      Python and NumPy's C structs in C#.

      2. Import your proxy in C# and marshal a C# array to a IntPtr. That
      will allow you to map a C# array to a NumPy ndarray C struct in your
      proxy.

      The latter method is less hassle.

      In any case you also need to make sure you are using a .NET runtime
      that are linked to the same CRT as Python (.NET 1.1 should work).

      Using IronPython will not work, as neither NumPy nor SciPy is ported to
      IronPython (and porting is not trivial either; but if you take the task
      upon yourself, many will be happy if you succeeed.)

      Comment

      Working...