Skip to content

Make mapCube/xmap mathods specific for array type #520

@danlooo

Description

@danlooo

Currently, there is only one method of mapCube and xmap for a YAXArray.
Do we want to add xmap methods for each array type, e.g. Matrix, DiskArrays.CachedDiskArray so that the three calls above perform similar? Seems that mapCube treats everything like a DiskArray.

using YAXArrays
using BenchmarkTools

data = ones(1000, 1000)
a = YAXArray(data)

@benchmark map(x -> 5, a)

@benchmark mapCube(
    a,
    indims=InDims(:Dim_1, :Dim_2),
    outdims=OutDims(a.Dim_1, a.Dim_2),
) do xout, xin
    xout .= 5
end

@benchmark mapCube(
    cache(a),
    indims=InDims(:Dim_1, :Dim_2),
    outdims=OutDims(a.Dim_1, a.Dim_2),
) do xout, xin
    xout .= 5
end

Resulting in

julia> @benchmark map(x -> 5, a)
BenchmarkTools.Trial: 8181 samples with 1 evaluation per sample.
 Range (min … max):  441.142 μs …   3.996 ms  ┊ GC (min … max):  0.00% … 63.13%
 Time  (median):     520.456 μs               ┊ GC (median):     0.00%
 Time  (mean ± σ):   607.869 μs ± 255.064 μs  ┊ GC (mean ± σ):  14.72% ± 18.98%

  ▇▆▅▄██▆▅▄▃▁                           ▂▂▁▁ ▁▂▄▄▃▂▁            ▂
  ████████████▇▅▆▃▄▄▄▃▁▁▁▁▅▁▄▁▄▁▁▁▁▁▃▅▆██████████████▇▆▆▆▅▅▆▅▅▆ █
  441 μs        Histogram: log(frequency) by time        1.4 ms <

 Memory estimate: 7.63 MiB, allocs estimate: 29.

julia> @benchmark mapCube(
           a,
           indims=InDims(:Dim_1, :Dim_2),
           outdims=OutDims(a.Dim_1, a.Dim_2),
       ) do xout, xin
           xout .= 5
       end
BenchmarkTools.Trial: 76 samples with 1 evaluation per sample.
 Range (min … max):  61.399 ms … 103.611 ms  ┊ GC (min … max): 91.74% … 92.86%
 Time  (median):     65.496 ms               ┊ GC (median):    91.27%
 Time  (mean ± σ):   66.599 ms ±   6.308 ms  ┊ GC (mean ± σ):  91.48% ±  1.10%

  ▃  ▂█▂  ▂ ▃▃▂                                                 
  █▁▇███▇▇█████▇▅▄▇▁▁▄▁▁▁▄▁▄▁▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▁▄ ▁
  61.4 ms         Histogram: frequency by time         89.2 ms <

 Memory estimate: 32.46 MiB, allocs estimate: 932.

julia> @benchmark mapCube(
           cache(a),
           indims=InDims(:Dim_1, :Dim_2),
           outdims=OutDims(a.Dim_1, a.Dim_2),
       ) do xout, xin
           xout .= 5
       end
BenchmarkTools.Trial: 75 samples with 1 evaluation per sample.
 Range (min … max):  62.597 ms … 84.940 ms  ┊ GC (min … max): 88.99% … 88.09%
 Time  (median):     66.699 ms              ┊ GC (median):    88.10%
 Time  (mean ± σ):   67.298 ms ±  4.022 ms  ┊ GC (mean ± σ):  88.76% ±  1.84%

       ▁▆     ▁▃█ ▁                                            
  ▄▄▇▆▇██▇▇▆▇▇███▄█▄▄▆▇▆▄▄▁▄▁▁▁▄▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▄▄ ▁
  62.6 ms         Histogram: frequency by time        81.6 ms <

 Memory estimate: 40.09 MiB, allocs estimate: 997.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions