Open sjhsbhqf opened 10 months ago
代码如下
Matrix *M_Relu(Matrix *_mat_origin) {/* * Absolute the value of elements in the Matrix (create). * 矩阵所有元素取Relu函数值,大于0不变,小于0赋值0*/ Matrix *_mat = (Matrix *) malloc(sizeof(Matrix)); _mat->row = _mat_origin->row; _mat->column = _mat_origin->column; int size = _mat->row * _mat->column; _mat->data = (MATRIX_TYPE *) malloc((size) * sizeof(MATRIX_TYPE)); int i; for (i = 0; i < size; i++) { if(_mat_origin->data[i]<0) { _mat->data[i] = 0; continue; } _mat->data[i] = _mat_origin->data[i]; } return _mat; }
代码如下