【转载】SciPy for .NET & IronPython

原文地址;http://blog.enthought.com/python/scipy-for-net/#.Wiaho7puKUl

This week Enthought and Microsoft are announcing the availability of NumPy and SciPy for IronPython and the .NET Framework, released in conjunction with the release of Microsoft’s Python Tool for Visual Studio release. These packages implement a fast and flexible multi-dimensional array package (NumPy) and a large collection of scientific and numerical algorithms built on top of the array (SciPy) andare two fundamental building blocking for technical computing in Python. CPython users are well familiar with both but up until now they have not been available on other Python environments. This is because both packages include many heavily optimized native-code (typically C or FORTRAN) implementation of the algorithms, thus requiringcustom wrappers to integrate them into each Python environment.

The result of the project isIronPython ports of NumPy and SciPy, which are full .NET ports and include custom C#/C interfaces to a common native C core. This means that the full functionality is available not only to IronPython but to all .NET languages such as C# or F# by directly accessing the C# interface objects.

Completing the port required considerably more work than just writing new interfaces IronPython. To start with large parts of the NumPy C code were written specifically for CPython and made free use of the CPython APIs. To support additional Python environments the codebase had to be refactored into a Python-independent core library plus a CPython-specific interface layer. A big advantage to this architectural separation is that the core NumPy library can now be used from applications written in C or C++ much more easily and ports to other Python environments will require less work.

The second supporting project was an extension of Cython to support IronPython. Cython, not to be confused with CPython, is a tool that allows C extensions to be written for Python using a language based on Python with extensions for interacting with native code libraries. Up until now Cython has only supported the CPython environment. We have extended Cython to be able to generate C++/CLI code interfaces for .NET, and thus IronPython. Using a single Cython input file it is now possible to target both CPython and IronPython environments.

The main driver for the Cython project was the nature of the SciPy library. SciPy consists of dozens of different packages, many of which have a hand-written C interface for CPython. One option was to write a matching C# interface for each of these to support IronPython. While this would have taken less time, the result would have been a significant duplication of code and more maintenance work in the future. Instead we chose to port Cython to .NET and then rewrite each C module in Cython so one a single source file is needed.

The first release of SciPy and NumPy for .NET are available now as binary distributions from SciPy.org or directly from Enthought. All of the code for these and the supporting projects are open source and available at the links below.

This entry was posted in News, NumPy, Python, SciPy and tagged FORTRAN, NET on Aug 29, 2011 by admin.

Post navigation

Import registry hooks in EPD EPD 7.2 released

24 thoughts on “SciPy for .NET & IronPython”

  1. avatarsean Aug 29, 2011 at 14:16 CST

    This is a monumental work & a big welcome for the IronPython & .Net communities.

    Reply
    1. avatarjmccampbell Aug 29, 2011 at 16:39 CST

      Thank you. I like IronPython a lot and I hope the packages turn out to be valuable and add to the technical computing environment.

      Reply
      1. avatarTom Kennedy Nov 7, 2011 at 08:30 CST

        Hi JM,

        I have tried to get these libs working but it doesnt seem to install all of the Scipy stuff.

        I have asked the question on the enthought list but nobody has replied.

        Could I private mail you?

        Regards,
        Tom

        Reply
  2. avatarCraig Aug 29, 2011 at 14:48 CST

    Are the changes that were required to Cython, SciPy, and NumPy merged into their repositories so that a user of SciPy for .NET will benefit from continued work on these other tools / libraries?

    Reply
    1. avatarjmccampbell Aug 29, 2011 at 16:37 CST

      For the most part, no not yet. It will require involvement from the respective communities and whether they see value in the changes. I suspect some of this will depend on how the community develops around the .NET ports. My hope is that by adding the .NET platform it grows the overall community to the benefit of users on both platforms.

      Reply
  3. avatarQi Qi Aug 29, 2011 at 15:12 CST

    Will it be ported to use with Mono and ironPython on linux?

    Reply
    1. avatarjmccampbell Aug 29, 2011 at 16:32 CST

      Part of it perhaps. The core NumPy work is easy to port and I have run parts of it under Mono during development. All of the code is C# and cross-platform C/C++.

      Anything dependent on Cython (a few of the smaller NumPy support packages and most of SciPy) is a much bigger issue. The problem is Cython generates C++/CLI instead of C# and Mono doesn’t support C++/CLI. We tried to avoid it but the nature of Cython requires the generation of managed code that can access native data structures. Getting the field offsets correct is handled automatically in C++/CLI because it can parse the header files. Reproducing this and instead generating C# is a fairly large project.

      Reply
  4. avatararman Aug 29, 2011 at 18:24 CST

    This is wonderful. Thanks for your efforts.

    I wonder if your work will also be useful in getting Cython to work with pypy. I really hope the Cython people will merge your efforts.

    Reply
  5. avatarManuel Aug 30, 2011 at 02:33 CST

    Which fwrap branch on github is the one used by scipy? Is it the ‘scipy’ branch? And has it waf already integrated? Thanks for the great work!

    Reply
  6. avatarcbc Aug 30, 2011 at 04:20 CST

    This is great! But why can’t I import scipy.sparse?

    Reply
  7. avatarchadbr Aug 31, 2011 at 06:49 CST

    Are there any plans to build a Matplotlib backend to support ironPython?

    Reply
  8. avatarnaveen Sep 1, 2011 at 21:04 CST

    Very exciting news.
    Thanks for putting the source code on github.
    I am trying to build from source for ipy27 for .net3.5.
    doing c:/> /ipy27/ipy iron_install.py doesn’t work, neither does building NumpyDotNet.sln in visual studio 2010.
    Could you please provide some build instructions ?
    are there any prerequisites besides the 4 repositories you have put on github ?
    do we need to change visual studio configuration (include libraries / headers between repos) ?

    Reply
  9. avatararman Sep 4, 2011 at 18:50 CST

    Are there any instructions for building Cython on Windows? A very quick attempt I building it from the bitbucket link above fails in converting Pyrex files to C. I can provide additional details if necessary.

    Reply
  10. avatarDirk Sep 22, 2011 at 02:30 CST

    Impressive! A commendable effort and a dream come true for our research department…
    I do have a practical question though. I installed everything and can work with numpy in IronPython etc. but we usually work in F# and I was hoping to be able to simply reference some DLL and get access to the well-known numpy functions.
    Is there a way to do this without running an embedded interpreter? Where do I find the C# interface that you talk about?
    For instance if I would want to use the poly1d function in C# or F#, how would I go about? Do I first need to compile .py scripts to a dll? Is there documentation about what is available in the precompiled dlls I can find in the C:\Program Files (x86)\IronPython 2.7\DLLs folder?
    Apologies for the many questions, but I am very enthusiastic about the possibilities and I have the impression I’m missing something…

    Reply
  11. avatarBrian Oct 19, 2011 at 13:30 CST

    Unfortunately, despite what the documentation says, integrate is missing from scipy in the 1.0 release. Hope it will be in a future release.

    Reply
  12. Pingback: What is the typical time overhead in using an open source package vs. an equivalent commercial package? - Quora

  13. avatarLuis Mar 12, 2012 at 11:14 CST

    Hi Guys!

    It seems that NumPy and SciPy were working along with PyTools very well until PyTools 1.1 RC

    http://pytools.codeplex.com/workitem/656

    are you aware of this issue?

    Is there a fix for this or a work arround?

    I really appreciate your help! I’m a Python n00b and really need this working for my MS thesis.

    Reply
  14. avatarTim Hochberg Apr 3, 2012 at 13:40 CST

    I’m very happy to see this project, but what is the correct forum for posting bug reports about NumPy for IronPython?

    There is a bad interaction between copy.copy and the numpy scalar types:

    IronPython 2.7.2.1 (2.7.0.40) on .NET 4.0.30319.239 (32-bit)
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import numpy, copy
    >>> x = numpy.float32(1)
    >>> print x, copy.copy(x), copy.copy(float(x))
    1.0 6.72623e-44 1.0

    Note that copy.copy works fine on float, but fails on float32 (and other numpy scalar types).

    Reply
  15. avatarMatthew Ishimaru Jul 10, 2013 at 20:06 CST

    Is the SciPy for .NET effort officially dead? Was a 64-bit version version ever release?

    Reply
    1. avatarJason McCampbell Jul 22, 2013 at 13:28 CST

      Hi Matthew, no new work is going into SciPy for .NET from our end, though all of the work is open source and I know some people are using it. I’m not sure if anyone else is contributing right now. When Microsoft switched from IronPython to more of a implementation-agnostic strategy funding dried up. The cost of porting a critical mass of packages from CPython is substantial so in our projects involving .NET we have preferred to make CPython work with .NET as opposed to using IronPython.

      We never released the 64-bit binaries though it should generally be 64-bit clean. I’m not sure what work is needed to make it run.

      Reply
    2. avatarMark DeArman Nov 13, 2013 at 15:01 CST

      I just built a slim version of NumPy for IronPython 2.7.4 64-bit from the source and the only top level issue I ran into was some improper type definitions in ndarray. If you are still interested in getting this working you can email me. I haven’t fully tested all the functionality I wanted to include in my application, so there might be other issues lurking.

      Reply
      1. avatarPatrick Dec 13, 2013 at 12:34 CST

        n a 64bit machine I am getting a BadImageFormat for NpyAccessLib.dll. Does you version solve that?

        If so please post somewhere.

        Reply
        1. avatarMark DeArman Jan 1, 2014 at 14:34 CST

          My contact info is on my website. Please send me an email.

          Reply
  16. avatarNilster Jan 6, 2016 at 04:42 CST

    For those struggling to get numpy/scipy install for ironpythopn, enthought have moved the download link to https://store.enthought.com/repo/.iron/ . The link would only allow you in if you are registered.

    Therefore first up you’d have to register yourself for free, then open the above link, then follow the steps below
    1. Download the IronPython-2.7.msi and install it.
    2. Download ironpkg-1.0.0.py from the above link.
    3. Using command line navigate to the directory where you placed ironpkg-1.0.0.py and run
    ipy ironpkg-1.0.0.py –install
    Check whether the install worked using
    ironpkg -h
    3. The last step is lightly different to the one suggested by enthoughts. Running ironpkg scipy won’t work as it looks at the old web address for download. Instead download all the eggs and index-depend.txt from the above link. For installation to work, you would have to modify the download location in the config file to point to the local drive instead of website. The config file can be found at C:\Users\Nilster\.ironpkg . Open it in textpad and change the location to directory where you downloaded eggs Eg, mine looks like
    IndexedRepos = [
    ‘file://C:\Work\Python\Enthought_Eggs’,
    ]
    4. Then run the following to install numpy/scipy
    ironpkg scipy
    5. Check whether the install worked using
    ipy -X:Frames -c “import scipy”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值