-
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
More conversion in PDMat
#212
base: master
Are you sure you want to change the base?
Conversation
The eltype restriction is just a small cleanup. The key aspect of this is the "constructor cascade" that supports conversion/coercion via Also, #188 is a pretty deep change, and it's been open for more than a year. I hoped this could get merged quickly and a new release made. |
Concretely, if one runs the test block "test the functionality" from this PR on Testing PDMat{Float32, Matrix{Float32}} of size (3, 3)
PDMat from Matrix: Error During Test at REPL[8]:7
Got exception outside of a @test
MethodError: no method matching (PDMat{Float64})(::Matrix{Float32})
Stacktrace: and several similar errors. |
If you're OK with it, I'd plan to solve the failure on Julia 1.0 by dropping support for anything before 1.10. Since this package is still in 0.x releases, we don't have to bump the minor version to do so. The CI error on nightly is unrelated to this PR. |
I'm fine with that but I'm still curious which and why some of the changes are problematic on Julia 1.0. |
I'm a little puzzled about that as well. But it's only the julia> @code_typed PDMat(S, C)
CodeInfo(
22 1 ─ %1 = %new(PDMat{Float64,SArray{Tuple{4,4},Float64,2,16}}, mat, chol)::PDMat{Float64,SArray{Tuple{4,4},Float64,2,16}} │╻ Type
└── return %1 │
) => PDMat{Float64,SArray{Tuple{4,4},Float64,2,16}} it's a little weird that it allocates at all. I dunno, I am not personally that interested in pursuing why Julia 1.0 allocates in this circumstance. |
You may want to think about whether we want a5c0ce8, I added it hoping that it would fix the allocations on Julia 1.0. But it doesn't, and it makes the code more verbose; on the other hand, it tightens the applicability of the methods to things that can actually work. Let me know whether you'd prefer to drop it or keep it. |
This adds a "constructor cascade" that allows one to coerce the inputs to the chosen type. This is frequently useful in generic programming where you want an object to be of the same type as something else, for example when appending to a list of objects. Co-authored-by: David Widmann <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #212 +/- ##
==========================================
- Coverage 92.12% 91.56% -0.56%
==========================================
Files 9 9
Lines 660 676 +16
==========================================
+ Hits 608 619 +11
- Misses 52 57 +5 ☔ View full report in Codecov by Sentry. |
This should be ready. Let me know if you want more changes. And thanks for the review, it was very helpful. |
This allows one to convert both the eltype and matrix type. In practice, my main use for this is to support generic programming with both
Matrix
andStaticArrays.SMatrix
.Perhaps the only potentially-controversial aspect is moving the dimensionality check into the inner constructor. If we want to make it impossible to construct an inconsistent
PDMat
, that's where it has to be.