protected override void CopyDense(CholmodDense dense, DenseColumnMajorStorage <double> matrix) { Marshal.Copy(dense.x, matrix.Values, 0, (int)dense.nzmax); }
/// <inheritdoc /> public override void PointwiseMultiply(DenseColumnMajorStorage <double> other, DenseColumnMajorStorage <double> result) { if (RowCount != other.RowCount || ColumnCount != other.ColumnCount) { throw new ArgumentException(Resources.MatrixDimensions); } if (RowCount != result.RowCount || ColumnCount != result.ColumnCount) { throw new ArgumentException(Resources.MatrixDimensions); } var x = Values; var y = other.Values; var target = result.Values; int length = target.Length; for (int i = 0; i < length; i++) { target[i] = x[i] * y[i]; } }
/// <summary> /// Gets the determinant of the matrix. /// </summary> /// <returns></returns> public static double Determinant(this DenseColumnMajorStorage <double> matrix) { return(DenseLU.Create(matrix).Determinant()); }
protected override CholmodDense CreateDense(DenseColumnMajorStorage <double> matrix, List <GCHandle> handles) { return(CholmodHelper.CreateDense(matrix, handles)); }
public static void InPlaceTranspose(this DenseColumnMajorStorage <double> matrix) { TransposeInPlace(matrix); }
/// <summary> /// Checks if number of rows equals number of columns. /// </summary> /// <returns>True iff matrix is n by n.</returns> public static bool IsSquare(this DenseColumnMajorStorage <double> matrix) { return(matrix.RowCount == matrix.ColumnCount); }
/// <summary> /// Helper method to cast the storage to a <see cref="Matrix"/> instance. /// </summary> public static Matrix AsMatrix(this DenseColumnMajorStorage <double> matrix) { return(new Matrix(matrix.RowCount, matrix.ColumnCount, matrix.Values)); }
/// <summary> /// Create CHOLMOD dense matrix from managed type. /// </summary> /// <param name="matrix">The source matrix.</param> /// <param name="handles">List of handles.</param> /// <returns></returns> protected abstract CholmodDense CreateDense(DenseColumnMajorStorage <T> matrix, List <GCHandle> handles);
/// <summary> /// Copy native memory to dense matrix. /// </summary> /// <param name="dense">CHOLMOD dense matrix.</param> /// <param name="matrix">Target storage.</param> protected abstract void CopyDense(CholmodDense dense, DenseColumnMajorStorage <T> matrix);
/// <summary> /// Solve multiple systems of linear equations. /// </summary> /// <param name="sys">The system to solve.</param> /// <param name="input">Right hand side B</param> /// <param name="result">Solution matrix X.</param> protected virtual int DoSolve(CholmodSolve sys, DenseColumnMajorStorage <T> input, DenseColumnMajorStorage <T> result) { if (!factorized) { Factorize(); } var h = new List <GCHandle>(); try { var B = CreateDense(input, h); var ptr = NativeMethods.cholmod_solve((int)sys, ref L, ref B, ref common); if (common.status != Constants.CHOLMOD_OK) { return(common.status); } var X = (CholmodDense)Marshal.PtrToStructure(ptr, typeof(CholmodDense)); CopyDense(X, result); NativeMethods.cholmod_free_dense(ref ptr, ref common); return(common.status); } finally { InteropHelper.Free(h); } }
private static CompressedColumnStorage <double> DenseToSparse(DenseColumnMajorStorage <double> dense) { var cs = Converter.FromColumnMajorArray(dense.Values, dense.RowCount, dense.ColumnCount); return(Converter.ToCompressedColumnStorage(cs)); }