Lazy or efficient representation of `repeat` function on Arrays?

what is the best( lazy ? ) way to represent repeat function (other than doing following) the following

julia> @btime A = repeat([1 2],3,1)
  116.760 ns (2 allocations: 192 bytes)
3×2 Matrix{Int64}:
 1  2
 1  2
 1  2

i have tried LazyArray pkg , but then usual way seems more better.

using LazyArrays
a=[1,2,3];
julia> @btime @~ repeat(a,3,1)
  516.128 ns (5 allocations: 160 bytes)
Applied(repeat,[1, 2, 3],3,1)

julia> @btime repeat(a,3,1)
  170.044 ns (3 allocations: 224 bytes)
9×1 Matrix{Int64}:
 1
 2
 3
 1
 2
 3
 1
 2
 3

for larger arrays, lazyarrays does the job ! (so i might consider this as solution, unless we find even better solution ?)

julia> a=rand(100);

julia> @btime repeat(a,3,1);
  954.824 ns (3 allocations: 2.59 KiB)

julia> @btime @~ repeat(a,3,1);
  466.862 ns (5 allocations: 160 bytes)

1 Like