Skip to content

Commit aeb0664

Browse files
authored
Short-circuit in block print (#93)
* Short-circuit in block print * remove doc string * v0.10.2 * Add sortedin tests * use sortedin for matrices as well
1 parent 9d362bc commit aeb0664

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.10.1"
3+
version = "0.10.2"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/show.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
import Base.alignment
33

44
# A bit of a mess but does the job...
5+
6+
# sortedin(p, sc)
7+
# returns true if `p` is in `sc`, assuming that `sc` is monotonically increasing.
8+
function sortedin(x, itr)
9+
for y in itr
10+
if y == x
11+
return true
12+
elseif y > x
13+
return false
14+
end
15+
end
16+
return false
17+
end
18+
519
function _blockarray_print_matrix_row(io::IO,
620
X::AbstractVecOrMat, A::Vector,
721
i::Integer, cols::AbstractVector, sep::AbstractString)
@@ -53,9 +67,9 @@ function _blockarray_print_matrix_row(io::IO,
5367
n_chars -= 2
5468
end
5569

56-
if i in row_sum
70+
if sortedin(i, row_sum)
5771
print(row_buf, ""^(n_chars-1))
58-
if ndims(X) == 2 && k in col_sum
72+
if ndims(X) == 2 && sortedin(k,col_sum)
5973
print(row_buf, "")
6074
else
6175
print(row_buf, "")

test/test_blockarrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,4 @@ end
460460
B[2,2] = fill(4.0f0,2,2)
461461
@test mortar(B) == A
462462
@test mortar(B)[1,1] == 1.0
463-
end
463+
end

test/test_blockindices.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ end
7272
@test_throws BoundsError A[Block(2)[3]]
7373
@test_throws BoundsError A[Block(2)[3:3]]
7474
end
75+
76+
@testset "sortedin" begin
77+
v = [1,3,4]
78+
@test BlockArrays.sortedin(1,v)
79+
@test !BlockArrays.sortedin(2,v)
80+
@test !BlockArrays.sortedin(0,v)
81+
@test !BlockArrays.sortedin(5,v)
82+
end

0 commit comments

Comments
 (0)