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

dot operator inconsistency; broadcasting #1019

Closed
ViralBShah opened this issue Jul 9, 2012 · 4 comments
Closed

dot operator inconsistency; broadcasting #1019

ViralBShah opened this issue Jul 9, 2012 · 4 comments
Labels
needs decision A decision on this change is needed
Milestone

Comments

@ViralBShah
Copy link
Member

Inconsistency is that +(Matrix, Number) works, but >(Matrix, Number) does not.

julia> rand(5,5) > 0.5
no method isless(Float64,Array{Float64,2})
in method_missing at base.jl:60
in > at operators.jl:14

julia> rand(5,5) .> 0.5
5x5 Bool Array:
false true false true false
true true false true false
true false true false true
false true true false true
false true true true true

julia> rand(5,5) + 0.5
5x5 Float64 Array:
0.79251 1.06707 0.500777 0.953643 0.552748
0.879198 0.975167 0.671291 1.05633 0.99309
1.47143 1.28383 0.819195 1.09337 0.82331
1.44972 1.08734 0.510404 0.796567 0.523913
0.703234 0.701464 0.517295 0.569722 1.29657

julia> rand(5,5) .+ 0.5
syntax error: extra input after end of expression

@JeffBezanson
Copy link
Member

Fixed the syntax error in commit 02f5cc3.

@JeffBezanson
Copy link
Member

A related issue that hasn't come up yet is scalar broadcasting in assignment, e.g. A[:,1] = 2. This creates a major annoyance since there is an ambiguity in the case A[1:1,1:1] = [2,3]. Should that assign [2,3] as an element of the array, or is it elementwise assignment with a shape mismatch?

@JeffBezanson
Copy link
Member

Copying @StefanKarpinski . Another problem this causes is that we have to double every definition for assign to deal with the ambiguity, which is really annoying, and can cause performance problems since there are cases where 2 methods match that do the same thing, so the match should have been unique.

@StefanKarpinski
Copy link
Member

Hmm. That is perplexing. Tangentially, would the assign API be nicer if it looked like assign(A,I::Tuple,v) where I is always a tuple of indices? I suspect that would potentially slow things down, although I think it's a much cleaner API, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

3 participants