Skip to content

Commit c923c39

Browse files
committed
optional col ordering in nullspace
1 parent 018ac8d commit c923c39

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/structural_transformation/bareiss.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,22 @@ function bareiss!(M::AbstractMatrix{T}, swap_strategy=bareiss_colswap;
207207
return (n, pivot, column_permuted)
208208
end
209209

210-
function nullspace(A)
210+
function nullspace(A; col_order=nothing)
211211
column_pivots = collect(1:size(A, 2))
212212
B = copy(A)
213213
(rank, d, column_permuted) = bareiss!(B; column_pivots)
214214
reduce_echelon!(B, rank, d)
215+
216+
# The first rank entries in col_order are columns that give a basis
217+
# for the column space. The remainder give the free variables.
218+
if col_order !== nothing
219+
resize!(col_order, size(A,2))
220+
col_order .= 1:size(A,2)
221+
for (i,cp) in enumerate(column_pivots)
222+
@swap(col_order[i],col_order[cp])
223+
end
224+
end
225+
215226
N = ModelingToolkit.reduced_echelon_nullspace(rank, B)
216227
apply_inv_pivot_rows!(N, column_pivots)
217228
end

0 commit comments

Comments
 (0)