@@ -57,7 +57,7 @@ Parameter `sep::Integer` is number of spaces to put between elements.
57
57
Alignment is reported as a vector of (left,right) tuples, one for each
58
58
column going across the screen.
59
59
"""
60
- function alignment (io:: IO , X:: AbstractVecOrMat ,
60
+ function alignment (io:: IO , @nospecialize ( X:: AbstractVecOrMat ) ,
61
61
rows:: AbstractVector{T} , cols:: AbstractVector{V} ,
62
62
cols_if_complete:: Integer , cols_otherwise:: Integer , sep:: Integer ) where {T,V}
63
63
a = Tuple{T, V}[]
@@ -94,7 +94,7 @@ is specified as string sep.
94
94
`print_matrix_row` will also respect compact output for elements.
95
95
"""
96
96
function print_matrix_row (io:: IO ,
97
- X:: AbstractVecOrMat , A:: Vector ,
97
+ @nospecialize ( X:: AbstractVecOrMat ) , A:: Vector ,
98
98
i:: Integer , cols:: AbstractVector , sep:: AbstractString )
99
99
for (k, j) = enumerate (cols)
100
100
k > length (A) && break
@@ -158,16 +158,15 @@ string post (printed at the end of the last row of the matrix).
158
158
Also options to use different ellipsis characters hdots, vdots, ddots.
159
159
These are repeated every hmod or vmod elements.
160
160
"""
161
- function print_matrix (io:: IO , @nospecialize ( X:: AbstractVecOrMat ) ,
161
+ function print_matrix (io:: IO , X:: AbstractVecOrMat ,
162
162
pre:: AbstractString = " " , # pre-matrix string
163
163
sep:: AbstractString = " " , # separator between elements
164
164
post:: AbstractString = " " , # post-matrix string
165
165
hdots:: AbstractString = " \u 2026 " ,
166
166
vdots:: AbstractString = " \u 22ee" ,
167
167
ddots:: AbstractString = " \u 22f1 " ,
168
168
hmod:: Integer = 5 , vmod:: Integer = 5 )
169
- # use invokelatest to avoid backtracing in type invalidation, ref #37741
170
- invokelatest (_print_matrix, io, X, pre, sep, post, hdots, vdots, ddots, hmod, vmod, unitrange (axes (X,1 )), unitrange (axes (X,2 )))
169
+ _print_matrix (io, inferencebarrier (X), pre, sep, post, hdots, vdots, ddots, hmod, vmod, unitrange (axes (X,1 )), unitrange (axes (X,2 )))
171
170
end
172
171
173
172
function _print_matrix (io, @nospecialize (X:: AbstractVecOrMat ), pre, sep, post, hdots, vdots, ddots, hmod, vmod, rowsA, colsA)
@@ -191,12 +190,16 @@ function _print_matrix(io, @nospecialize(X::AbstractVecOrMat), pre, sep, post, h
191
190
halfheight = div (screenheight,2 )
192
191
if m > screenheight
193
192
rowsA = [rowsA[(0 : halfheight- 1 ) .+ firstindex (rowsA)]; rowsA[(end - div (screenheight- 1 ,2 )+ 1 ): end ]]
193
+ else
194
+ rowsA = [rowsA;]
194
195
end
195
196
# Similarly for columns, only necessary to get alignments for as many
196
197
# columns as could conceivably fit across the screen
197
198
maxpossiblecols = div (screenwidth, 1 + sepsize)
198
199
if n > maxpossiblecols
199
200
colsA = [colsA[(0 : maxpossiblecols- 1 ) .+ firstindex (colsA)]; colsA[(end - maxpossiblecols+ 1 ): end ]]
201
+ else
202
+ colsA = [colsA;]
200
203
end
201
204
A = alignment (io, X, rowsA, colsA, screenwidth, screenwidth, sepsize)
202
205
# Nine-slicing is accomplished using print_matrix_row repeatedly
@@ -268,12 +271,15 @@ end
268
271
269
272
# typeinfo agnostic
270
273
# n-dimensional arrays
271
- function show_nd (io:: IO , a:: AbstractArray , print_matrix:: Function , label_slices:: Bool )
274
+ show_nd (io:: IO , a:: AbstractArray , print_matrix:: Function , label_slices:: Bool ) =
275
+ _show_nd (io, inferencebarrier (a), print_matrix, label_slices, map (unitrange, axes (a)))
276
+
277
+ function _show_nd (io:: IO , @nospecialize (a:: AbstractArray ), print_matrix:: Function , label_slices:: Bool , axs:: Tuple{Vararg{AbstractUnitRange}} )
272
278
limit:: Bool = get (io, :limit , false )
273
279
if isempty (a)
274
280
return
275
281
end
276
- tailinds = tail (tail (axes (a) ))
282
+ tailinds = tail (tail (axs ))
277
283
nd = ndims (a)- 2
278
284
for I in CartesianIndices (tailinds)
279
285
idxs = I. I
@@ -284,7 +290,7 @@ function show_nd(io::IO, a::AbstractArray, print_matrix::Function, label_slices:
284
290
if length (ind) > 10
285
291
if ii == ind[firstindex (ind)+ 3 ] && all (d-> idxs[d]== first (tailinds[d]),1 : i- 1 )
286
292
for j= i+ 1 : nd
287
- szj = length (axes (a, j+ 2 ) )
293
+ szj = length (axs[ j+ 2 ] )
288
294
indj = tailinds[j]
289
295
if szj> 10 && first (indj)+ 2 < idxs[j] <= last (indj)- 3
290
296
@goto skip
@@ -302,7 +308,7 @@ function show_nd(io::IO, a::AbstractArray, print_matrix::Function, label_slices:
302
308
if label_slices
303
309
_show_nd_label (io, a, idxs)
304
310
end
305
- slice = view (a, axes (a, 1 ), axes (a, 2 ) , idxs... )
311
+ slice = view (a, axs[ 1 ], axs[ 2 ] , idxs... )
306
312
print_matrix (io, slice)
307
313
print (io, idxs == map (last,tailinds) ? " " : " \n\n " )
308
314
@label skip
@@ -379,10 +385,13 @@ end
379
385
`_show_nonempty(io, X::AbstractMatrix, prefix)` prints matrix X with opening and closing square brackets,
380
386
preceded by `prefix`, supposed to encode the type of the elements.
381
387
"""
382
- function _show_nonempty (io:: IO , X:: AbstractMatrix , prefix:: String )
388
+ _show_nonempty (io:: IO , X:: AbstractMatrix , prefix:: String ) =
389
+ _show_nonempty (io, inferencebarrier (X), prefix, axes (X))
390
+
391
+ function _show_nonempty (io:: IO , @nospecialize (X:: AbstractMatrix ), prefix:: String , axs:: Tuple{AbstractUnitRange,AbstractUnitRange} )
383
392
@assert ! isempty (X)
384
393
limit = get (io, :limit , false ):: Bool
385
- indr, indc = axes (X, 1 ), axes (X, 2 )
394
+ indr, indc = axs
386
395
nr, nc = length (indr), length (indc)
387
396
rdots, cdots = false , false
388
397
rr1, rr2 = unitrange (indr), 1 : 0
0 commit comments