You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a Matrix object is constructed with a single argument, the argument is currently assumes this argument to be an array containing the matrix. However, I think that the most common way to use the matrix class will not to pass a Numpy array, but to pass the path to the file. It would therefore be more intuitive if one could call the constructor with mat = ompy.matrix("raw_spectra.m") rather than mat = ompy.matrix(path="raw_spectra.m")
One way to solve this could be that if there is only one argument, then the constructor checks the type of the argument, and based on if's a string or a Numpy array it proceeds with the appropriate steps.
I suggest that one could do such a check for this with something like:
The downside is that the initialization signature would be quite complicated. A possible solution is to only allow the values/path variable to be set by position while forcing all others to be set by keyword.
To illustrate the problem, it is easy to guess what mat = om.Matrix(values, Eg, Ex) will result in. But what about mat = om.Matrix('raw.m', Eg). Should the Eg array overwrite the loaded array? Should it throw an error? If the former, then mat = om.Matrix('raw.m', values=values) ought to be allowed; load the energy vectors but overwrite the matrix with new values.
Forcing keywords have the other advantage of removing bugs of the type mat = om.Matrix(values, Ex, Eg), since with keywords we get the obviously correct mat = om.Matrix(values, Ex=Ex, Eg=Eg).
I agree with Erlend. In the code, we quite often create some (new) matrices using the type mat = om.Matrix(values, Ex, Eg). So I think it might be nice to have following signatures:
mat = om.Matrix('raw.m') -> load path
mat = om.Matrix(values, Ex=..., Eg=...) --> load matrix
mat = om.Matrix('raw.m', Eg) --> give an error
mat = om.Matrix('raw.m', values=values) --> give an error
mat = om.Matrix(values) --> is this really relevant / potentially again give an error
If a Matrix object is constructed with a single argument, the argument is currently assumes this argument to be an array containing the matrix. However, I think that the most common way to use the matrix class will not to pass a Numpy array, but to pass the path to the file. It would therefore be more intuitive if one could call the constructor with
mat = ompy.matrix("raw_spectra.m")
rather thanmat = ompy.matrix(path="raw_spectra.m")
One way to solve this could be that if there is only one argument, then the constructor checks the type of the argument, and based on if's a string or a Numpy array it proceeds with the appropriate steps.
I suggest that one could do such a check for this with something like:
The text was updated successfully, but these errors were encountered: