-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ type SparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} | |
function SparseMatrixCSC(m::Integer, n::Integer, colptr::Vector{Ti}, rowval::Vector{Ti}, nzval::Vector{Tv}) | ||
m < 0 && throw(ArgumentError("number of rows (m) must be ≥ 0, got $m")) | ||
n < 0 && throw(ArgumentError("number of columns (n) must be ≥ 0, got $n")) | ||
try | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
simonster
Author
Member
|
||
zero(Tv) | ||
catch e | ||
isa(e, MethodError) && throw(ArgumentError("cannot construct a SparseMatrixCSC{$Tv} because zero($Tv) is not defined")) | ||
rethrow(e) | ||
end | ||
new(Int(m), Int(n), colptr, rowval, nzval) | ||
end | ||
end | ||
|
@@ -184,9 +190,7 @@ convert{T}(::Type{AbstractMatrix{T}}, A::SparseMatrixCSC) = convert(SparseMatrix | |
convert(::Type{Matrix}, S::SparseMatrixCSC) = full(S) | ||
|
||
function full{Tv}(S::SparseMatrixCSC{Tv}) | ||
# Handle cases where zero(Tv) is not defined but the array is dense. | ||
# (Should we really worry about this?) | ||
A = length(S) == nnz(S) ? Array(Tv, S.m, S.n) : zeros(Tv, S.m, S.n) | ||
A = zeros(Tv, S.m, S.n) | ||
for col = 1 : S.n, k = S.colptr[col] : (S.colptr[col+1]-1) | ||
A[S.rowval[k], col] = S.nzval[k] | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -748,9 +748,8 @@ let S = spzeros(5,1), I = [false,true,false,true,false] | |
end | ||
|
||
# issue #9917 | ||
@test sparse([]') == reshape(sparse([]), 1, 0) | ||
@test full(sparse([])) == zeros(0, 1) | ||
This comment has been minimized.
Sorry, something went wrong.
tkelman
Contributor
|
||
@test_throws BoundsError sparse([])[1] | ||
@test sparse(Int[]') == reshape(sparse(Int[]), 1, 0) | ||
@test_throws BoundsError sparse(Int[])[1] | ||
x = speye(100) | ||
@test_throws BoundsError x[-10:10] | ||
|
||
|
1 comment
on commit c590f00
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should allow the construction of arrays of element type T
which does not admit a zero
method. Such matrices can still be used in many methods, where zero
is not invoked.
I have some cases of code that uses this constructor many times on small amounts of input data in an inner loop, I'd be worried about this try-catch slowing things down.