JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.74k stars 5.48k forks source link

ArrayRef to multidimensional index #39672

Open plut opened 3 years ago

plut commented 3 years ago

If A is a Matrix, I can (of course) access its elements by either linear or cartesian indices.

However, constructing a reference to an entry of A is possible only by linear indexing:

 A=[5 6; 7 8]; Ref(A,1,2)[]=10; A

Returns MethodError: no method matching Ref(::Array{Int64,2}, ::Int64, ::Int64).

Wouldn't it make sense to extend Ref (there are only 4 methods total, 3 of them indexing by a single Integer) to have the same API as getindex?

simeonschaub commented 3 years ago

You can just use view instead, but we might want to allow this as well.

prithvitewatia commented 3 years ago

@plut @simeonschaub Can I try to solve this issue?

simeonschaub commented 3 years ago

Sure, go ahead!

prithvitewatia commented 3 years ago

@simeonschaub I have made the necessary changes but could not find the tests file. Can you please help me? (The source file is base/refpointer.jl)

simeonschaub commented 3 years ago

Sorry for not replying earlier. There is a file test/misc.jl, which is probably not a bad place for these tests to go.