Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vyudu committed Dec 20, 2024
1 parent 59e3aa6 commit a2b3aa4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function toexpr(a::MakeArray, st)
end

## Array
@inline function _create_array(::Type{<:Array}, T, ::Val{dims}, elems...) where dims
@inline function _create_array(::Type{<:AbstractArray}, T, ::Val{dims}, elems...) where dims
arr = Array{T}(undef, dims)
@assert prod(dims) == nfields(elems)
@inbounds for i=1:prod(dims)
Expand All @@ -495,35 +495,45 @@ end
arr
end

@inline function create_array(A::Type{<:Array}, T, ::Val, d::Val, elems...)
@inline function create_array(A::Type{<:AbstractArray}, T, ::Val, d::Val, elems...)
_create_array(A, T, d, elems...)
end

@inline function create_array(A::Type{<:Array}, ::Nothing, ::Val, d::Val{dims}, elems...) where dims
@inline function create_array(A::Type{<:AbstractArray}, ::Nothing, ::Val, d::Val{dims}, elems...) where dims
T = promote_type(map(typeof, elems)...)
_create_array(A, T, d, elems...)
end

## Vector
#
@inline function create_array(::Type{<:Array}, ::Nothing, ::Val{1}, ::Val{dims}, elems...) where dims
@inline function create_array(::Type{<:AbstractArray}, ::Nothing, ::Val{1}, ::Val{dims}, elems...) where dims
[elems...]
end

@inline function create_array(::Type{<:Array}, T, ::Val{1}, ::Val{dims}, elems...) where dims
@inline function create_array(::Type{<:AbstractArray}, T, ::Val{1}, ::Val{dims}, elems...) where dims
T[elems...]
end

## Matrix

@inline function create_array(::Type{<:Array}, ::Nothing, ::Val{2}, ::Val{dims}, elems...) where dims
@inline function create_array(::Type{<:AbstractArray}, ::Nothing, ::Val{2}, ::Val{dims}, elems...) where dims
vhcat(dims, elems...)
end

@inline function create_array(::Type{<:Array}, T, ::Val{2}, ::Val{dims}, elems...) where dims
@inline function create_array(::Type{<:AbstractArray}, T, ::Val{2}, ::Val{dims}, elems...) where dims
typed_vhcat(T, dims, elems...)
end

@inline function create_array(::Type{<:Base.ReinterpretArray}, ::Nothing,
::Val{1}, ::Val{dims}, elems...) where {dims}
[elems...]
end

@inline function create_array(
::Type{<:Base.ReinterpretArray}, T, ::Val{1}, ::Val{dims}, elems...) where {dims}
T[elems...]
end


vhcat(sz::Tuple{Int,Int}, xs::T...) where {T} = typed_vhcat(T, sz, xs...)
vhcat(sz::Tuple{Int,Int}, xs::Number...) = typed_vhcat(Base.promote_typeof(xs...), sz, xs...)
Expand Down

0 comments on commit a2b3aa4

Please sign in to comment.