@@ -53,22 +53,29 @@ function sparse_check_Ti(m::Integer, n::Integer, Ti::Type)
53
53
end
54
54
55
55
function sparse_check (n:: Integer , colptr:: Vector{Ti} , rowval, nzval) where Ti
56
+ # String interpolation is a performance bottleneck when it's part of the same function,
57
+ # ensure we only do it once committed to the error.
58
+ throwstart (ckp) = throw (ArgumentError (" $ckp == colptr[1] != 1" ))
59
+ throwmonotonic (ckp, ck, k) = throw (ArgumentError (" $ckp == colptr[$(k- 1 ) ] > colptr[$k ] == $ck " ))
60
+
56
61
sparse_check_length (" colptr" , colptr, n+ 1 , String) # don't check upper bound
57
62
ckp = Ti (1 )
58
- ckp == colptr[1 ] || throw ( ArgumentError ( " $ ckp == colptr[1] != 1 " ) )
63
+ ckp == colptr[1 ] || throwstart ( ckp)
59
64
@inbounds for k = 2 : n+ 1
60
65
ck = colptr[k]
61
- ckp <= ck || throw ( ArgumentError ( " $ ckp == colptr[ $(k - 1 ) ] > colptr[ $k ] == $ck " ) )
66
+ ckp <= ck || throwmonotonic ( ckp, ck, k )
62
67
ckp = ck
63
68
end
64
69
sparse_check_length (" rowval" , rowval, ckp- 1 , Ti)
65
70
sparse_check_length (" nzval" , nzval, 0 , Ti) # we allow empty nzval !!!
66
71
end
67
72
function sparse_check_length (rowstr, rowval, minlen, Ti)
73
+ throwmin (len, minlen, rowstr) = throw (ArgumentError (" $len == length($rowstr ) < $minlen " ))
74
+ throwmax (len, max, rowstr) = throw (ArgumentError (" $len == length($rowstr ) >= $max " ))
75
+
68
76
len = length (rowval)
69
- len >= minlen || throw (ArgumentError (" $len == length($rowstr ) < $minlen " ))
70
- ! isbitstype (Ti) || len < typemax (Ti) ||
71
- throw (ArgumentError (" $len == length($rowstr ) >= $(typemax (Ti)) " ))
77
+ len >= minlen || throwmin (len, minlen, rowstr)
78
+ ! isbitstype (Ti) || len < typemax (Ti) || throwmax (len, typemax (Ti), rowstr)
72
79
end
73
80
74
81
size (S:: SparseMatrixCSC ) = (getfield (S, :m ), getfield (S, :n ))
0 commit comments