@@ -7,59 +7,62 @@ include("larray.jl")
77include (" chainrules.jl" )
88
99# Common
10- @generated function __getindex (x:: Union{LArray,SLArray} ,:: Val{s} ) where s
10+ @generated function __getindex (x:: Union{LArray, SLArray} , :: Val{s} ) where {s}
1111 syms = symnames (x)
12- idx = syms isa NamedTuple ? syms[s] : findfirst (y-> y == s, syms)
12+ idx = syms isa NamedTuple ? syms[s] : findfirst (y -> y == s, syms)
1313 if idx === nothing
1414 :(error (" type $(typeof (x)) has no field $(s) " ))
1515 elseif idx isa Tuple
16- :(Base. @_propagate_inbounds_meta ; view (getfield (x,:__x ), $ idx... ))
16+ :(Base. @_propagate_inbounds_meta ; view (getfield (x, :__x ), $ idx... ))
1717 else
18- :(Base. @_propagate_inbounds_meta ; @views getfield (x,:__x )[$ idx])
18+ :(Base. @_propagate_inbounds_meta ; @views getfield (x, :__x )[$ idx])
1919 end
2020end
2121
2222using MacroTools
2323
24- struct PrintWrapper{T,N,F,X <: AbstractArray{T,N} } <: AbstractArray{T,N}
24+ struct PrintWrapper{T, N, F, X <: AbstractArray{T, N} } <: AbstractArray{T, N}
2525 f:: F
2626 x:: X
2727end
2828
2929import Base: eltype, length, ndims, size, axes, eachindex, stride, strides
30- MacroTools. @forward PrintWrapper. x eltype, length, ndims, size, axes, eachindex, stride, strides
30+ MacroTools. @forward PrintWrapper. x eltype, length, ndims, size, axes, eachindex, stride,
31+ strides
3132Base. getindex (A:: PrintWrapper , idxs... ) = A. f (A. x, A. x[idxs... ], idxs)
3233
3334function lazypair (A, x, idxs)
3435 syms = symnames (typeof (A))
3536 II = LinearIndices (A)
36- key = eltype (syms) <: Symbol ? syms[II[idxs... ]] : findfirst (syms) do sym
37+ key = eltype (syms) <: Symbol ? syms[II[idxs... ]] :
38+ findfirst (syms) do sym
3739 ii = idxs isa Tuple ? II[idxs... ] : II[idxs]
3840 sym isa Tuple ? ii in II[sym... ] : ii in II[sym]
3941 end
4042 key => x
4143end
4244
43- Base. show (io:: IO , :: MIME"text/plain" , x:: Union{LArray,SLArray} ) = show (io, x)
44- function Base. show (io:: IO , x:: Union{LArray,SLArray} )
45+ Base. show (io:: IO , :: MIME"text/plain" , x:: Union{LArray, SLArray} ) = show (io, x)
46+ function Base. show (io:: IO , x:: Union{LArray, SLArray} )
4547 syms = symnames (typeof (x))
4648 n = length (syms)
4749 pwrapper = PrintWrapper (lazypair, x)
48- if io isa IOContext && get (io, :limit , false ) && displaysize (io) isa Tuple{Integer, Integer}
49- io = IOContext (io, :limit => true , :displaysize => cld .(2 .* displaysize (io), 3 ))
50+ if io isa IOContext && get (io, :limit , false ) &&
51+ displaysize (io) isa Tuple{Integer, Integer}
52+ io = IOContext (io, :limit => true , :displaysize => cld .(2 .* displaysize (io), 3 ))
5053 end
5154 println (io, summary (x), ' :' )
5255 Base. print_array (io, pwrapper)
5356end
5457
55- Base. NamedTuple (x:: Union{LArray,SLArray} ) = NamedTuple {symnames(typeof(x))} (x. __x)
58+ Base. NamedTuple (x:: Union{LArray, SLArray} ) = NamedTuple {symnames(typeof(x))} (x. __x)
5659@inline Base. reshape (a:: SLArray , s:: Size ) = StaticArrays. similar_type (a, s)(Tuple (a))
5760
58- function ArrayInterface. ismutable (:: Type{<:LArray{T,N, Syms}} ) where {T,N, Syms}
61+ function ArrayInterface. ismutable (:: Type{<:LArray{T, N, Syms}} ) where {T, N, Syms}
5962 ArrayInterface. ismutable (T)
6063end
6164ArrayInterface. can_setindex (:: Type{<:SLArray} ) = false
62-
65+
6366export SLArray, LArray, SLVector, LVector, @SLVector , @LArray , @LVector , @SLArray
6467
6568export @SLSliced , @LSliced
0 commit comments