Esempio n. 1
0
        public static MFullArray <TScalar> ExpandScalar(TScalar value, MArrayShape shape)
        {
            var array = new TScalar[shape.Count];

            for (int i = 0; i < array.Length; ++i)
            {
                array[i] = value;
            }
            return(new MFullArray <TScalar>(array, shape));
        }
Esempio n. 2
0
        internal static int LinearizeIndex(MArrayShape shape, int rowIndex, int columnIndex)
        {
            if (rowIndex < 1 || rowIndex > shape.RowCount ||
                columnIndex < 1 || columnIndex > shape.ColumnCount)
            {
                throw new ArgumentOutOfRangeException();
            }

            return(rowIndex + (columnIndex - 1) * shape.RowCount);
        }
Esempio n. 3
0
        internal static int LinearizeIndex(MArrayShape shape, int rowIndex, int columnIndex, int sliceIndex)
        {
            int sliceCount = shape.GetDimensionSize(2);

            if (rowIndex < 1 || rowIndex > shape.RowCount ||
                columnIndex < 1 || columnIndex > shape.ColumnCount ||
                sliceIndex < 1 || sliceIndex > sliceCount)
            {
                throw new ArgumentOutOfRangeException();
            }

            return(rowIndex + ((sliceCount - 1) * shape.ColumnCount + columnIndex - 1) * shape.RowCount);
        }
Esempio n. 4
0
        public static void ArraySet <[AnyPrimitive] TScalar>(
            MFullArray <TScalar> array, MFullArray <int> rowIndices, MFullArray <int> columnIndices, MFullArray <TScalar> values)
        {
            Contract.Requires(array != null);
            Contract.Requires(rowIndices != null);
            Contract.Requires(columnIndices != null);
            Contract.Requires(values != null);

            var indexedShape = new MArrayShape(rowIndices.Count, columnIndices.Count);

            if (values.shape != indexedShape)
            {
                throw new MArrayShapeException();
            }

            for (int j = 0; j < columnIndices.Count; ++j)
            {
                int columnIndex = columnIndices[j];
                if (columnIndex < 1 || columnIndex > array.ColumnCount)
                {
                    throw new IndexOutOfRangeException();
                }

                for (int i = 0; i < rowIndices.Count; ++i)
                {
                    int rowIndex = rowIndices[i];
                    if (rowIndex < 1 || rowIndex > array.RowCount)
                    {
                        throw new IndexOutOfRangeException();
                    }

                    var value = values[j * indexedShape.RowCount + i];
                    array[(columnIndex - 1) * array.RowCount + (rowIndex - 1)] = value;
                }
            }
        }
Esempio n. 5
0
        public override void Resize(MArrayShape newShape)
        {
            var copyShape = MArrayShape.Min(shape, newShape);
            var newArray  = new TScalar[newShape.Count];

            if (copyShape.IsHigherDimensional)
            {
                throw new NotImplementedException("Resizing to or from higher-dimensional arrays.");
            }
            else
            {
                for (int columnIndex = 0; columnIndex < copyShape.ColumnCount; ++columnIndex)
                {
                    for (int rowIndex = 0; rowIndex < copyShape.RowCount; ++rowIndex)
                    {
                        var value = elements[columnIndex * shape.RowCount + rowIndex];
                        elements[columnIndex * newShape.RowCount + rowIndex] = value;
                    }
                }
            }

            elements = newArray;
            shape    = newShape;
        }
Esempio n. 6
0
 public override void Resize(MArrayShape newShape)
 {
     throw new NotImplementedException("MCellArray.Resize");
 }
Esempio n. 7
0
 public MCellArray(MCell[] elements, MArrayShape shape)
     : base(shape)
 {
     Contract.Requires(elements != null && elements.Length >= shape.Count);
     this.elements = elements;
 }
Esempio n. 8
0
        public static MFullArray <TScalar> Expand <[AnyPrimitive] TScalar>(TScalar value, double rowCount, double columnCount)
        {
            var shape = MArrayShape.FromDoubles(rowCount, columnCount);

            return(MFullArray <TScalar> .ExpandScalar(value, shape));
        }
Esempio n. 9
0
 internal MArray(MArrayShape shape) : base(shape)
 {
 }
Esempio n. 10
0
 public MFullArray(MArrayShape shape)
     : base(shape)
 {
     elements = new TScalar[shape.Count];
 }
Esempio n. 11
0
 public MFullArray(TScalar[] backingArray, MArrayShape shape)
     : base(shape)
 {
     Contract.Requires(backingArray != null && backingArray.Length == shape.Count);
     this.elements = backingArray;
 }
Esempio n. 12
0
        public static MFullArray <TScalar> CreateWithShape(double rowCount, double columnCount)
        {
            var shape = MArrayShape.FromDoubles(rowCount, columnCount);

            return(CreateWithShape(shape));
        }
Esempio n. 13
0
 public static MFullArray <TScalar> CreateWithShape(MArrayShape shape)
 {
     return(new MFullArray <TScalar>(shape));
 }
Esempio n. 14
0
 public static MFullArray <TScalar> CreateColumnVector(params TScalar[] values)
 {
     return(new MFullArray <TScalar>(values, MArrayShape.ColumnVector(values.Length)));
 }
Esempio n. 15
0
 internal MValue(MArrayShape shape)
 {
     this.shape = shape;
 }
Esempio n. 16
0
 /// <summary>
 /// Resizes this value to the given shape.
 /// </summary>
 /// <param name="newShape">The new shape of the value.</param>
 public abstract void Resize(MArrayShape newShape);