Skip to content

Commit

Permalink
changes to use const for stack alloc comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgsharp committed Jun 11, 2024
1 parent 66774f7 commit d275019
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void CopyTo(scoped TensorSpan<T> destination)
{
scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -569,7 +569,7 @@ public bool TryCopyTo(scoped TensorSpan<T> destination)
{
scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -653,7 +653,7 @@ public ReadOnlyTensorSpan<T> Slice(params scoped ReadOnlySpan<NRange> ranges)

scoped Span<nint> lengths;
scoped Span<nint> offsets;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
lengths = stackalloc nint[Rank];
offsets = stackalloc nint[Rank];
Expand Down Expand Up @@ -692,7 +692,7 @@ public bool TryFlattenTo(scoped Span<T> destination)
{
scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -733,7 +733,7 @@ public void FlattenTo(scoped Span<T> destination)

scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public void Clear()
{
scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -570,7 +570,7 @@ public void CopyTo(scoped TensorSpan<T> destination)

scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -613,7 +613,7 @@ public bool TryCopyTo(scoped TensorSpan<T> destination)
{
scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -703,7 +703,7 @@ public TensorSpan<T> Slice(params scoped ReadOnlySpan<NRange> ranges)

scoped Span<nint> lengths;
scoped Span<nint> offsets;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
lengths = stackalloc nint[Rank];
offsets = stackalloc nint[Rank];
Expand Down Expand Up @@ -745,7 +745,7 @@ public bool TryFlattenTo(scoped Span<T> destination)
{
scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down Expand Up @@ -786,7 +786,7 @@ public void FlattenTo(scoped Span<T> destination)

scoped Span<nint> curIndexes;
nint[]? curIndexesArray;
if (Rank > 5)
if (Rank > TensorSpan.MaxRankForStackAlloc)
{
curIndexesArray = ArrayPool<nint>.Shared.Rent(Rank);
curIndexes = curIndexesArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace System.Numerics.Tensors
{
public static class TensorSpan
{
internal const int MaxRankForStackAlloc = 5;

#region SequenceEqual
/// <summary>
/// Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
Expand Down

0 comments on commit d275019

Please sign in to comment.