Giter Site home page Giter Site logo

john-h-k / mathsharp Goto Github PK

View Code? Open in Web Editor NEW
692.0 28.0 51.0 5.12 MB

A vector and matrix library written in C# using hardware intrinsics

License: MIT License

C# 95.63% Batchfile 0.11% Shell 1.52% PowerShell 1.39% Python 1.34%
hardware-intrinsics vector csharp dotnet dotnet-core 3d-graphics matrix vector-graphics

mathsharp's Introduction

MathSharp

Note: As of 2022 MathSharp is not recommended for general use

Since its inception, the .NET intrinsics and vectors have increased in performance and functionality massively, and they are recommended for any new projects

ko-fi Buy Me A Coffee

MIT license GitHub issues

Configuration Windows x86 Windows x64 Ubuntu 1604 x64 Mac OS x64
Debug Build Status Build Status Build Status Build Status
Release Build Status Build Status Build Status Build Status

MathSharp is a vector and matrix library written in C# using hardware intrinsics. Thanks to hardware acceleration, MathSharp is significantly faster than most mathematics libraries out there, but only supports .NET Core 3.0 and up.

MathSharp beats out all alternative for speed. Comparing it to the System.Numerics types and the OpenTk.Math types shows just how fast it is:

[All benchmarks were taken using BenchmarkDotNet on an i3-8350k at stock speeds with minimal background activity, with .NET Core 3.0.100]

Matrix Equality

Operation

Matrix4x4 == Matrix4x4

Results

Method Mean Error StdDev
OpenTk 10.984 ns 0.1087 ns 0.1017 ns
SystemNumerics 3.895 ns 0.0185 ns 0.0164 ns
MathSharp 1.622 ns 0.0109 ns 0.0102 ns

Matrix Transposition

Operation

Transpose(Matrix4x4)

Results

Method Mean Error StdDev
OpenTk 10.984 ns 0.1087 ns 0.1017 ns
SystemNumerics 3.895 ns 0.0185 ns 0.0164 ns
MathSharp 1.622 ns 0.0109 ns 0.0102 ns

Sine Wave Generation

Operation

const int SampleRate = 44100;
const float Tau = MathF.PI * 2;
const float Frequency = 440;

for (var i = 0; i < waveInputs.Length; i++)
{
    waveInputs[i] = Sin(Tau * Frequency * ((float)i / SampleRate));
}

Results

Method Mean Error StdDev
SystemMathF 412.30 us 1.6319 us 1.5265 us
MathSharp 80.37 us 0.6465 us 0.6048 us

Anchored Scale Operation

Operation

const Vector2 Translation = new Vector2(1.7f, 2.3f);
const Vector2 Anchor = new Vector2(1.0f, 0.0f);
const Vector2 Scale = new Vector2(7.0f, 3.6f);
const Vector2 Amount = new Vector2(0.5f, 0.25f);

Vector2 newScale = Scale * Amount;
Vector2 deltaT = Scale * (1 - Amount);
deltaT *= Anchor;
(Translation + deltaT) * newScale;

Results

Method Mean Error StdDev Rank
MathSharp 0.8542 ns 0.0084 ns 0.0079 ns 1
SystemNumerics 2.0281 ns 0.0123 ns 0.0115 ns 2
OpenTk 37.4250 ns 0.1585 ns 0.1483 ns 3

Vector addition

Operation

Vector4 + Vector4;

Results (within margin of error between MathSharp and System.Numerics)

Method Mean Error StdDev
OpenTk 6.5341 ns 0.0392 ns 0.0367 ns
SystemNumerics 0.0510 ns 0.0080 ns 0.0075 ns
MathSharp 0.0426 ns 0.0043 ns 0.0040 ns

Authors

MathSharp is a library written, managed, and maintained by John Kelly (@john-h-k)

How to use

TODO

Contributing

MathSharp uses and encourages Early Pull Requests. Please don't wait until you're done to open a PR!

  1. Install Git and the .Net Core SDK
  2. Fork MathSharp
  3. Create a branch on your fork.
  4. Add an empty commit to start your work off (and let you open a PR): git commit --allow-empty -m "start of [thing you're working on]"
  5. Open a Pull request with [WIP] in the title. Do this before you actually start working.
  6. Make your commits in small, incremental steps with clear descriptions.
  7. Tag a maintainer when you're done and ask for a review!

Click here for good first issues.

Click here for everything we need help with.

License & Copyright

MathSharp is licensed under the MIT license. Full copyright belongs to @john-h-k.

mathsharp's People

Contributors

fabpk90 avatar jay-madden avatar john-h-k avatar kozilord avatar macaba avatar perksey avatar tannergooding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mathsharp's Issues

Feasiblity of remove strong-name signing?

Strong-name signing isn't really used anymore and has caused a bunch of issues in OpenTK, thus we no longer recommend it. Plus, NuGet.org has it's own signature validation system so snk isn't really needed.

Consider removal?

[PROPOSAL] Adding a performance project to MathSharp

Proposal:

To make sure there is no performance regression in the repository, having a benchmark project in the solution is a good first step. Then we can start from there adding some automation (CI) to make sure a PR won’t impact the code negatively.

I proposed using the NuGet BenchmarkDotNet which is pretty much an industry standard.

Can't build after cloning repo

Hello,

I cloned the repo and tried both running the build.cmd script and going through visual studio build solution. Both have the following error:

I'm not sure if i'm doing something wrong, but I see this error:

1>C:\Users\aruss\Downloads\MathSharp-master\sources\MathSharp\Vector\Shared\BitComparisons.cs(8,33,8,39): error CS0101: The namespace 'MathSharp' already contains a definition for 'Vector'

Thanks

[PROPOSAL] Make all operations use 128 bit wide vectors and create a new API for 256 bit wide vectors.

Currently doubles use 256 wide vectors for vectorized math which can cause downclocking on most modern CPUs, there's also no way to use 256 bit wide vectors for float math.
I think adding a new static class named something like HeavyVector which would mirror the Vector class but that uses AVX instructions with fallbacks to SSE and software would allow users to decide for themselves if downclocking is worth it for their use case.

Geodesy

Any interest in a namespace for Geodesy algorithms?
I've just done a vector implementation of the Haversine formula (great circle distance between 2 points on a sphere model) and would be happy to contribute.

[PROPOSAL] Adding a documentation project to Math#

Using DocFX, it’s possible to automatically get a documentation website that is in synced with the source implementation. A good use case for this proposal is to quickly check the differences between the math library here and the one located in opentk.

Alternatives

None at the time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.