Skip to content

Conversation

@CheukHinHoJerry
Copy link
Contributor

@CheukHinHoJerry CheukHinHoJerry commented Jun 16, 2023

Ref #178 (comment)

Basically I just replace the type constrain of 'ForwardDiff.Dual' to 'HyperDualNumbers.Hyper' and create an extra module. Haven't done any serious test on it but it works okay on my end.

I guess it might be possible to combine into a single ext with ForwardDiff.Dual but I will just leave something workable for now since I am not sure where/how should I do this properly.

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Patch coverage: 86.95% and project coverage change: +3.97 🎉

Comparison is base (00d50b3) 86.42% compared to head (1a10ea4) 90.40%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
+ Coverage   86.42%   90.40%   +3.97%     
==========================================
  Files          13       14       +1     
  Lines        1002     1146     +144     
==========================================
+ Hits          866     1036     +170     
+ Misses        136      110      -26     
Impacted Files Coverage Δ
src/Octavian.jl 100.00% <ø> (+100.00%) ⬆️
ext/HyperDualNumbersExt.jl 86.95% <86.95%> (ø)

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@chriselrod
Copy link
Collaborator

Mind adding tests, adding hyper duals as a test dependency?
You can compare the answers with a naive or base multiplication.
I'd reinterpret to Float64 before comparing, because comparisons tend to only check the value, and not any of the partials.


Octavian.matmul!(C1, A1, B1, α, β)
LinearAlgebra.mul!(C2, A2, B2, α, β)
@test C1 ≈ C2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@test C1 C2
@test reinterpretH(C1) reinterpretHD(C2)


function reinterpretHD(T, A)
tmp = reinterpret(T, A)
return tmp[1:4:end, :]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the slice?

Copy link
Contributor Author

@CheukHinHoJerry CheukHinHoJerry Jun 17, 2023

Choose a reason for hiding this comment

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

reinterpreting a $N \times M$ matrix containing HyperDuals returns a $4N \times M$ matrix containing val, $\epsilon_{1}$, $\epsilon_{2}$ and $\epsilon_{12}$ part of each of the entries.

This is essentially checking only the val part of the matrix $A$.

I will do some updates and name the tests properly on what they are checking.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we also want to check the epsilons?

Copy link
Contributor Author

@CheukHinHoJerry CheukHinHoJerry Jun 17, 2023

Choose a reason for hiding this comment

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

I thought what you mean in #179 (comment) is that we only check val part. Sorry for misunderstanding that and I will fix it now.

Copy link
Collaborator

@chriselrod chriselrod Jun 17, 2023

Choose a reason for hiding this comment

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

I meant that is what isapprox only checks the real part, so we need to reinterpret to check the entire thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now check the entire thing and it should be ready for review. Sorry for iterating so many times.

@CheukHinHoJerry
Copy link
Contributor Author

CheukHinHoJerry commented Jun 17, 2023

Stucked on a bug on two dual arrays since I was not notcing it would be a bit different as in ForwardDiff.Dual but just got that fix and it should be fine now. Basically I checked:

  • real array mul from right
  • real array mul from left
  • tranpose arrays
  • two dual arrays

Now I check also the correectness of the epsilons and the reinterpredHD function is now a sanity check which I use LinearAlgebra.mul! to calcualte only the val part of the result. I think this can be removed but it doesn't harm if we keep that.

Copy link
Collaborator

@chriselrod chriselrod left a comment

Choose a reason for hiding this comment

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

Okay, great!
One last thing: mind bumping the version, so we can tag a new release?

A1dual = randdual(A1)
C1dual = randdual(C1)

A2dual = deepcopy(A1dual)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, but some of these copies are unnecessary.

@CheukHinHoJerry
Copy link
Contributor Author

Okay, great! One last thing: mind bumping the version, so we can tag a new release?

Just bumped to 0.3.23. Thank you for your review.

@chriselrod chriselrod merged commit a37ae26 into JuliaLinearAlgebra:master Jun 18, 2023
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.

2 participants