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)); }
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); }
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); }
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; } } }
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; }
public override void Resize(MArrayShape newShape) { throw new NotImplementedException("MCellArray.Resize"); }
public MCellArray(MCell[] elements, MArrayShape shape) : base(shape) { Contract.Requires(elements != null && elements.Length >= shape.Count); this.elements = elements; }
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)); }
internal MArray(MArrayShape shape) : base(shape) { }
public MFullArray(MArrayShape shape) : base(shape) { elements = new TScalar[shape.Count]; }
public MFullArray(TScalar[] backingArray, MArrayShape shape) : base(shape) { Contract.Requires(backingArray != null && backingArray.Length == shape.Count); this.elements = backingArray; }
public static MFullArray <TScalar> CreateWithShape(double rowCount, double columnCount) { var shape = MArrayShape.FromDoubles(rowCount, columnCount); return(CreateWithShape(shape)); }
public static MFullArray <TScalar> CreateWithShape(MArrayShape shape) { return(new MFullArray <TScalar>(shape)); }
public static MFullArray <TScalar> CreateColumnVector(params TScalar[] values) { return(new MFullArray <TScalar>(values, MArrayShape.ColumnVector(values.Length))); }
internal MValue(MArrayShape shape) { this.shape = shape; }
/// <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);