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

broadcast with only one named matrix doesn't work #39

Closed
diegozea opened this issue Oct 19, 2016 · 4 comments
Closed

broadcast with only one named matrix doesn't work #39

diegozea opened this issue Oct 19, 2016 · 4 comments

Comments

@diegozea
Copy link
Contributor

diegozea commented Oct 19, 2016

Hi!

broadcast with only one named matrix doesn't work because the assertion nargs > 1 in verify_names.

julia> mat = rand(1:20,4,4)
4×4 Array{Int64,2}:
  7  2  11   9
  1  1  12  19
 18  6  10  18
  7  2  19  13

julia> namedmat = NamedArray(mat)
4×4 Named Array{Int64,2}
A ╲ B │  1   2   3   4
──────┼───────────────
17   2  11   9
21   1  12  19
318   6  10  18
47   2  19  13

julia> string.(mat)
4×4 Array{String,2}:
 "7"   "2"  "11"  "9" 
 "1"   "1"  "12"  "19"
 "18"  "6"  "10"  "18"
 "7"   "2"  "19"  "13"

julia> string.(namedmat)
ERROR: AssertionError: nargs > 1
 in verify_names(::NamedArrays.NamedArray{Int64,2,Array{Int64,2},Tuple{DataStructures.OrderedDict{String,Int64},DataStructures.OrderedDict{String,Int64}}}, ::Vararg{NamedArrays.NamedArray{Int64,2,Array{Int64,2},Tuple{DataStructures.OrderedDict{String,Int64},DataStructures.OrderedDict{String,Int64}}},N}) at /home/dzea/.julia/v0.5/NamedArrays/src/keepnames.jl:28
 in broadcast(::Function, ::NamedArrays.NamedArray{Int64,2,Array{Int64,2},Tuple{DataStructures.OrderedDict{String,Int64},DataStructures.OrderedDict{String,Int64}}}) at /home/dzea/.julia/v0.5/NamedArrays/src/keepnames.jl:47

Best

@davidavdav
Copy link
Owner

I read about the vectorized functions. I didn't realize they were already going to be in 0.5. But of course. I wonder if there is a nice general way to support these, I remember having seen the (function). is translated at the syntactical level.

@nalimilan
Copy link
Contributor

I remember having seen the (function). is translated at the syntactical level.

Yes, these are using broadcast (JuliaLang/julia#15032), so if you get it working you get the nice syntax for free.

@diegozea
Copy link
Contributor Author

In fact, It works with NamedArrays when more arguments are used. Only the case with one argument is broken because of the nargs > 1 assertion inside verify_names:

julia> A = NamedArray([1 2;3 4])
2×2 Named Array{Int64,2}
A ╲ B │ 1  2
──────┼─────
1     │ 1  2
2     │ 3  4

julia> B = NamedArray([10 10;10 10])
2×2 Named Array{Int64,2}
A ╲ B │  1   2
──────┼───────
1     │ 10  10
2     │ 10  10

julia> (*).(A,B)
2×2 Named Array{Int64,2}
A ╲ B │  1   2
──────┼───────
1     │ 10  20
2     │ 30  40

@diegozea
Copy link
Contributor Author

Thanks @davidavdav !

davidavdav added a commit that referenced this issue Oct 20, 2016
This is is temporarily necessary, because it contains julia code
that can't be parsed in julia-0.4.  So this file is conditionally
included.
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