Open KronosTheLate opened 1 year ago
Perhaps https://github.com/SciML/LinearSolve.jl/blob/8550cf9d09bab8ab5086e7b0e09b2dee2dd6a949/src/common.jl#L107 can be updated to
u0 = similar(b, promote_type(eltype(A), eltype(b)), size(A, 2))
Should it not always be a Float64, as the process of producing the new elements involves division? Even in the case of eltype(A) = Int64?
From what I can see from the wikipedia article on invertible matrix(full disclosure, I only looked at the first) it seems like there are metods of inversion that do in fact not include division. So if such a method is used, your proposal seems perfect.
If, however, a method involving division is used, the element-type of the output will be Float64
in all cases, right? I suppose if Float32
was ever used for both matrices, it would be nice to have that as the element type of the output, which I believe could be achieved by the verbose promote_type(typeof(one(eltype(A))/one(eltype(A))), typeof(one(eltype(b))/one(eltype(b))))
. Would this verbose beast not be the right type for methods involving division, and your proposal of promote_type(eltype(A), eltype(b))
would be right for methods that do not involve division? Is such a splitting of cases based on solver even possible?
In theory it can also be a rational number. But your promotion there should work for that as well.
The promotion with or without division? The one without should be a nobrainer to make the default AFAICT, so that could be done immideatly. That closes the issue of original example at least. I can then make a new issue for the case of eltype(A) <: Integer && eltype(b) <: Integer.
I think without. If you make a PR and add your test case it should be good to go.
My idea with https://github.com/SciML/LinearSolve.jl/issues/206#issuecomment-1271773381 wasn't that it would cover all cases, just catch more ones. There is no good way I think to infer the correct type anyway.
The following code errors:
The error can be quite intimidating, however the problem is simple and bound to arise several times. Could a better error message be provided in this case?