1
1
using SymbolicUtils: Rewriters
2
2
using Graphs. Experimental. Traversals
3
3
4
- const KEEP = typemin (Int)
5
-
6
4
function alias_eliminate_graph! (state:: TransformationState ; kwargs... )
7
5
mm = linear_subsys_adjmat! (state; kwargs... )
8
6
if size (mm, 1 ) == 0
@@ -225,8 +223,9 @@ the `constraint`.
225
223
vertices = eadj[i]
226
224
if constraint (length (vertices))
227
225
for (j, v) in enumerate (vertices)
228
- (mask === nothing || mask[v]) &&
226
+ if (mask === nothing || mask[v])
229
227
return (CartesianIndex (i, v), M. row_vals[i][j])
228
+ end
230
229
end
231
230
end
232
231
end
241
240
row = @view M[i, :]
242
241
if constraint (count (! iszero, row))
243
242
for (v, val) in enumerate (row)
244
- iszero (val) && continue
245
243
if mask === nothing || mask[v]
246
244
return CartesianIndex (i, v), val
247
245
end
@@ -325,7 +323,8 @@ function Base.setindex!(ag::AliasGraph, v::Integer, i::Integer)
325
323
return 0 => 0
326
324
end
327
325
328
- function Base. setindex! (ag:: AliasGraph , p:: Union{Pair{Int, Int}, Tuple{Int, Int}} ,
326
+ function Base. setindex! (ag:: AliasGraph ,
327
+ p:: Union{Pair{<:Integer, Int}, Tuple{<:Integer, Int}} ,
329
328
i:: Integer )
330
329
(c, v) = p
331
330
if c == 0 || v == 0
@@ -530,7 +529,7 @@ function find_linear_variables(graph, linear_equations, var_to_diff, irreducible
530
529
return linear_variables
531
530
end
532
531
533
- function aag_bareiss! (graph, var_to_diff, mm_orig:: SparseMatrixCLIL )
532
+ function aag_bareiss! (graph, var_to_diff, mm_orig:: SparseMatrixCLIL{T, Ti} ) where {T, Ti}
534
533
mm = copy (mm_orig)
535
534
linear_equations_set = BitSet (mm_orig. nzrows)
536
535
@@ -554,7 +553,16 @@ function aag_bareiss!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
554
553
end
555
554
solvable_variables = findall (is_linear_variables)
556
555
557
- return mm, solvable_variables, do_bareiss! (mm, mm_orig, is_linear_variables)
556
+ local bar
557
+ try
558
+ bar = do_bareiss! (mm, mm_orig, is_linear_variables)
559
+ catch e
560
+ e isa OverflowError || rethrow (e)
561
+ mm = convert (SparseMatrixCLIL{BigInt, Ti}, mm_orig)
562
+ bar = do_bareiss! (mm, mm_orig, is_linear_variables)
563
+ end
564
+
565
+ return mm, solvable_variables, bar
558
566
end
559
567
560
568
function do_bareiss! (M, Mold, is_linear_variables)
@@ -589,6 +597,7 @@ function do_bareiss!(M, Mold, is_linear_variables)
589
597
end
590
598
bareiss_ops = ((M, i, j) -> nothing , myswaprows!,
591
599
bareiss_update_virtual_colswap_mtk!, bareiss_zero!)
600
+
592
601
rank2, = bareiss! (M, bareiss_ops; find_pivot = find_and_record_pivot)
593
602
rank1 = something (rank1r[], rank2)
594
603
(rank1, rank2, pivots)
@@ -983,7 +992,7 @@ function locally_structure_simplify!(adj_row, pivot_var, ag)
983
992
nirreducible = 0
984
993
# When this row only as the pivot element, the pivot is zero by homogeneity
985
994
# of the linear system.
986
- alias_candidate:: Union{Int, Pair{Int , Int}} = 0
995
+ alias_candidate:: Union{Int, Pair{eltype(adj_row) , Int}} = 0
987
996
988
997
# N.B.: Assumes that the non-zeros iterator is robust to modification
989
998
# of the underlying array datastructure.
0 commit comments