Follow

@philipwhite

Depends a lot on the use case. Do you want the vectors to be huge (usually used in "struct of arrays" configuration) or small ("array of structs") or both?

I've worked with a "small vector, in place only, explicit copy" library before, since couldn't trust the language used to optimize anything, and have to say it can be a real pain sometimes, both to write/read through all the explicit copies (which also encourages you to use some unnatural expressions, like -2+5, instead of 5-2), and occasionally to debug a problem that turns out to be a missing copy. My advice would be to provide both, mostly use the copying versions, and only optimize performance sensitive code with in-place versions. I would suggest names like add, subtract, multiply for in-place versions (mimicking assembly) and plus, minus, times for copying versions (mimicking operators and the way equations/formulas are read).

For huge vectors (which I don't have as much experience with), while it is a good idea to enforce explicit copy, I'm skeptical whether providing this kind of one function per operation interface is a good idea itself. Usually if you are passing through a huge vector like that (or several), you want to do as many operations as possible at once (even if there is no special instruction), so you'll end up needing some lazy evaluation optimization, which can get really complicated (potentially even deprecating the explicit copy restriction), in contrast to the more common and straight forward map/zip approach.

@amiloradovsky@functional.cafe

· · SubwayTooter · 0 · 0 · 1
Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.