Best practice of type for a scalar value #18328
Answered
by
jakevdp
ToshiyukiBandai
asked this question in
Q&A
-
Hi JAX community, In my code, there are some physical constants. I am wondering what is the best practice of the type for scalar values. I think there are three options:
It seems to me that the last option is the most computationally effective because it can avoid type promotion when interacting with other 1D array objects. Does anyone have specific recommendations? |
Beta Was this translation helpful? Give feedback.
Answered by
jakevdp
Oct 30, 2023
Replies: 1 comment 4 replies
-
All of these should be fine. There are several differences:
Does that answer your question? |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
ToshiyukiBandai
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All of these should be fine. There are several differences:
x = 1.0; y = 2.0; z = x * y
is a host-side multiplication, not a multiplication on device.x * jnp.bfloat16(1.0)
, the result will bebfloat16
rather than promoting the bfloat32 to float32 or float64x * jnp…