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

How do I create a scalar value that does not depend on the independent variables ? #609

Open
bradbell opened this issue Oct 10, 2023 · 0 comments

Comments

@bradbell
Copy link

bradbell commented Oct 10, 2023

I would try using Jax , but the install does not work on my system and Jax has 1.3k open issues, so I think that my install questions would get lost in the noise; see
google/jax#18084

How do I create a scalar value that does not depend on the independent variables ?
The following function works (fails) if you set flag to False (True).

flag = False
import autograd

def my_fun(x) :  
   Scalar = type( x[0] )
   result = x[0] * x[1]
   if flag :
      result = result + Scalar(0.0) 
   return result

my_grad = autograd.grad(my_fun)
my_x    = autograd.numpy.array( [ 2.0, 3.0 ] )
my_g    = my_grad( my_x )
ok      = my_g[0] == my_x[1] and my_g[1] == my_x[0]
print( f'ok = {ok}' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@bradbell and others