Amoiensis / Matrix_hub

A lib of Matrix operation for C language. (矩阵运算库--C语言)
Apache License 2.0
234 stars 53 forks source link

【relu】激活函数的添加 #16

Open sjhsbhqf opened 10 months ago

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