@@ -1529,10 +1529,10 @@ vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
1529
1529
hcat (X:: T... ) where {T} = T[ X[j] for i= 1 : 1 , j= 1 : length (X) ]
1530
1530
hcat (X:: T... ) where {T<: Number } = T[ X[j] for i= 1 : 1 , j= 1 : length (X) ]
1531
1531
1532
- vcat (X:: Number... ) = hvcat_fill (Vector {promote_typeof(X...)} (undef, length (X)), X)
1533
- hcat (X:: Number... ) = hvcat_fill (Matrix {promote_typeof(X...)} (undef, 1 ,length (X)), X)
1534
- typed_vcat (:: Type{T} , X:: Number... ) where {T} = hvcat_fill (Vector {T} (undef, length (X)), X)
1535
- typed_hcat (:: Type{T} , X:: Number... ) where {T} = hvcat_fill (Matrix {T} (undef, 1 ,length (X)), X)
1532
+ vcat (X:: Number... ) = hvcat_fill! (Vector {promote_typeof(X...)} (undef, length (X)), X)
1533
+ hcat (X:: Number... ) = hvcat_fill! (Matrix {promote_typeof(X...)} (undef, 1 ,length (X)), X)
1534
+ typed_vcat (:: Type{T} , X:: Number... ) where {T} = hvcat_fill! (Vector {T} (undef, length (X)), X)
1535
+ typed_hcat (:: Type{T} , X:: Number... ) where {T} = hvcat_fill! (Matrix {T} (undef, 1 ,length (X)), X)
1536
1536
1537
1537
vcat (V:: AbstractVector... ) = typed_vcat (promote_eltype (V... ), V... )
1538
1538
vcat (V:: AbstractVector{T} ...) where {T} = typed_vcat (T, V... )
@@ -1993,9 +1993,13 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
1993
1993
a
1994
1994
end
1995
1995
1996
- function hvcat_fill (a:: Array , xs:: Tuple )
1997
- k = 1
1996
+ function hvcat_fill! (a:: Array , xs:: Tuple )
1998
1997
nr, nc = size (a,1 ), size (a,2 )
1998
+ len = length (xs)
1999
+ if nr* nc != len
2000
+ throw (ArgumentError (" argument count $(len) does not match specified shape $((nr,nc)) " ))
2001
+ end
2002
+ k = 1
1999
2003
for i= 1 : nr
2000
2004
@inbounds for j= 1 : nc
2001
2005
a[i,j] = xs[k]
@@ -2016,11 +2020,7 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T
2016
2020
throw (ArgumentError (" row $(i) has mismatched number of columns (expected $nc , got $(rows[i]) )" ))
2017
2021
end
2018
2022
end
2019
- len = length (xs)
2020
- if nr* nc != len
2021
- throw (ArgumentError (" argument count $(len) does not match specified shape $((nr,nc)) " ))
2022
- end
2023
- hvcat_fill (Matrix {T} (undef, nr, nc), xs)
2023
+ hvcat_fill! (Matrix {T} (undef, nr, nc), xs)
2024
2024
end
2025
2025
2026
2026
function typed_hvcat (:: Type{T} , rows:: Tuple{Vararg{Int}} , as... ) where T
@@ -2136,9 +2136,9 @@ function hvncat_fill!(A::Array, row_first::Bool, xs::Tuple)
2136
2136
if row_first
2137
2137
nr, nc = size (A, 1 ), size (A, 2 )
2138
2138
nrc = nr * nc
2139
- @inbounds na = prod (size (A)[3 : end ])
2139
+ na = prod (size (A)[3 : end ])
2140
2140
k = 1
2141
- @inbounds for d ∈ 1 : na
2141
+ for d ∈ 1 : na
2142
2142
dd = nrc * (d - 1 )
2143
2143
for i ∈ 1 : nr
2144
2144
Ai = dd + i
@@ -2150,7 +2150,7 @@ function hvncat_fill!(A::Array, row_first::Bool, xs::Tuple)
2150
2150
end
2151
2151
end
2152
2152
else
2153
- @inbounds for k ∈ eachindex (xs)
2153
+ for k ∈ eachindex (xs)
2154
2154
A[k] = xs[k]
2155
2155
end
2156
2156
end
@@ -2162,24 +2162,24 @@ _typed_hvncat(T::Type, ::Val{N}, xs::Number...) where N = _typed_hvncat(T, (ntup
2162
2162
function _typed_hvncat (:: Type{T} , :: Val{N} , as:: AbstractArray... ) where {T, N}
2163
2163
# optimization for arrays that can be concatenated by copying them linearly into the destination
2164
2164
# conditions: the elements must all have 1- or 0-length dimensions above N
2165
- @inbounds for a ∈ as
2165
+ for a ∈ as
2166
2166
ndims (a) <= N || all (x -> size (a, x) == 1 , (N + 1 ): ndims (a)) ||
2167
2167
return _typed_hvncat (T, (ntuple (x -> 1 , N - 1 )... , length (as)), false , as... )
2168
2168
end
2169
2169
2170
2170
nd = max (N, ndims (as[1 ]))
2171
2171
2172
2172
Ndim = 0
2173
- @inbounds for i ∈ 1 : lastindex (as)
2173
+ for i ∈ 1 : lastindex (as)
2174
2174
Ndim += cat_size (as[i], N)
2175
2175
for d ∈ 1 : N - 1
2176
2176
cat_size (as[1 ], d) == cat_size (as[i], d) || throw (ArgumentError (" mismatched size along axis $d in element $i " ))
2177
2177
end
2178
2178
end
2179
2179
2180
- @inbounds A = Array {T, nd} (undef, ntuple (d -> cat_size (as[1 ], d), N - 1 )... , Ndim, ntuple (x -> 1 , nd - N)... )
2180
+ A = Array {T, nd} (undef, ntuple (d -> cat_size (as[1 ], d), N - 1 )... , Ndim, ntuple (x -> 1 , nd - N)... )
2181
2181
k = 1
2182
- @inbounds for a ∈ as
2182
+ for a ∈ as
2183
2183
for i ∈ eachindex (a)
2184
2184
A[k] = a[i]
2185
2185
k += 1
@@ -2196,7 +2196,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
2196
2196
# into the destination
2197
2197
nd = N
2198
2198
Ndim = 0
2199
- @inbounds for a ∈ as
2199
+ for a ∈ as
2200
2200
if a isa AbstractArray
2201
2201
cat_size (a, N) == length (a) ||
2202
2202
throw (ArgumentError (" all dimensions of elements other than $N must be of length 1" ))
@@ -2205,10 +2205,10 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
2205
2205
Ndim += cat_size (a, N)
2206
2206
end
2207
2207
2208
- @inbounds A = Array {T, nd} (undef, ntuple (x -> 1 , N - 1 )... , Ndim, ntuple (x -> 1 , nd - N)... )
2208
+ A = Array {T, nd} (undef, ntuple (x -> 1 , N - 1 )... , Ndim, ntuple (x -> 1 , nd - N)... )
2209
2209
2210
2210
k = 1
2211
- @inbounds for a ∈ as
2211
+ for a ∈ as
2212
2212
if a isa AbstractArray
2213
2213
lena = length (a)
2214
2214
copyto! (A, k, a, 1 , lena)
@@ -2226,17 +2226,17 @@ function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool,
2226
2226
d2 = row_first ? 1 : 2
2227
2227
2228
2228
# discover dimensions
2229
- @inbounds nd = max (N, cat_ndims (as[1 ]))
2229
+ nd = max (N, cat_ndims (as[1 ]))
2230
2230
outdims = zeros (Int, nd)
2231
2231
2232
2232
# discover number of rows or columns
2233
- @inbounds for i ∈ 1 : dims[d1]
2233
+ for i ∈ 1 : dims[d1]
2234
2234
outdims[d1] += cat_size (as[i], d1)
2235
2235
end
2236
2236
2237
2237
currentdims = zeros (Int, nd)
2238
2238
blockcount = 0
2239
- @inbounds for i ∈ eachindex (as)
2239
+ for i ∈ eachindex (as)
2240
2240
currentdims[d1] += cat_size (as[i], d1)
2241
2241
if currentdims[d1] == outdims[d1]
2242
2242
currentdims[d1] = 0
@@ -2287,18 +2287,18 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
2287
2287
d1 = row_first ? 2 : 1
2288
2288
d2 = row_first ? 1 : 2
2289
2289
shape = collect (shape) # saves allocations later
2290
- @inbounds shapelength = shape[end ][1 ]
2290
+ shapelength = shape[end ][1 ]
2291
2291
lengthas = length (as)
2292
2292
shapelength == lengthas || throw (ArgumentError (" number of elements does not match shape; expected $(shapelength) , got $lengthas )" ))
2293
2293
2294
2294
# discover dimensions
2295
- @inbounds nd = max (N, cat_ndims (as[1 ]))
2295
+ nd = max (N, cat_ndims (as[1 ]))
2296
2296
outdims = zeros (Int, nd)
2297
2297
currentdims = zeros (Int, nd)
2298
2298
blockcounts = zeros (Int, nd)
2299
2299
shapepos = ones (Int, nd)
2300
2300
2301
- @inbounds for i ∈ eachindex (as)
2301
+ for i ∈ eachindex (as)
2302
2302
wasstartblock = false
2303
2303
for d ∈ 1 : N
2304
2304
ad = (d < 3 && row_first) ? (d == 1 ? 2 : 1 ) : d
@@ -2328,7 +2328,7 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
2328
2328
end
2329
2329
2330
2330
if row_first
2331
- @inbounds outdims[1 ], outdims[2 ] = outdims[2 ], outdims[1 ]
2331
+ outdims[1 ], outdims[2 ] = outdims[2 ], outdims[1 ]
2332
2332
end
2333
2333
2334
2334
# @assert all(==(0), currentdims)
@@ -2340,11 +2340,11 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
2340
2340
return A
2341
2341
end
2342
2342
2343
- @inline function hvncat_fill! (A:: Array{T, N} , scratch1:: Vector{Int} , scratch2:: Vector{Int} , d1:: Int , d2:: Int , as:: Tuple{Vararg} ) where {T, N}
2343
+ function hvncat_fill! (A:: Array{T, N} , scratch1:: Vector{Int} , scratch2:: Vector{Int} , d1:: Int , d2:: Int , as:: Tuple{Vararg} ) where {T, N}
2344
2344
outdims = size (A)
2345
2345
offsets = scratch1
2346
2346
inneroffsets = scratch2
2347
- @inbounds for a ∈ as
2347
+ for a ∈ as
2348
2348
if isa (a, AbstractArray)
2349
2349
for ai ∈ a
2350
2350
Ai = hvncat_calcindex (offsets, inneroffsets, outdims, N)
0 commit comments