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

vec(::Matrix) allocates #570

Open
gdalle opened this issue Oct 11, 2024 · 5 comments
Open

vec(::Matrix) allocates #570

gdalle opened this issue Oct 11, 2024 · 5 comments
Labels
core Related to the core utilities of the package

Comments

@gdalle
Copy link
Member

gdalle commented Oct 11, 2024

As pointed out by @mcabbott in #564, vec(::Matrix) is not free. Neither is reshape for that matter. He suggested directly using ReshapedArray

@gdalle gdalle added the core Related to the core utilities of the package label Oct 11, 2024
@amontoison
Copy link

Are you sure that it's not free for Matrix?
For other types maybe, but for Array it should be free.

@gdalle
Copy link
Member Author

gdalle commented Nov 22, 2024

julia> using BenchmarkTools

julia> @benchmark vec(M) setup=(M=rand(2, 3))
BenchmarkTools.Trial: 10000 samples with 999 evaluations.
 Range (min  max):  12.624 ns   5.056 μs  ┊ GC (min  max):  0.00%  98.51%
 Time  (median):     14.606 ns              ┊ GC (median):     0.00%
 Time  (mean ± σ):   20.292 ns ± 98.337 ns  ┊ GC (mean ± σ):  14.24% ±  3.10%

  ▃█▅▁▇▇▁        ▁▂▃▃▄▅▄▂▂▃▄▂              ▂▃▃▃▂▁▁            ▂
  ███████▇▇▆▆▆▆▇▇████████████▇▆▃▃▃▁▄▁▅████████████▇▆▅▅▅▅▅▆▅▆▆ █
  12.6 ns      Histogram: log(frequency) by time        36 ns <

 Memory estimate: 32 bytes, allocs estimate: 1.

@amontoison
Copy link

amontoison commented Nov 22, 2024

Don't you need to use vec($M) to not take into account the storage related to the pointer?

@amontoison
Copy link

@gdalle
Copy link
Member Author

gdalle commented Nov 22, 2024

No because I create M in the setup phase, it is not a global variable. The interpolation of a global matrix variable would give the same result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the core utilities of the package
Projects
None yet
Development

No branches or pull requests

2 participants