Coder Social home page Coder Social logo

Comments (3)

tjosepo avatar tjosepo commented on May 18, 2024

I managed to get slices working locally by modifying PyObject.proxy and using strings:

// ✅ Passes
Deno.test("slice", () => {
  const array = [1, 2, 3];
  const list = python.list(array);
  assertEquals(list["1:"].valueOf(), [2, 3]);
  assertEquals(list["1:2"].valueOf(), [2]);
  assertEquals(list[":2"].valueOf(), [1, 2]);
  assertEquals(list["0:3:2"].valueOf(), [1, 3]);
  assertEquals(list["-2:"].valueOf(), [2, 3]);
});

// ✅ Passes
Deno.test("multidimensional slice", () => {
  const np = python.import("numpy");
  const slice = np.arange(15).reshape(3, 5);
  slice["1:, ::2"] = -99;
  assertEquals(slice.tolist().valueOf(), [
    [0, 1, 2, 3, 4],
    [-99, 6, -99, 8, -99],
    [-99, 11, -99, 13, -99],
  ]);
});

It's pretty neat, but I'm wondering if it's the right approach.

from deno_python.

DjDeveloperr avatar DjDeveloperr commented on May 18, 2024

Did you use the PySlice_* APIs? I think that's the right way to do it. If you have worked on it you're most welcome to PR, otherwise I can try looking into it this weekend (and review your other PR as well, sorry for delay I'm just really busy with school 😓)

from deno_python.

tjosepo avatar tjosepo commented on May 18, 2024

Did you use the PySlice_* APIs?

Yes. PySlice_New for creating the slice, then PyObject_Get/SetItem.

For multidimensional slices, PySlice_New for each slice, then merge them using PyTuple_Pack, then PyObject_Get/SetItem.

sorry for delay I'm just really busy with school

No worries! I should be studying for finals too 😅 instead I'm procrastinating and doing this.

I already worked on it, I'll clean up my code and try to open a PR before the end of the week. No need to review it immediately.

from deno_python.

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.