internal static IVectorCollection Subcollection(IVectorCollection collection, CollectionType type, int startIndex, int length) { if (collection.Count <= startIndex) { throw new ArgumentOutOfRangeException(); } if (length < 0) { throw new ArgumentException(); } int endIndex = (collection.Count < startIndex + length) ? collection.Count : startIndex + length; int[] idxs = new int[endIndex - startIndex]; for (int i = 0; i < idxs.Length; ++i) { idxs[i] = i + startIndex; } return(new SubCollection(collection, idxs, type)); }
internal static IEnumerator <IVector> Enumerator(IVectorCollection collection) { for (int i = 0; i < collection.Count; ++i) { yield return(collection[i]); } }
internal static IVectorCollection ForEach(IVectorCollection collection, VectorCollectionActionWithIndex action) { for (int i = 0; i < collection.Count; ++i) { action(i, collection[i]); } return(collection); }
internal static Matrix ToMatrix(IVectorCollection collection, CollectionType type) { if (type == CollectionType.Rows) { return(RowsToMatrix(collection)); } else { return(ColumnsToMatrix(collection)); } }
internal static void Setter(IVectorCollection collection, int index, IVector value) { IVector dst = collection[index]; IVector src = value; VectorChecker.MismatchSize(src, dst); for (int i = 0; i < src.Size; ++i) { dst[i] = src[i]; } }
public static Matrix CreateAsRows <C>(IVectorCollection <C> collection) where C : IVectorCollection <C> { int rowSize = collection.Count; int colSize = collection[0].Size; Matrix m = new Matrix(rowSize, colSize); for (int r = 0; r < rowSize; ++r) { m.Rows[r] = collection[r]; } return(m); }
public static Matrix CreateAsColumns <C>(IVectorCollection <C> collection) where C : IVectorCollection <C> { int rowSize = collection[0].Size; int colSize = collection.Count; Matrix m = new Matrix(rowSize, colSize); for (int c = 0; c < colSize; ++c) { m.Columns[c] = collection[c]; } return(m); }
internal static Matrix ColumnsToMatrix(IVectorCollection collection) { int rowSize = collection[0].Size; int colSize = collection.Count; Matrix m = new Matrix(rowSize, colSize); for (int c = 0; c < colSize; ++c) { m.Columns[c] = collection[c]; } return(m); }
internal static Matrix RowsToMatrix(IVectorCollection collection) { int rowSize = collection.Count; int colSize = collection[0].Size; Matrix m = new Matrix(rowSize, colSize); for (int r = 0; r < rowSize; ++r) { m.Rows[r] = collection[r]; } return(m); }
internal static void CheckIndexes(IVectorCollection collection, int[] indexes) { if (indexes == null) { throw new Exception.IllegalArgumentException(); } if (indexes.Length <= 0 || collection.Count < indexes.Length) { throw new Exception.IllegalArgumentException(); } foreach (int i in indexes) { if (i < 0 || collection.Count <= i) { throw new IndexOutOfRangeException(); } } }
internal static void HasIndexes <C>(IVectorCollection <C> collection, int[] indexes) where C : IVectorCollection <C> { if (indexes == null) { throw new ArgumentNullException("indexes"); } if (indexes.Length <= 0 || collection.Count < indexes.Length) { throw new ArgumentOutOfRangeException("illegal length"); } foreach (int i in indexes) { if (i < 0 || collection.Count <= i) { throw new IndexOutOfRangeException(); } } }
internal static IVectorCollection Swap(IVectorCollection collection, int index1, int index2) { if (index1 < 0 || collection.Count <= index1 || index2 < 0 || collection.Count <= index2) { throw new IndexOutOfRangeException(); } if (index1 != index2) { IVector rv1 = collection[index1]; IVector rv2 = collection[index2]; for (int i = 0; i < rv1.Size; ++i) { double val = rv1[i]; rv1[i] = rv2[i]; rv2[i] = val; } } return(collection); }
public void Test02() { Matrix m = new Matrix( new RowVector(0, 1, -1), new RowVector(-1, 1, 0), new RowVector(2, 1, 0)); IVector row0 = m.Rows[0]; // 1行目を取得 Assert.IsTrue(Vector.HaveSameValues(new Vector(0, 1, -1), row0)); IVectorCollection vc = m.Rows[0, 2]; // 1行目と3行目のセットを取得 vc[1][2] = 999; // コレクションにおいて,index==1 のベクトル(元の行列でいう3行目)の3番目の要素値を変更 Assert.AreEqual(999, m[2, 2], LisysConfig.CalculationLowerLimit); vc[1][2] = -1; Matrix u1 = new Matrix(3, 3).Add(1); // unit行列を作成 Assert.AreEqual(new Matrix(new double[, ] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }), u1); m = new Matrix(new double[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }); Matrix m1 = m.Rows[0, 2].Swap(0, 1).ToMatrix(); Assert.AreEqual(new Matrix(new double[, ] { { 7, 8, 9 }, { 1, 2, 3 } }), m1); }
internal SubCollection(IVectorCollection body, int[] indexes, CollectionType type) { this._body = body; this._indexes = indexes; this._type = type; }
/// <summary> /// 列コレクションを行列として出力 /// </summary> public static Matrix ToMatrix(this IVectorCollection <ColumnCollection> cc) { return(Matrix.CreateAsColumns(cc)); }
internal static IVectorCollection Subcollection(IVectorCollection collection, CollectionType type, int startIndex) { return(Subcollection(collection, type, startIndex, collection.Count - startIndex)); }
/// <summary> /// 行コレクションを行列として出力 /// </summary> public static Matrix ToMatrix(this IVectorCollection <RowCollection> rc) { return(Matrix.CreateAsRows(rc)); }
internal SubCollection(IVectorCollection <Owner> body, int[] indexes) { this._body = body; this._indexes = indexes; }
internal static IVectorCollection <C> Subcollection <C>(IVectorCollection <C> collection, int startIndex) where C : IVectorCollection <C> { return(Subcollection(collection, startIndex, collection.Count - startIndex)); }