namespace arrange; final wrap scheduale solution

This commit is contained in:
Youmu Liu
2025-10-13 20:59:14 +08:00
parent 31f649015c
commit a95e9b1ff7
44 changed files with 683 additions and 926 deletions
+12 -20
View File
@@ -28,20 +28,12 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using StgSharp.Graphics.ShaderEdit;
using StgSharp.HighPerformance;
using StgSharp.Mathematics;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics
namespace StgSharp.Mathematics.Graphic
{
public sealed class Camera : IglConvertable
{
@@ -150,7 +142,7 @@ namespace StgSharp.Graphics
public unsafe void SetAllUniforms()
{
// Console.WriteLine(Projection * ViewBase);
OpenGL.OpenGLFunction.CurrentGL.SetUniformValue(convertedUniform, Projection * View);
OpenGLFunction.CurrentGL.SetUniformValue(convertedUniform, Projection * View);
}
public void SetViewDirection(Vec3 position, Vec3 target, Vec3 up)
@@ -172,7 +164,7 @@ namespace StgSharp.Graphics
_isLookAtAvailable = false;
Linear.Orthogonalize(ref direction, ref up);
direction.Orthogonalize(ref up);
Vec3 right = Linear.Orthogonalize(Linear.Cross(up, direction));
@@ -186,24 +178,24 @@ namespace StgSharp.Graphics
InternalYaw();
}
public void SetViewRange(Radius fovRadius, Vec2 size, Vec2 offset, (float front, float back) dephRange)
public void SetViewRange(Radius fovRadius, Vec2 size, Vec2 offset, (float front, float back) depthRange)
{
float
distance = _target.GetLength(),
near = distance - dephRange.front,
far = distance + dephRange.back,
near = distance - depthRange.front,
far = distance + depthRange.back,
offsetX = offset.X,
offsetY = offset.Y,
width = Scaler.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
height = (width * size.Y) / size.X;
height = width * size.Y / size.X;
_projection.colum0.X = (2 * near) / width;
_projection.colum1.Y = (2 * near) / height;
_projection.colum2.X = (2 * offsetX) / width;
_projection.colum2.Y = (2 * offsetY) / height;
_projection.colum0.X = 2 * near / width;
_projection.colum1.Y = 2 * near / height;
_projection.colum2.X = 2 * offsetX / width;
_projection.colum2.Y = 2 * offsetY / height;
_projection.colum2.Z = (far + near) / (near - far);
_projection.colum2.W = -1;
_projection.colum3.Z = (2 * near * far) / (near - far);
_projection.colum3.Z = 2 * near * far / (near - far);
}
public void Test(params Vec4[] vec)
@@ -29,7 +29,7 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Internal.Intrinsic;
using StgSharp.Mathematics.Numeric;
using System;
using System.ComponentModel;
using System.Drawing;
@@ -37,9 +37,9 @@ using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Graphic
{
[StructLayout(LayoutKind.Explicit, Size = (2 * 16 * sizeof(float)) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = 2 * 16 * sizeof(float) + sizeof(bool), Pack = 16)]
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMatrix<Matrix44>
{
@@ -115,9 +115,9 @@ namespace StgSharp.Mathematics
}
#endif
InternalTranspose();
fixed (float* p = &this.transpose.m00)
fixed (float* p = &transpose.m00)
{
ulong pBit = ((ulong)p) + (((ulong)sizeof(Vector4)) * ((ulong)rowNum)) + (((ulong)sizeof(float)) * ((ulong)columNum));
ulong pBit = (ulong)p + (ulong)sizeof(Vector4) * (ulong)rowNum + sizeof(float) * (ulong)columNum;
return *(float*)pBit;
}
}
@@ -133,9 +133,9 @@ namespace StgSharp.Mathematics
}
#endif
InternalTranspose();
fixed (float* p = &this.transpose.m00)
fixed (float* p = &transpose.m00)
{
ulong pbit = ((ulong)p) + (((ulong)sizeof(Vector4)) * ((ulong)rowNum)) + (((ulong)sizeof(float)) * ((ulong)columNum));
ulong pbit = (ulong)p + (ulong)sizeof(Vector4) * (ulong)rowNum + sizeof(float) * (ulong)columNum;
*(float*)pbit = value;
}
isTransposed = false;
@@ -147,7 +147,7 @@ namespace StgSharp.Mathematics
get
{
InternalTranspose();
return new Matrix44(this.transpose);
return new Matrix44(transpose);
}
}
@@ -169,7 +169,7 @@ namespace StgSharp.Mathematics
public override bool Equals(object? obj)
{
return (obj is Matrix44 x) && Equals(x);
return obj is Matrix44 x && Equals(x);
}
public bool Equals(Matrix44 other)
@@ -197,6 +197,8 @@ namespace StgSharp.Mathematics
{
fixed (ColumnSet4* source = &mat, target = &transpose)
{
InternalIO.Intrinsic.f32_transpose(source, target);
// InternalIO.Intrinsic.transpose44(source, target);
}
isTransposed = true;
@@ -29,20 +29,20 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.Mathematics.Numeric;
using System.Net.Http.Headers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Graphic
{
/// <summary>
/// A two dimension vector defined by two elements. Vec2 in World are default used as colum
/// vector.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec2 : IFixedVector<Vec2>
public struct Vec2 : IUnmanagedVector<Vec2>
{
[FieldOffset(0)] internal unsafe fixed float num[2];
@@ -108,7 +108,7 @@ namespace StgSharp.Mathematics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Cross(Vec2 right)
{
return (X * right.Y) - (Y * right.X);
return X * right.Y - Y * right.X;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -29,6 +29,7 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.Mathematics.Numeric;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -36,11 +37,11 @@ using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Graphic
{
[CollectionBuilder(typeof(Vec3), nameof(Vec3.FromSpan))]
[CollectionBuilder(typeof(Vec3), nameof(FromSpan))]
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec3 : IEquatable<Vec3>, IFixedVector<Vec3>, IEnumerable<float>
public struct Vec3 : IEquatable<Vec3>, IUnmanagedVector<Vec3>, IEnumerable<float>
{
[FieldOffset(0)] internal unsafe fixed float num[3];
@@ -93,7 +94,7 @@ namespace StgSharp.Mathematics
public unsafe Vec2 XY
{
get => new Vec2(this.reg);
get => new Vec2(reg);
set
{
fixed (Vector3* vptr = &v) {
@@ -132,7 +133,7 @@ namespace StgSharp.Mathematics
public bool Equals(Vec3 other)
{
return this.reg == other.reg;
return reg == other.reg;
}
public override bool Equals(object obj)
@@ -171,8 +172,8 @@ namespace StgSharp.Mathematics
public float GetMaxValue()
{
float ret = X;
ret = (ret > Y) ? ret : Y;
ret = (ret > Z) ? ret : Z;
ret = ret > Y ? ret : Y;
ret = ret > Z ? ret : Z;
return ret;
}
@@ -30,18 +30,17 @@
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.Internal.Intrinsic;
using StgSharp.Mathematics;
using StgSharp.Mathematics.Numeric;
using System;
using System.Data.Common;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Graphic
{
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec4 : IEquatable<Vec4>, IFixedVector<Vec4>
public struct Vec4 : IEquatable<Vec4>, IUnmanagedVector<Vec4>
{
[FieldOffset(0)] internal unsafe fixed float num[4];
@@ -131,7 +130,7 @@ namespace StgSharp.Mathematics
public override bool Equals(object obj)
{
return (obj is Vec4 v) ? (v == this) : false;
return obj is Vec4 v ? v == this : false;
}
public override int GetHashCode()
@@ -1,7 +1,7 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Vec4HP.cs"
// Project: StgSharp
// file="Vector.Cross.cs"
// Project: World
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
@@ -28,43 +28,25 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.Mathematics.Graphic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics.HighPrecision
namespace StgSharp.Mathematics.Graphic
{
[StructLayout(LayoutKind.Explicit, Pack =16)]
public struct Vec4HP : IFixedVector<Vec4HP>
public static unsafe partial class Linear
{
[FieldOffset(0)] private M256 buffer;
[FieldOffset(0)] private Vector256<float> clrBuffer;
[FieldOffset(3 * sizeof(double))] public double W;
[FieldOffset(0 * sizeof(double))] public double X;
[FieldOffset(1 * sizeof(double))] public double Y;
[FieldOffset(2 * sizeof(double))] public double Z;
public Vec4HP(double x, double y, double z, double w)
public static float Cross(Vec2 vec1, Vec2 vec2)
{
this.X = x;
this.Y = y;
this.Z = z;
this.W = w;
Unsafe.SkipInit(out buffer);
Unsafe.SkipInit(out clrBuffer);
return (vec1.X * vec2.Y) - (vec1.Y * vec2.X);
}
public static Vec4HP Zero => new Vec4HP(0, 0, 0, 0);
public static Vec4HP One => new Vec4HP(1, 1, 1, 1);
public static Vec3 Cross(Vec3 vec1, Vec3 vec2)
{
return new Vec3(
(vec1.Y * vec2.Z) - (vec1.Z * vec2.Y),
(vec1.X * vec2.Z) - (vec1.Z * vec2.X),
(vec1.X * vec2.Y) - (vec1.Y * vec2.X));
}
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Vec2HP.cs"
// file="Vector.GetAngle.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -28,40 +28,23 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.Mathematics.Graphic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics.HighPrecision
namespace StgSharp.Mathematics.Graphic
{
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public struct Vec2HP : IFixedVector<Vec2HP>
public static unsafe partial class Linear
{
[FieldOffset(0)] private M256 buffer;
[FieldOffset(0)] private Vector256<float> clrBuffer;
[FieldOffset(0 * sizeof(double))] public double X;
[FieldOffset(1 * sizeof(double))] public double Y;
public Vec2HP(double x, double y)
public static float GetAngle(Vec2 vec1, Vec2 vec2)
{
this.X = x;
this.Y = y;
Unsafe.SkipInit(out buffer);
Unsafe.SkipInit(out clrBuffer);
return Scaler.ACos(
1 / (vec1.GetLength() * vec2.GetLength()));
}
public static Vec2HP Zero => new Vec2HP(0, 0);
public static Vec2HP One => new Vec2HP(1, 1);
public static float GetAngle(Vec3 vec1, Vec3 vec2)
{
return Scaler.ACos((vec1 * vec2) / (vec1.GetLength() * vec2.GetLength()));
}
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixMarshal.cs"
// file="Vector.GetLength.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -28,13 +28,22 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StgSharp.Mathematics.Graphic;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Graphic
{
public readonly ref struct MatrixMarshal { }
public static unsafe partial class Linear
{
public static float GetLength(this Vec3 vec)
{
return Scaler.Sqrt(vec.Dot(vec));
}
public static float GetLength(this Vec2 vec)
{
return Scaler.Sqrt(vec.Dot(vec));
}
}
}
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Vector.Normalize.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Mathematics.Graphic;
using System.Numerics;
namespace StgSharp.Mathematics.Graphic
{
public static partial class Linear
{
public static Vec4 Normalize(Vec4 vec)
{
return new Vec4
{
vec = Vector4.Normalize(vec.vec)
};
}
public static Vec3 Normalize(Vec3 vec)
{
return new Vec3
{
v = Vector3.Normalize(vec.v)
};
}
public static unsafe void Normalize(ref Vec4 source, ref Vec4 target)
{
Vector4 s = source.vec;
Vector4 t = target.vec;
s = Vector4.Normalize(s);
Vector4 projection = Vector4.Multiply(s, t);
t -= projection;
source.vec = s;
target.vec = t;
}
public static unsafe void Normalize(ref Vec3 source, ref Vec3 target)
{
Vector3 s = source.v;
Vector3 t = target.v;
s = Vector3.Normalize(s);
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
t -= projection;
t = Vector3.Normalize(t);
source.v = s;
target.v = t;
}
}
}
@@ -1,7 +1,7 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Vec3HP.cs"
// Project: StgSharp
// file="Vector.Orthogonalize.cs"
// Project: World
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
@@ -28,58 +28,67 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.Mathematics.Graphic;
using System.Numerics;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics.HighPrecision
namespace StgSharp.Mathematics.Graphic
{
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public struct Vec3HP : IFixedVector<Vec3HP>
public static partial class Linear
{
[FieldOffset(0)] internal M256 buffer;
[FieldOffset(0)] internal Vector256<float> clrBuffer;
[FieldOffset(0 * sizeof(double))] public double X;
[FieldOffset(1 * sizeof(double))] public double Y;
[FieldOffset(2 * sizeof(double))] public double Z;
public Vec3HP() : this(0, 0, 0) { }
public Vec3HP(Vector256<float> clrBuffer)
public static Vec4 Orthogonalize(this Vec4 vec)
{
this.X = 0;
this.Y = 0;
this.Z = 0;
Unsafe.SkipInit(out buffer);
Unsafe.SkipInit(out this.clrBuffer);
this.clrBuffer = clrBuffer;
return new Vec4
{
vec = Vector4.Normalize(vec.vec)
};
}
public Vec3HP(double x, double y, double z)
public static Vec3 Orthogonalize(Vec3 vec)
{
this.X = x;
this.Y = y;
this.Z = z;
Unsafe.SkipInit(out buffer);
Unsafe.SkipInit(out clrBuffer);
return new Vec3
{
v = Vector3.Normalize(vec.v)
};
}
public static Vec3HP Zero => new Vec3HP(1, 1, 1);
public static Vec3HP One => throw new NotImplementedException();
public override string ToString()
public static unsafe void Orthogonalize(this Vec4 source, ref Vec4 target)
{
return $"Double precision 3D Vector<{X},{Y},{Z}>";
Vector4 s = source.vec;
Vector4 t = target.vec;
s = Vector4.Normalize(s);
Vector4 projection = Vector4.Multiply(s, t);
t -= projection;
source.vec = s;
target.vec = t;
}
/// <summary>
/// Orthogonalize two <see cref="Vec3" />s, let their length be 1 and perpendicular to
/// each other.
/// </summary>
/// <param _label="source">
///
/// </param>
/// <param _label="target">
///
/// </param>
public static unsafe void Orthogonalize(this Vec3 source, ref Vec3 target)
{
Vector3 s = source.v;
Vector3 t = target.v;
s = Vector3.Normalize(s);
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
t -= projection;
t = Vector3.Normalize(t);
source.v = s;
target.v = t;
}
}
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
public enum CoordinatePlain
{
+26 -26
View File
@@ -1,40 +1,40 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IMatrix.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// -----------------------------------------------------------------------
// file="IMatrix.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
public interface IMatrix<TSelf> where TSelf: IMatrix<TSelf> { }
}
@@ -36,9 +36,9 @@ using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
public interface IFixedVector<TSelf> where TSelf: unmanaged, IFixedVector<TSelf>
public interface IUnmanagedVector<TSelf> where TSelf: unmanaged, IUnmanagedVector<TSelf>
{
public static abstract TSelf Zero { get; }
@@ -1,86 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Matrix.Basic.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
public static class Matrix
{
public static Matrix<float> Add(Matrix<float> left, Matrix<float> right)
{
if (left.ColumnLength != right.ColumnLength || left.RowLength != right.RowLength) {
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
}
MatrixParallel.LeadParallel();
try
{
Matrix<float> result = GCMatrix<float>.FromDefault(left.ColumnLength, left.RowLength);
unsafe
{
MatrixParallelTaskPackage<float>* handle = MatrixParallelFactory.CreateBaseTask<float>();
handle->Left = left.Buffer;
handle->Right = right.Buffer;
handle->Result = result.Buffer;
handle->ComputeHandle = (IntPtr)InternalIO.Intrinsic.f32_add;
handle->LeftPrimOffset = 0;
handle->RightPrimOffset = 0;
handle->LeftPrimStride = left.KernelColumnLength;
handle->LeftSecOffset = 1;
handle->LeftPrimOffset = 0;
handle->RightPrimOffset = 0;
handle->RightPrimStride = right.KernelColumnLength;
handle->RightSecOffset = 1;
handle->RightPrimOffset = 0;
handle->ResultPrimOffset = 0;
handle->ResultPrimStride = result.KernelColumnLength;
handle->ResultSecOffset = 1;
handle->ResultPrimOffset = 0;
handle->PrimCount = left.KernelRowLength;
handle->SecCount = left.KernelColumnLength;
}
MatrixParallel.LaunchParallel(SleepMode.DeepSleep);
return result;
}
finally
{
MatrixParallel.EndParallel();
}
}
}
}
@@ -39,7 +39,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
internal unsafe partial class GCMatrix<T> : Matrix<T> where T: unmanaged, INumber<T>
{
@@ -40,7 +40,7 @@ using System.Threading.Tasks;
using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
internal unsafe partial class HlsfMatrix<T> : Matrix<T> where T: unmanaged, INumber<T>
{
+2 -2
View File
@@ -38,7 +38,7 @@ using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegrega
// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
public abstract unsafe partial class Matrix<T> where T: unmanaged, INumber<T>
{
@@ -147,13 +147,13 @@ namespace StgSharp.Mathematics
{
private readonly MatrixKernel<T>* _source = source;
internal readonly int SecondaryStride = secondaryStride;
internal readonly int PrimOffset = primOffset;
internal readonly int PrimSize = primSize;
internal readonly int PrimStride = primStride;
internal readonly int SecondaryOffset = secondaryOffset;
internal readonly int SecondarySize = secondarySize;
internal readonly int SecondaryStride = secondaryStride;
internal readonly MatrixKernel<T>* Source
{
@@ -34,7 +34,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
public enum MatrixAllocation
{
@@ -29,14 +29,10 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
namespace StgSharp.Mathematics.Numeric
{
[StructLayout(LayoutKind.Sequential)]
public readonly struct MatrixIndex
@@ -1,187 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixParallel.Execute.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Runtime.CompilerServices;
namespace StgSharp.Mathematics
{
public static partial class MatrixParallel
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe void Compute_Binary(MatrixParallelTaskPackageNonGeneric* p)
{
int eSize = p->ElementSize;
nint l = p->Left, r = p->Right, a = p->Result;
long
lCount = (long)p->LeftPrimOffset * p->LeftPrimStride,
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
pCount = p->PrimCount,
lLimit = pCount - p->LeftPrimOffset,
rLimit = pCount - p->RightPrimOffset,
aLimit = pCount - p->ResultPrimOffset;
delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, void> op =
(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, void>)p->ComputeHandle;
for (long i = 0; i < pCount; i++)
{
lCount = i < lLimit ? lCount + p->LeftPrimOffset : 0;
rCount = i < rLimit ? rCount + p->RightPrimOffset : 0;
aCount = i < rLimit ? aCount + p->ResultPrimOffset : 0;
nint left = l + (nint)(lCount * eSize);
nint right = r + (nint)(rCount * eSize);
nint ans = a + (nint)(aCount * eSize);
long
lc = (long)p->LeftSecOffset * p->LeftSecStride,
rc = (long)p->RightSecOffset * p->RightSecStride,
ac = (long)p->ResultSecOffset * p->ResultSecStride,
sCount = p->SecCount;
long
ll = sCount - p->LeftSecOffset,
rl = sCount - p->RightSecOffset,
al = sCount - p->ResultSecOffset;
for (int j = 0; j < sCount; j++)
{
lc = j < ll ? lc + p->LeftSecOffset : 0;
rc = j < rl ? rc + p->RightSecOffset : 0;
ac = j < al ? ac + p->ResultSecOffset : 0;
op(left + (nint)lc, right + (nint)rc, ans + (nint)ac);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe void Compute_BinaryScalar(MatrixParallelTaskPackageNonGeneric* p)
{
nint l = p->Left, r = p->Right, a = p->Result;
long
lCount = p->LeftPrimOffset * p->LeftPrimStride,
rCount = p->RightPrimOffset * p->RightPrimStride,
aCount = p->ResultPrimOffset * p->ResultPrimStride,
pCount = p->PrimCount;
long
lLimit = pCount - p->LeftPrimOffset,
rLimit = pCount - p->RightPrimOffset,
aLimit = pCount - p->ResultPrimOffset;
delegate* unmanaged[Cdecl]<nint, nint, nint, ScalarPacket*, void> op =
(delegate* unmanaged[Cdecl]<nint, nint, nint, ScalarPacket*, void>)p->ComputeHandle;
ScalarPacket* scalar = p->Scalar;
for (long i = 0; i < pCount; i++)
{
lCount = i < lLimit ? lCount + p->LeftPrimOffset : 0;
rCount = i < rLimit ? rCount + p->RightPrimOffset : 0;
aCount = i < rLimit ? aCount + p->ResultPrimOffset : 0;
nint
left = l + (nint)lCount,
right = r + (nint)rCount,
ans = a + (nint)aCount;
long
lc = p->LeftSecOffset * p->LeftSecStride,
rc = p->RightSecOffset * p->RightSecStride,
ac = p->ResultSecOffset * p->ResultSecStride,
sCount = p->SecCount,
ll = sCount - p->LeftSecOffset,
rl = sCount - p->RightSecOffset,
al = sCount - p->ResultSecOffset;
for (int j = 0; j < sCount; j++)
{
lc = j < ll ? lc + p->LeftSecOffset : 0;
rc = j < rl ? rc + p->RightSecOffset : 0;
ac = j < al ? ac + p->ResultSecOffset : 0;
op(left + (nint)lc, right + (nint)rc, ans + (nint)ac, scalar);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe void Compute_Unary(MatrixParallelTaskPackageNonGeneric* p)
{
nint s = p->Right, a = p->Result;
long rCount = p->RightPrimOffset * p->RightPrimStride,
aCount = p->ResultPrimOffset * p->ResultPrimStride,
pCount = p->PrimCount;
long rLimit = pCount - p->RightPrimOffset,
aLimit = pCount - p->ResultPrimOffset;
delegate* unmanaged[Cdecl]<nint, nint, void> op =
(delegate* unmanaged[Cdecl]<nint, nint, void>)p->ComputeHandle;
for (long i = 0; i < pCount; i++)
{
rCount = i < rLimit ? rCount + p->RightPrimOffset : 0;
aCount = i < rLimit ? aCount + p->ResultPrimOffset : 0;
nint source = s + (nint)rCount, ans = a + (nint)aCount;
long rc = p->RightSecOffset * p->RightSecStride,
ac = p->ResultSecOffset * p->ResultSecStride,
sCount = p->SecCount;
long rl = sCount - p->RightSecOffset,
al = sCount - p->ResultSecOffset;
for (int j = 0; j < sCount; j++)
{
rc = j < rl ? rc + p->RightSecOffset : 0;
ac = j < al ? ac + p->ResultSecOffset : 0;
op(source + (nint)rc, ans + (nint)ac);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe void Compute_UnaryScalar(MatrixParallelTaskPackageNonGeneric* p)
{
nint s = p->Right, a = p->Result;
long rCount = p->RightPrimOffset * p->RightPrimStride,
aCount = p->ResultPrimOffset * p->ResultPrimStride,
pCount = p->PrimCount;
long rLimit = pCount - p->RightPrimOffset,
aLimit = pCount - p->ResultPrimOffset;
delegate* unmanaged[Cdecl]<nint, nint, ScalarPacket*, void> op =
(delegate* unmanaged[Cdecl]<nint, nint, ScalarPacket*, void>)p->ComputeHandle;
ScalarPacket* scalar = p->Scalar;
for (long i = 0; i < pCount; i++)
{
rCount = i < rLimit ? rCount + p->RightPrimOffset : 0;
aCount = i < rLimit ? aCount + p->ResultPrimOffset : 0;
nint source = s + (nint)rCount;
nint ans = a + (nint)aCount;
long rc = p->RightSecOffset * p->RightSecStride,
ac = p->ResultSecOffset * p->ResultSecStride,
sCount = p->SecCount;
long rl = sCount - p->RightSecOffset,
al = sCount - p->ResultSecOffset;
for (int j = 0; j < sCount; j++)
{
rc = j < rl ? rc + p->RightSecOffset : 0;
ac = j < al ? ac + p->ResultSecOffset : 0;
op(source + (nint)rc, ans + (nint)ac, scalar);
}
}
}
}
}
@@ -1,827 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixParallel.Publish.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
public static partial class MatrixParallel
{
public static unsafe void PublicTask<T>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation)
where T: unmanaged, INumber<T>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 1; // Unary
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation)
where T: unmanaged, INumber<T>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 3; // Binary
PublicTaskPrivate<T>(package);
}
// Unary with 1..8 scalars (each scalar is independent generic type)
public static unsafe void PublicTask<T, TScalar0>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2; // UnaryScalar
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
// Binary with 1..8 scalars (each scalar is independent generic type)
public static unsafe void PublicTask<T, TScalar0>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4; // BinaryScalar
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4, TScalar5>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4,
TScalar5 s5)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
where TScalar5: unmanaged, INumber<TScalar5>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
sp->Data<TScalar5>(5) = s5;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4, TScalar5, TScalar6>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4,
TScalar5 s5,
TScalar6 s6)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
where TScalar5: unmanaged, INumber<TScalar5>
where TScalar6: unmanaged, INumber<TScalar6>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
sp->Data<TScalar5>(5) = s5;
sp->Data<TScalar6>(6) = s6;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4, TScalar5>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4,
TScalar5 s5)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
where TScalar5: unmanaged, INumber<TScalar5>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
sp->Data<TScalar5>(5) = s5;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4, TScalar5, TScalar6, TScalar7>(
MatrixSegmentEnumeration<T> source,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4,
TScalar5 s5,
TScalar6 s6,
TScalar7 s7)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
where TScalar5: unmanaged, INumber<TScalar5>
where TScalar6: unmanaged, INumber<TScalar6>
where TScalar7: unmanaged, INumber<TScalar7>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Right = source.Source;
package->Result = ans.Source;
package->RightPrimOffset = source.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->RightPrimStride = source.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->RightSecOffset = source.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->RightSecStride = source.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = source.PrimSize;
package->SecCount = source.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 2;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
sp->Data<TScalar5>(5) = s5;
sp->Data<TScalar6>(6) = s6;
sp->Data<TScalar7>(7) = s7;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4, TScalar5, TScalar6>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4,
TScalar5 s5,
TScalar6 s6)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
where TScalar5: unmanaged, INumber<TScalar5>
where TScalar6: unmanaged, INumber<TScalar6>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
sp->Data<TScalar5>(5) = s5;
sp->Data<TScalar6>(6) = s6;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
public static unsafe void PublicTask<T, TScalar0, TScalar1, TScalar2, TScalar3, TScalar4, TScalar5, TScalar6, TScalar7>(
MatrixSegmentEnumeration<T> left,
MatrixSegmentEnumeration<T> right,
MatrixSegmentEnumeration<T> ans,
delegate*<MatrixKernel<T>*, MatrixKernel<T>*, MatrixKernel<T>*, void> Operation,
TScalar0 s0,
TScalar1 s1,
TScalar2 s2,
TScalar3 s3,
TScalar4 s4,
TScalar5 s5,
TScalar6 s6,
TScalar7 s7)
where T: unmanaged, INumber<T>
where TScalar0: unmanaged, INumber<TScalar0>
where TScalar1: unmanaged, INumber<TScalar1>
where TScalar2: unmanaged, INumber<TScalar2>
where TScalar3: unmanaged, INumber<TScalar3>
where TScalar4: unmanaged, INumber<TScalar4>
where TScalar5: unmanaged, INumber<TScalar5>
where TScalar6: unmanaged, INumber<TScalar6>
where TScalar7: unmanaged, INumber<TScalar7>
{
MatrixParallelTaskPackage<T>* package = MatrixParallelFactory.CreateBaseTask<T>();
package->Left = left.Source;
package->Right = right.Source;
package->Result = ans.Source;
package->LeftPrimOffset = left.PrimOffset;
package->RightPrimOffset = right.PrimOffset;
package->ResultPrimOffset = ans.PrimOffset;
package->LeftPrimStride = left.PrimStride;
package->RightPrimStride = right.PrimStride;
package->ResultPrimStride = ans.PrimStride;
package->LeftSecOffset = left.SecondaryOffset;
package->RightSecOffset = right.SecondaryOffset;
package->ResultSecOffset = ans.SecondaryOffset;
package->LeftSecStride = left.SecondaryStride;
package->RightSecStride = right.SecondaryStride;
package->ResultSecStride = ans.SecondaryStride;
package->PrimCount = left.PrimSize;
package->SecCount = left.SecondarySize;
package->ComputeHandle = (nint)Operation;
package->ElementSize = sizeof(T);
package->ComputeMode = 4;
ScalarPacket* sp = MatrixParallelFactory.CreateScalarPacket();
sp->Data<TScalar0>(0) = s0;
sp->Data<TScalar1>(1) = s1;
sp->Data<TScalar2>(2) = s2;
sp->Data<TScalar3>(3) = s3;
sp->Data<TScalar4>(4) = s4;
sp->Data<TScalar5>(5) = s5;
sp->Data<TScalar6>(6) = s6;
sp->Data<TScalar7>(7) = s7;
package->Scalar = sp;
PublicTaskPrivate<T>(package);
}
private static unsafe void PublicTaskPrivate<T>(MatrixParallelTaskPackage<T>* package)
where T: unmanaged, INumber<T>
{
int primCount = package->PrimCount;
int secCount = package->SecCount;
int threadPerGroup = (1024 / primCount) + 1;
secCount /= threadPerGroup;
}
}
}
@@ -1,210 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixParallel.Task.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Mathematics
{
public unsafe struct ScalarPacket
{
private fixed ulong data[8];
public ref T Data<T>(int index) where T: unmanaged,INumber<T>
{
if (index is < 0 or >= 8) {
throw new IndexOutOfRangeException();
}
return ref Unsafe.As<ulong, T>(ref data[index]);
}
}
[StructLayout(LayoutKind.Sequential)]
internal readonly unsafe struct MatrixParallelTaskPackageNonGeneric
{
#region source
// Group 1: Left/Right matrix kernel base address
public readonly IntPtr Left; // 8
public readonly IntPtr Right; // 8
#endregion
#region ans
// Group 2: Result kernel base address + reserved
public readonly IntPtr Result; // 8
public readonly int ElementSize;
public readonly int ReservedPtr0; // 4 (extension/reserved)
#endregion
#region left enum
public readonly int LeftPrimOffset; // 4
public readonly int LeftPrimStride; // 4
public readonly int LeftSecOffset; // 4
public readonly int LeftSecStride; // 4
#endregion
#region right enum
public readonly int RightPrimOffset; // 4
public readonly int RightPrimStride; // 4
public readonly int RightSecOffset; // 4
public readonly int RightSecStride; // 4
#endregion
#region ans enum
public readonly int ResultPrimOffset; // 4
public readonly int ResultPrimStride; // 4
public readonly int ResultSecOffset; // 4
public readonly int ResultSecStride; // 4
#endregion
#region scalar/compute
public readonly ScalarPacket* Scalar; // 8
public readonly IntPtr ComputeHandle; // 8
#endregion
#region global profile
public readonly int PrimCount; // 4
public readonly int ComputeMode; // 4
public readonly int SecCount; // 4
private readonly int ReservedInt0; // 4
#endregion
#region reserve
public readonly long ReservedLong0; // 8
public readonly long ReservedLong1; // 8
#endregion
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct MatrixParallelTaskPackage<T> where T: unmanaged, INumber<T>
{
public MatrixParallelTaskPackage()
{
Unsafe.SkipInit(out this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Copy(MatrixParallelTaskPackage<T>* source, MatrixParallelTaskPackage<T>* target)
{
Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage<T>), sizeof(MatrixParallelTaskPackage<T>));
}
#region source
// Group 1: Left/Right matrix kernel base address
public MatrixKernel<T>* Left; // 8
public MatrixKernel<T>* Right; // 8
#endregion
#region ans
// Group 2: Result kernel base address + reserved
public MatrixKernel<T>* Result; // 8
public int ElementSize = sizeof(T);
public int ReservedPtr0; // 4 (extension/reserved)
#endregion
#region left enum
public int LeftPrimOffset; // 4
public int LeftPrimStride; // 4
public int LeftSecOffset; // 4
public int LeftSecStride; // 4
#endregion
#region right enum
public int RightPrimOffset; // 4
public int RightPrimStride; // 4
public int RightSecOffset; // 4
public int RightSecStride; // 4
#endregion
#region ans enum
public int ResultPrimOffset; // 4
public int ResultPrimStride; // 4
public int ResultSecOffset; // 4
public int ResultSecStride; // 4
#endregion
#region scalar/compute
public ScalarPacket* Scalar; // 8
public IntPtr ComputeHandle; // 8
#endregion
#region global profile
public int PrimCount; // 4
public int ComputeMode; // 4
public int SecCount; // 4
private readonly int ReservedInt0; // 4
#endregion
#region reserve
public long ReservedLong0; // 8
public long ReservedLong1; // 8
#endregion
}
}
@@ -1,126 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixParallel.TaskFactory.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.HighPerformance.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using hlsfAllocator = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
namespace StgSharp.Mathematics
{
internal static unsafe class MatrixParallelFactory
{
private static hlsfAllocator _intermediateResult;
private static
#if NET9_0_OR_GREATER
Lock
#else
object
#endif
_hlsfLock = new();
private static SlabAllocator<ScalarPacket> _scalarAllocator ;
private static SlabAllocator<MatrixParallelTaskPackageNonGeneric> _wrapAllocator;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static MatrixParallelTaskPackage<T>* CreateBaseTask<T>() where T: unmanaged, INumber<T>
{
MatrixParallelTaskPackage<T>* p = (MatrixParallelTaskPackage<T>*)_wrapAllocator.Allocate();
Span<byte> s = new Span<byte>((byte*)p, sizeof(MatrixParallelTaskPackage<T>));
s.Fill(0);
return p;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ScalarPacket* CreateScalarPacket()
{
ScalarPacket* p = (ScalarPacket*)_scalarAllocator.Allocate();
return p;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe MatrixParallelTaskPackage<T>* FromExistPackage<T>(MatrixParallelTaskPackage<T>* exist)
where T: unmanaged, INumber<T>
{
MatrixParallelTaskPackage<T>* ptr = (MatrixParallelTaskPackage<T>*)_wrapAllocator.Allocate();
MatrixParallelTaskPackage<T>.Copy(exist, ptr);
return ptr;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Release(ScalarPacket* source)
{
_scalarAllocator.Free((nuint)source);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Release(MatrixParallelTaskPackageNonGeneric* source)
{
if (source->Scalar != null) {
_scalarAllocator.Free((nuint)source->Scalar);
}
_wrapAllocator.Free((nuint)source);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Release<T>(MatrixParallelTaskPackage<T>* source) where T: unmanaged, INumber<T>
{
if (source->Scalar != null) {
_scalarAllocator.Free((nuint)source->Scalar);
}
_wrapAllocator.Free((nuint)source);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Init()
{
if (_intermediateResult is null)
{
_intermediateResult = new hlsfAllocator(64 * 16 * 16);
_scalarAllocator = SlabAllocator<ScalarPacket>.Create(64 * 1024, SlabBufferLayout.Chunked);
_wrapAllocator = SlabAllocator<MatrixParallelTaskPackageNonGeneric>.
Create(128 * 1024, SlabBufferLayout.Chunked);
}
}
}
}
@@ -1,379 +0,0 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixParallel.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading;
namespace StgSharp.Mathematics
{
/*
* Thread wrapping to accelerate matrix operations by dividing threads into groups (wraps).
* For M wraps, each containing an average of N threads, we satisfy the condition M * N = T - 4,
* where T is the total thread count of the CPU. Typically, for modern consumer CPUs, T is around 16.
* For simplicity, let M * N = 16.
*
* The total time complexity for publishing tasks is O(M + N):
* - O(M) accounts for distributing tasks across M wraps.
* - O(N) accounts for threads within each wrap fetching tasks from the wrap queue.
*
* Using the inequality Sqrt(M * N) <= (M + N) / 2 (derived from the arithmetic-geometric mean inequality),
* the optimal configuration occurs when M = N. For M * N = 16, this gives M = N = 4.
*
* To ensure compatibility across a wide range of CPU architectures,
* we allow each wrap to contain either 3 or 4 threads, providing flexibility while maintaining efficiency.
*/
public static partial class MatrixParallel
{
// TODO
/*
* 目前认为应当按照如下方式进行调整:
* 1. 使用Queue进行线程束池化
* 2. 一次只能有一个线程进行发布活动(一次只能由一个线程持有)
* 3. 发布任务似乎应当分类进行,分类条件为q = n_task / n_thread
* 3.1 q=0时,不是全部任务束可以参与计算
* 3.2 q>0时,全部任务束可以参与计算
* 4. 后续分为a个q线程,b个q+1线程,然后分到线程束中,同时不保证束内任务同步
* 5. 仅可能保证线程间任务数量差异不超过512
*/
private static Thread[] _threads;
private static readonly (int a, int b)[] LookupTable = [
(1, 1), // 7
(0, 2), // 8 (no non-zero solution)
(3, 0), // 9 (no non-zero solution)
(2, 1), // 10
(1, 2), // 11
(0, 3), // 12 (no non-zero solution)
(3, 1), // 13
(2, 2), // 14
(1, 3), // 15
(4, 1), // 16
(3, 2), // 17
(2, 3), // 18
(1, 4), // 19
(4, 2), // 20
];
private static bool _meaningful;
private static volatile int RemainThreadCount = 0;
private static readonly object _lock = new();
private static ThreadPriority _AfterWork = ThreadPriority.Lowest;
public static bool SupportParallel { get; } = Environment.ProcessorCount > 6;
public static bool IsParallelMeaningful => Environment.ProcessorCount > 6 && IsInitialized;
public static MatrixParallelWrap.Handle LeaderHandle { get; private/**/ set; }
private static bool IsInitialized { get; set; } = false;
private static Queue<IntPtr> LeaderTask { get; set; }
public static void EndParallel()
{
Monitor.Exit(_lock);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (int count_3, int count_4) FastDecompose(int c)
{
if (c < 7) {
return (0, 0);
}
int t = c - 7;
int k = t / 14;
int d = t % 14;
(int a0, int b0) = LookupTable[d];
return (a0 + (2 * k), b0 + (2 * k));
}
public static void Init()
{
if (IsInitialized) {
return;
}
MatrixParallelFactory.Init();
if (!SupportParallel)
{
IsInitialized = true;
return;
}
int count = Environment.ProcessorCount - 4;
count = count == 5 ? 4 : count;
_threads = new Thread[count];
if (count < 6)
{
if (count == 3)
{
SmallWraps = [ new MatrixParallelWrap(0, count, true) ];
LargeWraps = [];
(LargeWrapCount, SmallWrapCount) = (0, 1);
LeaderHandle = new MatrixParallelWrap.Handle(0, SmallWraps[0]);
} else
{
count = 4;
LargeWraps = [ new MatrixParallelWrap(0, count, true) ];
SmallWraps = [];
(LargeWrapCount, SmallWrapCount) = (1, 0);
LeaderHandle = new MatrixParallelWrap.Handle(0, LargeWraps[0]);
}
} else if (count == 6)
{
SmallWraps = [ new MatrixParallelWrap(0, 3, true), new MatrixParallelWrap(3, 3, false) ];
LargeWraps = [];
(LargeWrapCount, SmallWrapCount) = (0, 2);
LeaderHandle = new MatrixParallelWrap.Handle(0, SmallWraps[0]);
} else
{
(int _3wrap, int _4wrap) = FastDecompose(count);
LargeWraps = new MatrixParallelWrap[_4wrap];
SmallWraps = new MatrixParallelWrap[_3wrap];
int id = 0;
for (int idx = 0; idx < _3wrap; idx++, id += 3) {
SmallWraps[idx] = new MatrixParallelWrap(idx, 3, id == 0);
}
for (int idx = 0; idx < _3wrap + _4wrap; idx++, id += 4) {
LargeWraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
}
LeaderHandle = new MatrixParallelWrap.Handle(0, _3wrap == 0 ? LargeWraps[0] : SmallWraps[0]);
}
LeaderTask = LeaderHandle.Wrap.GetWorkerTaskQueue(0);
IsInitialized = true;
}
public static void LaunchParallel(SleepMode afterWork)
{
RemainThreadCount = _threads.Length;
_AfterWork = (ThreadPriority)afterWork;
SetAllWrap();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LeadParallel()
{
Monitor.Enter(_lock);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void MatrixParallelLeaderWork()
{
MatrixParallelWrap.ExecuteTaskPackage(LeaderTask);
_ = Interlocked.Decrement(ref RemainThreadCount);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ResetThreadCount()
{
RemainThreadCount = _threads.Length;
}
public static void SetAllWrap()
{
ResetThreadCount();
foreach (MatrixParallelWrap item in LargeWraps) {
item.SchedulerReset.Set();
}
foreach (MatrixParallelWrap item in SmallWraps) {
item.SchedulerReset.Set();
}
}
public unsafe class MatrixParallelWrap
{
private readonly Queue<IntPtr>[] _cache;
private readonly Thread[] _threads;
private readonly ManualResetEventSlim[] _workerReset;
public MatrixParallelWrap(int id, int wrapSize, bool isFirst)
{
ID = id;
int begin = isFirst ? 1 : 0, end = wrapSize - 1;
_cache = new Queue<IntPtr>[wrapSize];
_workerReset = new ManualResetEventSlim[end];
_threads = new Thread[wrapSize];
for (int i = 0; i < end; i++) {
_workerReset[i] = new ManualResetEventSlim(false);
}
for (int i = 0; i < _cache.Length; i++) {
_cache[i] = new Queue<IntPtr>(8);
}
for (int i = begin; i < end; i++)
{
_threads[i] = new Thread(MatrixParallelWorker)
{
IsBackground = true,
Priority = ThreadPriority.BelowNormal,
Name = $"MPT#{ID}_{i}"
};
_threads[i].Start(new Handle(i, this));
}
_threads[end] = new Thread(MatrixParallelScheduler)
{
IsBackground = true,
Priority = ThreadPriority.BelowNormal,
Name = $"MPT#{ID}_{end}*"
};
_threads[end].Start(new Handle(end, this));
}
public int ID { get; init; }
internal ManualResetEventSlim SchedulerReset { get; } = new(false);
public Span<IntPtr> EnqueuePackage(Span<IntPtr> packageSpan)
{
int idx = 0;
for (; idx < _cache.Length; idx++) {
_cache[idx].Enqueue(packageSpan[idx]);
}
return packageSpan[idx..];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ManualResetEventSlim GetWorkerResetEvent(int id)
{
return _workerReset[id];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Queue<IntPtr> GetWorkerTaskQueue(int idInWrap)
{
return _cache[idInWrap];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetAllWorker()
{
foreach (ManualResetEventSlim item in _workerReset) {
item.Set();
}
}
public record class Handle(int InWrapIndex, MatrixParallelWrap Wrap);
#region ThreadOperation
private static unsafe void MatrixParallelWorker([AllowNull] object obj)
{
Handle handle = (obj as Handle)!;
MatrixParallelWrap wrap = handle.Wrap;
int inWrapIndex = handle.InWrapIndex;
Thread self = Thread.CurrentThread;
ManualResetEventSlim reset = wrap.GetWorkerResetEvent(inWrapIndex);
do
{
reset.Wait();
reset.Reset();
self.Priority = ThreadPriority.Highest;
ExecuteTaskPackage(wrap.GetWorkerTaskQueue(inWrapIndex));
_ = Interlocked.Decrement(ref RemainThreadCount);
self.Priority = _AfterWork;
} while (true);
}
private static unsafe void MatrixParallelScheduler([AllowNull] object obj)
{
Handle handle = (obj as Handle)!;
MatrixParallelWrap wrap = handle.Wrap;
int inWrapIndex = handle.InWrapIndex;
Queue<IntPtr> taskQueue = wrap.GetWorkerTaskQueue(inWrapIndex);
ManualResetEventSlim resetEvent = wrap.SchedulerReset;
Thread self = Thread.CurrentThread;
do
{
resetEvent.Wait();
resetEvent.Reset();
self.Priority = ThreadPriority.Highest;
// TODO task publication to worker in wrap
wrap.SetAllWorker();
ExecuteTaskPackage(taskQueue);
_ = Interlocked.Decrement(ref RemainThreadCount);
self.Priority = _AfterWork;
} while (true);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ExecuteTaskPackage(Queue<IntPtr> taskQueue)
{
while (taskQueue.TryDequeue(out nint handle))
{
MatrixParallelTaskPackageNonGeneric* p = (MatrixParallelTaskPackageNonGeneric*)handle;
switch (p->ComputeMode)
{
case 1:
Compute_Unary(p);
break;
case 2:
Compute_UnaryScalar(p);
break;
case 3:
Compute_Binary(p);
break;
case 4:
Compute_BinaryScalar(p);
break;
default:
break;
}
}
}
#endregion
}
#region wrap field
private static MatrixParallelWrap[] LargeWraps;
private static MatrixParallelWrap[] SmallWraps;
private static int LargeWrapCount;
private static int SmallWrapCount;
#endregion
}
public enum SleepMode
{
QuickWakeup = ThreadPriority.AboveNormal,
NormalSleep = ThreadPriority.BelowNormal,
DeepSleep = ThreadPriority.Lowest,
}
}
@@ -1,50 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.Cross.cs"
// Project: World
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Mathematics
{
public static unsafe partial class Linear
{
public static float Cross( Vec2 vec1, Vec2 vec2 )
{
return ( vec1.X * vec2.Y ) - ( vec1.Y * vec2.X );
}
public static Vec3 Cross( Vec3 vec1, Vec3 vec2 )
{
return new Vec3(
( vec1.Y * vec2.Z ) - ( vec1.Z * vec2.Y ),
( vec1.X * vec2.Z ) - ( vec1.Z * vec2.X ),
( vec1.X * vec2.Y ) - ( vec1.Y * vec2.X ) );
}
}
}
@@ -1,50 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.GetAngle.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Mathematics
{
public static unsafe partial class Linear
{
public static float GetAngle( Vec2 vec1, Vec2 vec2 )
{
return Scaler.ACos(
1
//vec1.multiple(vec2)
/ ( vec1.GetLength() * vec2.GetLength() ) );
}
public static float GetAngle( Vec3 vec1, Vec3 vec2 )
{
return Scaler.ACos( ( vec1 * vec2 ) / ( vec1.GetLength() * vec2.GetLength() ) );
}
}
}
@@ -1,47 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.GetLength.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Mathematics
{
public static unsafe partial class Linear
{
public static float GetLength( this Vec3 vec )
{
return Scaler.Sqrt( vec.Dot( vec ) );
}
public static float GetLength( this Vec2 vec )
{
return Scaler.Sqrt( vec.Dot( vec ) );
}
}
}
@@ -1,94 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.Normalize.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Internal;
using StgSharp.Mathematics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
public static partial class Linear
{
public static Vec4 Normalize( Vec4 vec )
{
return new Vec4
{
vec = Vector4.Normalize( vec.vec )
};
}
public static Vec3 Normalize( Vec3 vec )
{
return new Vec3
{
v = Vector3.Normalize( vec.v )
};
}
public static unsafe void Normalize( ref Vec4 source, ref Vec4 target )
{
Vector4 s = source.vec;
Vector4 t = target.vec;
s = Vector4.Normalize( s );
float dotProduct = Vector4.Dot( s, t );
Vector4 projection = Vector4.Multiply( s, t );
t -= projection;
source.vec = s;
target.vec = t;
}
public static unsafe void Normalize( ref Vec3 source, ref Vec3 target )
{
Vector3 s = source.v;
Vector3 t = target.v;
s = Vector3.Normalize( s );
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s, s ) ) * s;
t -= projection;
t = Vector3.Normalize( t );
source.v = s;
target.v = t;
}
}
}
@@ -1,104 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.Orthogonalize.cs"
// Project: World
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Internal.Intrinsic;
using StgSharp.Mathematics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
public static partial class Linear
{
public static Vec4 Orthogonalize( Vec4 vec )
{
return new Vec4
{
vec = Vector4.Normalize( vec.vec )
};
}
public static Vec3 Orthogonalize( Vec3 vec )
{
return new Vec3
{
v = Vector3.Normalize( vec.v )
};
}
public static unsafe void Orthogonalize( ref Vec4 source, ref Vec4 target )
{
Vector4 s = source.vec;
Vector4 t = target.vec;
s = Vector4.Normalize( s );
float dotProduct = Vector4.Dot( s, t );
Vector4 projection = Vector4.Multiply( s, t );
t -= projection;
source.vec = s;
target.vec = t;
}
/// <summary>
/// Orthogonalize two <see cref="Vec3" />s, let their length be 1 and perpendicular to
/// each other.
/// </summary>
/// <param _label="source">
///
/// </param>
/// <param _label="target">
///
/// </param>
public static unsafe void Orthogonalize( ref Vec3 source, ref Vec3 target )
{
Vector3 s = source.v;
Vector3 t = target.v;
s = Vector3.Normalize( s );
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s, s ) ) * s;
t -= projection;
t = Vector3.Normalize( t );
source.v = s;
target.v = t;
}
}
}
+27 -27
View File
@@ -1,33 +1,33 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ASin.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// -----------------------------------------------------------------------
// file="ASin.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
namespace StgSharp.Mathematics
@@ -52,9 +52,9 @@ namespace StgSharp.Mathematics
/// <exception cref="ArgumentException">
///
/// </exception>
public static float ASin( float x )
public static float ASin(float x)
{
return MathF.Asin( x );
return MathF.Asin(x);
/*
int sign = 1;
float y;
+28 -28
View File
@@ -1,33 +1,33 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cos.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// -----------------------------------------------------------------------
// file="Cos.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Runtime.CompilerServices;
@@ -36,8 +36,8 @@ namespace StgSharp.Mathematics
public static partial class Scaler
{
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static float Cos( float x )
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Cos(float x)
{
/*
float refer = x / 360.0f;
@@ -53,7 +53,7 @@ namespace StgSharp.Mathematics
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
*/
return MathF.Cos( x );
return MathF.Cos(x);
}
}