Skip to content
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

Problems with matrices and vectors #48

Open
jonasrauber opened this issue Jan 4, 2015 · 6 comments
Open

Problems with matrices and vectors #48

jonasrauber opened this issue Jan 4, 2015 · 6 comments

Comments

@jonasrauber
Copy link

I have multiple problems when using SIUnits with matrices and vectors.

A minimal working example of the underlying problem is shown in the following code. I would expect the second statement returning the same type as the first, but it doesn't.

julia> typeof(collect(1Hz:5Hz))
Array{SIQuantity{Int64,0,0,-1,0,0,0,0},1}

julia> typeof(collect(1:5)Hz)
Array{SIQuantity{Int64,m,kg,s,A,K,mol,cd},1}
@timholy
Copy link
Collaborator

timholy commented Jan 4, 2015

This is actually a julia problem, not a SIUnits problem. The underlying issue is that promote_rule simply isn't flexible enough for SIUnits.

See JuliaLang/julia#8027 and JuliaLang/julia#8974.

@tomasaschan
Copy link
Collaborator

I was just about to file the same issue; I've hit some problems because of it over in JuliaMath/Interpolations.jl#19.

It becomes even more apparent that something is broken here considering the following example:

julia> A = rand(10) * Meter
10-element Array{SIQuantity{Float64,m,kg,s,A,K,mol,cd},1}:
   ...

julia> B = zeros(A)
10-element Array{SIQuantity{Float64,m,kg,s,A,K,mol,cd},1}:
   ...

julia> A + B
ERROR: Unit mismatch. Got (m ) + ()
 in error at error.jl:21
 in + at /home/tlycken/.julia/v0.3/SIUnits/src/SIUnits.jl:156
 in + at array.jl:721

@timholy, you're faster than me! :P

Could SIUnits work around this by manually tightening array types when possible (i.e. when all elements in an array result has the same unit), or would that lead to too great a performance problem?

@timholy
Copy link
Collaborator

timholy commented Jan 4, 2015

I suppose SIUnits could redefine all the .*, .+, .-, and ./ methods in array.jl. That seems to be a potentially-viable solution. It's a bandaid, but not a crazy one since it's unclear when the underlying problem will be fixed (it's kinda waiting on JuliaLang/julia#8974).

@tomasaschan
Copy link
Collaborator

I made an attempt at defining .+ and .-, but I'm getting a bunch of ambiguity warnings about collisions between e.g. .+(x::SIQuantity{T,m,kg,s,A,K,mol,cd}, Y::StridedArray{S<:Number}) and .+(x::Number, Y::BitArray{N<:Number}), asking me to define .+(x::SIQuantity{T,m,kg,s,A,K,mol,cd}, BitArray{N<:Number}). Does that method even make sense to define?

@timholy
Copy link
Collaborator

timholy commented Jan 4, 2015

You can always create error methods for such functionsmethods. Someday, julia will create those automatically, but for now you have to do it manually.

@jonasrauber
Copy link
Author

#25 describes the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants