Re: How to support .NET class slicing using python syntax

Stéphane Lozier
 

IronPython uses IronPython.Runtime.Slice. Looks like the NDArray class in Numpy.NET has a string overload that takes slice notation so you could add an overload like:

public NDarray this[IronPython.Runtime.Slice slice] {
    get {
        return this[$"{slice.start ?? string.Empty}:{slice.stop ?? string.Empty}:{slice.step ?? string.Empty}"];
    }
    set {
        this[$"{slice.start ?? string.Empty}:{slice.stop ?? string.Empty}:{slice.step ?? string.Empty}"] = value;
    }
}

Stéphane


On Thu, Dec 12, 2019 at 11:11 AM Hailiang Shen <hailiang@...> wrote:

Dear all, as far as I know there is still no equivalent numpy lib available to IronPython. Please correct me if this is not the case anymore.

 

We have a few scripts that require numpy lib (using very basic functions e.g. numpy.array). To respond, I am planning to create a C# lib to support these numpy functions, to minimize the effort on the users (ideally just by updating from numpy.net import numpy as np, and the rest of the code can be kept unchanged). One issue is to support slicing using python syntax, e.g. arr[1:3], where arr is a .NET class ndarray object. How can I modify ndarray class so its objects can be sliced in a pythonic way. Not sure implementing the special function __getitem__(self, index) will work since the index will be a slice object. A very simple example will work.

 

Also, what are other options you would use to mimic numpy lib?

 

Thanks for your inputs,

 

Hailiang

 

Join users@ironpython.groups.io to automatically receive all group messages.