arrange of c lib
This commit is contained in:
@@ -29,7 +29,6 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
@@ -66,17 +65,28 @@ namespace StgSharp.Mathematics
|
||||
|
||||
protected int KernelRowCount { get; init; }
|
||||
|
||||
public abstract MatrixKernel* GetMatrixKernel(int column, int row);
|
||||
public abstract ref MatrixKernel GetMatrixKernel(int column, int row);
|
||||
|
||||
[Obsolete("This method does not contain boarder check, so be careful on size or use indexer instead.", false)]
|
||||
public abstract T* UnsafeIndex(int column, int row);
|
||||
public abstract ref T UnsafeIndex(int column, int row);
|
||||
|
||||
private protected void AssertIndex(int column, int row)
|
||||
{
|
||||
if (column < 0 || column >= ColumnCount) {
|
||||
throw new ArgumentOutOfRangeException(nameof(column));
|
||||
}
|
||||
|
||||
if (row < 0 || row >= RowCount) {
|
||||
throw new ArgumentOutOfRangeException(nameof(row));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal unsafe class GCMatrix<T> : Matrix<T> where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private MatrixKernel[,] buffer;
|
||||
private readonly MatrixKernel[,] buffer;
|
||||
|
||||
public GCMatrix(int column, int row)
|
||||
{
|
||||
@@ -89,6 +99,7 @@ namespace StgSharp.Mathematics
|
||||
{
|
||||
get
|
||||
{
|
||||
AssertIndex(column, row);
|
||||
int kernelColumn = column / 4, c = column % 4;
|
||||
int kernelRow = row / t_count, r = row % t_count;
|
||||
ref MatrixKernel kernel = ref buffer[kernelColumn, kernelRow];
|
||||
@@ -102,14 +113,20 @@ namespace StgSharp.Mathematics
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override unsafe MatrixKernel* GetMatrixKernel(int column, int row)
|
||||
public override unsafe ref MatrixKernel GetMatrixKernel(int column, int row)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
AssertIndex(column, row);
|
||||
int kernelColumn = column / 4;
|
||||
int kernelRow = row / t_count;
|
||||
return ref buffer[kernelColumn, kernelRow];
|
||||
}
|
||||
|
||||
public override unsafe T* UnsafeIndex(int column, int row)
|
||||
public override ref T UnsafeIndex(int column, int row)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int kernelColumn = column / 4, c = column % 4;
|
||||
int kernelRow = row / t_count, r = row % t_count;
|
||||
ref MatrixKernel kernel = ref buffer[kernelColumn, kernelRow];
|
||||
return ref kernel.UnsafeIndex<T>(c, r);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -117,16 +134,28 @@ namespace StgSharp.Mathematics
|
||||
internal unsafe class HlsfMatrix<T> : Matrix<T> where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private hlsfHandle handle;
|
||||
private readonly MatrixKernel* k_buffer;
|
||||
private readonly hlsfHandle handle;
|
||||
|
||||
internal HlsfMatrix(int column, int row, hlsfAllocator allocator)
|
||||
{
|
||||
KernelColumnCount = (column + 3) / 4;
|
||||
KernelRowCount = (row + 3) / t_count;
|
||||
this.handle = allocator.Alloc((uint)(KernelColumnCount * KernelRowCount * sizeof(MatrixKernel)));
|
||||
k_buffer = (MatrixKernel*)handle.Pointer;
|
||||
}
|
||||
|
||||
public override ref T this[int column, int row] => throw new NotImplementedException();
|
||||
public override ref T this[int column, int row]
|
||||
{
|
||||
get
|
||||
{
|
||||
AssertIndex(column, row);
|
||||
int kernelColumn = column / 4, c = column % 4;
|
||||
int kernelRow = row / t_count, r = row % t_count;
|
||||
ref MatrixKernel kernel = ref k_buffer[(kernelColumn * kernelColumn) + kernelRow];
|
||||
return ref kernel.UnsafeIndex<T>(c, r);
|
||||
}
|
||||
}
|
||||
|
||||
public override Matrix<T> this[ReadOnlySpan<MatrixIndex> column, ReadOnlySpan<MatrixIndex> row]
|
||||
{
|
||||
@@ -134,14 +163,20 @@ namespace StgSharp.Mathematics
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override unsafe MatrixKernel* GetMatrixKernel(int column, int row)
|
||||
public override unsafe ref MatrixKernel GetMatrixKernel(int column, int row)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
AssertIndex(column, row);
|
||||
int kernelColumn = column / 4, c = column % 4;
|
||||
int kernelRow = row / t_count, r = row % t_count;
|
||||
return ref k_buffer[(kernelColumn * kernelColumn) + kernelRow];
|
||||
}
|
||||
|
||||
public override unsafe T* UnsafeIndex(int column, int row)
|
||||
public override ref T UnsafeIndex(int column, int row)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
int kernelColumn = column / 4, c = column % 4;
|
||||
int kernelRow = row / t_count, r = row % t_count;
|
||||
ref MatrixKernel kernel = ref k_buffer[(kernelColumn * kernelColumn) + kernelRow];
|
||||
return ref kernel.UnsafeIndex<T>(c, r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user