-
Notifications
You must be signed in to change notification settings - Fork 148
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
Naming for small vectors #24
Comments
Also interesting: SIMD.jl is probably closer to |
OK, I'll respond with the history of my decision and we can work on the future from there:
|
The name If there is an overall consistent naming scheme, then renaming |
Yes, all valid points. On the subject of verbosity, I feel that What's the idea behind |
@eschnett @c42f Would a typealias for
Well, it could be used for C interop (or non-garbage collected arrays with |
In other words, |
Oh I see - I'm not sure about a |
There's always |
Well, last year using pointers was a disaster for codegen... And since the compiler devs are discouraging the use of pointers, I'd be surprised if this changed substantially ;) Also, things get ugly very quickly :-D I just hope this damn mutable tuples julep will come soon! :-D |
I agree Simon, but note that Apart from the fact that it lacks SIMD and might have an extra pointer indirection, it is possible the codegen is worse still for other silly reasons - I'd like to understand this better. But like I said in many cases, The mutable tuple thing should resolve all of this and these 3 types will become 1. |
@andyferris What about On the other hand, renaming |
Yes I meant |
One decent option, could implement ImmutableArrays-style # Option 1, this list is direct from ImmutableArrays.jl
export Vector1, Vector2, Vector3, Vector4,
Matrix1x1, Matrix1x2, Matrix1x3, Matrix1x4,
Matrix2x1, Matrix2x2, Matrix2x3, Matrix2x4,
Matrix3x1, Matrix3x2, Matrix3x3, Matrix3x4,
Matrix4x1, Matrix4x2, Matrix4x3, Matrix4x4
# Option 2: Some new hybrid FixedSizeArray/ImmutableArray names
typealias Vec3{T} SVector{3,T}
typealias Mat3x3{T} SMatrix{3,3,T,9}
# etc...
# Option 3: Seen this in C++, but I just realized OpenEXR's Imath::V3d is "d" for "double" not "dimensions"
typealias V3d{T} SVector{3,T}
# Option 4, these are probably the correct Imath equivalents in Julia
typealias V3{T} SVector{3,T}
typealias M33{T} SMatrix{3,3,T,9} # or M3x3{T} ? Works beyond dimension 9. Option 1 can be implemented just like our compatibility layer for FixedSizeArrays, so users type To be honest, option 4 seems pretty sweet to me. |
@twadleigh I'll ping you since your opinion could be valuable here after authoring ImmutableArrays. |
And option 2 is also quite readable. |
Since I find something like |
Cool, thanks for that. Do you still find the I'm not sure why you chose But the short fallbacks for small square matrices like Or maybe Julia counterparts: Vec3
Vec3f32
Vec3i
Vec3i64
Vec3i32
Vec3c
Vec3c32 where |
I do, mostly for graphics/plotting them differently ;) But I also like it, that you can read code and immediately know that a point in space is meant. The list you propose looks agreeable ;) |
I agree that is very nice to read.
I'm leaning towards |
Well, I'm using mostly |
Oh wait, I just saw that :) OK I think we agree to that. Another thing to consider is |
OK in that case having |
I agree and that's also where it was originally located.. I think there was only a minor reason why I moved it to FixedSizeArrays ;) |
OK, nice. I will have a closer look at GeometryTypes. |
What about generic types |
We haven't ruled out We unfortunately need I have been using StaticArrays for a while now and I don't typically mind typing |
You might be able to use |
Right, yes... that is the way FixedSizeArrays does it. Unfortunately, I wasn't sure this always worked well - we rely on codegen to get rid of a lot of loads in In general I've pushed towards maximal performance (because if you want convenience just use |
Yes, FixedSizeArrays uses a tuple of tuples internally because of julia-0.4 limitations, but it was fairly painful to work with in the implementation, and the 0.4 compiler had a hard time when the nesting exceeded a certain depth (
For anyone following the breadcrumbs, this ended up being a dup of JuliaLang/julia#8322 For extra context, the most common time I'd be typing/reading v = Vec(1,2,3)
m = @Mat [1 2; 3 4]
vs = [Vec(i,i+1) for i=1:10] where the fact that |
For the problem of naming short aliases, it's hard to know how to be very concise but julian about it. From the Imath library I've grown somewhat fond of Regarding
|
Here's a thought for easier syntax, using julia> using StaticArrays
julia> abstract S{T}
julia> Base.getindex{N}(::Type{S}, x::Vararg{Any,N}) = SVector{N}(x)
julia> Base.getindex{N,T}(::Type{S{T}}, x::Vararg{Any, N}) = SVector{N,T}(x)
julia> S[1,2,3]
3-element StaticArrays.SVector{3,Int64}:
1
2
3
julia> S{Float64}[1,2,3]
3-element StaticArrays.SVector{3,Float64}:
1.0
2.0
3.0 The thought here was inspired distrubted array which defines things like We also nicely get that most functions like One downside is that |
I really like the |
Ok, the |
I like the short form as it reminds of non-standard string literals...
…On Tue, Dec 20, 2016 at 11:19 AM Chris Foster ***@***.***> wrote:
Ok, the S[1,2] syntax is a pretty great hack, I like this a lot. S is too
short to be sensible, but SA[1,2,3] might do. Or Static[1,2,3]?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUWz6axgPaMqBJc79qjZNTCdEKZgjjbks5rJ7nIgaJpZM4J00MC>
.
|
In isolation the short form is the prettiest, no doubt about it. However, I just spent a little time looking at this in the context of a larger chunk of code which lightly uses |
Hm I'm not sure if I'm a big fan of this. As it is, I already regularly confuse indexing with typed array construction. Also it just looks like the result should be a Julia array. Fun fact, a year (or two?) ago I proposed this exact construction syntax, but after confusing this syntax a couple of times, my opinion has changed. {1,2,3}
Float32{1,2,3} |
Right... lowering of comprehensions is extremely direct to making an array:
The things you learn. On the other hand we can do
and so could overload The only thing I'm worried about is that inference will not treat not treat the |
We could also do an |
Right, point taken, but string literals don't take part in the same namespace that normal types and functions do (at least not until they've been name-mangled). Taking a one-letter name for a relatively little-used feature like string macros seems a bit more reasonable than taking it in this case. Simon wrote
Yes, some other kind of brackets would be great... but I wouldn't want to bless them for use with static arrays. Hmm, now if only we could have "bracket macros" of some kind. Then Of course, we've not got enough types of ascii brackets - all the existing ones are taken for important core features, and we already suffer from the syntax pun which is typed array construction vs indexing. |
or perhaps I should clarify - this is a feature which is very commonly used, but not super commonly extended, so the |
Well, just for fun, here's a branch which adds "angle bracket macros" to the parser: https://github.com/c42f/julia/commits/extra-brackets Demo: julia> macro S_mathangle(exs...)
quote
SVector($exs)
end
end
@S_mathangle (macro with 1 method)
julia> S⟨1,2⟩ .< S⟨1.5, 1.5⟩
2-element StaticArrays.SVector{2,Bool}:
true
false To ease the pain of typing these special unicode brackets, I added |
Ok, super impressive :). I was wondering if we could dump a bunch of brackets in the parser and match them to a set of functions like `Base.vect()`. But the macro thing certainly is also useful as it can be shared between packages rather than "first come, first serve".
|
Yes I was thinking more about this, and came to the conclusion that having it as a macro is kind of bizarre and useless because it doesn't achieve much over normal macros, other than a relatively minor difference in notation. I'd hope for something more powerful than that. Like you say, it might be more interesting to desugar these to a function call. Allowing juxtaposition with an expression like normal square brackets would allow many packages to cooperate using the additional bracket types, just like |
Related: JuliaLang/julia#23519 |
I've just tried to allow @SArray[1 2; 3 4] * @SArray[1,2] through JuliaLang/julia#23547 |
I feel like this was never resolved in a fully satisfying way so I finally revisited this and implemented the One thing that makes this more compelling in 1.0 is that the SA[1 2
3 4] can be made inferrable as |
cc @EvertSchippers @MeganDawson |
This gives a way to construct an `SVector` and `SMatrix` with a precise eltype, but without typing a verbose type name. I think this fixes #24 to the extent that it can be fixed. Also add some quickstart docs for `SA` and the new type aliases.
This gives a way to construct an `SVector` and `SMatrix` with a precise eltype, but without typing a verbose type name. I think this fixes #24 to the extent that it can be fixed. Also add some quickstart docs for `SA` and the new type aliases.
As discussed at SimonDanisch/FixedSizeArrays.jl#159, I rather liked writing
Vec
andMat
for small sized arrays in FixedSizeArrays. Perhaps we should try to recover these names for StaticArrays, perhaps not?Note that SIMD.jl has also started using Vec so there is unfortunately already a naming clash with FixedSizeArrays there @eschnett
The text was updated successfully, but these errors were encountered: