Matrix_hub icon indicating copy to clipboard operation
Matrix_hub copied to clipboard

【relu】激活函数的添加

Open sjhsbhqf opened this issue 1 year ago • 0 comments

代码如下

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;
}

sjhsbhqf avatar Oct 13 '23 09:10 sjhsbhqf