StatProfilerHTML.jl report
Generated on Mon, 01 Apr 2024 21:01:18
File source code
Line Exclusive Inclusive Code
1
2 @generated function (::Type{MArray{S,T,N}})(::UndefInitializer) where {S,T,N}
3 return quote
4 $(Expr(:meta, :inline))
5 MArray{S, T, N, $(tuple_prod(S))}(undef)
6 end
7 end
8
9 @generated function (::Type{MArray{S,T}})(::UndefInitializer) where {S,T}
10 return quote
11 $(Expr(:meta, :inline))
12 MArray{S, T, $(tuple_length(S)), $(tuple_prod(S))}(undef)
13 end
14 end
15
16 ####################
17 ## MArray methods ##
18 ####################
19
20 @propagate_inbounds function getindex(v::MArray, i::Int)
21 @boundscheck checkbounds(v,i)
22 T = eltype(v)
23
24 if isbitstype(T)
25 1 (2 %)
1 (2 %) samples spent in getindex
1 (100 %) (incl.) when called from macro expansion line 222
1 (100 %) samples spent calling unsafe_load
return GC.@preserve v unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), i)
26 end
27 getfield(v,:data)[i]
28 end
29
30 @propagate_inbounds function setindex!(v::MArray, val, i::Int)
31 @boundscheck checkbounds(v,i)
32 T = eltype(v)
33
34 if isbitstype(T)
35 1 (2 %)
1 (2 %) samples spent in setindex!
1 (100 %) (incl.) when called from macro expansion line 159
1 (100 %) samples spent calling unsafe_store!
GC.@preserve v unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i)
36 else
37 # This one is unsafe (#27)
38 # unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i)
39 error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.")
40 end
41
42 return v
43 end
44
45 @inline Tuple(v::MArray) = getfield(v,:data)
46
47 Base.dataids(ma::MArray) = (UInt(pointer(ma)),)
48
49 @inline function Base.unsafe_convert(::Type{Ptr{T}}, a::MArray{S,T}) where {S,T}
50 Base.unsafe_convert(Ptr{T}, pointer_from_objref(a))
51 end
52
53 """
54 @MArray [a b; c d]
55 @MArray [[a, b];[c, d]]
56 @MArray [i+j for i in 1:2, j in 1:2]
57 @MArray ones(2, 2, 2)
58
59 A convenience macro to construct `MArray` with arbitrary dimension.
60 See [`@SArray`](@ref) for detailed features.
61 """
62 macro MArray(ex)
63 static_array_gen(MArray, ex, __module__)
64 end
65
66 function promote_rule(::Type{<:MArray{S,T,N,L}}, ::Type{<:MArray{S,U,N,L}}) where {S,T,U,N,L}
67 MArray{S,promote_type(T,U),N,L}
68 end
69
70 @generated function _indices_have_bools(indices::Tuple)
71 return any(index -> index <: StaticVector{<:Any,Bool}, indices.parameters)
72 end
73
74 function Base.view(
75 a::MArray{S},
76 indices::Union{Integer, Colon, StaticVector, Base.Slice, SOneTo}...,
77 ) where {S}
78 view_from_invoke = invoke(view, Tuple{AbstractArray, typeof(indices).parameters...}, a, indices...)
79 if _indices_have_bools(indices)
80 return view_from_invoke
81 else
82 new_size = new_out_size(S, indices...)
83 return SizedArray{new_size}(view_from_invoke)
84 end
85 end
86
87 Base.elsize(::Type{<:MArray{<:Any, T}}) where T = Base.elsize(Vector{T})