Skip to content

Commit e04724e

Browse files
fiekerthofma
authored andcommitted
feat: better sub for [ZZ|QQ]Matrix
1 parent 2a1d29b commit e04724e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/matrix.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,30 @@ function sub(x::_MatTypes, r::AbstractUnitRange{Int}, c::AbstractUnitRange{Int})
2020
return deepcopy(view(x, r, c))
2121
end
2222

23-
getindex(x::_MatTypes, r::AbstractUnitRange{Int}, c::AbstractUnitRange{Int}) = sub(x, r, c)
23+
# flint does not support windows with non-continuous row or column indices
24+
# we overload some specific types to not hit the AA fallback
25+
for T in [ZZMatrix, QQMatrix]
26+
@eval begin
27+
function sub(M::$T, r::AbstractVector{<:Integer}, c::AbstractVector{<:Integer})
28+
N = zero_matrix(base_ring(M), length(r), length(c))
29+
ii = 1
30+
GC.@preserve M N begin
31+
for i in r
32+
jj = 1
33+
for j in c
34+
set!(mat_entry_ptr(N, ii, jj), mat_entry_ptr(M, i, j))
35+
jj += 1
36+
end
37+
ii += 1
38+
end
39+
end
40+
return N
41+
end
42+
end
43+
end
44+
45+
# make x[r, c] sugar for sub(x, r, c)
46+
getindex(x::_MatTypes, r::AbstractVector{Int}, c::AbstractVector{Int}) = sub(x, r, c)
2447

2548
################################################################################
2649
#

0 commit comments

Comments
 (0)