-
-
Notifications
You must be signed in to change notification settings - Fork 431
[WIP] [2.0] A maths library for Silk.NET #190
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
Conversation
aren't some of these types a bit redundant given SysNumerics ( |
1 similar comment
This comment has been minimized.
This comment has been minimized.
should implementations forward to .net (5) implementations as much as possible or re-implement everything? |
also, will this be available to other projects separately? |
@HurricanKai We can forward the float implementations to System.Numerics using Unsafe where applicable they'll likely be faster. Given that this is primarily targeting .NET Standard 2.0 (apart from hardware acceleration which will be done via multi-targeting), there's not much else we can do forwarding-wise. @HurricanKai (2) Yep, it won't even depend on Silk.NET.Core. It will be entirely standalone. @john-h-k There's no way I'll get the APIs I want in System.Numerics within this decade due to API review, so I have to do it here. As for MathSharp, well I mean MathSharp's just an intrinsics library right (albeit providing some minimal storage types) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@Perksey In line with what dotnet/runtime does, and also because I'd think performance wise it makes more sense, I'd suggest things like |
Yeah that'd make more sense, fine by me 👍 |
What is |
Yeah that's what it should be, didn't take into account NumberFormatInfo when originally speccing the API |
What's |
Ah you can ignore that, Length was gonna be var xhalf = 0.5f * x;
var i = *(int*)&x; // Read bits as integer.
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
x = *(float*)&i; // Convert bits back to float
x = x * (1.5f - (xhalf * x * x)); // Perform left single Newton-Raphson step.
return x; But in this day and age LengthFast is probably slower so you should just remove LengthFast, as well as most other *Fast methods as the implementation you come up with is likely as fast as it can be, and adding "fast" overloads will probably just end up confusing users. Sorry about all this, I had pulled up on the other screen the API spec for another maths library and wrote the overloads without thinking. |
or just use |
Hardware acceleration is coming after we have initial software prototypes ;)
…On Mon, 15 Jun 2020 at 18:32, John Kelly ***@***.***> wrote:
where InverseSqrtFast is:
or just use Sse.ReciprocalSqrt 😄 which is an approximation and super
super fast (way faster than 1 / qsrt)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#190 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACVEYI4MNCXK57WBE7NB6DLRWZLMDANCNFSM4N6JRMDQ>
.
|
what is |
The perpendicular dot product is |
What is |
Ah it interpolates 3 Vectors using Barycentric coordinates (so it returns a when u=0v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise). We should probably move these questions to Discord and the GitHub thread is getting pretty full |
* Add Scalar<T>.Two * Add Scalar<T>.Smaller * Add Scalar<T> SmallerEquals & LargerEquals * Implement Box2<T> * Make Min/Max public * Missed Equals * Box3<T> * Make Box2/3 readonly * Add With methods * Rename past tense Methods
* Make Vecttor2<T> readonly * Make Vector3<T> readonly * Make Vector4<T> readonly * Rename past tense Methods
Will begin with Matrix4x4 :) |
Awesome :D |
* Nullability * CLS compliance * Rename CLSCompliant.cs to AssemblyInfo.cs * <Nullable>enable</Nullable>
All Scalar methods with 9+ block need to be split up into multiple < 9 block functions. |
Damn that is really really unfortunate, but necessary if it poses a nuisance. I'm fine with that being done, albeit a little sad. |
For reference, G_M60209_IG01:
4883EC28 sub rsp, 40
C5F877 vzeroupper
G_M60209_IG02:
C5FA100519000000 vmovss xmm0, dword ptr [reloc @RWD00]
C5FA100D15000000 vmovss xmm1, dword ptr [reloc @RWD04]
E894F7FFFF call Silk.NET.Maths.Scalar`1[Single][System.Single]:Multiply(float,float):float
90 nop
G_M60209_IG03:
4883C428 add rsp, 40
C3 ret
RWD00 dd 3FC90FDBh
RWD04 dd 40000000h Split Multiply: G_M60209_IG01:
C5F877 vzeroupper
G_M60209_IG02:
C5FA100505000000 vmovss xmm0, dword ptr [reloc @RWD00]
G_M60209_IG03:
C3 ret
RWD00 dd 40490FDBh that's a rather big difference for a multiply |
Interesting, that is a massive improvement. |
currently exposing more of |
* Add Basic Scalar Tests & Fix Scalar mistakes * netcoreapp5.0 -> net5.0
src/Maths/Silk.NET.Maths/Scalar.cs
Outdated
@@ -248,57 +248,57 @@ public static T SquareRoot(T value) | |||
{ | |||
if (typeof(T) == typeof(byte)) | |||
{ | |||
return (T) (object) (MathF.Sqrt((byte) (object) value)); | |||
return (T) (object) (byte) (MathF.Sqrt((byte) (object) value)); |
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.
Don't lie about integral square root. Either this should use an integral square root path, or it should be not supported. Users will get very unexpected results doing this
src/Maths/Silk.NET.Maths/Scalar.cs
Outdated
@@ -1071,12 +1071,12 @@ public static T Acos(T value) | |||
|
|||
if (typeof(T) == typeof(ulong)) | |||
{ | |||
return (T) (object) (Math.Acos((ulong) (object) value)); | |||
return (T) (object) (ulong) (Math.Acos((ulong) (object) value)); |
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.
CC above. You shouldn't "fake" floating point ops on integral types
Co-authored-by: Dylan Perks <dmp9biz@gmail.com>
@HurricanKai It's probably best we close this PR and reopen it anew seeing as you've taken over maths development - the PR is currently still in my name. |
👍 |
HELP WANTED!
Help us implement the maths library (intrinsics not required, can be done at a later date)
Nice-to-haves
Information about generic implementations
Summary of the PR
Adds a maths library that patches in the holes left by System.Numerics.
What version does this PR target?
2.0
Related issues, Discord discussions, or proposals
Links go here.
Further Comments