HybridArrays.jl icon indicating copy to clipboard operation
HybridArrays.jl copied to clipboard

Easier syntax for constructor

Open plut opened this issue 4 years ago • 4 comments

Just like StaticArrays.jl has the nice SA[...] constructor, it should be possible to implement some easier-to-type HybridArray constructors. My suggestions would be a function HybridArray(n1,n2,...) which returns the type given by the arguments: either static if argument is an Integer, or dynamic otherwise (with another suggestion being to use either - or : as a shortcut for dynamic dimension). For example, HybridArray(2,:) would be a simpler alias for HybridArray{Tuple{2,StaticArrays.Dynamic()}}. (this is probably quite simple to code).

Another possibility which comes to mind would be to use cartesian product, so that, say, Vector*SVector{3} is computed as HybridArray{Tuple{StaticArrays.Dynamic(),3}}.

plut avatar Jan 12 '21 21:01 plut

HybridArray(n1,n2,...) looks quite nice, my only issue is that is would be quite unusual re-use of a type constructor. Maybe hybrid_array(n1,n2,...)(wrapped_array) would be better?

mateuszbaran avatar Jan 13 '21 08:01 mateuszbaran

This would be a welcome improvement. I suggest using : instead of -, since it already seems analogous to how : is used, for example in

reshape(A, 4, :)

I don't think - or ... have those connotations, or are commonly used like that.

As for the constructor syntax, is

HybridMatrix{2, :}(A)

possible? This is quite similar to StaticArrays: SMatrix{2, 5}(A).

DNF2 avatar Mar 24 '21 10:03 DNF2

IIRC there was some problem with using colon there but I may be wrong. I'll try that soon.

mateuszbaran avatar Mar 28 '21 08:03 mateuszbaran

OK, now I see what the problem is: Size struct in StaticArrays.jl only accepts integers and Dynamic(), and thus I'd have to get rid of every single usage of that struct in HybridArrays.jl. That should be possible but quite a bit of work.

mateuszbaran avatar Mar 28 '21 09:03 mateuszbaran