Skip to content
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

Remove inv_value and inv_diag #146

Merged
merged 4 commits into from
Nov 17, 2021
Merged

Remove inv_value and inv_diag #146

merged 4 commits into from
Nov 17, 2021

Conversation

devmotion
Copy link
Member

Alternative to #141 that removes inv_value and inv_diag fields from ScalMat and PDiagMat.

Advantages compared with the current master branch are that there are no problems (incompatible types or undesired type promotions) with vectors and values where the inverse are of different type. Two helper functions are added that use division instead of operating with inv(value) directly to avoid undesired type promotions (e.g., if x isa AbstractVector{Float32} and value isa Int, then inv(value) * x isa AbstractVector{Float64} whereas x / value isa AbstractVector{Float32}).

@@ -132,7 +127,7 @@ end
### tri products

function X_A_Xt(a::PDiagMat, x::StridedMatrix)
z = x .* reshape(sqrt.(a.diag), 1, dim(a))
z = x .* sqrt.(reshape(a.diag, 1, dim(a)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and similar line below) should be fixed in any case. It seems the current implementation prevents broadcast fusion and creates an additional intermediate array.

src/scalmat.jl Outdated
@@ -92,10 +89,10 @@ end

function X_invA_Xt(a::ScalMat, x::StridedMatrix)
@check_argdims dim(a) == size(x, 2)
lmul!(a.inv_value, x * transpose(x))
ldiv!(a.value, x * transpose(x))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems ldiv!(::Number, ::AbstractArray) is not available on Julia 1.0. I did not realize this since there is no note in the docstring: https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.ldiv!

@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2021

Codecov Report

Merging #146 (35a9832) into master (635a957) will decrease coverage by 0.52%.
The diff coverage is 83.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #146      +/-   ##
==========================================
- Coverage   88.85%   88.33%   -0.53%     
==========================================
  Files           8        8              
  Lines         377      403      +26     
==========================================
+ Hits          335      356      +21     
- Misses         42       47       +5     
Impacted Files Coverage Δ
src/scalmat.jl 94.00% <77.77%> (-0.12%) ⬇️
src/utils.jl 88.37% <80.76%> (-3.30%) ⬇️
src/pdiagmat.jl 97.77% <90.00%> (+0.02%) ⬆️
src/chol.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 635a957...35a9832. Read the comment docs.

@devmotion
Copy link
Member Author

@Wynand I also added your failing example as a test.

@andreasnoack
Copy link
Member

Should we consider this a breaking change?

1 similar comment
@andreasnoack
Copy link
Member

Should we consider this a breaking change?

@devmotion
Copy link
Member Author

It is supposed to be non-breaking - I deprecated the constructors but considered the fields to be not part of the public API (alternatively, I could add a deprecation warning in getproperty). But maybe it's safer to tag a breaking release?

@andreasnoack
Copy link
Member

It would at least break https://github.com/devmotion/CalibrationErrorsDistributions.jl/blob/41be6f90f9cf57e3f9e8333d3d1f4eb73d55002e/src/mvnormal.jl#L106 which might be familiar to you so maybe let's bump the minor version.

@andreasnoack
Copy link
Member

I went through all the direct dependencies and yours is the only one that touches the field so I'd also be okay with just making it a patch release.

@devmotion
Copy link
Member Author

Ah I'd like to avoid breaking my package, even if it accesses (internal?) fields 😄 I'll update the package in a way that does not use inv_diag/inv_value first before merging this PR.

@devmotion
Copy link
Member Author

I fixed CalibrationErrorsDistributions and updated the README which I forgot initially.

@devmotion
Copy link
Member Author

I'd also be okay with just making it a patch release.

Now I'm fine with it as well 🙂

@devmotion devmotion merged commit 2f3a83e into master Nov 17, 2021
@devmotion devmotion deleted the dw/inv branch November 17, 2021 15:02
@@ -1,6 +1,6 @@
name = "PDMats"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.3"
version = "0.11.4"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have bumped to 0.11.5? It looks like 0.11.4 was already released when this was merged: https://github.com/JuliaStats/PDMats.jl/releases/tag/v0.11.4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should, JuliaRegistrator noticed it as well: 2f3a83e#commitcomment-60431201 The PR was created before the other PR was merged and released, so the diff in the PR was outdated and based on an earlier version of the master branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it: 15fecad 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants