The following innocent code gives a TypeError?:
e=random_matrix(ZZ,4,5,algorithm='echelon_form')
while I should have given:
e=random_matrix(ZZ,4,5,algorithm='echelon_form', num_pivots=3)
The code should just use a random value for the number of pivots when the argument isn't given.
I would like to work on this issue. So, when either random_matrix() or matrix.random() is called with the keyword argument algorithm=echelon_form, the following piece of code gets run:
def random_matrix(...):
...
elif algorithm == 'echelon_form':
return random_rref_matrix(parent, *args, **kwds)
This calls the following signature:
def random_rref_matrix(parent, num_pivots)
Both of these pieces of code are in the file: sage/local/lib/python3.7/site-packages/sage/matrix/special.py
Now I guess I have two options to fix it:
random_matrix() function:I could check whether kwds has the value
num_pivots. If it doesn't, I will callrandom_rref_matrixwith a random number in the range [0, min(nrows, ncols)]. Will also have to check ifncolsis there or not.
I guess this is safe but will make the code look a little ugly.
random_rref_matrix() function:I will change the signature to include a
*argsand a**kwds. Check within the function for the existence ofnum_pivotsand assignnum_pivotsappropriately if it is not there.
Will have to ensure the error messages would be the same as before? Seems a bit unsafe as a lot of other functions might call this function, but should be cleaner.
Which way should I proceed? Is there anything I'm missing?
______________