Comments (8)
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.
@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.
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.
Except it only works in the scalar case (i.e. when condlist and choicelist are lists of scalars)... reopening!
from autograd.
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.
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.
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.
The consensus is that 2ae6bed is a good fix!
from autograd.
Related Issues (20)
- support for Jax-like custom forward pass definition? HOT 1
- Gradient become Nan for 0 value test HOT 1
- Is it possible to see gradient function? HOT 2
- Four scipy tests are failing HOT 6
- Add np.float128,np.complex256 dtypes to vspaces and boxes registers HOT 2
- unsafe URL HOT 1
- Numpy 1.25 breaks a few linalg functions HOT 1
- `autograd` 1.6 breaks Apple M-series macOS and Windows builds (module `numpy` has no attribute `float128`) HOT 3
- Can I differentiate this function?
- Python 2 and dependency on future HOT 2
- `'ArrayBox' object has no attribute 'dot'` when differentiating function containing `x.dot(y)` HOT 1
- How do I create a scalar value that does not depend on the independent variables ?
- AttributeError: module 'autograd.numpy' has no attribute 'numpy_extra'
- Autograd for quantum circuits
- [BUG] Differentiating `autograd.numpy.linalg.norm` gives incorrect results
- Support for advanced library based on autograd HOT 4
- Release new version 1.6.3 on PyPI HOT 3
- autograd return nan with to norm function
- Saving `ArrayBox` to hdf5 file
- Incompatibility with numpy 2.0.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autograd.