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

Code in README no longer works #127

Closed
tlnagy opened this issue Oct 16, 2017 · 4 comments
Closed

Code in README no longer works #127

tlnagy opened this issue Oct 16, 2017 · 4 comments

Comments

@tlnagy
Copy link

tlnagy commented Oct 16, 2017

The last example in the readme:

B = AxisArray(randn(100,100,100), :x, :y, :z)
Itotal = sumz = 0.0
for iter in eachindex(B)  # traverses in storage order for cache efficiency
    I = B[iter]  # intensity in a single voxel
    Itotal += I
    sumz += I * iter[axisdim(B, Axis{:z})]  # axisdim "looks up" the z dimension
end
meanz = sumz/Itotal

doesn't work under Julia 0.6. It gives a bounds error:

ERROR: BoundsError
Stacktrace:
 [1] getindex(::Int64, ::Int64) at ./number.jl:38
 [2] macro expansion at ./REPL[4]:4 [inlined]
 [3] anonymous at ./<missing>:?

I believe this is due to eachindex returning a single value instead of a tuple. This is likely because it is using fast linear indexing instead of Cartesian indexing. What would the updated version of this code look like? @timholy

@tlnagy
Copy link
Author

tlnagy commented Oct 19, 2017

Thoughts @mbauman?

@timholy
Copy link
Member

timholy commented Oct 20, 2017

Good catch!

That example should be changed to for iter in CartesianRange(indices(B)). eachindex is deliberately not guaranteed to return a CartesianIndex.

@tlnagy
Copy link
Author

tlnagy commented Nov 10, 2017

The original eachindex code had the following comment: # traverses in storage order for cache efficiency is that true for the CartesianRange code as well?

@timholy
Copy link
Member

timholy commented Nov 10, 2017

Yes, at least for anything that's not a PermutedDimsArray.

yakir12 added a commit to yakir12/AxisArrays.jl that referenced this issue Feb 15, 2018
In reference to issue JuliaArrays#127
This was referenced Feb 15, 2018
mbauman pushed a commit that referenced this issue May 1, 2018
In reference to issue #127
@tlnagy tlnagy closed this as completed Jan 3, 2019
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