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

interpolateTypedArray #65

Closed
wants to merge 4 commits into from
Closed

interpolateTypedArray #65

wants to merge 4 commits into from

Conversation

Fil
Copy link
Member

@Fil Fil commented Jun 12, 2019

@Fil Fil requested a review from mbostock June 12, 2019 20:32
@Fil Fil mentioned this pull request Jun 12, 2019
2 tasks
@mbostock
Copy link
Member

What do you think about folding this into interpolateArray (so that interpolateArray checks the type of the target array b) rather than adding a new interpolateTypeArray method?

@Fil
Copy link
Member Author

Fil commented Nov 17, 2019

That detection is now made at the level of interpolate; having it at the level of interpolateArray would mean we have it twice (not a big deal).

Another consequence is that it would prevent the use of interpolateArray to coerce to a standard array (but this is something that we should not recommend in any way). The typical example for this is d3.interpolate([0.9], Uint8Array.from([0]))(0.1): d3.interpolateArray gives Array[0.81], the new method gives Uint8Array[0].

Internally, interpolateArray and interpolateTypedArray have a different machinery: to interpolate typed arrays we have no intermediate array of interpolators, only a for loop on the two arrays (we can't even use an array of the differences, because of unsigned types). So that function will still be here, only not exposed as a separate method. But it simplifies the API and does "the right thing", so overall it's probably better to fold this into interpolateArray.

@mbostock
Copy link
Member

It also occurs to me that we could have an interpolateNumberArray that works on all types arrays but also works on a generic array, coercing the elements to numbers in the same fashion as interpolateNumber and avoiding the need to create an interpolator function per element. Then if you wanted the “fast” interpolator for a generic array, you could opt-in to interpolateNumberArray instead of interpolateArray.

@Fil
Copy link
Member Author

Fil commented Nov 18, 2019

I think I would advertise interpolate (a, Float64Array.from(b)) as the faster solution (rather than add another API method).

This was referenced Nov 18, 2019
@Fil Fil closed this Nov 19, 2019
@Fil Fil deleted the interpolateTypedArray branch November 20, 2019 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Interpolate typed arrays?
2 participants