warp.value#
- warp.value(x: Float) Float#
Return the value of a scalar jet without its derivatives, or a plain float unchanged.
Experimental
Forward-mode jets are experimental and subject to change without a formal deprecation cycle. See
warp.JetSpace().Comparisons such as
a < bare not defined on jets, so a function written generically over plain floats and jets compareswp.value(a) < wp.value(b)instead. A branch chosen this way carries the derivative of the branch taken.The signatures listed here take plain floats. Each space
J = wp.JetSpace(...)orJ = wp.JetSpace2(...)adds one that takes a scalar jet of that space, an instance ofJ.scalarsuch asJ.seed(1.5)(not the spaceJitself), and returns itsvaluefield.The result carries no forward-mode derivatives, but
wp.value()is not a stop-gradient: in reverse mode it is the identity, so awarp.Tapeorwarp.grad()still differentiates through it.- Parameters:
x – A
float16,float32orfloat64scalar, or a scalar jet (an instance ofJ.scalarfor a jet spaceJ).- Returns:
xitself for a plain float, otherwise the jet’svaluefield, a plain float of the jet’s dtype.
Example
Branch on a value in a function that takes plain floats and scalar jets alike:
J = wp.JetSpace(1) @wp.func def ramp_squared(x: Any): if wp.value(x) > 0.0: return x * x return 0.0 * x @wp.kernel def ramp_kernel(out: wp.array[float]): x = J.seed(1.5) y = ramp_squared(x) # a jet out[0] = wp.value(y) # its value, a plain float out[1] = y.grad[0] # its derivative, d(x**2)/dx = 2x out[2] = ramp_squared(1.5) # the same function on a plain float out = wp.zeros(3, dtype=float) wp.launch(ramp_kernel, dim=1, outputs=[out]) print(out.numpy())
[2.25 3. 2.25]