--- rpl/src/statistiques.c 2010/06/24 10:10:47 1.9 +++ rpl/src/statistiques.c 2020/01/10 11:15:52 1.66 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.17 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.32 + Copyright (C) 1989-2020 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,7 +20,7 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" /* @@ -36,7 +36,8 @@ */ struct_vecteur * -sommation_statistique(struct_matrice *s_matrice) +sommation_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice) { integer8 *cumul_entier; @@ -47,10 +48,11 @@ sommation_statistique(struct_matrice *s_ struct_vecteur *s_vecteur; - unsigned long i; - unsigned long j; + integer8 i; + integer8 j; - if ((s_vecteur = (struct_vecteur *) malloc(sizeof(struct_vecteur))) == NULL) + if ((s_vecteur = (struct_vecteur *) malloc(sizeof(struct_vecteur))) + == NULL) { return NULL; } @@ -61,8 +63,8 @@ sommation_statistique(struct_matrice *s_ if ((*s_matrice).type == 'I') { - if ((cumul_entier = (integer8 *) malloc((*s_matrice).nombre_colonnes * - sizeof(integer8))) == NULL) + if ((cumul_entier = (integer8 *) malloc(((size_t) (*s_matrice) + .nombre_colonnes) * sizeof(integer8))) == NULL) { free(s_vecteur); return NULL; @@ -103,15 +105,15 @@ sommation_statistique(struct_matrice *s_ free(cumul_entier); - if (((*s_vecteur).tableau = malloc((*s_matrice).nombre_colonnes * - sizeof(real8))) == NULL) + if (((*s_vecteur).tableau = malloc(((size_t) (*s_matrice) + .nombre_colonnes) * sizeof(real8))) == NULL) { free(s_vecteur); return NULL; } - if ((colonne = (real8 *) malloc((*s_matrice).nombre_lignes * - sizeof(real8))) == NULL) + if ((colonne = (real8 *) malloc(((size_t) (*s_matrice) + .nombre_lignes) * sizeof(real8))) == NULL) { free(s_vecteur); return NULL; @@ -149,14 +151,14 @@ sommation_statistique(struct_matrice *s_ else if ((*s_matrice).type == 'R') { - if (((*s_vecteur).tableau = malloc((*s_matrice).nombre_colonnes * - sizeof(real8))) == NULL) + if (((*s_vecteur).tableau = malloc(((size_t) (*s_matrice) + .nombre_colonnes) * sizeof(real8))) == NULL) { free(s_vecteur); return NULL; } - if ((colonne = (real8 *) malloc((*s_matrice).nombre_lignes * + if ((colonne = (real8 *) malloc(((size_t) (*s_matrice).nombre_lignes) * sizeof(real8))) == NULL) { free(s_vecteur); @@ -204,8 +206,9 @@ sommation_statistique(struct_matrice *s_ */ struct_vecteur * -sommation_produits_colonnes_statistiques(struct_matrice *s_matrice, - unsigned long position_1, unsigned long position_2) +sommation_produits_colonnes_statistiques(struct_processus *s_etat_processus, + struct_matrice *s_matrice, + integer8 position_1, integer8 position_2) { integer8 *cumul_entier; integer8 tampon; @@ -217,7 +220,7 @@ sommation_produits_colonnes_statistiques struct_vecteur *s_vecteur; - unsigned long i; + integer8 i; if ((s_vecteur = (struct_vecteur *) malloc(sizeof(struct_vecteur))) == NULL) { @@ -281,8 +284,8 @@ sommation_produits_colonnes_statistiques return NULL; } - if ((colonne = (real8 *) malloc((*s_matrice).nombre_lignes * - sizeof(real8))) == NULL) + if ((colonne = (real8 *) malloc(((size_t) (*s_matrice) + .nombre_lignes) * sizeof(real8))) == NULL) { free(s_vecteur); return NULL; @@ -325,7 +328,7 @@ sommation_produits_colonnes_statistiques return NULL; } - if ((colonne = (real8 *) malloc((*s_matrice).nombre_lignes * + if ((colonne = (real8 *) malloc(((size_t) (*s_matrice).nombre_lignes) * sizeof(real8))) == NULL) { free(s_vecteur); @@ -370,7 +373,8 @@ sommation_produits_colonnes_statistiques */ struct_vecteur * -sommation_colonne_statistique(struct_matrice *s_matrice, unsigned long position) +sommation_colonne_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice, integer8 position) { integer8 *cumul_entier; @@ -381,7 +385,7 @@ sommation_colonne_statistique(struct_mat struct_vecteur *s_vecteur; - unsigned long i; + integer8 i; if ((s_vecteur = (struct_vecteur *) malloc(sizeof(struct_vecteur))) == NULL) { @@ -439,8 +443,8 @@ sommation_colonne_statistique(struct_mat return NULL; } - if ((colonne = (real8 *) malloc((*s_matrice).nombre_lignes * - sizeof(real8))) == NULL) + if ((colonne = (real8 *) malloc(((size_t) (*s_matrice) + .nombre_lignes) * sizeof(real8))) == NULL) { free(s_vecteur); return NULL; @@ -481,7 +485,7 @@ sommation_colonne_statistique(struct_mat return NULL; } - if ((colonne = (real8 *) malloc((*s_matrice).nombre_lignes * + if ((colonne = (real8 *) malloc(((size_t) (*s_matrice).nombre_lignes) * sizeof(real8))) == NULL) { free(s_vecteur); @@ -525,7 +529,8 @@ sommation_colonne_statistique(struct_mat */ struct_vecteur * -moyenne_statistique(struct_matrice *s_matrice) +moyenne_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice) { integer8 *tampon; @@ -533,9 +538,10 @@ moyenne_statistique(struct_matrice *s_ma struct_vecteur *s_vecteur; - unsigned long i; + integer8 i; - if ((s_vecteur = sommation_statistique(s_matrice)) == NULL) + if ((s_vecteur = sommation_statistique(s_etat_processus, s_matrice)) + == NULL) { return NULL; } @@ -574,7 +580,7 @@ moyenne_statistique(struct_matrice *s_ma { tampon = (*s_vecteur).tableau; - if (((*s_vecteur).tableau = malloc((*s_vecteur).taille * + if (((*s_vecteur).tableau = malloc(((size_t) (*s_vecteur).taille) * sizeof(real8))) == NULL) { return NULL; @@ -610,21 +616,22 @@ moyenne_statistique(struct_matrice *s_ma */ struct_vecteur * -variance_statistique(struct_matrice *s_matrice, unsigned char type) +variance_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice, unsigned char type) { integer8 *tampon; logical1 erreur_memoire; - unsigned long i; - unsigned long j; + integer8 i; + integer8 j; real8 *cumul; struct_vecteur *s_moyenne; struct_vecteur *s_variance; - if ((s_moyenne = moyenne_statistique(s_matrice)) == NULL) + if ((s_moyenne = moyenne_statistique(s_etat_processus, s_matrice)) == NULL) { return NULL; } @@ -633,8 +640,8 @@ variance_statistique(struct_matrice *s_m * Le résultat de cette fonction est toujours réel. */ - if ((cumul = (real8 *) malloc((*s_matrice).nombre_lignes * sizeof(real8))) - == NULL) + if ((cumul = (real8 *) malloc(((size_t) (*s_matrice).nombre_lignes) * + sizeof(real8))) == NULL) { return NULL; } @@ -649,8 +656,8 @@ variance_statistique(struct_matrice *s_m { tampon = (*s_moyenne).tableau; - if (((*s_moyenne).tableau = malloc((*s_moyenne).taille * sizeof(real8))) - == NULL) + if (((*s_moyenne).tableau = malloc(((size_t) (*s_moyenne).taille) * + sizeof(real8))) == NULL) { return NULL; } @@ -664,8 +671,8 @@ variance_statistique(struct_matrice *s_m free(tampon); } - if (((*s_variance).tableau = malloc((*s_matrice).nombre_colonnes * - sizeof(real8))) == NULL) + if (((*s_variance).tableau = malloc(((size_t) (*s_matrice).nombre_colonnes) + * sizeof(real8))) == NULL) { return NULL; } @@ -759,13 +766,15 @@ variance_statistique(struct_matrice *s_m */ struct_vecteur * -ecart_type_statistique(struct_matrice *s_matrice, unsigned char type) +ecart_type_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice, unsigned char type) { struct_vecteur *s_vecteur; - unsigned long i; + integer8 i; - if ((s_vecteur = variance_statistique(s_matrice, type)) == NULL) + if ((s_vecteur = variance_statistique(s_etat_processus, s_matrice, type)) + == NULL) { return NULL; } @@ -794,7 +803,7 @@ ecart_type_statistique(struct_matrice *s real8 correlation_statistique(struct_matrice *s_matrice, - unsigned long colonne_1, unsigned long colonne_2, logical1 *erreur) + integer8 colonne_1, integer8 colonne_2, logical1 *erreur) { logical1 erreur_memoire; @@ -804,13 +813,13 @@ correlation_statistique(struct_matrice * real8 numerateur; real8 *vecteur; - unsigned long i; - unsigned long nombre_observations; + integer8 i; + integer8 nombre_observations; (*erreur) = d_absence_erreur; - if ((vecteur = (real8 *) malloc((nombre_observations = - (*s_matrice).nombre_lignes) * sizeof(real8))) == NULL) + if ((vecteur = sys_malloc(((size_t) (nombre_observations = + (*s_matrice).nombre_lignes)) * sizeof(real8))) == NULL) { (*erreur) = d_erreur; return 0; @@ -827,7 +836,8 @@ correlation_statistique(struct_matrice * } moyenne_colonne_1 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -841,7 +851,8 @@ correlation_statistique(struct_matrice * } moyenne_colonne_2 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -908,7 +919,8 @@ correlation_statistique(struct_matrice * } moyenne_colonne_1 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -923,7 +935,8 @@ correlation_statistique(struct_matrice * } moyenne_colonne_2 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -985,7 +998,7 @@ correlation_statistique(struct_matrice * denominateur = sqrt(denominateur); } - free(vecteur); + sys_free(vecteur); return numerateur / denominateur; } @@ -1004,9 +1017,8 @@ correlation_statistique(struct_matrice * */ real8 -covariance_statistique(struct_matrice *s_matrice, - unsigned long colonne_1, unsigned long colonne_2, - unsigned char type, logical1 *erreur) +covariance_statistique(struct_matrice *s_matrice, integer8 colonne_1, + integer8 colonne_2, unsigned char type, logical1 *erreur) { logical1 erreur_memoire; @@ -1016,13 +1028,13 @@ covariance_statistique(struct_matrice *s real8 numerateur; real8 *vecteur; - unsigned long i; - unsigned long nombre_observations; + integer8 i; + integer8 nombre_observations; (*erreur) = d_absence_erreur; - if ((vecteur = (real8 *) malloc((nombre_observations = - (*s_matrice).nombre_lignes) * sizeof(real8))) == NULL) + if ((vecteur = sys_malloc(((size_t) (nombre_observations = + (*s_matrice).nombre_lignes)) * sizeof(real8))) == NULL) { (*erreur) = d_erreur; return 0; @@ -1033,11 +1045,11 @@ covariance_statistique(struct_matrice *s if (type == 'E') { - denominateur = nombre_observations - 1; + denominateur = ((real8) nombre_observations) - 1; } else { - denominateur = nombre_observations; + denominateur = ((real8) nombre_observations); } if ((*s_matrice).type == 'R') @@ -1048,7 +1060,8 @@ covariance_statistique(struct_matrice *s } moyenne_colonne_1 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -1062,7 +1075,8 @@ covariance_statistique(struct_matrice *s } moyenne_colonne_2 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -1095,7 +1109,8 @@ covariance_statistique(struct_matrice *s } moyenne_colonne_1 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -1110,7 +1125,8 @@ covariance_statistique(struct_matrice *s } moyenne_colonne_2 = sommation_vecteur_reel(vecteur, - &nombre_observations, &erreur_memoire) / nombre_observations; + &nombre_observations, &erreur_memoire) / + ((real8) nombre_observations); if (erreur_memoire == d_vrai) { @@ -1136,7 +1152,7 @@ covariance_statistique(struct_matrice *s } } - free(vecteur); + sys_free(vecteur); return numerateur / denominateur; }