Skip to content

Commit a110b89

Browse files
thofmalgoettgens
andcommitted
Apply suggestions from code review
Co-authored-by: Lars Göttgens <lars.goettgens@rwth-aachen.de>
1 parent e04724e commit a110b89

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/matrix.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ end
2424
# we overload some specific types to not hit the AA fallback
2525
for T in [ZZMatrix, QQMatrix]
2626
@eval begin
27-
function sub(M::$T, r::AbstractVector{<:Integer}, c::AbstractVector{<:Integer})
27+
# have to "duplicate" this, otherwise we get ambiguity errors
28+
function sub(x::$T, r::AbstractUnitRange{Int}, c::AbstractUnitRange{Int})
29+
return deepcopy(view(x, r, c))
30+
end
31+
32+
function sub(M::$T, r::AbstractVector{Int}, c::AbstractVector{Int})
2833
N = zero_matrix(base_ring(M), length(r), length(c))
29-
ii = 1
3034
GC.@preserve M N begin
31-
for i in r
32-
jj = 1
33-
for j in c
35+
for (ii, i) in enumerate(r)
36+
for (jj, j) in enumerate(c)
3437
set!(mat_entry_ptr(N, ii, jj), mat_entry_ptr(M, i, j))
35-
jj += 1
3638
end
37-
ii += 1
3839
end
3940
end
4041
return N

test/flint/fmpz_mat-test.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ end
259259
C[1, 1] = 20
260260
@test B == matrix_space(ZZ, 2, 2)([10 2; 4 5])
261261
@test A == S([1 2 3; 4 5 6; 7 8 9])
262+
263+
m = ZZ[1 2 4; 5 6 7]
264+
n = m[[1], [1, 3]]
265+
@test n == ZZ[1 4]
266+
n = m[1:2, 1:2]
267+
@test n == ZZ[1 2; 5 6]
262268
end
263269

264270
@testset "ZZMatrix.unary_ops" begin

0 commit comments

Comments
 (0)