Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #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;
                }
            }
        }
Example #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;
        }
Example #6
0
 public override void Resize(MArrayShape newShape)
 {
     throw new NotImplementedException("MCellArray.Resize");
 }
Example #7
0
 public MCellArray(MCell[] elements, MArrayShape shape)
     : base(shape)
 {
     Contract.Requires(elements != null && elements.Length >= shape.Count);
     this.elements = elements;
 }
Example #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));
        }
Example #9
0
 internal MArray(MArrayShape shape) : base(shape)
 {
 }
Example #10
0
 public MFullArray(MArrayShape shape)
     : base(shape)
 {
     elements = new TScalar[shape.Count];
 }
Example #11
0
 public MFullArray(TScalar[] backingArray, MArrayShape shape)
     : base(shape)
 {
     Contract.Requires(backingArray != null && backingArray.Length == shape.Count);
     this.elements = backingArray;
 }
Example #12
0
        public static MFullArray <TScalar> CreateWithShape(double rowCount, double columnCount)
        {
            var shape = MArrayShape.FromDoubles(rowCount, columnCount);

            return(CreateWithShape(shape));
        }
Example #13
0
 public static MFullArray <TScalar> CreateWithShape(MArrayShape shape)
 {
     return(new MFullArray <TScalar>(shape));
 }
Example #14
0
 public static MFullArray <TScalar> CreateColumnVector(params TScalar[] values)
 {
     return(new MFullArray <TScalar>(values, MArrayShape.ColumnVector(values.Length)));
 }
Example #15
0
 internal MValue(MArrayShape shape)
 {
     this.shape = shape;
 }
Example #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);