Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math:colmeans,colsums: Add new functions to pal #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/pal_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ void p_min_f32(const float *a, float *c, int *index, int n);
*
****************************************************************
*/
/*means of columns of matrix: c = mean ( a[, n-1:0] ) */
void p_colmeans_f32(const float *a, float *c, size_t m, size_t n);

/*sum of columns of matrix: c = sum ( a[, n-1:0] ) */
void p_colsums_f32(const float *a, float *c, size_t m, size_t n);

/*sort an array*/
void p_sort_f32(const float *a, float *c, int n);
Expand Down
2 changes: 2 additions & 0 deletions src/math/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ libpal_math_la_SOURCES = \
p_atan.c \
p_atanh.c \
p_cbrt.c \
p_colmeans.c \
p_colsums.c \
p_cos.c \
p_cosh.c \
p_div.c \
Expand Down
33 changes: 33 additions & 0 deletions src/math/p_colmeans.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <pal.h>

/**
*
* Calculates the means vector 'c' of matrix 'a' columns.
*
* @param a Pointer to input matrix
*
* @param c Pointer to output vector
*
* @param m Number of matrix rows
*
* @param n Number of matrix columns and size of output vector
*
* @return None
*
*/

void p_colmeans_f32(const float *a, float *c, size_t m, size_t n)
{
const float *pa;
float *pc;
size_t i;

pa = a;
pc = c;

p_colsums_f32(pa, pc, m, n);

for (i = 0; i < n; ++i) {
*(pc + i) /= n;
}
}
31 changes: 31 additions & 0 deletions src/math/p_colsums.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <pal.h>

/**
*
* Calculates the sums vector 'c' of matrix 'a' columns.
*
* @param a Pointer to input matrix
*
* @param c Pointer to output vector
*
* @param m Number of matrix rows
*
* @param n Number of matrix columns and size of output vector
*
* @return None
*
*/

void p_colsums_f32(const float *a, float *c, size_t m, size_t n)
{
const float *pa;
float *pc;
size_t i;

pa = a;
pc = c;

for (i = 0; i < m * n; ++i) {
*(pc + i % n) += *(pa + i);
}
}
6 changes: 6 additions & 0 deletions tests/math/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ check_PROGRAMS = \
check_p_atan_f32 \
check_p_atanh_f32 \
check_p_cbrt_f32 \
check_p_colmeans_f32 \
check_p_colsums_f32 \
check_p_cos_f32 \
check_p_cosh_f32 \
check_p_div_f32 \
Expand Down Expand Up @@ -126,6 +128,8 @@ check_p_atan2_f32_SOURCES = $(SIMPLE) p_atan2.c
check_p_atan_f32_SOURCES = $(SIMPLE) p_atan.c
check_p_atanh_f32_SOURCES = $(SIMPLE) p_atanh.c
check_p_cbrt_f32_SOURCES = $(SIMPLE) p_cbrt.c
check_p_colmeans_f32_SOURCES = notest.c
check_p_colsums_f32_SOURCES = notest.c
check_p_cos_f32_SOURCES = $(SIMPLE) p_cos.c
check_p_cosh_f32_SOURCES = $(SIMPLE) p_cosh.c
check_p_div_f32_SOURCES = $(SIMPLE)
Expand Down Expand Up @@ -172,6 +176,8 @@ check_p_atan2_f32_CFLAGS = -DFUNCTION=p_atan2_f32 -DIS_BINARY
check_p_atan_f32_CFLAGS = -DFUNCTION=p_atan_f32 -DIS_UNARY
check_p_atanh_f32_CFLAGS = -DFUNCTION=p_atanh_f32 -DIS_UNARY
check_p_cbrt_f32_CFLAGS = -DFUNCTION=p_cbrt_f32 -DIS_UNARY
check_p_colmeans_f32_CFLAGS = -DFUNCTION=p_colmeans_f32 -DIS_UNARY
check_p_colsums_f32_CFLAGS = -DFUNCTION=p_colsums_f32 -DIS_UNARY
check_p_cos_f32_CFLAGS = -DFUNCTION=p_cos_f32 -DIS_UNARY
check_p_cosh_f32_CFLAGS = -DFUNCTION=p_cosh_f32 -DIS_UNARY
check_p_div_f32_CFLAGS = -DFUNCTION=p_div_f32 -DIS_BINARY
Expand Down