Replace min_float by fminf

This commit is contained in:
julienChemillier 2023-03-09 14:27:23 +01:00
parent fec4651946
commit 9d2d61703d
7 changed files with 11 additions and 47 deletions

View File

@ -5,12 +5,7 @@
#include "../include/colors.h"
#include "include/function.h"
float max_float(float a, float b) {
return a < b ? b:a;
}
#define BOUND_RELU 15
float identity(float x) {
return x;
@ -33,7 +28,7 @@ float sigmoid_derivative(float x) {
float relu(float x) {
return max_float(0, x);
return fmaxf(0, fminf(x, BOUND_RELU));
}
float relu_derivative(float x) {
@ -45,7 +40,7 @@ float relu_derivative(float x) {
float leaky_relu(float x) {
if (x>0)
return x;
return fminf(x, BOUND_RELU);
return x*LEAKER;
}
@ -72,7 +67,7 @@ void apply_softmax_input(float ***input, int depth, int rows, int columns) {
for (int i=0; i < depth; i++) {
for (int j=0; j < rows; j++) {
for (int k=0; k < columns; k++) {
m = max_float(m, input[i][j][k]);
m = fmaxf(m, input[i][j][k]);
}
}
}

View File

@ -16,11 +16,6 @@
typedef float (*ptr)(float);
typedef ptr (*pm)();
/*
* Fonction max pour les floats
*/
float max_float(float a, float b);
float identity(float x);
float identity_derivative(float x);

View File

@ -8,6 +8,7 @@
#define ZERO 0
#define GLOROT 1
#define XAVIER 1 // Xavier et Glorot initialisations sont indentiques
#define NORMALIZED_GLOROT 2
#define NORMALIZED_XAVIER 2
#define HE 3

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <float.h>
#include <math.h>
#include "include/convolution.h"
#include "../include/colors.h"
@ -11,17 +12,6 @@
#define BLOCKSIZE_y 8
#define BLOCKSIZE_z 8
float max_flt(float a, float b) {
// Return the max between the two floats
if (a > b) {
return a;
}
return b;
}
/*
* Average Pooling
@ -142,7 +132,7 @@ void make_max_pooling_cpu(float*** input, float*** output, int size, int output_
m = FLT_MIN;
for (int a=0; a < size; a++) {
for (int b=0; b < size; b++) {
m = max_flt(m, input[i][size*j +a][size*k +b]);
m = fmaxf(m, input[i][size*j +a][size*k +b]);
}
}
output[i][j][k] = m;

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <float.h>
#include <math.h>
#include "include/convolution.h"
#include "../include/colors.h"
@ -11,17 +12,6 @@
#define BLOCKSIZE_y 8
#define BLOCKSIZE_z 8
float max_flt(float a, float b) {
// Return the max between the two floats
if (a > b) {
return a;
}
return b;
}
/*
* Average Pooling
@ -142,7 +132,7 @@ void make_max_pooling_cpu(float*** input, float*** output, int size, int output_
m = FLT_MIN;
for (int a=0; a < size; a++) {
for (int b=0; b < size; b++) {
m = max_flt(m, input[i][size*j +a][size*k +b]);
m = fmaxf(m, input[i][size*j +a][size*k +b]);
}
}
output[i][j][k] = m;

View File

@ -77,9 +77,6 @@ void free_matrix(float*** matrix, int n, int p) {
free(matrix);
}
float max_float(float a, float b) {
return a > b ? a : b;
}
bool check_matrices_equality(float*** m1, float*** m2, int n, int p, int q, int acceptation) {
float err_max = 0.;
@ -93,7 +90,7 @@ bool check_matrices_equality(float*** m1, float*** m2, int n, int p, int q, int
//return false;
}
err_percent = 2*fabs(m1[i][j][k] - m2[i][j][k])/fabs(m1[i][j][k] + m2[i][j][k]);
err_max = max_float(err_max, err_percent);
err_max = fmaxf(err_max, err_percent);
err_moy += err_percent;
}
}

View File

@ -55,10 +55,6 @@ float** create_empty_matrix(int n, int p) {
return matrix;
}
float max_float(float a, float b) {
return a > b ? a : b;
}
bool check_matrices_equality(float** m1, float** m2, int n, int p) {
float err_max = 0.;
@ -71,7 +67,7 @@ bool check_matrices_equality(float** m1, float** m2, int n, int p) {
//return false;
}
err_percent = 2*fabs(m1[i][j] - m2[i][j])/fabs(m1[i][j] + m2[i][j]);
err_max = max_float(err_max, err_percent);
err_max = fmaxf(err_max, err_percent);
err_moy += err_percent;
}
}