Skip to content

Commit

Permalink
scale_row! fixed (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
BD-00 authored May 1, 2024
1 parent 3ed50fd commit 969c5f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Sparse/Row.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,15 @@ function scale_row!(a::SRow{T}, b::T) where T
if isone(b)
return
end
for i=1:length(a.pos)
i = 1
while i <= length(a)
a.values[i] *= b
if iszero(a.values[i])
deleteat!(a.values, i)
deleteat!(a.pos, i)
else
i += 1
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/Sparse/Row.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testset "Row" begin
R = FlintZZ
S, _ = residue_ring(ZZ, 4)

# Construction

Expand Down Expand Up @@ -82,7 +83,10 @@

A = sparse_row(FlintZZ, [1, 2, 4], ZZRingElem[1, 2, 3])
scale_row!(A, ZZRingElem(2))
B = sparse_row(S, [1, 3, 4], [1, 2, 3])
scale_row!(B, S(2))
@test A == sparse_row(FlintZZ, [1, 2, 4], ZZRingElem[2, 4, 6])
@test B == sparse_row(S, [1, 4], [2, 2])

# Addition
A = sparse_row(FlintZZ, [1, 2, 3, 5], ZZRingElem[1, 2, 3, 5])
Expand Down

0 comments on commit 969c5f5

Please sign in to comment.