Skip to content

Commit 18be616

Browse files
authored
Revert "Check if Ti is sufficient for size of SparseMatrixCSC (#31118)" (#31667)
This reverts commit 4236774.
1 parent 5ce256c commit 18be616

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

stdlib/SparseArrays/src/sparsematrix.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ struct SparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti}
2222

2323
function SparseMatrixCSC{Tv,Ti}(m::Integer, n::Integer, colptr::Vector{Ti}, rowval::Vector{Ti},
2424
nzval::Vector{Tv}) where {Tv,Ti<:Integer}
25-
26-
sparse_check_Ti(m, n, Ti)
25+
@noinline throwsz(str, lbl, k) =
26+
throw(ArgumentError("number of $str ($lbl) must be ≥ 0, got $k"))
27+
m < 0 && throwsz("rows", 'm', m)
28+
n < 0 && throwsz("columns", 'n', n)
2729
new(Int(m), Int(n), colptr, rowval, nzval)
2830
end
2931
end
@@ -33,17 +35,6 @@ function SparseMatrixCSC(m::Integer, n::Integer, colptr::Vector, rowval::Vector,
3335
SparseMatrixCSC{Tv,Ti}(m, n, colptr, rowval, nzval)
3436
end
3537

36-
function sparse_check_Ti(m::Integer, n::Integer, Ti::Type)
37-
@noinline throwsz(str, lbl, k) =
38-
throw(ArgumentError("number of $str ($lbl) must be ≥ 0, got $k"))
39-
@noinline throwTi(str, lbl, k) =
40-
throw(ArgumentError("$str ($lbl = $k) does not fit in Ti = $(Ti)"))
41-
m < 0 && throwsz("rows", 'm', m)
42-
n < 0 && throwsz("columns", 'n', n)
43-
!isbitstype(Ti) || m typemax(Ti) || throwTi("number of rows", "m", m)
44-
!isbitstype(Ti) || n typemax(Ti) || throwTi("number of columns", "n", n)
45-
!isbitstype(Ti) || n*m+1 typemax(Ti) || throwTi("maximal nnz+1", "m*n+1", n*m+1)
46-
end
4738
size(S::SparseMatrixCSC) = (S.m, S.n)
4839

4940
# Define an alias for views of a SparseMatrixCSC which include all rows and a unit range of the columns.
@@ -594,7 +585,6 @@ function sparse!(I::AbstractVector{Ti}, J::AbstractVector{Ti},
594585
csccolptr::Vector{Ti}, cscrowval::Vector{Ti}, cscnzval::Vector{Tv}) where {Tv,Ti<:Integer}
595586

596587
require_one_based_indexing(I, J, V)
597-
sparse_check_Ti(m, n, Ti)
598588
# Compute the CSR form's row counts and store them shifted forward by one in csrrowptr
599589
fill!(csrrowptr, Ti(0))
600590
coolen = length(I)

stdlib/SparseArrays/test/sparse.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,14 +2561,6 @@ end
25612561
@test sparse(Adjoint(UpperTriangular(A'))) == Adjoint(UpperTriangular(B'))
25622562
end
25632563

2564-
@testset "Ti cannot store all potential values #31024" begin
2565-
@test_throws ArgumentError SparseMatrixCSC(128, 1, [Int8(1), Int8(1)], Int8[], Int[])
2566-
@test_throws ArgumentError SparseMatrixCSC(12, 12, [Int8(1), Int8(1)], Int8[], Int[])
2567-
I1 = [Int8(i) for i in 1:20 for _ in 1:20]
2568-
J1 = [Int8(i) for _ in 1:20 for i in 1:20]
2569-
@test_throws ArgumentError sparse(I1, J1, zero(length(I1)zero(length(I1))))
2570-
end
2571-
25722564
@testset "unary operations on matrices where length(nzval)>nnz" begin
25732565
# this should create a sparse matrix with length(nzval)>nnz
25742566
A = SparseMatrixCSC(Complex{BigInt}[1+im 2+2im]')'[1:1, 2:2]

0 commit comments

Comments
 (0)