-
Notifications
You must be signed in to change notification settings - Fork 187
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
Add d3.linspace. #150
base: main
Are you sure you want to change the base?
Add d3.linspace. #150
Conversation
I can see how it would be useful, esp. if it returned a Float64Array (or had some option like
For logspace and geomspace it looks like there is no particular algorithmic challenge and not much use. I wouldn't want to add weight (bytes and documentation and cognitive load) just for the sake of it :) |
Very nice! |
This looks like a nice PR. Could be merged I suppose. |
I don’t think the positional arguments with defaults are appropriate here because they aren’t analogous to Python’s named arguments. For example in Python you would say stuff like np.linspace(2.0, 3.0, 5)
np.linspace(2.0, 3.0, num=5)
np.linspace(2.0, 3.0, num=5, endpoint=False)
np.linspace(2.0, 3.0, endpoint=False) and the meaning is fairly clear. However in JavaScript it would be d3.linspace(2, 3, 5)
d3.linspace(2, 3, 5)
d3.linspace(2, 3, 5, false)
d3.linspace(2, 3, undefined, false) which I think is much less obvious. So I wonder if instead we should do something like: d3.linspace(2, 3, 5)
d3.linspace(2, 3, {num: 5})
d3.linspace(2, 3, {num: 5, endpoint: false})
d3.linspace(2, 3, {endpoint: false}) This would also allow us to create typed arrays: d3.linspace(2, 3, {num: 5, type: Float64Array}) I also don’t really like feeling stuck with Python’s names for these options. I think I’d prefer And lastly I wonder if there should be more symmetry between d3.range and d3.linspace. Like, what about: d3.range(2, 3, {length: 5, inclusive: true}) Also this feels fairly low priority and ambiguous so I’m not very motivated to think about this too much. 🤷 Sorry! |
Related #90.