forked from huawei/openGauss-server
Update matrix.cpp
This commit is contained in:
parent
41d9fcfd26
commit
3900e88c53
|
|
@ -33,6 +33,11 @@ calculation, and for a square matrix, determinant calculation is also required.*
|
|||
|
||||
#define MATRIX_LIMITED_OUTPUT 30
|
||||
|
||||
|
||||
/*Function: void matrix_ Init_ Random_ Gaussian
|
||||
Formal parameters: (Matrix * matrix, int rows, int columns, float8 mu, float8 sigma, int seed)
|
||||
Return: None
|
||||
Production random Gaussian matrix*/
|
||||
// using Box-Muller implementation
|
||||
void matrix_init_random_gaussian(Matrix *matrix, int rows, int columns, float8 mu, float8 sigma, int seed)
|
||||
{
|
||||
|
|
@ -60,12 +65,20 @@ void matrix_init_random_gaussian(Matrix *matrix, int rows, int columns, float8 m
|
|||
}
|
||||
}
|
||||
|
||||
/*Function: matrix_ Init_ Kernel_ Gaussian
|
||||
Formal parameters: (int features, int components, float8 gamma, int seed, Matrix * weights, Matrix * offsets)
|
||||
Return: None
|
||||
Initialize a matrix using a specified number*/
|
||||
void matrix_init_kernel_gaussian(int features, int components, float8 gamma, int seed, Matrix *weights, Matrix *offsets)
|
||||
{
|
||||
matrix_init_random_gaussian(weights, features, components, 0.0, sqrt(2.0 * gamma), seed);
|
||||
matrix_init_random_uniform(offsets, components, 1, 0.0, 2.0 * M_PI, seed+1);
|
||||
}
|
||||
|
||||
/*Function: matrix_ Transform_ Kernel_ Gaussian
|
||||
Formal parameters: (const Matrix * input, const Matrix * weights, const Matrix * offsets, Matrix * output)
|
||||
Return: None
|
||||
Matrix transpose*/
|
||||
void matrix_transform_kernel_gaussian(const Matrix *input, const Matrix *weights, const Matrix *offsets, Matrix *output)
|
||||
{
|
||||
int components = weights->columns;
|
||||
|
|
@ -91,6 +104,10 @@ void matrix_transform_kernel_gaussian(const Matrix *input, const Matrix *weights
|
|||
matrix_mult_scalar(output, sqrt(2.0 / components));
|
||||
}
|
||||
|
||||
/*Function: matrix_ Init_ Random_ Uniform
|
||||
Formal parameters: (Matrix * matrix, int rows, int columns, float8 min, float8 max, int seed)
|
||||
Return: None
|
||||
Initializing a matrix using random floating-point numbers*/
|
||||
void matrix_init_random_uniform(Matrix *matrix, int rows, int columns, float8 min, float8 max, int seed)
|
||||
{
|
||||
Assert(min < max);
|
||||
|
|
@ -109,7 +126,10 @@ void matrix_init_random_uniform(Matrix *matrix, int rows, int columns, float8 mi
|
|||
*pd++ = min + range * u;
|
||||
}
|
||||
}
|
||||
|
||||
/*Function: matrix_ Init_ Random_ Bernoulli
|
||||
Formal parameters: (Matrix * matrix, int rows, int columns, float8 p, float8 min, float8 max, int seed)
|
||||
Return: None
|
||||
Generate Random Bernoulli Matrix*/
|
||||
void matrix_init_random_bernoulli(Matrix *matrix, int rows, int columns, float8 p, float8 min, float8 max, int seed)
|
||||
{
|
||||
matrix_init(matrix, rows, columns);
|
||||
|
|
@ -126,6 +146,11 @@ void matrix_init_random_bernoulli(Matrix *matrix, int rows, int columns, float8
|
|||
}
|
||||
}
|
||||
|
||||
/*Function: matrix_ Init_ Kernel_ Polynomial
|
||||
Formal parameters: (int features, int components, int degree, float8 coef0, int seed, Matrix * weights,
|
||||
Matrix * coefs)
|
||||
Return: int*
|
||||
Initialize a polynomial matrix using a specified number*/
|
||||
int *matrix_init_kernel_polynomial(int features, int components, int degree, float8 coef0, int seed, Matrix *weights,
|
||||
Matrix *coefs)
|
||||
{
|
||||
|
|
@ -160,6 +185,11 @@ int *matrix_init_kernel_polynomial(int features, int components, int degree, flo
|
|||
return pcomponents;
|
||||
}
|
||||
|
||||
/*Function: matrix_ Transform_ Kernel_ Polynomial
|
||||
Formal parameters: (const Matrix * input, int ncomponents, int * components, const Matrix * weights,
|
||||
Const Matrix * coefficients, Matrix * output)
|
||||
Return: None
|
||||
Polynomial matrix transpose*/
|
||||
void matrix_transform_kernel_polynomial(const Matrix *input, int ncomponents, int *components, const Matrix *weights,
|
||||
const Matrix *coefficients, Matrix *output)
|
||||
{
|
||||
|
|
@ -185,6 +215,10 @@ void matrix_transform_kernel_polynomial(const Matrix *input, int ncomponents, in
|
|||
matrix_mult_scalar(output, sqrt(1.0 / output->rows));
|
||||
}
|
||||
|
||||
/*Function: matrix_ Mult
|
||||
Formal parameters: (const Matrix * matrix1, const Matrix * matrix2, Matrix * result)
|
||||
Return value: None
|
||||
matrix multiplication*/
|
||||
void matrix_mult(const Matrix *matrix1, const Matrix *matrix2, Matrix *result)
|
||||
{
|
||||
Assert(matrix1 != nullptr);
|
||||
|
|
@ -213,6 +247,10 @@ void matrix_mult(const Matrix *matrix1, const Matrix *matrix2, Matrix *result)
|
|||
}
|
||||
}
|
||||
|
||||
/*Function: matrix_ Print
|
||||
Formal parameters: (const Matrix * matrix, StringInfo buf, bool full)
|
||||
Return value: None
|
||||
Print Matrix*/
|
||||
void matrix_print(const Matrix *matrix, StringInfo buf, bool full)
|
||||
{
|
||||
Assert(matrix != nullptr);
|
||||
|
|
@ -253,6 +291,24 @@ void matrix_print(const Matrix *matrix, StringInfo buf, bool full)
|
|||
appendStringInfoChar(buf, ']');
|
||||
}
|
||||
|
||||
/*Function: elog_ Matrix
|
||||
Formal parameters: (int level, const char * msg, const matrix * matrix)
|
||||
Return value: None
|
||||
Matrix error*/
|
||||
/*elog is an old mode that can be equivalent to the ereport mode.
|
||||
You can see that it provides level and the error level is the same,
|
||||
but it does not provide errcode. As mentioned earlier, the default
|
||||
errcode is provided based on the severity level. Then the message
|
||||
is passed through an auxiliary function errmsg_ Internal() goes to
|
||||
show it, and the process is different from the errmsg in ereport mentioned
|
||||
earlier. errmsg() is set according to regional settings, such as it can be
|
||||
translated into the language of the corresponding country, such as Chinese.
|
||||
In fact, errmsg_ Internal() is a language that is not limited by translation and
|
||||
can automatically print out the original language.
|
||||
Why should we keep this old pattern? Because it is concise enough, when
|
||||
there are some internal errors, such as internal errors in the PG kernel, these
|
||||
errors are not actually displayed to the user and are not of interest to the user.
|
||||
This concise mode can be used for printing, which is very convenient and has been preserved.*/
|
||||
void elog_matrix(int elevel, const char *msg, const Matrix *matrix)
|
||||
{
|
||||
if (is_errmodule_enable(elevel, MOD_DB4AI)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue