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: p_minmax: Implement minmax algorithm and related tests/benchmarks, removing unused variables from check_scalar_and_index.c #226

Open
wants to merge 4 commits 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Makefile.in
/tests/*.log
/tests/*.sum
/tests/*/check_p_*
!/tests/*/check_p_*.h
!/tests/*/check_p_*.c
/tests/*/*.log

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ FUNCTION | NOTES
[p_log10()](src/math/p_log10.c) | denary log
[p_max()](src/math/p_max.c) | finds max val
[p_min()](src/math/p_min.c) | finds min val
[p_mean()](src/math/p_mean.c) | mean operation
[p_minmax()](src/math/p_minmax.c) | finds min and max val
[p_mean()](src/math/p_mean.c) | mean operation
[p_median()](src/math/p_median.c) | finds middle value
[p_mode()](src/math/p_mode.c) | finds most common value
[p_mul()](src/math/p_mul.c) | multiplication
Expand Down
4 changes: 4 additions & 0 deletions benchmark/math/Makemodule.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ benchmark/math/bench_p_max_f32 \
benchmark/math/bench_p_mean_f32 \
benchmark/math/bench_p_median_f32 \
benchmark/math/bench_p_min_f32 \
benchmark/math/bench_p_minmax_f32 \
benchmark/math/bench_p_mul_f32 \
benchmark/math/bench_p_popcount_u32 \
benchmark/math/bench_p_popcount_u64 \
Expand Down Expand Up @@ -81,6 +82,7 @@ benchmark_math_bench_p_max_f32_SOURCES = benchmark/math/p_max_f32.c
benchmark_math_bench_p_mean_f32_SOURCES = benchmark/math/one.c
benchmark_math_bench_p_median_f32_SOURCES = benchmark/math/one.c
benchmark_math_bench_p_min_f32_SOURCES = benchmark/math/p_min_f32.c
benchmark_math_bench_p_minmax_f32_SOURCES = benchmark/math/p_minmax_f32.c
benchmark_math_bench_p_mode_f32_SOURCES = benchmark/math/one.c
benchmark_math_bench_p_mul_f32_SOURCES = benchmark/math/one.c
benchmark_math_bench_p_popcount_u32_SOURCES = benchmark/math/p_popcount_u32.c
Expand Down Expand Up @@ -126,6 +128,7 @@ benchmark_math_bench_p_max_f32_CFLAGS = -DFUNCTION=p_max_f32 -DIS_
benchmark_math_bench_p_mean_f32_CFLAGS = -DFUNCTION=p_mean_f32 -DIS_UNARY
benchmark_math_bench_p_median_f32_CFLAGS = -DFUNCTION=p_median_f32 -DIS_UNARY
benchmark_math_bench_p_min_f32_CFLAGS = -DFUNCTION=p_min_f32 -DIS_UNARY
benchmark_math_bench_p_minmax_f32_CFLAGS = -DFUNCTION=p_minmax_f32 -DIS_UNARY
benchmark_math_bench_p_mode_f32_CFLAGS = -DFUNCTION=p_mode_f32 -DIS_UNARY
benchmark_math_bench_p_mul_f32_CFLAGS = -DFUNCTION=p_mul_f32 -DIS_BINARY
benchmark_math_bench_p_popcount_u32_CFLAGS = -DFUNCTION=p_popcount_u32 -DIS_UNARY
Expand Down Expand Up @@ -171,6 +174,7 @@ benchmark_math_bench_p_max_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_mean_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_median_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_min_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_minmax_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_mode_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_mul_f32_LDADD = $(benchmark_math_LDADD)
benchmark_math_bench_p_popcount_u32_LDADD = $(benchmark_math_LDADD)
Expand Down
7 changes: 7 additions & 0 deletions benchmark/math/all.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ void bench_p_min_f32(const struct p_bench_specification *spec)
p_min_f32(spec->mem.i1.p_float, spec->mem.i2.p_float, spec->mem.o1.p_int,
spec->current_size);
}
void bench_p_minmax_f32(const struct p_bench_specification *spec)
{
p_minmax_f32(spec->mem.i1.p_float, spec->mem.i2.p_float,
spec->mem.i3.p_float, spec->mem.o1.p_int, spec->mem.o2.p_int,
spec->current_size);
}
declare_unary(p_mode_f32)
declare_binary(p_mul_f32)
void bench_p_popcount_u32(const struct p_bench_specification *spec)
Expand Down Expand Up @@ -104,6 +110,7 @@ const struct p_bench_item benchmark_items[] = {
item(p_mean_f32),
item(p_median_f32),
item(p_min_f32),
item(p_minmax_f32),
item(p_mode_f32),
item(p_mul_f32),
item(p_popcount_u32),
Expand Down
14 changes: 14 additions & 0 deletions benchmark/math/p_minmax_f32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "../bench_tmpl.h"

void bench_p_minmax_f32(const struct p_bench_specification *spec)
{
p_minmax_f32(spec->mem.i1.p_float, spec->mem.i2.p_float,
spec->mem.i3.p_float, spec->mem.o1.p_int, spec->mem.o2.p_int,
spec->current_size);
}

const struct p_bench_item benchmark_items[] = {
item(p_minmax_f32),

{ NULL, NULL }
};
4 changes: 4 additions & 0 deletions include/pal_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ void p_max_f64(const double *a, double *c, int *index, int n);
void p_min_f32(const float *a, float *c, int *index, int n);
void p_min_f64(const double *a, double *c, int *index, int n);

/*find min and max values and their indices from input vector */
void p_minmax_f32(const float *a, float *c1, float *c2, int *index1, int *index2, int n);
void p_minmax_f64(const double *a, double *c1, double *c2, int *index1, int *index2, int n);

