@@ -2350,37 +2350,34 @@ function setindex!(A::SparseMatrixCSC{Tv,Ti}, v::Tv, i::Ti, j::Ti) where Tv wher
2350
2350
return A
2351
2351
end
2352
2352
2353
- setindex! (A:: SparseMatrixCSC , v:: AbstractArray , i:: Integer , J:: AbstractVector{<:Integer} ) = setindex! (A, v, [i], J)
2354
- setindex! (A:: SparseMatrixCSC , v:: AbstractArray , I:: AbstractVector{<:Integer} , j:: Integer ) = setindex! (A, v, I, [j])
2355
-
2356
2353
# Colon translation
2357
2354
setindex! (A:: SparseMatrixCSC , x:: AbstractArray , :: Colon ) = setindex! (A, x, 1 : length (A))
2358
2355
setindex! (A:: SparseMatrixCSC , x:: AbstractArray , :: Colon , :: Colon ) = setindex! (A, x, 1 : size (A, 1 ), 1 : size (A,2 ))
2359
2356
setindex! (A:: SparseMatrixCSC , x:: AbstractArray , :: Colon , j:: Union{Integer, AbstractVector} ) = setindex! (A, x, 1 : size (A, 1 ), j)
2360
2357
setindex! (A:: SparseMatrixCSC , x:: AbstractArray , i:: Union{Integer, AbstractVector} , :: Colon ) = setindex! (A, x, i, 1 : size (A, 2 ))
2361
2358
2362
- # TODO : Revamp this guy to use broadcast
2363
- # function setindex!(A::SparseMatrixCSC{Tv}, x::Number,
2364
- # I::AbstractVector{<:Integer} , J::AbstractVector{<:Integer}) where Tv
2365
- # if isempty(I) || isempty(J); return A; end
2366
- # # lt=≤ to check for strict sorting
2367
- # if !issorted(I, lt=≤); I = sort!(unique(I)); end
2368
- # if !issorted(J, lt=≤); J = sort!(unique(J)); end
2369
- # if (I[1] < 1 || I[end] > A.m) || (J[1] < 1 || J[end] > A.n)
2370
- # throw(BoundsError(A, (I, J)))
2371
- # end
2372
- # if x == 0
2373
- # _spsetz_setindex!(A, I, J)
2374
- # else
2375
- # _spsetnz_setindex!(A, convert(Tv, x), I, J)
2376
- # end
2377
- # end
2359
+ function Base . fill! (V :: SubArray {Tv, <: Any , <: SparseMatrixCSC , Tuple{Vararg{Union{Integer, AbstractVector{ <: Integer }}, 2 }}}, x) where Tv
2360
+ A = V . parent
2361
+ I , J = V . indices
2362
+ if isempty (I) || isempty (J); return A; end
2363
+ # lt=≤ to check for strict sorting
2364
+ if ! issorted (I, lt= ≤ ); I = sort! (unique (I)); end
2365
+ if ! issorted (J, lt= ≤ ); J = sort! (unique (J)); end
2366
+ if (I[1 ] < 1 || I[end ] > A. m) || (J[1 ] < 1 || J[end ] > A. n)
2367
+ throw (BoundsError (A, (I, J)))
2368
+ end
2369
+ if x == 0
2370
+ _spsetz_setindex! (A, I, J)
2371
+ else
2372
+ _spsetnz_setindex! (A, convert (Tv, x), I, J)
2373
+ end
2374
+ end
2378
2375
"""
2379
2376
Helper method for immediately preceding setindex! method. For all (i,j) such that i in I and
2380
2377
j in J, assigns zero to A[i,j] if A[i,j] is a presently-stored entry, and otherwise does nothing.
2381
2378
"""
2382
2379
function _spsetz_setindex! (A:: SparseMatrixCSC ,
2383
- I:: AbstractVector{<:Integer} , J:: AbstractVector{<:Integer} )
2380
+ I:: Union{Integer, AbstractVector{<:Integer}} , J:: Union{Integer, AbstractVector{<:Integer} } )
2384
2381
lengthI = length (I)
2385
2382
for j in J
2386
2383
coljAfirstk = A. colptr[j]
@@ -2416,7 +2413,7 @@ and j in J, assigns x to A[i,j] if A[i,j] is a presently-stored entry, and alloc
2416
2413
assigns x to A[i,j] if A[i,j] is not presently stored.
2417
2414
"""
2418
2415
function _spsetnz_setindex! (A:: SparseMatrixCSC{Tv} , x:: Tv ,
2419
- I:: AbstractVector{<:Integer} , J:: AbstractVector{<:Integer} ) where Tv
2416
+ I:: Union{Integer, AbstractVector{<:Integer}} , J:: Union{Integer, AbstractVector{<:Integer} } ) where Tv
2420
2417
m, n = size (A)
2421
2418
lenI = length (I)
2422
2419
@@ -2521,16 +2518,14 @@ function _spsetnz_setindex!(A::SparseMatrixCSC{Tv}, x::Tv,
2521
2518
return A
2522
2519
end
2523
2520
2524
- setindex! (A:: SparseMatrixCSC{Tv,Ti} , S:: Matrix , I:: AbstractVector{T} , J:: AbstractVector{T} ) where {Tv,Ti,T<: Integer } =
2521
+ setindex! (A:: SparseMatrixCSC{Tv,Ti} , S:: Matrix , I:: Union{Integer, AbstractVector{T}} , J:: Union{Integer, AbstractVector{T} } ) where {Tv,Ti,T<: Integer } =
2525
2522
setindex! (A, convert (SparseMatrixCSC{Tv,Ti}, S), I, J)
2526
2523
2527
- setindex! (A:: SparseMatrixCSC , v:: AbstractVector , I:: AbstractVector{<:Integer} , j:: Integer ) = setindex! (A, v, I, [j])
2528
- setindex! (A:: SparseMatrixCSC , v:: AbstractVector , i:: Integer , J:: AbstractVector{<:Integer} ) = setindex! (A, v, [i], J)
2529
- setindex! (A:: SparseMatrixCSC , v:: AbstractVector , I:: AbstractVector{T} , J:: AbstractVector{T} ) where {T<: Integer } =
2524
+ setindex! (A:: SparseMatrixCSC , v:: AbstractVector , I:: Union{Integer, AbstractVector{T}} , J:: Union{Integer, AbstractVector{T}} ) where {T<: Integer } =
2530
2525
setindex! (A, reshape (v, length (I), length (J)), I, J)
2531
2526
2532
2527
# A[I,J] = B
2533
- function setindex! (A:: SparseMatrixCSC{Tv,Ti} , B:: SparseMatrixCSC{Tv,Ti} , I:: AbstractVector{T} , J:: AbstractVector{T} ) where {Tv,Ti,T<: Integer }
2528
+ function setindex! (A:: SparseMatrixCSC{Tv,Ti} , B:: SparseMatrixCSC{Tv,Ti} , I:: Union{Integer, AbstractVector{T}} , J:: Union{Integer, AbstractVector{T} } ) where {Tv,Ti,T<: Integer }
2534
2529
if size (B,1 ) != length (I) || size (B,2 ) != length (J)
2535
2530
throw (DimensionMismatch (" " ))
2536
2531
end
0 commit comments