From 08907f873ad769a7f2326d15c9a20a84bcef5008 Mon Sep 17 00:00:00 2001 From: Brijeshcr Date: Tue, 1 Aug 2017 16:18:48 +0530 Subject: Added Moment --- 2.3-1/src/c/statisticsFunctions/includes/moment.h | 42 ++++++++++++++++++++++ .../c/statisticsFunctions/interfaces/int_moment.h | 33 +++++++++++++++++ .../src/c/statisticsFunctions/moment/dmomentcola.c | 18 ++++++++++ .../src/c/statisticsFunctions/moment/dmomentrowa.c | 18 ++++++++++ 2.3-1/src/c/statisticsFunctions/moment/dmoments.c | 17 +++++++++ .../src/c/statisticsFunctions/moment/smomentcola.c | 18 ++++++++++ .../src/c/statisticsFunctions/moment/smomentrowa.c | 18 ++++++++++ 2.3-1/src/c/statisticsFunctions/moment/smoments.c | 17 +++++++++ .../src/c/statisticsFunctions/moment/zmomentcola.c | 20 +++++++++++ .../src/c/statisticsFunctions/moment/zmomentrowa.c | 20 +++++++++++ 2.3-1/src/c/statisticsFunctions/moment/zmoments.c | 22 ++++++++++++ 11 files changed, 243 insertions(+) create mode 100644 2.3-1/src/c/statisticsFunctions/includes/moment.h create mode 100644 2.3-1/src/c/statisticsFunctions/interfaces/int_moment.h create mode 100644 2.3-1/src/c/statisticsFunctions/moment/dmomentcola.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/dmomentrowa.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/dmoments.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/smomentcola.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/smomentrowa.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/smoments.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/zmomentcola.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/zmomentrowa.c create mode 100644 2.3-1/src/c/statisticsFunctions/moment/zmoments.c (limited to '2.3-1/src/c/statisticsFunctions') diff --git a/2.3-1/src/c/statisticsFunctions/includes/moment.h b/2.3-1/src/c/statisticsFunctions/includes/moment.h new file mode 100644 index 00000000..3f419d06 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/includes/moment.h @@ -0,0 +1,42 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Brijesh Gupta C R + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ + +#ifndef __MOMENT_H__ +#define __MOMENT_H__ +#include "types.h" +#include "doubleComplex.h" +#include "floatComplex.h" +#include "pow.h" +#include "addition.h" + +#ifdef __cplusplus +extern "C" { +#endif + +double dmoments (double* inp, int size, double ord); +void dmomentrowa (double* inp, int row, int col, double ord, double* out); +void dmomentcola (double* inp, int row, int col, double ord, double* out); + +float smoments (float* inp, int size, double ord); +void smomentrowa (float* inp, int row, int col, double ord, float* out); +void smomentcola (float* inp, int row, int col, double ord, float* out); + +doubleComplex zmoments (doubleComplex* inp, int size, double ord); +void zmomentrowa (doubleComplex* inp, int row, int col, double ord, doubleComplex* out); +void zmomentcola (doubleComplex* inp, int row, int col, double ord, doubleComplex* out); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__MOMENT_H__*/ diff --git a/2.3-1/src/c/statisticsFunctions/interfaces/int_moment.h b/2.3-1/src/c/statisticsFunctions/interfaces/int_moment.h new file mode 100644 index 00000000..5e9a0362 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/interfaces/int_moment.h @@ -0,0 +1,33 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Brijesh Gupta C R + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_MOMENT_H__ +#define __INT_MOMENT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define d2d0momentd0(in1,size,in2) dmoments(in1,size[0]*size[1], in2) +#define d2d0g2momentd2(in1, size, in2, in3, size2 ,out) (in3[0] == 'r') ? dmomentrowa(in1, size[0], size[1], in2, out) : dmomentcola(in1, size[0], size[1], in2, out) + +#define s2d0moments0(in1,size,in2) smoments(in1,size[0]*size[1], in2) +#define s2d0g2moments2(in1, size, in2, in3, size2 ,out) (in3[0] == 'r') ? smomentrowa(in1, size[0], size[1], in2, out) : smomentcola(in1, size[0], size[1], in2, out) + +#define z2d0momentz0(in1,size,in2) zmoments(in1,size[0]*size[1], in2) +#define z2d0g2momentz2(in1, size, in2, in3, size2 ,out) (in3[0] == 'r') ? zmomentrowa(in1, size[0], size[1], in2, out) : zmomentcola(in1, size[0], size[1], in2, out) + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__INT_MOMENT_H__*/ diff --git a/2.3-1/src/c/statisticsFunctions/moment/dmomentcola.c b/2.3-1/src/c/statisticsFunctions/moment/dmomentcola.c new file mode 100644 index 00000000..538328e3 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/dmomentcola.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include "moment.h" + +void dmomentcola (double* inp, int row, int col, double ord, double* out) +{ + double vect[col]; + for(int i = 0; i < row ; i++) + { + for(int j = 0; j < col ; j++) + { + vect[j] = inp[i + j*row]; + } + out[i] = dmoments(vect, col, ord); + } + +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/dmomentrowa.c b/2.3-1/src/c/statisticsFunctions/moment/dmomentrowa.c new file mode 100644 index 00000000..811aac39 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/dmomentrowa.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include "moment.h" + +void dmomentrowa (double* inp, int row, int col, double ord, double* out) +{ + double vect[row]; + for(int i = 0; i < col ; i++) + { + for(int j = 0; j < row ; j++) + { + vect[j] = inp[j + i*row]; + } + out[i] = dmoments(vect, row, ord); + } + +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/dmoments.c b/2.3-1/src/c/statisticsFunctions/moment/dmoments.c new file mode 100644 index 00000000..b9d8564a --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/dmoments.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include "moment.h" + + +double dmoments (double* inp, int size, double ord) +{ + double sum = 0; + + for(int i = 0; i < size; i++) + { + sum = sum + pow(inp[i], ord); + } + + return sum/size; +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/smomentcola.c b/2.3-1/src/c/statisticsFunctions/moment/smomentcola.c new file mode 100644 index 00000000..4255782c --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/smomentcola.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include "moment.h" + +void smomentcola (float* inp, int row, int col, double ord, float* out) +{ + float vect[col]; + for(int i = 0; i < row ; i++) + { + for(int j = 0; j < col ; j++) + { + vect[j] = inp[i + j*row]; + } + out[i] = smoments(vect, col, ord); + } + +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/smomentrowa.c b/2.3-1/src/c/statisticsFunctions/moment/smomentrowa.c new file mode 100644 index 00000000..574ebe76 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/smomentrowa.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include "moment.h" + +void smomentrowa (float* inp, int row, int col, double ord, float* out) +{ + float vect[row]; + for(int i = 0; i < col ; i++) + { + for(int j = 0; j < row ; j++) + { + vect[j] = inp[j + i*row]; + } + out[i] = smoments(vect, row, ord); + } + +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/smoments.c b/2.3-1/src/c/statisticsFunctions/moment/smoments.c new file mode 100644 index 00000000..aee9dc9e --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/smoments.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include "moment.h" + + +float smoments (float* inp, int size, double ord) +{ + float sum = 0; + + for(int i = 0; i < size; i++) + { + sum = sum + pow(inp[i], ord); + } + + return sum/size; +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/zmomentcola.c b/2.3-1/src/c/statisticsFunctions/moment/zmomentcola.c new file mode 100644 index 00000000..2b3cebb1 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/zmomentcola.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "moment.h" +#include "doubleComplex.h" +#include "floatComplex.h" + +void zmomentcola (doubleComplex* inp, int row, int col, double ord, doubleComplex* out) +{ + double vect[col]; + for(int i = 0; i < row ; i++) + { + for(int j = 0; j < col ; j++) + { + vect[j] = inp[i + j*row]; + } + out[i] = zmoments(vect, col, ord); + } + +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/zmomentrowa.c b/2.3-1/src/c/statisticsFunctions/moment/zmomentrowa.c new file mode 100644 index 00000000..e1e1b47d --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/zmomentrowa.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "moment.h" +#include "doubleComplex.h" +#include "floatComplex.h" + +void zmomentrowa (doubleComplex* inp, int row, int col, double ord, doubleComplex* out) +{ + doubleComplex vect[row]; + for(int i = 0; i < col ; i++) + { + for(int j = 0; j < row ; j++) + { + vect[j] = inp[j + i*row]; + } + out[i] = zmoments(vect, row, ord); + } + +} diff --git a/2.3-1/src/c/statisticsFunctions/moment/zmoments.c b/2.3-1/src/c/statisticsFunctions/moment/zmoments.c new file mode 100644 index 00000000..1b847376 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/moment/zmoments.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include "moment.h" +#include "doubleComplex.h" +#include "floatComplex.h" +#include "pow.h" +#include "addition.h" +#include "division.h" + + +doubleComplex zmoments (doubleComplex* inp, int size, double ord) +{ + doubleComplex sum = DoubleComplex(0,0); + + for(int i = 0; i < size; i++) + { + sum = zadds(sum,zpows(inp[i], ord)); + } + + return zrdivs(sum,size); +} -- cgit