/*
****************************************************************
* Miscellaneous Operations
Expand Down
1 change: 1 addition & 0 deletions src/math/Makemodule.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ src/math/p_max.c \
src/math/p_mean.c \
src/math/p_median.c \
src/math/p_min.c \
src/math/p_minmax.c \
src/math/p_mode.c \
src/math/p_mul.c \
src/math/p_sin.c \
Expand Down
45 changes: 45 additions & 0 deletions src/math/p_minmax.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <pal.h>

/**
*
* Finds the minimum and maximum values in vector 'a'. Returns the min and max
* values and the indices of the minimum and maximum values.
*
* @param a Pointer to input vector
*
* @param c1 Pointer to output scalar (minimum)
*
* @param c2 Pointer to output scalar (maximum)
*
* @param[out] index1 Pointer to return index of min
*
* @param[out] index2 Pointer to return index of max
*
* @param n Size of 'a' vector.
*
* @return None
*
*/
void PSYM(p_minmax)(const PTYPE *a, PTYPE *c1, PTYPE *c2, int *index1, int *index2, int n)
{
int pos_min = 0;
int pos_max = 0;
PTYPE min = *a;
PTYPE max = *a;
int i;

for (i = 1; i < n; i++) {
if (*(a + i) < min) {
pos_min = i;
min = *(a + i);
}
else if (*(a + i) > max) {
pos_max = i;
max = *(a + i);
}
}
*c1 = min;
*c2 = max;
*index1 = pos_min;
*index2 = pos_max;
}
16 changes: 16 additions & 0 deletions tests/math/Makemodule.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tests/math/gold/p_max_f32.gold.h \
tests/math/gold/p_mean_f32.gold.h \
tests/math/gold/p_median_f32.gold.h \
tests/math/gold/p_min_f32.gold.h \
tests/math/gold/p_minmax_f32.gold.h \
tests/math/gold/p_mode_f32.gold.h \
tests/math/gold/p_mul_f32.gold.h \
tests/math/gold/p_pow_f32.gold.h \
Expand Down Expand Up @@ -91,6 +92,7 @@ tests/math/gold/p_max_f64.gold.h \
tests/math/gold/p_mean_f64.gold.h \
tests/math/gold/p_median_f64.gold.h \
tests/math/gold/p_min_f64.gold.h \
tests/math/gold/p_minmax_f64.gold.h \
tests/math/gold/p_mode_f64.gold.h \
tests/math/gold/p_mul_f64.gold.h \
tests/math/gold/p_pow_f64.gold.h \
Expand Down Expand Up @@ -154,6 +156,7 @@ tests/math/check_p_max_f32 \
tests/math/check_p_mean_f32 \
tests/math/check_p_median_f32 \
tests/math/check_p_min_f32 \
tests/math/check_p_minmax_f32 \
tests/math/check_p_mode_f32 \
tests/math/check_p_mul_f32 \
tests/math/check_p_popcount \
Expand Down Expand Up @@ -200,6 +203,7 @@ tests/math/check_p_max_f64 \
tests/math/check_p_mean_f64 \
tests/math/check_p_median_f64 \
tests/math/check_p_min_f64 \
tests/math/check_p_minmax_f64 \
tests/math/check_p_mode_f64 \
tests/math/check_p_mul_f64 \
tests/math/check_p_pow_f64 \
Expand Down Expand Up @@ -244,6 +248,7 @@ tests_math_check_p_max_f32_SOURCES = $(CHECK_SCALAR_AND_INDEX) tests/mat
tests_math_check_p_mean_f32_SOURCES = $(SIMPLETEST)
tests_math_check_p_median_f32_SOURCES = $(SIMPLETEST)
tests_math_check_p_min_f32_SOURCES = $(CHECK_SCALAR_AND_INDEX) tests/math/p_min.c
tests_math_check_p_minmax_f32_SOURCES = tests/math/check_p_minmax.c tests/math/check_p_minmax.h tests/math/p_minmax.c
tests_math_check_p_mode_f32_SOURCES = $(SIMPLETEST)
tests_math_check_p_mul_f32_SOURCES = $(SIMPLETEST)
tests_math_check_p_popcount_SOURCES = $(NOTEST)
Expand Down Expand Up @@ -289,6 +294,7 @@ tests_math_check_p_max_f64_SOURCES = $(tests_math_check_p_max_f32_SOURCE
tests_math_check_p_mean_f64_SOURCES = $(tests_math_check_p_mean_f32_SOURCES)
tests_math_check_p_median_f64_SOURCES = $(tests_math_check_p_median_f32_SOURCES)
tests_math_check_p_min_f64_SOURCES = $(tests_math_check_p_min_f32_SOURCES)
tests_math_check_p_minmax_f64_SOURCES = $(tests_math_check_p_minmax_f32_SOURCES)
tests_math_check_p_mode_f64_SOURCES = $(tests_math_check_p_mode_f32_SOURCES)
tests_math_check_p_mul_f64_SOURCES = $(tests_math_check_p_mul_f32_SOURCES)
tests_math_check_p_pow_f64_SOURCES = $(NOTEST)
Expand Down Expand Up @@ -331,6 +337,7 @@ tests_math_check_p_max_f32_SOURCES += tests/math/gold/p_max_f32.gold.h
tests_math_check_p_mean_f32_SOURCES += tests/math/gold/p_mean_f32.gold.h
tests_math_check_p_median_f32_SOURCES += tests/math/gold/p_median_f32.gold.h
tests_math_check_p_min_f32_SOURCES += tests/math/gold/p_min_f32.gold.h
tests_math_check_p_minmax_f32_SOURCES += tests/math/gold/p_minmax_f32.gold.h
tests_math_check_p_mode_f32_SOURCES += tests/math/gold/p_mode_f32.gold.h
tests_math_check_p_mul_f32_SOURCES += tests/math/gold/p_mul_f32.gold.h
tests_math_check_p_pow_f32_SOURCES += tests/math/gold/p_pow_f32.gold.h
Expand Down Expand Up @@ -373,6 +380,7 @@ tests_math_check_p_max_f64_SOURCES += tests/math/gold/p_max_f64.gold.h
tests_math_check_p_mean_f64_SOURCES += tests/math/gold/p_mean_f64.gold.h
tests_math_check_p_median_f64_SOURCES += tests/math/gold/p_median_f64.gold.h
tests_math_check_p_min_f64_SOURCES += tests/math/gold/p_min_f64.gold.h
tests_math_check_p_minmax_f64_SOURCES += tests/math/gold/p_minmax_f64.gold.h
tests_math_check_p_mode_f64_SOURCES += tests/math/gold/p_mode_f64.gold.h
tests_math_check_p_mul_f64_SOURCES += tests/math/gold/p_mul_f64.gold.h
#tests_math_check_p_pow_f64_SOURCES += tests/math/gold/p_pow_f64.gold.h
Expand Down Expand Up @@ -416,6 +424,7 @@ tests_math_check_p_max_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUN
tests_math_check_p_mean_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_mean_f32 -DIS_UNARY -DSCALAR_OUTPUT
tests_math_check_p_median_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_median_f32 -DIS_UNARY -DSCALAR_OUTPUT
tests_math_check_p_min_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_min_f32 -DSCALAR_OUTPUT
tests_math_check_p_minmax_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_minmax_f32
tests_math_check_p_mode_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_mode_f32 -DIS_UNARY -DSCALAR_OUTPUT
tests_math_check_p_mul_f32_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_mul_f32 -DIS_BINARY
tests_math_check_p_popcount_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_SINGLE -DFUNCTION=p_popcount
Expand Down Expand Up @@ -462,6 +471,7 @@ tests_math_check_p_max_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUN
tests_math_check_p_mean_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUNCTION=p_mean_f64 -DIS_UNARY -DSCALAR_OUTPUT
tests_math_check_p_median_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUNCTION=p_median_f64 -DIS_UNARY -DSCALAR_OUTPUT
tests_math_check_p_min_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUNCTION=p_min_f64 -DSCALAR_OUTPUT
tests_math_check_p_minmax_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUNCTION=p_minmax_f64
tests_math_check_p_mode_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUNCTION=p_mode_f64 -DIS_UNARY -DSCALAR_OUTPUT
tests_math_check_p_mul_f64_CFLAGS = -DP_FLOAT_TYPE=P_FLOAT_DOUBLE -DFUNCTION=p_mul_f64 -DIS_BINARY
# Override fault tolerance for p_pow_f64
Expand Down Expand Up @@ -506,6 +516,7 @@ tests_math_check_p_max_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_mean_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_median_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_min_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_minmax_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_mode_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_mul_f32_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_popcount_CPPFLAGS = $(CPPFLAGS_tests_math)
Expand Down Expand Up @@ -551,6 +562,7 @@ tests_math_check_p_max_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_mean_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_median_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_min_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_minmax_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_mode_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_mul_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
tests_math_check_p_pow_f64_CPPFLAGS = $(CPPFLAGS_tests_math)
Expand Down Expand Up @@ -594,6 +606,7 @@ tests_math_check_p_max_f32_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_mean_f32_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_median_f32_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_min_f32_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_minmax_f32_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_mode_f32_LDFLAGS = $(LDFLAGS_tests_large)
tests_math_check_p_mul_f32_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_popcount_LDFLAGS = $(LDFLAGS_tests)
Expand Down Expand Up @@ -639,6 +652,7 @@ tests_math_check_p_max_f64_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_mean_f64_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_median_f64_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_min_f64_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_minmax_f64_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_mode_f64_LDFLAGS = $(LDFLAGS_tests_large)
tests_math_check_p_mul_f64_LDFLAGS = $(LDFLAGS_tests)
tests_math_check_p_pow_f64_LDFLAGS = $(LDFLAGS_tests)
Expand Down Expand Up @@ -682,6 +696,7 @@ tests_math_check_p_max_f32_LDADD = $(LDADD_tests)
tests_math_check_p_mean_f32_LDADD = $(LDADD_tests)
tests_math_check_p_median_f32_LDADD = $(LDADD_tests)
tests_math_check_p_min_f32_LDADD = $(LDADD_tests)
tests_math_check_p_minmax_f32_LDADD = $(LDADD_tests)
tests_math_check_p_mode_f32_LDADD = $(LDADD_tests)
tests_math_check_p_mul_f32_LDADD = $(LDADD_tests)
tests_math_check_p_popcount_LDADD = $(LDADD_tests)
Expand Down Expand Up @@ -727,6 +742,7 @@ tests_math_check_p_max_f64_LDADD = $(LDADD_tests)
tests_math_check_p_mean_f64_LDADD = $(LDADD_tests)
tests_math_check_p_median_f64_LDADD = $(LDADD_tests)
tests_math_check_p_min_f64_LDADD = $(LDADD_tests)
tests_math_check_p_minmax_f64_LDADD = $(LDADD_tests)
tests_math_check_p_mode_f64_LDADD = $(LDADD_tests)
tests_math_check_p_mul_f64_LDADD = $(LDADD_tests)
tests_math_check_p_pow_f64_LDADD = $(LDADD_tests)
Expand Down