Code Monkey home page Code Monkey logo

Comments (8)

mattjj avatar mattjj commented on August 27, 2024

I think the problem was that np.select was returning a 0-dimensional array (like np.array(FloatNode)) and those are a pain to handle. I think we just have to call wrap_if_nodes_inside. (My first fix unpacked the 0d array into a scalar type, but I realized that constitutes a change in behavior from the unwrapped numpy function.)

Reopen if still busted!

from autograd.

duvenaud avatar duvenaud commented on August 27, 2024

@mattjj Are you sure you don't want to add a test? A while ago I added a systematic test for np.select but left it commented out:
https://github.com/HIPS/autograd/blob/master/tests/test_systematic.py#L176

from autograd.

mattjj avatar mattjj commented on August 27, 2024

Yeah yeah okay :)

That test is actually for the gradient of select, right? My fix didn't implement a gradient for select so much as it made select work as control flow (as it would have done automatically if not for the zero-dimensional array issue, afaict).

from autograd.

mattjj avatar mattjj commented on August 27, 2024

Except it only works in the scalar case (i.e. when condlist and choicelist are lists of scalars)... reopening!

from autograd.

mattjj avatar mattjj commented on August 27, 2024

Okay, I undid the change because making np.select actually work in general seems like a bit of a mess and I can't think of a quick fix. Any ideas?

from autograd.

mattjj avatar mattjj commented on August 27, 2024

My quick-fix thinking was that we could just use the fact that np.select should work on object ndarrays, then just wrap its output back to an ArrayNode. I'm kind of confused at the moment as to why that's not working.

from autograd.

mattjj avatar mattjj commented on August 27, 2024

Okay, took another quick stab at this one. The basic strategy is for autograd.numpy.select to be a non-primitive function that unboxes its arguments (from ListNode to list, or just keeps them as lists if they come in as lists), uses the underlying np.select on the enclosed object ndarrays (containing FloatNodes and stuff), and then reboxes the result.

Maybe this is shady! But it passes both David's test and the OP's test case.

Since I haven't thought too hard about how shady this might be, I'm leaving it in a branch named issue36 for now.

from autograd.

mattjj avatar mattjj commented on August 27, 2024

The consensus is that 2ae6bed is a good fix!

from autograd.

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.