@ -80,7 +80,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <param name="columns">
/// <param name="columns">
/// The number of columns.
/// The number of columns.
/// </param>
/// </param>
public SparseMatrix ( int rows , int columns ) : base ( rows , columns )
public SparseMatrix ( int rows , int columns )
: base ( rows , columns )
{
{
_ rowIndex = new int [ rows ] ;
_ rowIndex = new int [ rows ] ;
}
}
@ -92,7 +93,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <exception cref="ArgumentException">
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// If <paramref name="order"/> is less than one.
/// </exception>
/// </exception>
public SparseMatrix ( int order ) : this ( order , order )
public SparseMatrix ( int order )
: this ( order , order )
{
{
}
}
@ -106,7 +108,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The number of columns.
/// The number of columns.
/// </param>
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
public SparseMatrix ( int rows , int columns , Complex32 value ) : this ( rows , columns )
public SparseMatrix ( int rows , int columns , Complex32 value )
: this ( rows , columns )
{
{
if ( value = = 0.0f )
if ( value = = 0.0f )
{
{
@ -144,7 +147,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Column-major_order </param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Column-major_order </param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="array"/> length is less than <paramref name="rows"/> * <paramref name="columns"/>.
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="array"/> length is less than <paramref name="rows"/> * <paramref name="columns"/>.
/// </exception>
/// </exception>
public SparseMatrix ( int rows , int columns , Complex32 [ ] array ) : this ( rows , columns )
public SparseMatrix ( int rows , int columns , Complex32 [ ] array )
: this ( rows , columns )
{
{
if ( rows * columns > array . Length )
if ( rows * columns > array . Length )
{
{
@ -164,7 +168,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array.
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array.
/// </summary>
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
/// <param name="array">The 2D array to create this matrix from.</param>
public SparseMatrix ( Complex32 [ , ] array ) : this ( array . GetLength ( 0 ) , array . GetLength ( 1 ) )
public SparseMatrix ( Complex32 [ , ] array )
: this ( array . GetLength ( 0 ) , array . GetLength ( 1 ) )
{
{
var rows = array . GetLength ( 0 ) ;
var rows = array . GetLength ( 0 ) ;
var columns = array . GetLength ( 1 ) ;
var columns = array . GetLength ( 1 ) ;
@ -1499,5 +1504,70 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
}
}
}
}
/// <summary>
/// Gets a value indicating whether this matrix is symmetric.
/// </summary>
public override bool IsSymmetric
{
get
{
if ( RowCount ! = ColumnCount )
{
return false ;
}
// todo: we might be able to speed this up by caching one half of the matrix
for ( var row = 0 ; row < RowCount - 1 ; row + + )
{
var start = _ rowIndex [ row ] ;
var end = _ rowIndex [ row + 1 ] ;
if ( start = = end )
{
continue ;
}
if ( ! CheckIfOppositesAreEqual ( start , end , row ) )
{
return false ;
}
}
var lastRow = _ rowIndex . Length - 1 ;
if ( _ rowIndex [ lastRow ] < NonZerosCount )
{
if ( ! CheckIfOppositesAreEqual ( _ rowIndex [ lastRow ] , NonZerosCount , lastRow ) )
{
return false ;
}
}
return true ;
}
}
/// <summary>
/// Checks if opposites in a range are equal.
/// </summary>
/// <param name="start">The start of the range.</param>
/// <param name="end">The end of the range.</param>
/// <param name="row">The row the row to check.</param>
/// <returns>If the values are equal or not.</returns>
private bool CheckIfOppositesAreEqual ( int start , int end , int row )
{
for ( var index = start ; index < end ; index + + )
{
var column = _ columnIndices [ index ] ;
var opposite = At ( column , row ) ;
if ( ! _ nonZeroValues [ index ] . Equals ( opposite ) )
{
return false ;
}
}
return true ;
}
}
}
}
}