You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -87,7 +87,9 @@ function LinearAlgebra.mul!(C::SparseMatrixCSC{Tv,Ti},
87
87
end
88
88
for ip in nzrange(C,j)
89
89
i = IC[ip]
90
-
VC[ip] = x[i]
90
+
if xb[i] == j
91
+
VC[ip] = x[i]
92
+
end
91
93
end
92
94
end
93
95
C
@@ -132,7 +134,9 @@ function LinearAlgebra.mul!(C::SparseMatrixCSC{Tv,Ti},
132
134
end
133
135
for ip in nzrange(C,j)
134
136
i = IC[ip]
135
-
VC[ip] += α*x[i]
137
+
if xb[i] == j
138
+
VC[ip] += α*x[i]
139
+
end
136
140
end
137
141
end
138
142
C
@@ -482,12 +486,6 @@ function LinearAlgebra.mul!(C::SparseMatrixCSC{Tv,Ti},
482
486
C
483
487
end
484
488
485
-
# function LinearAlgebra.mul!(C::SparseMatrixCSC{Tv,Ti},At::Transpose{Tv,SparseMatrixCSC{Tv,Ti}},Bt::Transpose{Tv,SparseMatrixCSC{Tv,Ti}},α::Number,β::Number) where {Tv,Ti}
486
-
# mul!(C,Bt.parent,At.parent,α,β)
487
-
# C
488
-
# end
489
-
490
-
491
489
function LinearAlgebra.mul!(C::SparseMatrixCSR{Bi,Tv,Ti},
492
490
A::SparseMatrixCSR{Bi,Tv,Ti},
493
491
B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
@@ -553,7 +551,7 @@ function LinearAlgebra.mul!(C::SparseMatrixCSR{Bi,Tv,Ti},
553
551
end
554
552
555
553
# Alternative to lazy csr to csc for matrix addition that does not drop structural zeros.
556
-
function +(A::SparseMatrixCSR{Bi,Tv,Ti},B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
554
+
function Base.:+(A::SparseMatrixCSR{Bi,Tv,Ti},B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
557
555
if size(A) == size(B) || throw(DimensionMismatch("Size of B $(size(B)) must match size of A $(size(A))"));end
558
556
p,q = size(A)
559
557
nnz_C_upperbound = nnz(A) + nnz(B)
@@ -611,7 +609,7 @@ function +(A::SparseMatrixCSR{Bi,Tv,Ti},B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,
611
609
end
612
610
613
611
# Alternative to lazy csr to csc for matrix subtraction that does not drop structural zeros. Subtracts B from A, i.e. A - B.
614
-
function -(A::SparseMatrixCSR{Bi,Tv,Ti},B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
612
+
function Base.:-(A::SparseMatrixCSR{Bi,Tv,Ti},B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
615
613
if size(A) == size(B) || throw(DimensionMismatch("Size of B $(size(B)) must match size of A $(size(A))"));end
616
614
nnz_C_upperbound = nnz(A) + nnz(B)
617
615
p,r = size(A)
@@ -668,7 +666,7 @@ function -(A::SparseMatrixCSR{Bi,Tv,Ti},B::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,
668
666
SparseMatrixCSR{Bi}(p,r,IC,JC,VC) # A += B
669
667
end
670
668
671
-
function -(A::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
669
+
function Base.:-(A::SparseMatrixCSR{Bi,Tv,Ti}) where {Bi,Tv,Ti}
# # local column pointer, refresh every row, start at 0 to allow empty rows
1499
-
# # loop over columns "j" in row i of A
1500
-
# for jp in nzrange(Pl, i)
1501
-
# j = JPl[jp]
1502
-
# # loop over columns "k" in row j of B
1503
-
# for kp in nzrange(A, j)
1504
-
# k = JA[kp]
1505
-
# # since C is constructed rowwise, xb tracks if a column index is present in a new row in C.
1506
-
# if xb[k] != i
1507
-
# lp[] += 1
1508
-
# JRA[lp[]] = k
1509
-
# xb[k] = i
1510
-
# end
1511
-
# end
1512
-
# end
1513
-
# sort!(JRA_permutation,alg=QuickSort,by=i -> i <= lp[] ? JRA[i] : typemax(i))
1514
-
# j_min = JRA[JRA_permutation[1]]
1515
-
# j_max = JRA[JRA_permutation[lp[]]]
1516
-
# for j in 1:size(Prt,2)
1517
-
# ip_range = nzrange(Pr,j)
1518
-
# ip = ip_range.start
1519
-
# ip_stop = ip_range.stop
1520
-
# i_min = IPr[ip]
1521
-
# i_max = IPr[ip_stop]
1522
-
# if i_min > j_max || j_min > i_max # no intersection
1523
-
# continue
1524
-
# end
1525
-
# while ip <= ip_stop
1526
-
# iPr = IPr[ip]
1527
-
# if xb[iPr] == i
1528
-
# JC[nnz_C] = j
1529
-
# nnz_C += 1
1530
-
# break
1531
-
# end
1532
-
# ip +=1
1533
-
# end
1534
-
# end
1535
-
# IC[i+1] = nnz_C
1536
-
# end
1537
-
# nnz_C -= 1
1538
-
# resize!(JC,nnz_C)
1539
-
# VC = zeros(Tv,nnz_C)
1540
-
# cache = (xb,x,JRA)
1541
-
# SparseMatrixCSR{Bi}(p,s,IC,JC,VC), cache # values not yet initialized
1542
-
# end
1543
-
1544
-
# function RAP_numeric!(C,Pl,A,Prt,cache)
1545
-
# Pr = Prt.parent
1546
-
# JPl = colvals(Pl)
1547
-
# VPl = nonzeros(Pl)
1548
-
# JA = colvals(A)
1549
-
# VA = nonzeros(A)
1550
-
# IPr = colvals(Pr) # colvals can be interpreted as rowvals when Pr is virtually transposed.
1551
-
# VPr = nonzeros(Pr)
1552
-
# JC = colvals(C)
1553
-
# VC = nonzeros(C)
1554
-
# (xb,x,_) = cache
1555
-
# for i in 1:p
1556
-
# # loop over columns "j" in row i of A
1557
-
# for jp in nzrange(Pl, i)
1558
-
# j = JPl[jp]
1559
-
# # loop over columns "k" in row j of B
1560
-
# for kp in nzrange(A, j)
1561
-
# k = JA[kp]
1562
-
# # since C is constructed rowwise, xb tracks if a column index is present in a new row in C.
1563
-
# if xb[k] != i
1564
-
# xb[k] = i
1565
-
# x[k] = VPl[jp] * VA[kp]
1566
-
# else
1567
-
# x[k] += VPl[jp] * VA[kp]
1568
-
# end
1569
-
# end
1570
-
# end
1571
-
# for col_ptr in nzrange(C,i)
1572
-
# Pr_col = JC[col_ptr]
1573
-
# Pr_rows_range = nzrange(Pr,Pr_col) # column l of Pr^T
1574
-
# for ip in Pr_rows_range
1575
-
# Pr_row = IPr[ip]
1576
-
# if xb[Pr_row] == i
1577
-
# VC[col_ptr] += x[Pr_row]*VPr[ip]
1578
-
# end
1579
-
# end
1580
-
# end
1581
-
# end
1582
-
# end
1583
-
# function _RAP(Pl,A,Prt)
1584
-
# C,cache = RAP_symbolic!(Pl,A,Prt)
1585
-
# # @code_warntype RAP_symbolic!(Pl,A,Prt)
1586
-
# xb = cache[1]
1587
-
# xb.=0
1588
-
# RAP_numeric!(C,Pl,A,Prt,cache)
1589
-
# # @code_warntype RAP_numeric!(C,Pl,A,Prt,cache)
1590
-
1591
-
# C,cache
1592
-
# end
1593
-
# _RAP(Pl,A,Prt)
1594
-
# end
1595
-
1596
1460
function RAP!(C::SparseMatrixCSR{Bi,Tv,Ti}, Pl::SparseMatrixCSR{Bi,Tv,Ti}, A::SparseMatrixCSR{Bi,Tv,Ti}, Prt::Transpose{Tv,SparseMatrixCSR{Bi,Tv,Ti}},cache) where {Bi,Tv,Ti}
1597
1461
p,q = size(Pl)
1598
1462
m,r = size(A)
@@ -1659,8 +1523,6 @@ function RAP!(C::SparseMatrixCSR{Bi,Tv,Ti}, Pl::SparseMatrixCSR{Bi,Tv,Ti}, A::Sp
1659
1523
VC .*= β
1660
1524
# some cache items are present with the regular RAP product in mind, which is how the allocating verison is performed
1661
1525
(xb,_,x,_,_) = cache
1662
-
# yes = 0
1663
-
# no = 0
1664
1526
for i in 1:p
1665
1527
# loop over columns "j" in row i of A
1666
1528
for jp in nzrange(Pl, i)
@@ -1685,16 +1547,12 @@ function RAP!(C::SparseMatrixCSR{Bi,Tv,Ti}, Pl::SparseMatrixCSR{Bi,Tv,Ti}, A::Sp
0 commit comments