MoYeArray
Index
MoYe.ViewEngine
— TypeViewEngine{T, P}
A wrapper of a pointer. P
is the type of the pointer.
MoYe.ArrayEngine
— TypeArrayEngine{T, L} <: DenseVector{T}
A owning and mutable vector of type T
with static length L
.
Examples
julia> x = ArrayEngine{Float32}(undef, _3)
3-element ArrayEngine{Float32, 3}:
-9.8271385f-36
7.57f-43
-9.8271385f-36
julia> x[1] = 10f0
10.0f0
julia> x
3-element ArrayEngine{Float32, 3}:
10.0
7.57f-43
-9.8271385f-36
MoYe.MoYeArray
— TypeMoYeArray(engine::Engine, layout::Layout)
MoYeArray{T}(::UndefInitializer, layout::StaticLayout)
MoYeArray(ptr, layout::Layout)
Create a MoYeArray from an engine and a layout. See also ArrayEngine
and ViewEngine
.
Examples
julia> slayout = @Layout (5, 2);
julia> array_engine = ArrayEngine{Float32}(undef, cosize(slayout)); # owning array
julia> MoYeArray(array_engine, slayout)
5×2 MoYeArray{Float32, 2, ArrayEngine{Float32, 10}, Layout{2, Tuple{Static.StaticInt{5}, Static.StaticInt{2}}, Tuple{Static.StaticInt{1}, Static.StaticInt{5}}}}:
-3.24118f12 0.0
7.57f-43 0.0
0.0 0.0
0.0 0.0
7.89217f-40 0.0
julia> MoYeArray{Float32}(undef, slayout)
5×2 MoYeArray{Float32, 2, ArrayEngine{Float32, 10}, Layout{2, Tuple{Static.StaticInt{5}, Static.StaticInt{2}}, Tuple{Static.StaticInt{1}, Static.StaticInt{5}}}}:
4.0f-45 7.57f-43
0.0 0.0
-1.81623f7 0.0
7.57f-43 0.0
-1.81623f7 0.0
julia> A = ones(10);
julia> MoYeArray(pointer(A), slayout) # non-owning array
5×2 MoYeArray{Float64, 2, ViewEngine{Float64, Ptr{Float64}}, Layout{2, Tuple{Static.StaticInt{5}, Static.StaticInt{2}}, Tuple{Static.StaticInt{1}, Static.StaticInt{5}}}}:
1.0 1.0
1.0 1.0
1.0 1.0
1.0 1.0
1.0 1.0
julia> function test_alloc() # when powered by a ArrayEngine, MoYeArray is stack-allocated
slayout = @Layout (2, 3) # and mutable
x = MoYeArray{Float32}(undef, slayout)
fill!(x, 1.0f0)
return sum(x)
end
test_alloc (generic function with 2 methods)
julia> @allocated(test_alloc())
0
MoYe.recast
— Functionrecast(::Type{NewType}, x::MoYeArray{OldType}) -> MoYeArray{NewType}
Recast the element type of a MoYeArray. This is similar to Base.reinterpret
, but dose all the computation at compile time, if possible.
Examples
julia> x = MoYeArray{Int32}(undef, @Layout((2,3)))
2×3 MoYeArray{Int32, 2, ArrayEngine{Int32, 6}, Layout{2, Tuple{Static.StaticInt{2}, Static.StaticInt{3}}, Tuple{Static.StaticInt{1}, Static.StaticInt{2}}}}:
-1948408944 0 2
514 -268435456 0
julia> x2 = recast(Int16, x)
4×3 MoYeArray{Int16, 2, ViewEngine{Int16, Ptr{Int16}}, Layout{2, Tuple{Static.StaticInt{4}, Static.StaticInt{3}}, Tuple{Static.StaticInt{1}, Static.StaticInt{4}}}}:
-23664 0 2
-29731 0 0
514 0 0
0 -4096 0
julia> x3 = recast(Int64, x)
1×3 MoYeArray{Int64, 2, ViewEngine{Int64, Ptr{Int64}}, Layout{2, Tuple{Static.StaticInt{1}, Static.StaticInt{3}}, Tuple{Static.StaticInt{1}, Static.StaticInt{1}}}}:
2209959748496 -1152921504606846976 2
MoYe.zeros!
— Functionzeros!(x::MoYeArray)
Fill x
with zeros.