-
Notifications
You must be signed in to change notification settings - Fork 43
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
Implement dot product #209
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -203,3 +203,9 @@ function invquad(a::PDiagMat{<:Real,<:Vector}, x::Matrix) | |||||
return invquad!(Vector{T}(undef, size(x, 2)), a, x) | ||||||
end | ||||||
|
||||||
### dot product | ||||||
|
||||||
function LinearAlgebra.dot(x::AbstractVector, a::PDiagMat, y::AbstractVector) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we restrict this to
Suggested change
? |
||||||
dot(x, Diagonal(a.diag), y) | ||||||
end | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -187,3 +187,9 @@ function Xt_invA_X(a::ScalMat, x::Matrix{<:Real}) | |||||||||
@check_argdims LinearAlgebra.checksquare(a) == size(x, 1) | ||||||||||
return Symmetric(_rdiv!(transpose(x) * x, a.value)) | ||||||||||
end | ||||||||||
|
||||||||||
### dot product | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
Suggested change
|
||||||||||
function LinearAlgebra.dot(x::AbstractVector, a::ScalMat, y::AbstractVector) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check that the dimensions match:
Suggested change
|
||||||||||
dot(x, UniformScaling(a.value), y) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess even simpler would be
Suggested change
? |
||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,3 +28,13 @@ end | |||||||||
@test isposdef(PDMat([1.0 0.0; 0.0 1.0])) | ||||||||||
@test isposdef(PDiagMat([1.0, 1.0])) | ||||||||||
@test isposdef(ScalMat(2, 3.0)) | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
@testset "dot products" begin | ||||||||||
pm1 = PDiagMat([1., 2., 3.]) | ||||||||||
pm2 = ScalMat(3, 2.) | ||||||||||
x = [13., 42., .7] | ||||||||||
y = [0.5, .125, 20.24] | ||||||||||
|
||||||||||
@test dot(x, pm1, y) ≈ dot(x, Matrix(pm1), y) | ||||||||||
@test dot(x, pm2, y) ≈ dot(x, Matrix(pm2), y) | ||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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.
This has to be put behind a version check: