Repository navigation
[3.0] Generic Matrix Math #2528
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
base: develop/3.0
Are you sure you want to change the base?
Changes from 1 commit
3c95d6d
04846e7
7afd57f
249be1f
709c142
94a912d
051785d
88b8405
d1eade9
9b68e35
6a3cf88
cc7ebb6
6af8612
737b5a8
191de4e
1cecebe
291ec1e
cfee012
91c7982
650f30b
8ebcfb9
9bd27fe
a617eb8
d57f94d
d5a8b54
3c538bd
4f74ab3
c9e57f2
a4b8a6c
5a82141
16e68e2
7efc1eb
0cb1569
c9ce628
aac298a
25f6994
41aa58d
0f2d43c
09e674c
070c6f5
aefd7ea
acaf6b4
ffb7f58
d07c355
80fbbfc
2a79fd8
5e0e7d9
5973151
69be9de
75b1c5d
ac8e94e
f71206c
0345ba5
9497be8
9aa76de
2d6c95b
1c2b6f8
bfe143c
de7b9f1
be95c6b
7099d0d
a9ad742
55cfcf8
7770ded
09e6b93
3f38988
0b61138
43a8130
5d73712
6ae88de
516c52e
38b1672
59587cd
6c9eace
c54f0bf
1ea91c9
c2c5cd0
43868c3
8e06b11
b36e272
a9c2add
6599187
bf41b90
f3c058b
69c3403
10a1266
883061c
beac54d
4b0d54f
dbf1a86
1b466f1
e6f4ba9
7230574
faa5a22
483d41b
69b7c1c
be372bd
2f28558
de43e88
5db55ad
a6d33cd
443df2c
b265dde
253048f
4f81855
8782ca4
7ea4b10
681f214
fe5e1cb
0b95fc8
71731b4
09617fc
f9b294a
4228f25
7142a6b
3547040
112f6ce
41fb5be
4a09494
8606907
c3ac0c0
5fcac20
56ec1c8
e08d3aa
5fa6c58
b1dd62b
e2f7dff
d326d31
3ebd6bf
51999ca
481fb53
e902edc
339fb48
8021f43
128071f
cf6375e
0d8933e
e5ae355
f5b5dce
8627d6a
88f8402
3212049
0db5cb6
129207c
42fb35a
9410cc5
856095a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .vs/ | ||
| bin/ | ||
| obj/ | ||
| /DemoLibrary/**/*.cs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 18 | ||
| VisualStudioVersion = 18.3.11505.172 d18.3 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateMatrixMath", "GenerateMatrixMath\GenerateMatrixMath.csproj", "{505330B8-C28A-4E36-AC44-3C48BF551B34}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {505330B8-C28A-4E36-AC44-3C48BF551B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {505330B8-C28A-4E36-AC44-3C48BF551B34}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {505330B8-C28A-4E36-AC44-3C48BF551B34}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {505330B8-C28A-4E36-AC44-3C48BF551B34}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {6A29E176-1DE7-4A4E-A935-7B5D223FEFE9} | ||
| EndGlobalSection | ||
| EndGlobal |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ static void Main() | |
| }; | ||
|
|
||
| var outputPaths = new[] { | ||
| @"C:\Users\otac0n\Projects\Silk.NET\sources\Maths\Maths\", | ||
| @"W:\projects\Silk.NET\sources\Maths\Maths\", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded, consider introducing a GetOutputPath method which has a CallerFilePathAttribute argument with which you can then use a relative path instead. |
||
| }; | ||
|
|
||
| var dims = new HashSet<Dimension>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ namespace Silk.NET.Maths | |
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Numerics; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| /// <summary>A structure encapsulating a {{= size}} matrix.</summary> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the documentation comment denote this structure as row-major? |
||
|
|
@@ -186,56 +187,126 @@ namespace Silk.NET.Maths | |
| /// <param name="left">The first matrix to compare.</param> | ||
| /// <param name="right">The second matrix to compare.</param> | ||
| /// <returns><c>true</c> if the given matrices are equal; <c>false</c> otherwise.</returns> | ||
| public static bool operator ==({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| {{each r in rows}}left.Row{{= r}} == right.Row{{= r}}{{delimit}} && | ||
| {{/each}}; | ||
| {{if generateNumericsCast}} | ||
| public static bool operator ==({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
| return Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(left) == Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(right); | ||
| return {{each r in rows}}left.Row{{= r}} == right.Row{{= r}}{{delimit}} && | ||
| {{/each}}; | ||
| } | ||
| {{else}} | ||
| public static bool operator ==({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| {{each r in rows}}left.Row{{= r}} == right.Row{{= r}}{{delimit}} && | ||
| {{/each}}; | ||
| {{/if}} | ||
|
|
||
| /// <summary>Returns a boolean indicating whether the given two matrices are not equal.</summary> | ||
| /// <param name="left">The first matrix to compare.</param> | ||
| /// <param name="right">The second matrix to compare.</param> | ||
| /// <returns><c>true</c> if the given matrices are not equal; <c>false</c> otherwise.</returns> | ||
| public static bool operator !=({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| {{each r in rows}}left.Row{{= r}} != right.Row{{= r}}{{delimit}} || | ||
| {{/each}}; | ||
| {{if generateNumericsCast}} | ||
| public static bool operator !=({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our experience methods that have generic specialisation should be AggressiveInlining and AggressiveOptimization, otherwise you run the risk of having shared generics if the inliner blows its budget with the standard settings. |
||
| return Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(left) != Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(right); | ||
| return {{each r in rows}}left.Row{{= r}} != right.Row{{= r}}{{delimit}} || | ||
| {{/each}}; | ||
| } | ||
| {{else}} | ||
| public static bool operator !=({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| {{each r in rows}}left.Row{{= r}} != right.Row{{= r}}{{delimit}} || | ||
| {{/each}}; | ||
| {{/if}} | ||
|
|
||
| /// <summary>Adds two matrices together.</summary> | ||
| /// <param name="left">The first source matrix.</param> | ||
| /// <param name="right">The second source matrix.</param> | ||
| /// <returns>The result of the addition.</returns> | ||
| public static {{@Name thisType}}<T> operator +({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| new({{each r in rows}}left.Row{{= r}} + right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{if generateNumericsCast}} | ||
| public static {{@Name thisType}}<T> operator +({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
| return Unsafe.BitCast<{{= numericsName}}, {{@Name thisType}}<T>>(Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(left) + Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(right)); | ||
| return new({{each r in rows}}left.Row{{= r}} + right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| } | ||
| {{else}} | ||
| public static {{@Name thisType}}<T> operator +({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| new({{each r in rows}}left.Row{{= r}} + right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{/if}} | ||
|
|
||
| /// <summary>Subtracts the second matrix from the first.</summary> | ||
| /// <param name="left">The first source matrix.</param> | ||
| /// <param name="right">The second source matrix.</param> | ||
| /// <returns>The result of the subtraction.</returns> | ||
| public static {{@Name thisType}}<T> operator -({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| new({{each r in rows}}left.Row{{= r}} - right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{if generateNumericsCast}} | ||
| public static {{@Name thisType}}<T> operator -({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
| return Unsafe.BitCast<{{= numericsName}}, {{@Name thisType}}<T>>(Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(left) - Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(right)); | ||
| return new({{each r in rows}}left.Row{{= r}} - right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| } | ||
| {{else}} | ||
| public static {{@Name thisType}}<T> operator -({{@Name thisType}}<T> left, {{@Name thisType}}<T> right) => | ||
| new({{each r in rows}}left.Row{{= r}} - right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{/if}} | ||
|
|
||
| /// <summary>Returns a new matrix with the negated elements of the given matrix.</summary> | ||
| /// <param name="value">The source matrix.</param> | ||
| /// <returns>The negated matrix.</returns> | ||
| public static {{@Name thisType}}<T> operator -({{@Name thisType}}<T> value) => | ||
| new({{each r in rows}}-value.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{if generateNumericsCast}} | ||
| public static {{@Name thisType}}<T> operator -({{@Name thisType}}<T> value) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
| return Unsafe.BitCast<{{= numericsName}}, {{@Name thisType}}<T>>(-Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(value)); | ||
| return new({{each r in rows}}-value.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| } | ||
| {{else}} | ||
| public static {{@Name thisType}}<T> operator -({{@Name thisType}}<T> value) => | ||
| new({{each r in rows}}-value.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{/if}} | ||
|
|
||
| /// <summary>Multiplies a matrix by a scalar value.</summary> | ||
| /// <param name="left">The scaling factor.</param> | ||
| /// <param name="right">The source matrix.</param> | ||
| /// <returns>The scaled matrix.</returns> | ||
| public static {{@Name thisType}}<T> operator *(T left, {{@Name thisType}}<T> right) => | ||
| new({{each r in rows}}left * right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{if generateNumericsCast}} | ||
| public static {{@Name thisType}}<T> operator *(T left, {{@Name thisType}}<T> right) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
| return Unsafe.BitCast<{{= numericsName}}, {{@Name thisType}}<T>>(Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(right) * Unsafe.BitCast<T, float>(left)); | ||
| return new({{each r in rows}}left * right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| } | ||
| {{else}} | ||
| public static {{@Name thisType}}<T> operator *(T left, {{@Name thisType}}<T> right) => | ||
| new({{each r in rows}}left * right.Row{{= r}}{{delimit}}, | ||
| {{/each}}); | ||
| {{/if}} | ||
|
|
||
| /// <summary>Multiplies a matrix by a scalar value.</summary> | ||
| /// <param name="left">The source matrix.</param> | ||
| /// <param name="right">The scaling factor.</param> | ||
| /// <returns>The scaled matrix.</returns> | ||
| public static {{@Name thisType}}<T> operator *({{@Name thisType}}<T> left, T right) => | ||
| new({{each r in rows}}left.Row{{= r}} * right{{delimit}}, | ||
| {{/each}}); | ||
| {{if generateNumericsCast}} | ||
| public static {{@Name thisType}}<T> operator *({{@Name thisType}}<T> left, T right) | ||
| { | ||
| if (typeof(T) == typeof(float)) | ||
| return Unsafe.BitCast<{{= numericsName}}, {{@Name thisType}}<T>>(Unsafe.BitCast<{{@Name thisType}}<T>, {{= numericsName}}>(left) * Unsafe.BitCast<T, float>(right)); | ||
| return new({{each r in rows}}left.Row{{= r}} * right{{delimit}}, | ||
| {{/each}}); | ||
| } | ||
| {{else}} | ||
| public static {{@Name thisType}}<T> operator *({{@Name thisType}}<T> left, T right) => | ||
| new({{each r in rows}}left.Row{{= r}} * right{{delimit}}, | ||
| {{/each}}); | ||
| {{/if}} | ||
|
|
||
| {{if size.Columns < 5 && size.Rows < 5}} | ||
| {{ | ||
|
|
||
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.
Suggest deleting, all of this should be handled by the top-level gitignore (save for DemoLibrary which shouldn't exist anyway but appreciate this was probably used for point-in-time demoing :))