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

Matrix operators #398

Merged
merged 12 commits into from
May 8, 2021
Merged

Matrix operators #398

merged 12 commits into from
May 8, 2021

Conversation

WhiteBlackGoose
Copy link
Member

|+, |-, |*, |/, |** will return an instance of Matrix, no matter what. Any feedback on the API?

@WhiteBlackGoose WhiteBlackGoose added Proposal Contribute to the project by proposing some improvements Opinions wanted We are interested in your opinion about the topic labels Apr 29, 2021
@WhiteBlackGoose WhiteBlackGoose linked an issue Apr 29, 2021 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2021

Codecov Report

Merging #398 (78fd180) into master (11e738f) will decrease coverage by 0.03%.
The diff coverage is 82.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
- Coverage   80.61%   80.57%   -0.04%     
==========================================
  Files         145      145              
  Lines       12451    12512      +61     
  Branches     1676     1704      +28     
==========================================
+ Hits        10037    10082      +45     
- Misses       1902     1919      +17     
+ Partials      512      511       -1     
Impacted Files Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 68.22% <ø> (+0.27%) ⬆️
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 84.80% <ø> (+1.99%) ⬆️
...rces/AngouriMath/Core/Entity/Omni/Entity.Matrix.cs 79.39% <82.60%> (+0.42%) ⬆️
...iMath/Core/Exceptions/UserInputInvalidException.cs 69.23% <0.00%> (-7.70%) ⬇️
...inuous/Solvers/EquationSolver/ExponentialSolver.cs 92.64% <0.00%> (-2.95%) ⬇️
...Solvers/EquationSolver/AnalyticalEquationSolver.cs 81.25% <0.00%> (-2.09%) ⬇️
Sources/AngouriMath/Core/Parser.cs 88.00% <0.00%> (+6.42%) ⬆️

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 11e738f...78fd180. Read the comment docs.

@WhiteBlackGoose WhiteBlackGoose added the Area: F# The issue is related to the AngouriMath.FSharp package label May 2, 2021
@WhiteBlackGoose WhiteBlackGoose linked an issue May 5, 2021 that may be closed by this pull request
@WhiteBlackGoose
Copy link
Member Author

Moving PeterONumbers from 1.7.4 to 1.8 broke a couple of tests, 🦆

@WhiteBlackGoose WhiteBlackGoose linked an issue May 6, 2021 that may be closed by this pull request
[Fact] public void PowI_2() => Test(Pow(i, 2), "-1");
[Fact] public void PowI_I() => Test(Pow(i, i), "0.2078795763507619085469556198349787700338778416317696080751358830554198772854821397886002778654260353");
[Fact] public void Pow0D5M0D8I_0D5() => Test(Pow(0.5m-0.8m*i, 0.5m), "0.8495287261787150364907695626370349126367049237188233590072351305588742785045041120988684216395800850 - 0.4708492928770629369416080841473292873459093837847060526082076263776372676635818831502937646218684434i");
[Fact] public void Sqrt0D5M0D8I() => Test(Sqrt(0.5m-0.8m*i), "0.8495287261787150364907695626370349126367049237188233590072351305588742785045041120988684216395800853 - 0.4708492928770629369416080841473292873459093837847060526082076263776372676635818831502937646218684426i");
[Fact] public void Pow3P2I_3M2I() => Test(Pow(3+2*i,3-2*i), "105.7489754858859776057429151808913270583911891854438642007164406579203854865458413612560669739008053 - 109.0885464095191985068230453514141449073149001480712525014939233398460315014292268679635166428957469i");
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 all stuff... due to some precision regression in PeterO.Numbers 1.8.0 (as compared to 1.7.4, the previous version). Should be reported to their repo.

Copy link
Member

Choose a reason for hiding this comment

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

Then is there a reason to update?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just because updated is better than non-updated?

