@@ -1635,6 +1635,12 @@ cat_size(A::AbstractArray) = size(A)
1635
1635
cat_size (A, d) = 1
1636
1636
cat_size (A:: AbstractArray , d) = size (A, d)
1637
1637
1638
+ cat_length (:: Any ) = 1
1639
+ cat_length (a:: AbstractArray ) = length (a)
1640
+
1641
+ cat_ndims (a) = 0
1642
+ cat_ndims (a:: AbstractArray ) = ndims (a)
1643
+
1638
1644
cat_indices (A, d) = OneTo (1 )
1639
1645
cat_indices (A:: AbstractArray , d) = axes (A, d)
1640
1646
@@ -2034,22 +2040,25 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as...) where T
2034
2040
T[rs... ;]
2035
2041
end
2036
2042
2037
- # nd concatenation
2043
+ # # N-dimensional concatenation ##
2038
2044
2039
2045
"""
2046
+ hvncat(dim::Int, row_first, values...)
2040
2047
hvncat(dims::Tuple{Vararg{Int}}, row_first, values...)
2041
2048
hvncat(shape::Tuple{Vararg{Tuple}}, row_first, values...)
2042
2049
2043
2050
Horizontal, vertical, and n-dimensional concatenation of many `values` in one call.
2044
2051
2045
- This function is called
2046
- for block matrix syntax. The first argument either specifies the shape of the concatenation,
2047
- similar to `hvcat`, as a tuple of tuples, or the dimensions that specify the key number of
2048
- elements along each axis, and is used to determine the output dimensions. The `dims` form
2049
- is more performant, and is used by default when the concatenation operation has the same
2050
- number of elements along each axis (e.g., [a b; c d;;; e f ; g h]). The `shape` form is used
2051
- when the number of elements along each axis is unbalanced (e.g., [a b ; c]). Unbalanced
2052
- syntax needs additional validation overhead.
2052
+ This function is called for block matrix syntax. The first argument either specifies the
2053
+ shape of the concatenation, similar to `hvcat`, as a tuple of tuples, or the dimensions that
2054
+ specify the key number of elements along each axis, and is used to determine the output
2055
+ dimensions. The `dims` form is more performant, and is used by default when the concatenation
2056
+ operation has the same number of elements along each axis (e.g., [a b; c d;;; e f ; g h]).
2057
+ The `shape` form is used when the number of elements along each axis is unbalanced
2058
+ (e.g., [a b ; c]). Unbalanced syntax needs additional validation overhead. The `dim` form
2059
+ is an optimization for concatenation along just one dimension. `row_first` indicates how
2060
+ `values` are ordered. The meaning of the first and second elements of `shape` are also
2061
+ swapped based on `row_first`.
2053
2062
2054
2063
# Examples
2055
2064
```jldoctest
@@ -2097,6 +2106,24 @@ julia> hvncat(((3, 3), (3, 3), (6,)), true, a, b, c, d, e, f)
2097
2106
[:, :, 2] =
2098
2107
4 5 6
2099
2108
```
2109
+
2110
+ # Examples for construction of the arguments:
2111
+ [a b c ; d e f ;;;
2112
+ g h i ; j k l ;;;
2113
+ m n o ; p q r ;;;
2114
+ s t u ; v w x]
2115
+ => dims = (2, 3, 4)
2116
+
2117
+ [a b ; c ;;; d ;;;;]
2118
+ ___ _ _
2119
+ 2 1 1 = elements in each row (2, 1, 1)
2120
+ _______ _
2121
+ 3 1 = elements in each column (3, 1)
2122
+ _____________
2123
+ 4 = elements in each 3d slice (4,)
2124
+ _____________
2125
+ 4 = elements in each 4d slice (4,)
2126
+ => shape = ((2, 1, 1), (3, 1), (4,), (4,)) with `rowfirst` = true
2100
2127
"""
2101
2128
hvncat (:: Tuple{} , :: Bool ) = []
2102
2129
hvncat (:: Tuple{} , :: Bool , xs... ) = []
@@ -2188,9 +2215,6 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
2188
2215
return A
2189
2216
end
2190
2217
2191
- cat_ndims (a) = 0
2192
- cat_ndims (a:: AbstractArray ) = ndims (a)
2193
-
2194
2218
function _typed_hvncat (:: Type{T} , :: Val{N} , as... ) where {T, N}
2195
2219
# optimization for scalars and 1-length arrays that can be concatenated by copying them linearly
2196
2220
# into the destination
@@ -2257,12 +2281,12 @@ function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool,
2257
2281
elseif currentdims[d] < outdims[d] # dimension in progress
2258
2282
break
2259
2283
else # exceeded dimension
2260
- ArgumentError (" argument $i has too many elements along axis $d " ) |> throw
2284
+ throw ( ArgumentError (" argument $i has too many elements along axis $d " ))
2261
2285
end
2262
2286
end
2263
2287
end
2264
2288
elseif currentdims[d1] > outdims[d1] # exceeded dimension
2265
- ArgumentError (" argument $i has too many elements along axis $d1 " ) |> throw
2289
+ throw ( ArgumentError (" argument $i has too many elements along axis $d1 " ))
2266
2290
end
2267
2291
end
2268
2292
@@ -2308,7 +2332,8 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
2308
2332
if d == 1 || i == 1 || wasstartblock
2309
2333
currentdims[d] += dsize
2310
2334
elseif dsize != cat_size (as[i - 1 ], ad)
2311
- ArgumentError (" argument $i has a mismatched number of elements along axis $ad ; expected $(cat_size (as[i - 1 ], ad)) , got $dsize " ) |> throw
2335
+ throw (ArgumentError (""" argument $i has a mismatched number of elements along axis $ad ; \
2336
+ expected $(cat_size (as[i - 1 ], ad)) , got $dsize """ ))
2312
2337
end
2313
2338
2314
2339
wasstartblock = blockcounts[d] == 1 # remember for next dimension
@@ -2318,7 +2343,8 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
2318
2343
if outdims[d] == 0
2319
2344
outdims[d] = currentdims[d]
2320
2345
elseif outdims[d] != currentdims[d]
2321
- ArgumentError (" argument $i has a mismatched number of elements along axis $ad ; expected $(abs (outdims[d] - (currentdims[d] - dsize))) , got $dsize " ) |> throw
2346
+ throw (ArgumentError (""" argument $i has a mismatched number of elements along axis $ad ; \
2347
+ expected $(abs (outdims[d] - (currentdims[d] - dsize))) , got $dsize """ ))
2322
2348
end
2323
2349
currentdims[d] = 0
2324
2350
blockcounts[d] = 0
@@ -2382,9 +2408,6 @@ end
2382
2408
Ai
2383
2409
end
2384
2410
2385
- cat_length (a:: AbstractArray ) = length (a)
2386
- cat_length (:: Any ) = 1
2387
-
2388
2411
# # Reductions and accumulates ##
2389
2412
2390
2413
function isequal (A:: AbstractArray , B:: AbstractArray )
0 commit comments