You’re an expert programmer with a detailed understanding of high quality coding practices, a technical focus and numerical computing. You always review the code I give to you before you answer to check if there would be code improvements needed to apply first before proceeding with your answer, and when you make code improvements consider the change weight and how it would effect working with large Tensors<float> or Tensor<Double> for large neural networks in real world application. You will think and plan step by step carefully for best possible answer with best performance and least memory footprint,  use ParallelizationThreshold when preferred or required for best practices. you will produce fully complete and working code. 
Please note that Tensor<T> is partial class on multiply files. If you want to know if certain parts method or properties exists ask and I will provide to you the current implementation, this is to help you on producing better quaility code.

Programming language : c#
Application Type: class library
Describe the application in full (what does it do?): Neural network library

public partial class Tensor<T> : IDisposable, ICloneable, IEquatable<Tensor<T>>, IEnumerable<T>
    where T : unmanaged, INumber<T>, IExponentialFunctions<T>, ITrigonometricFunctions<T>, ILogarithmicFunctions<T>, IFloatingPointIeee754<T>, IRootFunctions<T>
{

    public T this[params int[] indices]
    {
        get
        {
            EnsureNotDisposed();
            int flatIndex = CalculateFlatIndex(indices);
            return data[flatIndex];
        }
        set
        {
            EnsureNotDisposed();
            int flatIndex = CalculateFlatIndex(indices);
            data[flatIndex] = value;
        }
    }

    /// <summary>
    /// Gets or sets the scalar value of a 0-dimensional tensor.
    /// </summary>
    public T ScalarValue
    {
        get
        {
            EnsureNotDisposed();
            if (Rank != 0)
                throw new InvalidOperationException("ScalarValue can only be accessed on a 0-dimensional tensor.");
            return data[offset];
        }
        set
        {
            EnsureNotDisposed();
            if (Rank != 0)
                throw new InvalidOperationException("ScalarValue can only be set on a 0-dimensional tensor.");
            data[offset] = value;
        }
    }

    private int CalculateFlatIndex(int[] indices)
    {
        if (indices == null)
            throw new ArgumentNullException(nameof(indices));
        if (indices.Length != shape.Length)
            throw new ArgumentException("Number of indices must match number of tensor dimensions.", nameof(indices));

        int flatIndex = 0;
        if (isRowMajor)
        {
            for (int i = 0; i < indices.Length; i++)
            {
                int index = indices[i];
                int dim = shape[i];
                if (index < 0 || index >= dim)
                    throw new ArgumentOutOfRangeException(nameof(indices), $"Index {index} out of bounds for dimension {i} of size {dim}.");

                flatIndex += indices[i] * strides[i];
            }
        }
        else // Column-major
        {
            for (int i = indices.Length - 1; i >= 0; i--)
            {
                int index = indices[i];
                int dim = shape[i];
                if (index < 0 || index >= dim)
                    throw new ArgumentOutOfRangeException(nameof(indices), $"Index {index} out of bounds for dimension {i} of size {dim}.");

                flatIndex += indices[i] * strides[i];
            }
        }
        return flatIndex + offset; // Include offset in the flat index
    }

    private int[] UnflattenIndex(int flatIndex, int[] shape)
    {
        int[] indices = new int[shape.Length];
        if (isRowMajor)
        {
            for (int i = 0; i < shape.Length; i++)
            {
                indices[i] = flatIndex / strides[i];
                flatIndex %= strides[i];
            }
        }
        else // Column-major
        {
            for (int i = shape.Length - 1; i >= 0; i--)
            {
                indices[i] = flatIndex / strides[i];
                flatIndex %= strides[i];
            }
        }
        return indices;
    }

    private static int GetFlatIndex(int[] indices, int[] strides, bool isRowMajor)
    {
        int flatIndex = 0;
        if (isRowMajor)
        {
            for (int i = 0; i < indices.Length; i++)
            {
                flatIndex += indices[i] * strides[i];
            }
        }
        else
        {
            for (int i = indices.Length - 1; i >= 0; i--)
            {
                flatIndex += indices[i] * strides[i];
            }
        }
        return flatIndex;
    }

    private int CalculateResultIndex(int[] indices, int axis, int[] newStrides)
    {
        int resultIndex = 0;
        for (int j = 0; j < indices.Length; j++)
        {
            if (j == axis)
                continue;
            resultIndex += indices[j] * newStrides[j < axis ? j : j - 1];
        }
        return resultIndex;
    }

    private static int[] CalculateStrides(int[] shape, bool isRowMajor)
    {
        int[] strides = new int[shape.Length];
        if (isRowMajor)
        {
            int stride = 1;
            for (int i = shape.Length - 1; i >= 0; i--)
            {
                strides[i] = stride;
                stride *= shape[i];
            }
        }
        else
        {
            int stride = 1;
            for (int i = 0; i < shape.Length; i++)
            {
                strides[i] = stride;
                stride *= shape[i];
            }
        }
        return strides;
    }
}
create mstest for the methods provided in that partial class