@WhiteBlackGoose WhiteBlackGoose marked this pull request as ready for review May 7, 2021 15:52
public void TestInverseWithGT101Issue400(string matrixRaw)
{
Matrix a = matrixRaw;
var inverse = a.Inverse!;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

ThrowWhenNull is an attribute for return though. null is a perfectly valid return from Inverse. So I'll just make a Assert.NotNull (I actually thought that ! throws an exception!)

Copy link
Member

Choose a reason for hiding this comment

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

ThrowWhenNull is not an attribute, and [NotNull] can be specified at the argument position as documented.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can check, now it's AsNotNull<>.

public static T AsNotNull<T>(T? value)
{
Assert.NotNull(value);
return value!;
}

[Fact] public void PowI_2() => Test(Pow(i, 2), "-1");
[Fact] public void PowI_I() => Test(Pow(i, i), "0.2078795763507619085469556198349787700338778416317696080751358830554198772854821397886002778654260353");
[Fact] public void Pow0D5M0D8I_0D5() => Test(Pow(0.5m-0.8m*i, 0.5m), "0.8495287261787150364907695626370349126367049237188233590072351305588742785045041120988684216395800850 - 0.4708492928770629369416080841473292873459093837847060526082076263776372676635818831502937646218684434i");
[Fact] public void Sqrt0D5M0D8I() => Test(Sqrt(0.5m-0.8m*i), "0.8495287261787150364907695626370349126367049237188233590072351305588742785045041120988684216395800853 - 0.4708492928770629369416080841473292873459093837847060526082076263776372676635818831502937646218684426i");
[Fact] public void Pow3P2I_3M2I() => Test(Pow(3+2*i,3-2*i), "105.7489754858859776057429151808913270583911891854438642007164406579203854865458413612560669739008053 - 109.0885464095191985068230453514141449073149001480712525014939233398460315014292268679635166428957469i");
Copy link
Member

Choose a reason for hiding this comment

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

Then is there a reason to update?

.Substitute("B", 2)
.Substitute("C", 3)
.Substitute("D", 4);
Assert.Equal(-2, v.EvalNumerical());
Assert.NotNull(v);
Assert.Equal(-2, v!.EvalNumerical());
Copy link
Member

Choose a reason for hiding this comment

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

public Entity? Determinant => determinant.GetValue(
static @this =>
{
if ([email protected])
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this check be in GenericTensor?

Copy link
Member Author

@WhiteBlackGoose WhiteBlackGoose May 7, 2021

Choose a reason for hiding this comment

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

Yes, but it is exception-based. Here we want to return a null in that case. (sure we can catch exceptions, but... quack. Maybe we will after the GenericTensorBaseException implemented)

Copy link
Member

Choose a reason for hiding this comment

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

Then don't throw exceptions in GenericTensor!

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +212 to +216
if ([email protected])
return null;
if (@this.Determinant is null)
return null;
if (@this.Determinant == 0)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these checks be in GenericTensor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same thing, we want to return null to avoid an exception

Copy link
Member

Choose a reason for hiding this comment

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

Then don't throw exceptions in GenericTensor!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmmmmmmmmmmmmmmmmmmmmmmmmmm. We can have 1.0.1-noexcept package for it. Since if you remember, there's ALLOW_EXCEPTION flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

@MomoDeve would love this

Comment on lines 8 to 12
(*

Matrix and matrix operators

*)
Copy link
Member

Choose a reason for hiding this comment

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

This can be just a single-line comment

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 was trying to make it "bold" :).

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol

Sources/Wrappers/AngouriMath.FSharp/MatrixOperators.fs Outdated Show resolved Hide resolved
Comment on lines 26 to 31
(*

Matrix and scalar operators
Scalar and matrix operators

*)
Copy link
Member

Choose a reason for hiding this comment

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

Can be two single-line comments

@WhiteBlackGoose WhiteBlackGoose merged commit ce56555 into master May 8, 2021
@WhiteBlackGoose WhiteBlackGoose deleted the matrix-operators branch May 30, 2021 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: F# The issue is related to the AngouriMath.FSharp package Opinions wanted We are interested in your opinion about the topic Proposal Contribute to the project by proposing some improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No exception for Adjugate and Inverse Unexpected inverse Matrix operators
3 participants