66
77function LArray {T, N, D, Syms} (:: UndefInitializer , n:: Int64 ) where {T, N, D, Syms}
88 @assert sum (lenfun, Syms) == n
9- LArray {T, N, D, Syms} (similar (D, n))
9+ return LArray {T, N, D, Syms} (similar (D, n))
1010end
1111
1212# ####################################
1515# # LArray to named tuple
1616function Base. convert (:: Type{NamedTuple} , x:: LArray{T, N, D, Syms} ) where {T, N, D, Syms}
1717 tup = NTuple {length(Syms), T} (x)
18- NamedTuple {Syms, typeof(tup)} (tup)
18+ return NamedTuple {Syms, typeof(tup)} (tup)
1919end
2020Base. keys (x:: LArray{T, N, D, Syms} ) where {T, N, D, Syms} = Syms
2121
@@ -43,7 +43,7 @@ LArray((2, 2); a = 1, b = 2, c = 3, d = 4)
4343"""
4444function LArray (size:: NTuple{S, Int} , tup:: NamedTuple{Syms, Tup} ) where {S, Syms, Tup}
4545 __x = reshape (collect (tup), size)
46- LArray {Syms} (__x)
46+ return LArray {Syms} (__x)
4747end
4848LArray (size:: NTuple{S, Int} ; kwargs... ) where {S} = LArray (size, values (kwargs))
4949
@@ -68,7 +68,7 @@ LVector(; kwargs...) = LVector(values(kwargs))
6868# # pairs iterator
6969function Base. pairs (x:: LArray{T, N, D, Syms} ) where {T, N, D, Syms}
7070 # (label => getproperty(x, label) for label in Syms) # not type stable?
71- (Syms[i] => x[i] for i in 1 : length (Syms))
71+ return (Syms[i] => x[i] for i in 1 : length (Syms))
7272end
7373
7474# ####################################
@@ -95,7 +95,7 @@ Base.@propagate_inbounds function Base.setproperty!(x::LArray, s::Symbol, y)
9595 if s == :__x
9696 return setfield! (x, :__x , y)
9797 end
98- setindex! (x, y, Val (s))
98+ return setindex! (x, y, Val (s))
9999end
100100
101101Base. @propagate_inbounds Base. getindex (x:: LArray , s:: Symbol ) = getindex (x, Val (s))
@@ -122,13 +122,15 @@ Base.@propagate_inbounds Base.setindex!(x::LArray, v, s::Symbol) = setindex!(x,
122122end
123123
124124Base. @propagate_inbounds function Base. getindex (x:: LArray , s:: AbstractArray{Symbol, 1} )
125- [getindex (x, si) for si in s]
125+ return [getindex (x, si) for si in s]
126126end
127127
128- function Base. similar (x:: LArray{T, K, D, Syms} , :: Type{S} ,
129- dims:: NTuple{N, Int} ) where {T, K, D, Syms, S, N}
128+ function Base. similar (
129+ x:: LArray{T, K, D, Syms} , :: Type{S} ,
130+ dims:: NTuple{N, Int}
131+ ) where {T, K, D, Syms, S, N}
130132 tmp = similar (x. __x, S, dims)
131- LArray {S, N, typeof(tmp), Syms} (tmp)
133+ return LArray {S, N, typeof(tmp), Syms} (tmp)
132134end
133135
134136# Allow copying LArray of uninitialized data, as with regular Array
@@ -137,23 +139,29 @@ Base.copyto!(x::LArray, y::LArray) = copyto!(getfield(x, :__x), getfield(y, :__x
137139
138140# enable the usage of LAPACK
139141function Base. unsafe_convert (:: Type{Ptr{T}} , a:: LArray{T, N, D, S} ) where {T, N, D, S}
140- Base. unsafe_convert (Ptr{T}, getfield (a, :__x ))
142+ return Base. unsafe_convert (Ptr{T}, getfield (a, :__x ))
141143end
142144
143145Base. convert (:: Type{T} , x) where {T <: LArray } = T (x)
144146Base. convert (:: Type{T} , x:: T ) where {T <: LArray } = x
145147Base. convert (:: Type{<:Array} , x:: LArray ) = convert (Array, getfield (x, :__x ))
146- function Base. convert (:: Type{AbstractArray{T, N}} ,
147- x:: LArray{S, N, <:Any, Syms} ) where {T, S, N, Syms}
148- LArray {Syms} (convert (AbstractArray{T, N}, getfield (x, :__x )))
148+ function Base. convert (
149+ :: Type{AbstractArray{T, N}} ,
150+ x:: LArray{S, N, <:Any, Syms}
151+ ) where {T, S, N, Syms}
152+ return LArray {Syms} (convert (AbstractArray{T, N}, getfield (x, :__x )))
149153end
150154Base. convert (:: Type{AbstractArray{T, N}} , x:: LArray{T, N} ) where {T, N} = x
151155
152- function ArrayInterface. restructure (x:: LArray{T, N, D, Syms} ,
153- y:: LArray{T2, N2, D2, Syms} ) where {T, N, D, T2, N2,
156+ function ArrayInterface. restructure (
157+ x:: LArray{T, N, D, Syms} ,
158+ y:: LArray{T2, N2, D2, Syms}
159+ ) where {
160+ T, N, D, T2, N2,
154161 D2,
155- Syms}
156- reshape (y, size (x)... )
162+ Syms,
163+ }
164+ return reshape (y, size (x)... )
157165end
158166
159167# ####################################
@@ -162,22 +170,26 @@ end
162170struct LAStyle{T, N, L} <: Broadcast.AbstractArrayStyle{N} end
163171LAStyle {T, N, L} (x:: Val{i} ) where {T, N, L, i} = LAStyle {T, N, L} ()
164172Base. BroadcastStyle (:: Type{LArray{T, N, D, L}} ) where {T, N, D, L} = LAStyle {T, N, L} ()
165- function Base. BroadcastStyle (:: LabelledArrays.LAStyle{T, N, L} ,
166- :: LabelledArrays.LAStyle{E, N, L} ) where {T, E, N, L}
167- LAStyle {promote_type(T, E), N, L} ()
173+ function Base. BroadcastStyle (
174+ :: LabelledArrays.LAStyle{T, N, L} ,
175+ :: LabelledArrays.LAStyle{E, N, L}
176+ ) where {T, E, N, L}
177+ return LAStyle {promote_type(T, E), N, L} ()
168178end
169179
170180@generated function labels2axes (:: Val{t} ) where {t}
171- if t isa NamedTuple && all (x -> x isa Union{Integer, UnitRange}, values (t)) # range labelling
181+ return if t isa NamedTuple && all (x -> x isa Union{Integer, UnitRange}, values (t)) # range labelling
172182 (Base. OneTo (maximum (Iterators. flatten (v for v in values (t)))),)
173183 elseif t isa NTuple{<: Any , Symbol}
174184 axes (t)
175185 else
176186 error (" $t label isn't supported for broadcasting. Try to formulate it in terms of linear indexing." )
177187 end
178188end
179- function Base. similar (bc:: Broadcast.Broadcasted{LAStyle{T, N, L}} ,
180- :: Type{ElType} ) where {T, N, L, ElType}
189+ function Base. similar (
190+ bc:: Broadcast.Broadcasted{LAStyle{T, N, L}} ,
191+ :: Type{ElType}
192+ ) where {T, N, L, ElType}
181193 tmp = similar (Array{ElType}, axes (bc))
182194 if axes (bc) != labels2axes (Val (L))
183195 return tmp
@@ -304,7 +316,7 @@ julia> symbols(z)
304316```
305317"""
306318function symbols (:: LArray{T, N, D, Syms} ) where {T, N, D, Syms}
307- Syms isa NamedTuple ? keys (Syms) : Syms
319+ return Syms isa NamedTuple ? keys (Syms) : Syms
308320end
309321
310322# copy constructors
@@ -321,7 +333,7 @@ For example:
321333"""
322334function LVector (v1:: Union{SLArray, LArray} ; kwargs... )
323335 t2 = merge (convert (NamedTuple, v1), values (kwargs))
324- LVector (t2)
336+ return LVector (t2)
325337end
326338
327339"""
@@ -337,7 +349,7 @@ For example:
337349"""
338350function LArray (v1:: Union{SLArray, LArray} ; kwargs... )
339351 t2 = merge (convert (NamedTuple, v1), values (kwargs))
340- LArray (size (v1), t2)
352+ return LArray (size (v1), t2)
341353end
342354
343355# moved vom slarray.js to here because LArray need to be known
@@ -353,7 +365,7 @@ For example:
353365"""
354366function SLVector (v1:: Union{SLArray, LArray} ; kwargs... )
355367 t2 = merge (convert (NamedTuple, v1), values (kwargs))
356- SLVector (t2)
368+ return SLVector (t2)
357369end
358370
359371"""
@@ -367,26 +379,36 @@ For example:
367379 B = ABCD(1,2,3,4);
368380 B2 = SLArray(B; c=30 )
369381"""
370- function SLArray (v1:: Union{SLArray{S, T, N, L, Syms}, LArray{T, N, D, Syms}} ;
371- kwargs... ) where {S, T, N, L, Syms, D}
382+ function SLArray (
383+ v1:: Union{SLArray{S, T, N, L, Syms}, LArray{T, N, D, Syms}} ;
384+ kwargs...
385+ ) where {S, T, N, L, Syms, D}
372386 t2 = merge (convert (NamedTuple, v1), values (kwargs))
373- SLArray {S} (t2)
387+ return SLArray {S} (t2)
374388end
375389
376390function Base. vcat (x:: LArray , y:: LArray )
377- LArray {(LabelledArrays.symnames(typeof(x))..., LabelledArrays.symnames(typeof(y))...)} (vcat (
378- x. __x,
379- y. __x))
391+ return LArray {(LabelledArrays.symnames(typeof(x))..., LabelledArrays.symnames(typeof(y))...)} (
392+ vcat (
393+ x. __x,
394+ y. __x
395+ )
396+ )
380397end
381398
382399Base. elsize (:: Type{<:LArray{T}} ) where {T} = sizeof (T)
383400
384- function RecursiveArrayTools. recursive_unitless_eltype (a:: Type {LArray{
385- T, N, D, Syms}}) where {
401+ function RecursiveArrayTools. recursive_unitless_eltype (
402+ a:: Type {
403+ LArray{
404+ T, N, D, Syms,
405+ },
406+ }
407+ ) where {
386408 T,
387409 N,
388410 D,
389- Syms
390- }
391- LArray{typeof (one (T)), N, D, Syms}
411+ Syms,
412+ }
413+ return LArray{typeof (one (T)), N, D, Syms}
392414end
0 commit comments