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

Error using linear indexing #188

Closed
ngphuoc opened this issue Dec 7, 2017 · 12 comments
Closed

Error using linear indexing #188

ngphuoc opened this issue Dec 7, 2017 · 12 comments

Comments

@ngphuoc
Copy link

ngphuoc commented Dec 7, 2017

julia> a = rand(3,4)
3×4 Array{Float64,2}:
 0.748611  0.985436  0.376666   0.912038
 0.262307  0.514791  0.860165   0.262203
 0.685377  0.273166  0.0209705  0.561497

julia> k = AFArray(a)
AFArray: 3×4 Array{Float64,2}:
 0.748611  0.985436  0.376666   0.912038
 0.262307  0.514791  0.860165   0.262203
 0.685377  0.273166  0.0209705  0.561497

julia> a[:]==k[:]
ERROR: AssertionError: length(idx1) == length(size(a)) - 1
Stacktrace:
 [1] getindex(::ArrayFire.AFArray{Float64,2}, ::Colon) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:73
@ngphuoc
Copy link
Author

ngphuoc commented Dec 7, 2017

This one works

julia> k[:].=a[:]
12-element SubArray{Float64,1,ArrayFire.AFArray{Float64,1},Tuple{Base.Slice{Base.OneTo{Int64}}},false}:
 0.748611
 0.262307
 0.685377
 0.985436
 0.514791
 0.273166
 0.376666
 0.860165
 0.0209705
 0.912038
 0.262203
 0.561497

@ghost
Copy link

ghost commented Dec 7, 2017

In general mixing Array with AFArray in the same expression is not supported.

@ngphuoc
Copy link
Author

ngphuoc commented Dec 7, 2017

Error indexing by array:

julia> k.>0.5
AFArray: 3×4 Array{Bool,2}:
  true   true  false   true
 false  false   true  false
 false  false  false  false

julia> k[k.>0.5]
ERROR: AssertionError: length(idx1) == length(size(a)) - 1
Stacktrace:
 [1] getindex(::ArrayFire.AFArray{Float64,2}, ::ArrayFire.AFArray{Bool,2}) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:73

@ghost
Copy link

ghost commented Dec 7, 2017

duplicate: indexing is broken - #181

@ngphuoc
Copy link
Author

ngphuoc commented Dec 7, 2017

But the following gives error

julia> k[:]
ERROR: AssertionError: length(idx1) == length(size(a)) - 1
Stacktrace:
 [1] getindex(::ArrayFire.AFArray{Float64,2}, ::Colon) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:73

@ngphuoc
Copy link
Author

ngphuoc commented Dec 7, 2017

It's strange, assignment works but print doesn't:

julia> k[find(k.>0.5)]
ERROR: AssertionError: length(idx1) == length(size(a)) - 1
Stacktrace:
 [1] getindex(::ArrayFire.AFArray{Float64,2}, ::ArrayFire.AFArray{Int64,2}) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:73

julia> k[find(k.>0.5)] = 0
0

@ngphuoc
Copy link
Author

ngphuoc commented Dec 7, 2017

No, it works for 1D array in #181 but not 2D:

julia> k[find(k.>0.5)] = 0
0

julia> k
AFArray: 3×4 Array{Float64,2}:
 0.790436  0.522505  0.333179  0.632241
 0.751422  0.841604  0.715114  0.928544
 0.884082  0.39492   0.654672  0.21895

@ngphuoc
Copy link
Author

ngphuoc commented Dec 7, 2017

Some more tests:

julia> k[]
ERROR: ArrayFire Error (202) : Invalid input argument
In function af_err af_index_gen(void**, af_array, dim_t, const af_index_t*)
In file src/api/c/index.cpp:160
Invalid argument at index 2
Expected: (ndims>0)

Stacktrace:
 [1] _error(::UInt32) at /home/phuoc/.julia/v0.6/ArrayFire/src/util.jl:85
 [2] index_gen(::ArrayFire.AFArray{Float64,2}, ::Int64, ::Ptr{ArrayFire.af_index_t}) at /home/phuoc/.julia/v0.6/ArrayFire/src/wrap.jl:721
 [3] getindex(::ArrayFire.AFArray{Float64,2}) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:110

julia> k[1,:].>0.5
AFArray: 1×4 Array{Bool,2}:
 true  true  false  true

julia> k[:,k[1,:].>0.5]
AFArray: 3×3 Array{Float64,2}:
 0.574376  0.984427  0.514344
 0.460361  0.514912  0.416142
 0.386582  0.525051  0.862911

julia> k[:,k[1,:].>0.5]=0
ERROR: ArrayFire Error (203) : Invalid input size
In function af_err af_assign_gen(void**, af_array, dim_t, const af_index_t*, af_array)
In file src/api/c/assign.cpp:311
Size mismatch between input and output

