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

document the array-of-structure and structure-of-array layout #154

Open
johnnychen94 opened this issue Sep 8, 2020 · 1 comment
Open
Labels
best practice workflows and best practice that are useful in JuliaImages and/or Julia

Comments

@johnnychen94
Copy link
Member

johnnychen94 commented Sep 8, 2020

JuliaImages uses the array of structure layout to fully use the multiple dispatch mechanism without introducing too many ambiguities. Intrinsically, this array-of-structure layout is slower than structure-of-array layout when we need a contiguous memory per channel.

For example, compute the norm of a RGB image:

julia> versioninfo()
Julia Version 1.6.0-DEV.850
Commit bf886b5953 (2020-09-06 08:55 UTC)

julia> x = rand(RGB{Float64}, 100, 100);

julia> cx = collect(channelview(x));

julia> @btime norm($x)
  28.822 μs (0 allocations: 0 bytes)
100.60011111008363

julia> @btime norm($cx)
  7.552 μs (0 allocations: 0 bytes)
100.60011111008343

julia> @btime norm(channelview($x)) # 😢 
  99.228 μs (2 allocations: 112 bytes)

I was only aware of this issue months ago and still not very familiar with this topic, @timholy would you mind giving a section or page documenting aspects that we need to be aware of wrt this? These differences might be emphasized in the docs because most other image processing libraries use the structure-of-array layout.

@timholy
Copy link
Member

timholy commented Sep 8, 2020

Yes, we should document this. But I am actually gradually working on this area now (the ReinterpretArray work is part of it) and I am planning to provide better support for other layouts.

@johnnychen94 johnnychen94 added the best practice workflows and best practice that are useful in JuliaImages and/or Julia label Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
best practice workflows and best practice that are useful in JuliaImages and/or Julia
Projects
None yet
Development

No branches or pull requests

2 participants