Nemocas / Nemo.jl

Julia bindings for various mathematical libraries (including flint2)
http://nemocas.github.io/Nemo.jl/
Other
186 stars 58 forks source link

backsolve! and solve! do not conform to mutation policy #277

Open wbhart opened 6 years ago

wbhart commented 6 years ago

We decided that matrix functions with an exclamation mark should not mutate the objects that occur as entries of a matrix, though should be allowed to arbitrarily replace/swap the entries that appear in the matrix. In other words, these functions should be interpreted as inplace operations, rather than operations that are allowed to mutate the actual entries themselves.

For this reason, they should probably also be renamed, perhaps to solve_inplace! or something like this.

At present, however, some functions, such as solve! and backsolve! actually mutate entries, rather than just replacing/swapping entries of a matrix. This needs to be fixed.

wbhart commented 6 years ago

The reduce_row! functions also don't conform. On the other hand, these functions are only useful for minpoly. So they could possibly just be documented as mutating and placed in the unsafe section, and then we can check that they are only ever applied to matrices that we have control over (I think this is the case, but it is actually slightly complicated to analyse).

wbhart commented 6 years ago

We also need to check that by adhering to this new policy everywhere, that we have not introduced O(n^3) copies. We want the number of copies made to be limited to O(n^2) throughout. This can usually be done by analyzing the algorithm and making sure that the first write makes a new entry/copy, and then the remaining mutations of that entry using unsafe operators are fine.