Stacktrace:
 [1] _error(::UInt32) at /home/phuoc/.julia/v0.6/ArrayFire/src/util.jl:85
 [2] assign_gen(::ArrayFire.AFArray{Float64,2}, ::Int64, ::Ptr{ArrayFire.af_index_t}, ::ArrayFire.AFArray{Float64,2}) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:51
 [3] setindex!(::ArrayFire.AFArray{Float64,2}, ::ArrayFire.AFArray{Float64,2}, ::Colon, ::ArrayFire.AFArray{Bool,2}) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:120
 [4] setindex!(::ArrayFire.AFArray{Float64,2}, ::Int64, ::Colon, ::ArrayFire.AFArray{Bool,2}) at /home/phuoc/.julia/v0.6/ArrayFire/src/indexing.jl:132

julia> k[:,k[1,:].>0.5].=0
ERROR: BoundsError: attempt to access 3×4 ArrayFire.AFArray{Float64,2} at index [Base.Slice(Base.OneTo(3)), Base.LogicalIndex(AFArray: Bool[true true false true])]
Stacktrace:
 [1] throw_boundserror(::ArrayFire.AFArray{Float64,2}, ::Tuple{Base.Slice{Base.OneTo{Int64}},Base.LogicalIndex{CartesianIndex{2},ArrayFire.AFArray{Bool,2}}}) at ./abstractarray.jl:433
 [2] checkbounds(::ArrayFire.AFArray{Float64,2}, ::Base.Slice{Base.OneTo{Int64}}, ::Base.LogicalIndex{CartesianIndex{2},ArrayFire.AFArray{Bool,2}}) at ./abstractarray.jl:362
 [3] view(::ArrayFire.AFArray{Float64,2}, ::Colon, ::Vararg{Any,N} where N) at ./subarray.jl:113
 [4] dotview(::ArrayFire.AFArray{Float64,2}, ::Colon, ::Vararg{Any,N} where N) at ./broadcast.jl:537

julia> pointer(k)
ERROR: conversion to pointer not defined for ArrayFire.AFArray{Float64,2}
Stacktrace:
 [1] pointer(::ArrayFire.AFArray{Float64,2}) at ./abstractarray.jl:863


ghost pushed a commit that referenced this issue Dec 7, 2017
@ghost
Copy link

ghost commented Jan 6, 2018

fixed in 92de2d9

@ghost ghost closed this as completed Jan 6, 2018
@hayatoikoma
Copy link
Contributor

Is it really fixed? I just tried it on the master.
It worked on 1d array but didn't work for 2d array.

julia> a1d = AFArray(rand(5))
AFArray: 5-element Array{Float64,1}:
 0.983842
 0.398841
 0.217953
 0.770181
 0.478076

julia> a1d[find(a1d.>0.5)] = 1
1

julia> a1d
AFArray: 5-element Array{Float64,1}:
 1.0
 0.398841
 0.217953
 1.0
 0.478076

julia> a2d = AFArray(rand(5,5))
AFArray: 5×5 Array{Float64,2}:
 0.414244  0.703552   0.463749  0.223488  0.722257
 0.509738  0.216766   0.789492  0.684924  0.137261
 0.462514  0.0957764  0.663805  0.796688  0.887247
 0.753675  0.593526   0.169375  0.549912  0.120235
 0.537148  0.307667   0.125833  0.158792  0.00143258

julia> a2d[find(a2d.>0.5)] = 1
1

julia> a2d
AFArray: 5×5 Array{Float64,2}:
 0.414244  0.703552   0.463749  0.223488  0.722257
 0.509738  0.216766   0.789492  0.684924  0.137261
 0.462514  0.0957764  0.663805  0.796688  0.887247
 0.753675  0.593526   0.169375  0.549912  0.120235

@ghost
Copy link

ghost commented Mar 2, 2018

Make sure you got the latest master from https://github.com/JuliaComputing/ArrayFire.jl , should work just fine even without find

julia> a2d = AFArray(rand(5,5))
AFArray: 5×5 Array{Float64,2}:
 0.786437  0.837583   0.845785   0.257565   0.417475 
 0.429835  0.912153   0.805885   0.0414585  0.0215296
 0.373297  0.322926   0.0918821  0.715103   0.956392 
 0.81288   0.0600418  0.312362   0.284699   0.703298 
 0.39498   0.542362   0.752585   0.038305   0.290987 

julia> a2d[find(a2d.>0.5)] = 1
1

julia> a2d
AFArray: 5×5 Array{Float64,2}:
 1.0       1.0        1.0        0.257565   0.417475 
 0.429835  1.0        1.0        0.0414585  0.0215296
 0.373297  0.322926   0.0918821  1.0        1.0      
 1.0       0.0600418  0.312362   0.284699   1.0      
 0.39498   1.0        1.0        0.038305   0.290987 

julia> a2d[a2d.>0.5] = 2
2

julia> a2d
AFArray: 5×5 Array{Float64,2}:
 2.0       2.0        2.0        0.257565   0.417475 
 0.429835  2.0        2.0        0.0414585  0.0215296
 0.373297  0.322926   0.0918821  2.0        2.0      
 2.0       0.0600418  0.312362   0.284699   2.0      
 0.39498   2.0        2.0        0.038305   0.290987 

@hayatoikoma
Copy link
Contributor

Oh, sorry. I was accidentally using your fork on the machine I used today.
It worked fine. Thank you for checking it.

This issue was closed.
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

2 participants