Giter VIP home page Giter VIP logo

Comments (6)

megawattfs avatar megawattfs commented on August 11, 2024

Update: I have tried to dig into this issue by copying the slicing by string code over from NDarray.cs to figure out why it breaks down:

using Numpy;
using static Numpy.np;
using System.Numerics;
using Numpy.Models;
using Python.Runtime;

public static void numpy_test()
    {
        Python.Runtime.PythonEngine.Initialize();

        NDarray arr = np.array(new float[]{ 1, 2, 3, 4, 5 });

        var tuple = new PyTuple(Numpy.Models.Slice.ParseSlices("2:4").Select(s =>
        {
            if (s.IsIndex)
                return new PyInt(s.Start.Value);
            else
                return s.ToPython();
        }).ToArray());
        var arr0 = new NDarray(arr.PyObject[tuple]);
        Debug.Log("Numpy test passed.");
    }

But this does not compile because "The type 'PyObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Python.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'."

But the most recent version of Python.Runtime available on NuGet is 2.5.2, which does have a definition for Python.Runtime.PyObject, as does Numpy.Models. Not sure what is going on here but will keep looking into it.

from numpy.net.

henon avatar henon commented on August 11, 2024

I just added a little test case with your code and it works perfectly in my test environment.

        [TestMethod]
        public void IssueByMegawattFs()
        {
            var arr = np.array(new int[] { 1, 2, 3, 4, 5 });
            var slice0 = new Slice(2, 4);
            var arr4 = arr[slice0];
            Assert.AreEqual("array([3, 4])", arr4.repr);
            var slice1 = new Slice(2, -1);
            var arr5 = arr[slice1];
            Assert.AreEqual("array([3, 4])", arr5.repr);
            var arr1 = arr["2:4"];
            Assert.AreEqual("array([3, 4])", arr1.repr);
            var arr2 = arr[":4"];
            Assert.AreEqual("array([1, 2, 3, 4])", arr2.repr);
            var arr3 = arr[":-1"];
            Assert.AreEqual("array([1, 2, 3, 4])", arr3.repr);
        }

Here are the dependencies of my test project:
image

As you can see the difference is that Numpy references pythonnet 3.0.0-preview2022-04-11

I don't understand why yours uses Python.Runtime.dll version 2.5.2. I'll make a test project with the nuget to see if there is something wrong with the numpy 3.10.1.30 nuget.

from numpy.net.

henon avatar henon commented on August 11, 2024

Have a look at the source code. I added a new SlicingExample for you which works just fine with the latest nuget

image

from numpy.net.

megawattfs avatar megawattfs commented on August 11, 2024

I see what happened:

I am using Unity, which is not compatible with NuGet. My process for adding Numpy to my project was as follows:

  1. Download the .nupkg directly from the NuGet website.
  2. Look under "Dependencies" on the NuGet page and download the .nupkg for all the dependencies
  3. Repeat step 2 with the NuGet page for all the dependencies until there are none left
  4. Extract the .nupkg files and add the .NET Standard 2 version of each package to my Unity project assets folder.

On the NuGet page for Numpy, Python.Runtime is not even listed as a dependency:
image

Therefore, I determined which version of Python.Runtime to use based on Python.Included, which lists Python.Runtime v2.5.2 as the minimum requirement and links to this download:
image

I see now that there is a version 3.0.0 available at https://www.nuget.org/packages/pythonnet/3.0.0-rc4. I will try that and see if it works. Maybe this version should be listed under dependencies for Numpy on the NuGet page?

Thank you for looking into this!

from numpy.net.

megawattfs avatar megawattfs commented on August 11, 2024

Never mind--I see now that I was using the wrong version of Python.Included (I got mixed up because NuGet linked me to the "latest" non-preview version of Python.Included from Numpy's dependency page, but I needed 3.10.0-preview2).

from numpy.net.

henon avatar henon commented on August 11, 2024

Correct ;). Closing this. Should you still have issues you can reopen.

from numpy.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.