morpho icon indicating copy to clipboard operation
morpho copied to clipboard

[Feature Request] Range arithmetic

Open joshichaitanya3 opened this issue 2 years ago • 6 comments

As the recent issues point out, the Ranges are tricky with floats as spacing. It'd be nice to be able to do arithmetic on Ranges, so that we can have Ranges generated from integers and multiplied by the required spacing later on. Something like this

// Go from 0 to 1 in N+1 steps
var N = 10
var range = 0..N // I think this is always exact?
range = range/N // This operation, if possible, would give a Range going from 0 to 1 exactly in N+1 steps, without worrying about floating point.

Alternatively or additionally, we could have a different kind of Range object going from a to b in a fixed number of steps (like NumPy's linspace), may be with the notation a..b::N or something?

joshichaitanya3 avatar Mar 08 '22 18:03 joshichaitanya3

I just realized that the above example isn't the greatest, since we can just do 0..1:(1/(N+1)) and it works, but there are other spots where it could be more useful.

joshichaitanya3 avatar Mar 08 '22 18:03 joshichaitanya3

If you want to do this you can do it with Matrix(List(range))/N

We might want to consider a constructor of type Matrix(range) (and Array(range)) to avoid the call to list first?

ConduitDan avatar Mar 29 '22 14:03 ConduitDan

Nice

eihabhala avatar Apr 10 '23 19:04 eihabhala

I am seeing something Amazing with this language. But the Question is How to Build Packages For It appreciated if You Guys Can Point Me With Just That :)

eihabhala avatar Apr 10 '23 19:04 eihabhala

@eihabhala Thanks for the feedback! We are working on detailed information for developers, including how to build packages for our upcoming release.

softmattertheory avatar Jan 30 '24 11:01 softmattertheory

Thanks 💐

eihabhala avatar Jan 30 '24 13:01 eihabhala