MoYeArray

MoYeArray befinits from the Layout to be able to create all kinds of special arrays. For example, we can create a FillArray-like array

julia> using MoYe
julia> MoYeArray{Float64}(one, @Layout((3,4), (0, 0)))3×4 MoYeArray{Float64, 2, ArrayEngine{Float64, 1}, StaticLayout{2, Tuple{Static.StaticInt{3}, Static.StaticInt{4}}, Tuple{Static.StaticInt{0}, Static.StaticInt{0}}}} with indices _1:_3×_1:_4: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
julia> ans.engine1-element ArrayEngine{Float64, 1}: 1.0

As you can see the array only contains one element. Under the hood, the physical length of that array is calculated by cosize:

julia> cosize(@Layout((3,4), (0, 0)))_1

The underlying implementation of MoYeArray determines that linear indexing is actually periodic.

julia> function f()
           B = MoYeArray([1,2,3], @Layout((3,), (1,)))
           @show @inbounds B[4], B[5], B[6], B[7]
       endf (generic function with 1 method)
julia> f();#= REPL[1]:3 =# @inbounds((B[4], B[5], B[6], B[7])) = (140642377173432, 140642377173408, 6, 296964)

We can also easily create a so-called BlockArray:

julia> data = collect(1:48);
julia> B=MoYeArray(data, @Layout(((2,3), (2,4)), ((1, 16), (2, 4))))6×8 MoYeArray{Int64, 2, ViewEngine{Int64, Ptr{Int64}}, StaticLayout{2, Tuple{Tuple{Static.StaticInt{2}, Static.StaticInt{3}}, Tuple{Static.StaticInt{2}, Static.StaticInt{4}}}, Tuple{Tuple{Static.StaticInt{1}, Static.StaticInt{16}}, Tuple{Static.StaticInt{2}, Static.StaticInt{4}}}}} with indices _1:_6×_1:_8: 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 16 17 19 21 23 25 27 29 31 18 20 22 24 26 28 30 32 33 35 37 39 41 43 45 47 34 36 38 40 42 44 46 48

Here we created a 2x3 block array with 2x4 blocks. The first mode is the index of the block, the second mode is the index within the block.

Slicing

It is required to use the syntax view(a, ids...) or@view a[ids...]`, depenting on your tast.

julia> data = [i for i in 1:164];
julia> a = MoYeArray(data, ((_3, 2), (2, _5, _2)), ((4,1), (_2, 13, 100)))6×20 MoYeArray{Int64, 2, ViewEngine{Int64, Ptr{Int64}}, Layout{2, Tuple{Tuple{Static.StaticInt{3}, Int64}, Tuple{Int64, Static.StaticInt{5}, Static.StaticInt{2}}}, Tuple{Tuple{Int64, Int64}, Tuple{Static.StaticInt{2}, Int64, Int64}}}}: 1 3 14 16 27 29 40 42 53 55 … 116 127 129 140 142 153 155 5 7 18 20 31 33 44 46 57 59 120 131 133 144 146 157 159 9 11 22 24 35 37 48 50 61 63 124 135 137 148 150 161 163 2 4 15 17 28 30 41 43 54 56 117 128 130 141 143 154 156 6 8 19 21 32 34 45 47 58 60 121 132 134 145 147 158 160 10 12 23 25 36 38 49 51 62 64 … 125 136 138 149 151 162 164
julia> b = @view a[2, :]20-element MoYeArray{Int64, 1, ViewEngine{Int64, Ptr{Int64}}, Layout{1, Tuple{Tuple{Int64, Static.StaticInt{5}, Static.StaticInt{2}}}, Tuple{Tuple{Static.StaticInt{2}, Int64, Int64}}}}: 5 7 18 20 31 33 44 46 57 59 105 107 118 120 131 133 144 146 157 159