Beispiel #1
0
        public static MFullArray <double> colon(double low, double high)
        {
            if (low > high)
            {
                return(MFullArray <double> .CreateEmpty());
            }

            var count = (int)(high - low) + 1;
            var array = new MFullArray <double>(1, count);

            for (int i = 0; i < count; ++i)
            {
                array[i] = low + i;
            }

            return(array);
        }
Beispiel #2
0
        public static MFullArray <double> colon(double from, double step, double to)
        {
            if (!(Math.Sign(to - from) * Math.Sign(step) == 1))
            {
                return(MFullArray <double> .CreateEmpty());
            }

            var count = (int)((to - from) / step) + 1;
            var array = new MFullArray <double>(1, count);

            for (int i = 0; i < count; ++i)
            {
                array[i] = from + step * i;
            }

            return(array);
        }
Beispiel #3
0
        internal static MFullArray <TScalar> horzcat <[AnyPrimitive] TScalar>(params MFullArray <TScalar>[] arrays)
        {
            Contract.Requires(arrays != null);

            if (arrays.Length == 0)
            {
                return(MFullArray <TScalar> .CreateEmpty());
            }

            var rowCount    = arrays[0].RowCount;
            int columnCount = 0;

            foreach (var array in arrays)
            {
                if (array.IsHigherDimensional)
                {
                    throw new NotImplementedException("horzcat on higher-dimensional arrays.");
                }

                if (array.RowCount != rowCount)
                {
                    throw new MArrayShapeException();
                }

                columnCount += array.ColumnCount;
            }

            var resultShape = new MArrayShape(rowCount, columnCount);
            var result      = new MFullArray <TScalar>(resultShape);

            int resultIndex = 0;

            foreach (var array in arrays)
            {
                for (int arrayColumnIndex = 0; arrayColumnIndex < array.ColumnCount; ++arrayColumnIndex)
                {
                    for (int rowIndex = 0; rowIndex < rowCount; ++rowIndex)
                    {
                        result[resultIndex] = array[arrayColumnIndex * rowCount + rowIndex];
                        resultIndex++;
                    }
                }
            }

            return(result);
        }