update matrix
This commit is contained in:
parent
db71a9a47f
commit
99a2de65d6
@ -33,4 +33,4 @@ add_example(array_ex OFF)
|
||||
add_example(gmt_ex OFF)
|
||||
add_example(gnuplot_ex OFF)
|
||||
add_example(stl_io_ex OFF)
|
||||
add_example(ply_io_ex ON)
|
||||
add_example(ply_io_ex OFF)
|
@ -36,14 +36,14 @@ namespace gctl
|
||||
template <typename MatValType> class matrix;
|
||||
|
||||
/*
|
||||
* Here we define some commonly used array types.
|
||||
* Here we define some commonly used matrix types.
|
||||
*/
|
||||
typedef matrix<int> _2i_matrix; ///< 2-D integer array
|
||||
typedef matrix<float> _2f_matrix; ///< 2-D single-precision floating-point array
|
||||
typedef matrix<double> _2d_matrix; ///< 2-D double-precision floating-point array
|
||||
typedef matrix<std::string> _2s_matrix; ///< 2-D string array
|
||||
typedef matrix<std::complex<float> > _2cf_matrix; ///< 1-D complex float array
|
||||
typedef matrix<std::complex<double> > _2cd_matrix; ///< 1-D complex double array
|
||||
typedef matrix<int> _2i_matrix; ///< 2-D integer matrix
|
||||
typedef matrix<float> _2f_matrix; ///< 2-D single-precision floating-point matrix
|
||||
typedef matrix<double> _2d_matrix; ///< 2-D double-precision floating-point matrix
|
||||
typedef matrix<std::string> _2s_matrix; ///< 2-D string matrix
|
||||
typedef matrix<std::complex<float> > _2cf_matrix; ///< 1-D complex float matrix
|
||||
typedef matrix<std::complex<double> > _2cd_matrix; ///< 1-D complex double matrix
|
||||
|
||||
/**
|
||||
* @brief 二维数组模版
|
||||
@ -260,12 +260,19 @@ namespace gctl
|
||||
*/
|
||||
void mean(array<MatValType> &m, matrix_order_e odr = RowMajor);
|
||||
|
||||
/**
|
||||
* @brief 按行或列归一化矩阵元素
|
||||
*
|
||||
* @param odr 计算行或列的平均值
|
||||
*/
|
||||
void normalize(matrix_order_e odr = RowMajor);
|
||||
|
||||
/**
|
||||
* @brief 计算矩阵的模长
|
||||
*
|
||||
* @param n_type 模的类型
|
||||
*/
|
||||
double norm(norm_type_e n_type = L2) const;
|
||||
double module(norm_type_e n_type = L2) const;
|
||||
|
||||
/**
|
||||
* @brief Set elements' value as a sequent.
|
||||
@ -829,7 +836,47 @@ namespace gctl
|
||||
}
|
||||
|
||||
template <typename MatValType>
|
||||
double matrix<MatValType>::norm(norm_type_e n_type) const
|
||||
void matrix<MatValType>::normalize(matrix_order_e odr)
|
||||
{
|
||||
if (odr == RowMajor)
|
||||
{
|
||||
for (size_t i = 0; i < row_length; i++)
|
||||
{
|
||||
MatValType sum = 0.0;
|
||||
for (size_t j = 0; j < col_length; j++)
|
||||
{
|
||||
sum += val[i][j]*val[i][j];
|
||||
}
|
||||
sum = sqrt(sum);
|
||||
|
||||
for (size_t j = 0; j < col_length; j++)
|
||||
{
|
||||
val[i][j] /= sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // ColMajor
|
||||
{
|
||||
for (size_t j = 0; j < col_length; j++)
|
||||
{
|
||||
MatValType sum = 0.0;
|
||||
for (size_t i = 0; i < row_length; i++)
|
||||
{
|
||||
sum += val[i][j]*val[i][j];
|
||||
}
|
||||
sum = sqrt(sum);
|
||||
|
||||
for (size_t i = 0; i < row_length; i++)
|
||||
{
|
||||
val[i][j] /= sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename MatValType>
|
||||
double matrix<MatValType>::module(norm_type_e n_type) const
|
||||
{
|
||||
MatValType nval = (MatValType) 0;
|
||||
if (n_type == L0)
|
||||
|
Loading…
Reference in New Issue
Block a user