-
Notifications
You must be signed in to change notification settings - Fork 20
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
Various errors with zero-size vectors and matrices #91
Comments
Actually, the 1x0 Mat constructor with no args works now with FixedSizeArrays master. |
I don't understand quite what's going on here. The simplest failing case is: julia> using FixedSizeArrays
julia> Vec{0, Int}(0)
ERROR: type Union has no field name
in fsa_abstract at /home/rdeits/.julia/v0.4/FixedSizeArrays/src/core.jl:46
in size_or at /home/rdeits/.julia/v0.4/FixedSizeArrays/src/core.jl:52
in call at /home/rdeits/.julia/v0.4/FixedSizeArrays/src/constructors.jl:78
in call at /home/rdeits/.julia/v0.4/FixedSizeArrays/src/FixedSizeArrays.jl:26 It fails because the typevar FSA in call() is |
May I ask why you would like to do this? I agree, the error messages should be clearer, but is there a case to make this possible at all? |
I'm not actually sure. I came across this bug while working on some code for representing linear systems (i.e. systems of the form xdot = A*x), and I occasionally end up with systems in which the length of x is 0. Being able to initialize 0-element vectors the same way I initialize vectors of any other length just lets me remove some special cases from my code. I think it's also somewhat analogous to the built-in That said, it's also easy for me to work around this by adding a few extra definitions to my code, e.g.: call{T}(::Type{Mat{0, 0, T}}, x::Number) = Mat{0,0,T}()
call{N, T}(::Type{Mat{0, N, T}}) = Mat{0, N, T}(tuple([tuple() for i in 1:N]...))
call{N, T}(::Type{Mat{0, N, T}}, x::Number) = Mat{0, N, T}()
call{M, T}(::Type{Mat{M, 0, T}}, x::Number) = Mat{M, 0, T}() and so on. |
If you're convinced that this is the correct behaviour, I wouldn't mind a PR ;) zero(Mat{0,0, Float32})
zero(Mat{0,10, Float32}) I guess this discussion is slightly similar to this one: #75 (comment) |
Ah, of course! I'd forgotten about the overloaded zero(). I'll switch to using that in my code, which should solve my problem nicely. Thanks! For what it's worth, I started out using Vec{N,T}(0) instead of zero(Vec{N, T}) because I saw the former in the readme and assumed that was the best way to construct a vector of zeros. But using zero() does make a Julian kind of sense. |
I'm encountering a related issue with the transpose of an Nx0 Mat:
|
I fixed it in #126 |
Great, thank you! |
Fixed-size vectors and matrices with one or more dimensions of zero length can cause various different issues when constructed:
I'll see if I can tell what's going on.
The text was updated successfully, but these errors were encountered: