Example #1
0
        private void ParseWeightFormat(string text)
        {
            switch (text)
            {
            case "FULL_MATRIX":
                weigthFormat = MatrixFormat.FullMatrix;
                break;

            case "LOWER_DIAG_COL":
                weigthFormat = MatrixFormat.LowerDiagCol;
                break;

            case "UPPER_ROW":
                weigthFormat = MatrixFormat.UpperRow;
                break;

            case "UPPER_DIAG_ROW":
                weigthFormat = MatrixFormat.UpperDiagRow;
                break;

            case "LOWER_DIAG_ROW":
                weigthFormat = MatrixFormat.LowerDiagRow;
                break;

            case "FUNCTION":
                break;

            default:
                throw new GtspException("{0} edge weight type is not supported.", text);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new matrix with the given <paramref name="elements"/>.
        /// </summary>
        /// <param name="format">The format of the matrix, either row-major or column-major.</param>
        /// <param name="elements">The elements to use to fill the matrix.</param>
        /// <exception cref="ArgumentNullException">Thrown when parameter 'elements' is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when length of 'elements' is 0
        /// or when the first element of 'elements' is an array of length 0.</exception>
        /// <exception cref="ArgumentException">When the arrays of 'elements' are not all the same length.</exception>
        public Matrix(MatrixFormat format, DoubleComponent[][] elements)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }

            if (elements.Length == 0 || elements[0] == null || elements[0].Length == 0)
            {
                throw new ArgumentException("Must have at least one element.", "elements");
            }

            _format = format;

            _rowCount    = format == MatrixFormat.RowMajor ? elements.Length : elements[0].Length;
            _columnCount = format == MatrixFormat.ColumnMajor ? elements.Length : elements[0].Length;

            _elements = new DoubleComponent[_rowCount * _columnCount];

            for (Int32 i = 0; i < (format == MatrixFormat.RowMajor ? _rowCount : _columnCount); i++)
            {
                if (_columnCount != elements[i].Length)
                {
                    throw new ArgumentException(
                              "Cannot create a matrix which has rows having different numbers of columns.");
                }

                for (Int32 j = 0; j < (format == MatrixFormat.ColumnMajor ? _rowCount : _columnCount); j++)
                {
                    this[i, j] = elements[i][j];
                }
            }
        }
Example #3
0
 /// <summary>
 /// Creates a rectangular Matrix of the given <paramref name="rowCount"/>
 /// by <paramref name="columnCount"/> with
 /// <paramref name="value"/> assigned to the diagonal.
 /// </summary>
 /// <param name="format">The format of the matrix, either row-major or column-major.</param>
 /// <param name="rowCount">Number of rows.</param>
 /// <param name="columnCount">Number of columns.</param>
 /// <param name="value">The value to assign to the diagonal.</param>
 /// <exception cref="ArgumentOutOfRangeException">Thrown when rowCount or columnCount is less than 1.</exception>
 public Matrix(MatrixFormat format, Int32 rowCount, Int32 columnCount, DoubleComponent value)
     : this(format, rowCount, columnCount)
 {
     for (Int32 i = 0; i < rowCount; i++)
     {
         _elements[i * rowCount + i] = value;
     }
 }
Example #4
0
 /// <summary>
 /// Creates a new identiy affine transform matrix (with default(T).One in each element of the diagonal)
 /// with the given <paramref name="rank"/> for the number of rows and number of columns.
 /// </summary>
 /// <param name="format">Storage format of the matrix, either row-major or column-major.</param>
 /// <param name="rank">Number of rows and columns in the affine matrix.</param>
 /// <exception cref="NotSupportedException">If the matrix has a rank other than 3 or 4.</exception>
 public AffineMatrix(MatrixFormat format, Int32 rank)
     : base(format, rank, rank)
 {
     for (Int32 i = 0; i < rank; i++)
     {
         this[i, i] = _one;
     }
 }
Example #5
0
 public static Matrix <float> RandomFloatMatrix(uint rows, uint cols, MatrixFormat matrixFormat)
 {
     return(new Matrix <float>(
                _rows: rows,
                _cols: cols,
                host_data: ImmutableArray.Create(UniformRandomFloatArray(rows * cols)),
                matrixFormat: matrixFormat));
 }
Example #6
0
 /// <summary>
 /// This routine sets the matrix format used in the cusolverRfSetup(),
 /// cusolverRfSetupHost(), cusolverRfResetValues(), cusolverRfExtractBundledFactorsHost() and cusolverRfExtractSplitFactorsHost() routines.
 /// </summary>
 /// <param name="format">the enumerated matrix format type.</param>
 /// <param name="diag">the enumerated unit diagonal type.</param>
 public void SetMatrixFormat(MatrixFormat format, UnitDiagonal diag)
 {
     res = CudaSolveNativeMethods.Refactorization.cusolverRfSetMatrixFormat(_handle, format, diag);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverRfSetMatrixFormat", res));
     if (res != cusolverStatus.Success)
     {
         throw new CudaSolveException(res);
     }
 }
Example #7
0
 public Matrix(
     uint _rows, uint _cols,
     ImmutableArray <T> host_data,
     MatrixFormat matrixFormat)
 {
     Rows         = _rows;
     Cols         = _cols;
     Data         = host_data;
     MatrixFormat = matrixFormat;
 }
Example #8
0
        public static string SetupGpuMatrix(out GpuMatrix gmOut, float[] data, uint rows,
                                            uint cols, MatrixFormat matrixFormat)
        {
            var gpuIn = new GpuMatrix(
                matrix: new Matrix <float>(
                    _rows: rows,
                    _cols: cols,
                    host_data: ImmutableArray.Create(data),
                    matrixFormat: matrixFormat),
                devPtr: new IntPtr(),
                devHostState: DevHostState.DeviceNotAllocated);

            GpuMatrix gpuDeviced;
            var       res = GpuMatrixOps.AllocateOnDevice(out gpuDeviced, gpuIn);

            res = res + GpuMatrixOps.CopyToDevice(out gmOut, gpuDeviced);
            return(res);
        }
Example #9
0
        /// <summary>
        /// Creates a zero rectangular Matrix of the given <paramref name="rowCount"/> by <paramref name="columnCount"/>.
        /// </summary>
        /// <param name="format">The format of the matrix, either row-major or column-major.</param>
        /// <param name="rowCount">Number of rows.</param>
        /// <param name="columnCount">Number of columns.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when rowCount or columnCount is less than 1.</exception>
        public Matrix(MatrixFormat format, Int32 rowCount, Int32 columnCount)
        {
            if (rowCount <= 0)
            {
                throw new ArgumentOutOfRangeExceptionEx("rowCount", rowCount, "Cannot create a matrix without rows.");
            }

            if (columnCount <= 0)
            {
                throw new ArgumentOutOfRangeExceptionEx("columnCount", columnCount,
                                                        "Cannot create a matrix without columns.");
            }

            _rowCount    = rowCount;
            _columnCount = columnCount;

            _format   = format;
            _elements = new DoubleComponent[rowCount * columnCount];
        }
Example #10
0
        public Matrix CreateMatrix(MatrixFormat format, Int32 rowCount, Int32 columnCount)
        {
            Matrix m = new Matrix(format, rowCount, columnCount);

            return(m);
        }
Example #11
0
 /// <summary>
 /// Generates a square matrix of the given <paramref name="rank"/> with
 /// the number 1 in each element of the diagonal.
 /// </summary>
 /// <param name="format">The format of the matrix, either row-major or column-major.</param>
 /// <param name="rank">Number of rows and columns of the <see cref="Matrix"/>.</param>
 /// <returns>An identiy matrix of the given rank.</returns>
 public static Matrix Identity(MatrixFormat format, Int32 rank)
 {
     return(new Matrix(format, rank, rank, new DoubleComponent(1)));
 }
Example #12
0
		/// <summary>
		/// This routine gets the matrix format used in the cusolverRfSetup(),
		/// cusolverRfSetupHost(), cusolverRfResetValues(), cusolverRfExtractBundledFactorsHost() and cusolverRfExtractSplitFactorsHost() routines.
		/// </summary>
		/// <param name="format">the enumerated matrix format type.</param>
		/// <param name="diag">the enumerated unit diagonal type.</param>
		public void GetMatrixFormat(ref MatrixFormat format, ref UnitDiagonal diag)
		{
			res = CudaSolveNativeMethods.Refactorization.cusolverRfGetMatrixFormat(_handle, ref format, ref diag);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverRfGetMatrixFormat", res));
			if (res != cusolverStatus.Success) throw new CudaSolveException(res);
		}
Example #13
0
 /// <summary>
 /// Creates a new affine transform matrix with the given <paramref name="elements"/>.
 /// </summary>
 /// <param name="format">Storage format of the matrix, either row-major or column-major.</param>
 /// <param name="elements">
 /// The elements for the array, with rows in the outer array for a <see cref="MatrixFormat.RowMajor"/>
 /// matrix, and columns in the outer array for a <see cref="MatrixFormat.ColumnMajor"/> matrix.
 /// </param>
 /// <exception cref="ArgumentException">If the matrix is not square.</exception>
 /// <exception cref="NotSupportedException">If the matrix has a rank other than 3 or 4.</exception>
 public AffineMatrix(MatrixFormat format, DoubleComponent[][] elements)
     : base(format, elements)
 {
     checkSquare(elements.Length, elements[0].Length);
 }
			public static extern cusolverStatus cusolverRfSetMatrixFormat(cusolverRfHandle handle, MatrixFormat format, UnitDiagonal diag);