コード例 #1
0
ファイル: THelper.cs プロジェクト: npolyak/NP.LinearAlgebra
        private static Tensor <T> ArangeImpl <T>(double begin, double end, double step)
        {
            if (end < begin)
            {
                step = -Math.Abs(step);
            }

            Type t = typeof(T);

            Converter <double, T> converter = NumericUtils.GetConverterFromDouble <T>();

            int numberSteps = (int)((end - begin) / step);

            T[]    array        = new T[numberSteps];
            double currentValue = begin;

            for (int i = 0; i < numberSteps; i++, currentValue += step)
            {
                array[i] = converter.Invoke(currentValue);
            }

            return(new Tensor <T>(array));
        }