redesign matrix design
This commit is contained in:
@@ -30,7 +30,6 @@ using StgSharp.Mathematics.Numeric;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
||||
|
||||
@@ -42,17 +41,61 @@ namespace StgSharp.Mathematics.Numeric
|
||||
private protected static readonly int t_count = 16 / sizeof(T);
|
||||
|
||||
private protected static readonly int t_size = sizeof(T);
|
||||
private MatrixMetadata _enumeration;
|
||||
|
||||
private MatrixKernelBoarder _boarder;
|
||||
private MatrixSize _size;
|
||||
private MatrixStorage<T> _buffer;
|
||||
|
||||
private protected Matrix() { }
|
||||
|
||||
public ref T this[int column, int row]
|
||||
public T this[int x, int y]
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
get
|
||||
{
|
||||
if (y < 0 || y > _size.ElementColumnLength || x < 0 || x > _size.ElementRowLength) {
|
||||
throw new ArgumentOutOfRangeException($"Index [{x},{y}] is out of matrix index range.");
|
||||
}
|
||||
|
||||
int
|
||||
k_c = y / 4,
|
||||
k_r = x / 4,
|
||||
c = y % 4,
|
||||
r = x % 4;
|
||||
ref MatrixKernel<T> kernel = ref GetMatrixKernel(k_c, k_r);
|
||||
return Unsafe.IsNullRef(ref kernel) ? T.Zero : kernel[c, r];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (y < 0 || y > _size.ElementColumnLength || x < 0 || x > _size.ElementRowLength) {
|
||||
throw new ArgumentOutOfRangeException($"Index [{x},{y}] is out of matrix index range.");
|
||||
}
|
||||
|
||||
int
|
||||
k_c = y / 4,
|
||||
k_r = x / 4,
|
||||
c = y % 4,
|
||||
r = x % 4;
|
||||
ref MatrixKernel<T> kernel = ref GetMatrixKernel(k_c, k_r);
|
||||
if (!Unsafe.IsNullRef(ref kernel)) {
|
||||
kernel[c, r] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matlab style indexer to generate a new matrix
|
||||
/// </summary>
|
||||
/// <param name="column">
|
||||
///
|
||||
/// </param>
|
||||
/// <param name="row">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
/// <exception cref="NotImplementedException">
|
||||
///
|
||||
/// </exception>
|
||||
public unsafe Matrix<T> this[
|
||||
ReadOnlySpan<MatrixIndex> column,
|
||||
ReadOnlySpan<MatrixIndex> row]
|
||||
@@ -64,34 +107,33 @@ namespace StgSharp.Mathematics.Numeric
|
||||
/// <summary>
|
||||
/// Length of the matrix in columns.
|
||||
/// </summary>
|
||||
public int ColumnLength { get; init; }
|
||||
public int ColumnLength => _size.ElementColumnLength;
|
||||
|
||||
/// <summary>
|
||||
/// Length of the matrix in rows.
|
||||
/// </summary>
|
||||
public int RowLength { get; init; }
|
||||
public int RowLength => _size.ElementRowLength;
|
||||
|
||||
public MatrixLayout Layout { get; init; }
|
||||
|
||||
internal MatrixKernel<T>* Buffer { get; }
|
||||
internal MatrixKernel<T>* Buffer
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (MatrixKernel<T>*)_buffer.BufferPointer;
|
||||
}
|
||||
|
||||
protected internal int KernelColumnLength { get; init; }
|
||||
|
||||
protected internal int KernelRowLength { get; init; }
|
||||
|
||||
public ref MatrixKernel<T> GetMatrixKernel(int column, int row)
|
||||
public unsafe ref MatrixKernel<T> GetMatrixKernel(int x, int y)
|
||||
{
|
||||
if (_enumeration.GetCurrentKernelIndex) { } else { }
|
||||
}
|
||||
|
||||
private protected void AssertIndex(int column, int row)
|
||||
{
|
||||
if (column < 0 || column >= ColumnLength) {
|
||||
throw new ArgumentOutOfRangeException(nameof(column));
|
||||
}
|
||||
|
||||
if (row < 0 || row >= RowLength) {
|
||||
throw new ArgumentOutOfRangeException(nameof(row));
|
||||
fixed (MatrixSize *msPtr = &_size)
|
||||
{
|
||||
MatrixKernelEnumerator* e = (MatrixKernelEnumerator*)msPtr;
|
||||
return ref _boarder.IsInBuffer(x, y, e) ?
|
||||
ref _buffer[_boarder.GetIndexOffset(x, y, e)] :
|
||||
ref Unsafe.NullRef<MatrixKernel<T>>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user