-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some linear algebra, via reinterpret
#437
base: master
Are you sure you want to change the base?
Conversation
test/runtests.jl
Outdated
@@ -41,6 +41,16 @@ using Dates: | |||
|
|||
const colon = Base.:(:) | |||
|
|||
ambig = sort(detect_ambiguities(Unitful), by = a -> [string(a[1].name), string(a[2].module)]) | |||
if length(ambig) > 0 | |||
println(stdout, "detect_ambiguities(Unitful) found $(length(ambig)) issues:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was concerned about creating ambiguities, so made it print them before starting.
In the end, overloading mul!
not *
seems not to create problems. But there are (for me) 30 other ambiguities this detects (and prints out).
Now moved to #439 instead.
src/linearalgebra.jl
Outdated
function LinearAlgebra.mul!(C::StridedVecOrMat{<:AbstractQuantity{T}}, | ||
A::StridedMatrix{<:AbstractQuantity{T}}, | ||
B::StridedVecOrMat{<:AbstractQuantity{T}}, | ||
alpha::Bool, beta::Bool) where {T<:Base.HWNumber} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case α, β::Bool
is what A * B
produces. Allowing other pure numbers ought to be fine. Allowing these to have units I haven't looked into.
I have restricted to A, B, C
having the same eltype
, as I think this is what BLAS handles. Julia sometimes copies a matrix to promote e.g. Float64 * Float32, but I don't recall at what stage.
5-arg mul!
doesn't exist on 1.0, but that's OK, this will just never be called, so you'll get the slow but correct fallback.
Codecov Report
@@ Coverage Diff @@
## master #437 +/- ##
==========================================
+ Coverage 83.84% 83.97% +0.12%
==========================================
Files 16 17 +1
Lines 1337 1354 +17
==========================================
+ Hits 1121 1137 +16
- Misses 216 217 +1
Continue to review full report at Codecov.
|
_linearalgebra_count() | ||
u = inv(unit(eltype(A))) | ||
Tu = typeof(one(eltype(C0)) * u) | ||
return reinterpret(Tu, C0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that these methods will return a ReinterpretArray{Quantity{...
not a Matrix
. There's no obvious analogue the mul!
overloaded for A * B
.
Codecov Report
@@ Coverage Diff @@
## master #437 +/- ##
=========================================
Coverage ? 82.05%
=========================================
Files ? 17
Lines ? 1393
Branches ? 0
=========================================
Hits ? 1143
Misses ? 250
Partials ? 0
Continue to review full report at Codecov.
|
This is a start on #46.