Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brainpy array does not support "where" argument in division #453

Open
3 tasks done
CloudyDory opened this issue Aug 22, 2023 · 1 comment
Open
3 tasks done

Brainpy array does not support "where" argument in division #453

CloudyDory opened this issue Aug 22, 2023 · 1 comment
Labels
brainpy.math issue belongs to brainpy.math module bug Something isn't working enhancement New feature or request

Comments

@CloudyDory
Copy link
Contributor

  • Check for duplicate issues.
  • Provide a complete example of how to reproduce the bug, wrapped in triple backticks like this:
  • If applicable, include full error messages/tracebacks.

I am trying to implement the function in Brainpy: x / (1.0 - bm.exp(-x)). When x->0, the function has a theoretical limit of 1.0, but if we directly set x=0, the function will output NaN.

In Numpy, this can be handled by: np.divide(x, 1.0-np.exp(-x), out=np.ones_like(x), where=np.abs(x)>=1.0e-6).

However, in Brainpy, the similar expression does not work: bm.divide(x, 1.0-bm.exp(-x), out=bm.ones_like(x), where=bm.abs(x)>=1.0e-6). The error message is: TypeError: true_divide() got an unexpected keyword argument 'where'.

How can we deal with situations like this in Brainpy?

@CloudyDory CloudyDory added the bug Something isn't working label Aug 22, 2023
@chaoming0625
Copy link
Collaborator

chaoming0625 commented Aug 22, 2023

Thank you for raising this missing functionality in brainpy.

Unfortunately, brainpy.math does not support where argument currently. We will add this in the near future.

However, this function can be rewritten to:

def f(x):
  return bm.where(bm.abs(x)<1.0e-6, 
                             bm.ones_like(x),
                             x / (1.0 - bm.exp(-x)))

Hoping this message will fix this issue.

@chaoming0625 chaoming0625 added enhancement New feature or request brainpy.math issue belongs to brainpy.math module labels Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brainpy.math issue belongs to brainpy.math module bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants