📄 matrix.cpp
字号:
{
return 0.0;
}
else
{
return m_Matrix.cplx[col][row].im;
}
}
else
{
return 0.0;
}
}
bool Matrix::isStoredAsComplex()
{
if( m_Matrix.isReal )
return false;
else
return true;
}
/// Is this a real matrix for accessing by (row,col) operator? e.g. double d = A(0,4).
bool Matrix::isReal()
{
BOOL isItReal = 0;
// not checking return value
MTX_isReal(&m_Matrix,&isItReal);
if( isItReal )
return true;
else
return false;
}
/// Is this a complex matrix for accessing by [row][col] operators? e.g. stComplex d = A[0][4].
bool Matrix::isComplex()
{
return !isReal();
}
bool Matrix::isVector()
{
if( m_Matrix.nrows == 1 )
return true;
if( m_Matrix.ncols == 1 )
return true;
// otherwise
return false;
}
bool Matrix::ReadFromFile( const char *path )
{
if( MTX_ReadFromFile( &m_Matrix, path ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_ReadFromFile returned false." );
return false;
}
}
bool Matrix::ReadFromFile( std::string path )
{
return ReadFromFile( path.c_str() );
}
bool Matrix::Copy( Matrix& src )
{
if( MTX_Copy( &src.m_Matrix, &m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Copy returned false." );
return false;
}
}
bool Matrix::Copy( const double& value )
{
if( !MTX_Malloc( &m_Matrix, 1, 1, true ) )
{
MTX_ERROR_MSG( "MTX_Malloc returned false." );
return false;
}
if( MTX_SetValue( &m_Matrix, 0, 0, value ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_SetValue returned false." );
return false;
}
}
bool Matrix::Copy( const std::complex<double>& cplx )
{
if( !MTX_Malloc( &m_Matrix, 1, 1, false ) )
{
MTX_ERROR_MSG( "MTX_Malloc returned false." );
return false;
}
if( MTX_SetComplexValue( &m_Matrix, 0, 0, cplx.real(), cplx.imag() ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_SetComplexValue returned false." );
return false;
}
}
bool Matrix::Save( const char* path )
{
if( MTX_SaveCompressed( &m_Matrix, path ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_SaveCompressed returned false." );
return false;
}
}
bool Matrix::Save( std::string path )
{
return Save( path.c_str() );
}
bool Matrix::Print( const char *path, const unsigned precision, bool append )
{
if( MTX_PrintAutoWidth( &m_Matrix, path, precision, append ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_PrintAutoWidth returned false." );
return false;
}
}
bool Matrix::Print( std::string path, const unsigned precision, bool append )
{
return Print( path.c_str(), precision );
}
bool Matrix::PrintStdout( const unsigned precision )
{
if( m_Matrix.ncols == 0 || m_Matrix.nrows == 0 )
{
printf( "\n" );
return true;
}
if( MTX_PrintStdoutAutoWidth( &m_Matrix, precision ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_PrintStdoutAutoWidth returned false." );
return false;
}
}
bool Matrix::PrintToBuffer( char* buffer, const unsigned maxlength, const unsigned precision )
{
if( MTX_PrintAutoWidth_ToBuffer( &m_Matrix, buffer, maxlength, precision ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_PrintAutoWidth_ToBuffer returned false." );
return false;
}
}
bool Matrix::PrintFixedWidth( const char* path, const unsigned width, const unsigned precision, bool append )
{
if( MTX_Print( &m_Matrix, path, width, precision, append ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Print returned false." );
return false;
}
}
bool Matrix::PrintFixedWidth( std::string path, const unsigned width, const unsigned precision, bool append )
{
return PrintFixedWidth( path.c_str(), width, precision, append );
}
bool Matrix::PrintFixedWidthToBuffer( char* buffer, const unsigned maxlength, const unsigned width, const unsigned precision )
{
if( MTX_Print_ToBuffer( &m_Matrix, buffer, maxlength, width, precision ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Print_ToBuffer returned false." );
return false;
}
}
bool Matrix::PrintDelimited( const char *path, const unsigned precision, const char delimiter, bool append )
{
if( MTX_PrintDelimited( &m_Matrix, path, precision, delimiter, append ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_PrintDelimited returned false." );
return false;
}
}
bool Matrix::PrintDelimited( std::string path, const unsigned precision, const char delimiter, bool append )
{
return PrintDelimited( path.c_str(), precision, delimiter, append );
}
bool Matrix::PrintDelimitedToBuffer( char *buffer, const unsigned maxlength, const unsigned precision, const char delimiter )
{
if( MTX_PrintDelimited_ToBuffer( &m_Matrix, buffer, maxlength, precision, delimiter ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_PrintDelimited_ToBuffer returned false." );
return false;
}
}
bool Matrix::PrintRowToString( const unsigned row, char *buffer, const unsigned maxlength, const int width, const int precision )
{
if( MTX_PrintRowToString( &m_Matrix, row, buffer, maxlength, width, precision ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_PrintRowToString returned false." );
return false;
}
}
bool Matrix::RemoveColumn( const unsigned col )
{
if( MTX_RemoveColumn( &m_Matrix, col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_RemoveColumn returned false." );
return false;
}
}
bool Matrix::RemoveColumnsAfterIndex( const unsigned col )
{
if( MTX_RemoveColumnsAfterIndex( &m_Matrix, col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_RemoveColumnsAfterIndex returned false." );
return false;
}
}
bool Matrix::RemoveRowsAndColumns( const unsigned nrows, const unsigned rows[], const unsigned ncols, const unsigned cols[] )
{
if( MTX_RemoveRowsAndColumns( &m_Matrix, nrows, rows, ncols, cols ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_RemoveRowsAndColumns returned false." );
return false;
}
}
bool Matrix::InsertColumn( const Matrix &src, const unsigned dst_col, const unsigned src_col )
{
if( MTX_InsertColumn( &m_Matrix, &src.m_Matrix, dst_col, src_col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_InsertColumn returned false." );
return false;
}
}
bool Matrix::AddColumn( const Matrix &src, const unsigned src_col )
{
if( MTX_AddColumn( &m_Matrix, &src.m_Matrix, src_col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_AddColumn returned false." );
return false;
}
}
bool Matrix::Concatonate( const Matrix &src )
{
if( MTX_Concatonate( &m_Matrix, &src.m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Concatonate returned false." );
return false;
}
}
bool Matrix::Redim( const unsigned nrows, const unsigned ncols )
{
if( MTX_Redim( &m_Matrix, nrows, ncols ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Redim returned false." );
return false;
}
}
bool Matrix::Resize( const unsigned nrows, const unsigned ncols )
{
if( MTX_Resize( &m_Matrix, nrows, ncols, m_Matrix.isReal ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Resize returned false." );
return false;
}
}
bool Matrix::SetFromStaticMatrix( const double mat[], const unsigned nrows, const unsigned ncols )
{
if( MTX_SetFromStaticMatrix( &m_Matrix, mat, nrows, ncols ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_SetFromStaticMatrix returned false." );
return false;
}
}
bool Matrix::SetFromMatrixString(const char* strMatrix)
{
if( MTX_SetFromMatrixString( &m_Matrix, strMatrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_SetFromStaticMatrix returned false." );
return false;
}
}
bool Matrix::CopyColumn( const unsigned src_col, Matrix &dst )
{
if( MTX_CopyColumn( &m_Matrix, src_col, &dst.m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_CopyColumn returned false." );
return false;
}
}
bool Matrix::InsertSubMatrix( const Matrix &src, const unsigned dst_row, const unsigned dst_col )
{
if( MTX_InsertSubMatrix( &m_Matrix, &src.m_Matrix, dst_row, dst_col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_InsertSubMatrix returned false." );
return false;
}
}
bool Matrix::ExtractSubMatrix(
Matrix &dst, //!< The destination matrix to contain the submatrix.
const unsigned from_row, //!< The zero-based index for the from row.
const unsigned from_col, //!< The zero-based index for the from column.
const unsigned to_row, //!< The zero-based index for the to row.
const unsigned to_col //!< The zero-based index for the to column.
)
{
if( MTX_ExtractSubMatrix( &m_Matrix, &dst.m_Matrix, from_row, from_col, to_row, to_col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_ExtractSubMatrix returned false." );
return false;
}
}
bool Matrix::Zero()
{
if( MTX_Zero( &m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Zero returned false." );
return false;
}
}
bool Matrix::ZeroColumn( const unsigned col )
{
if( MTX_ZeroColumn( &m_Matrix, col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_ZeroColumn returned false." );
return false;
}
}
bool Matrix::ZeroRow( const unsigned row )
{
if( MTX_ZeroRow( &m_Matrix, row ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_ZeroRow returned false." );
return false;
}
}
bool Matrix::Swap( Matrix &M )
{
if( MTX_Swap( &m_Matrix, &M.m_Matrix ) )
{
return true;
}
else
{
return false;
}
}
bool Matrix::Fill( const double value )
{
if( MTX_Fill( &m_Matrix, value ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Fill returned false." );
return false;
}
}
bool Matrix::FillColumn( const unsigned col, const double value )
{
if( MTX_FillColumn( &m_Matrix, col, value ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "FillColumn returned false." );
return false;
}
}
bool Matrix::FillRow( const unsigned row, const double value )
{
if( MTX_FillRow( &m_Matrix, row, value ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_FillRow returned false." );
return false;
}
}
bool Matrix::FlipColumn( const unsigned col )
{
if( MTX_FlipColumn( &m_Matrix, col ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_FlipColumn returned false." );
return false;
}
}
bool Matrix::FlipRow( const unsigned row )
{
if( MTX_FlipRow( &m_Matrix, row ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_FlipRow returned false." );
return false;
}
}
bool Matrix::Identity()
{
if( MTX_Identity( &m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Identity returned false." );
return false;
}
}
bool Matrix::Identity(const unsigned dimension)
{
if( MTX_Malloc( &m_Matrix, dimension, dimension, true ) )
{
if( MTX_Identity( &m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Identity returned false." );
return false;
}
}
else
{
MTX_ERROR_MSG( "MTX_Malloc returned false." );
return false;
}
}
bool Matrix::Inplace_Transpose()
{
if( MTX_TransposeInplace( &m_Matrix ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_TransposeInplace returned false." );
return false;
}
}
bool Matrix::Inplace_Round( const unsigned precision )
{
if( MTX_Round( &m_Matrix, precision ) )
{
return true;
}
else
{
MTX_ERROR_MSG( "MTX_Round returned false." );
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -