-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[BUG] linspace should always include the stop value #1872
Copy link
Copy link
Closed
Description
Describe the bug
linspace truncates values in some cases
To Reproduce
(lazily casting to numpy to print to see precision)
import mlx.core as mx
import jax.numpy as jnp
import numpy as np
range = (0.21436651, 0.96568555)
num = 6
a = mx.linspace(range[0], range[1], num, dtype=mx.float32)
print(np.array(a))
a = jnp.linspace(range[0], range[1], num, dtype=jnp.float32)
print(np.array(a))
# [0.21436651 0.3646303 0.5148941 0.6651579 0.8154217 0.9656855 ]
# [0.21436651 0.3646303 0.5148941 0.6651579 0.81542176 0.96568555]Expected behavior
I'd expect linspace to produce the same results as jax, without truncation for the same dtype
Desktop (please complete the following information):
- OS Version: 15.2
- Version: 0.23.0
Additional context
I was using this to create bin edges for a histogram, and it was excluding the right most value because of the truncation when calculating counts. I can work around this by setting the last value if it's not an easy fix.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels