1 /*
2  * Copyright (c) 2020 Stephanos Ioannidis <root@stephanos.io>
3  * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/ztest.h>
9 #include <zephyr/kernel.h>
10 #include <stdlib.h>
11 #include <arm_math.h>
12 #include "../../common/test_common.h"
13 
14 #include "barycenter_f32.pat"
15 
16 #define ABS_ERROR_THRESH	(1e-3)
17 
ZTEST(support_barycenter_f32,test_arm_barycenter_f32)18 ZTEST(support_barycenter_f32, test_arm_barycenter_f32)
19 {
20 	int test_index;
21 	const size_t length = ARRAY_SIZE(ref_barycenter);
22 	const uint16_t test_count = in_barycenter_dims[0];
23 	const uint16_t *dims = in_barycenter_dims + 1;
24 	const float32_t *input_val = (const float32_t *)in_barycenter_val;
25 	const float32_t *input_coeff = (const float32_t *)in_barycenter_coeff;
26 	float32_t *output, *output_buf;
27 
28 	/* Allocate output buffer */
29 	output_buf = malloc(length * sizeof(float32_t));
30 	zassert_not_null(output_buf, ASSERT_MSG_BUFFER_ALLOC_FAILED);
31 
32 	output = output_buf;
33 
34 	/* Enumerate tests */
35 	for (test_index = 0; test_index < test_count; test_index++) {
36 		const uint16_t vec_count = dims[0];
37 		const uint16_t vec_length = dims[1];
38 
39 		/* Run test function */
40 		arm_barycenter_f32(
41 			input_val, input_coeff, output, vec_count, vec_length);
42 
43 		/* Increment pointers */
44 		input_val += vec_count * vec_length;
45 		input_coeff += vec_count;
46 		output += vec_length;
47 		dims += 2;
48 	}
49 
50 	/* Validate output */
51 	zassert_true(
52 		test_near_equal_f32(
53 			length, output_buf, (float32_t *)ref_barycenter,
54 			ABS_ERROR_THRESH),
55 		ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED);
56 
57 	/* Free output buffer */
58 	free(output_buf);
59 }
60 
61 ZTEST_SUITE(support_barycenter_f32, NULL, NULL, NULL, NULL, NULL);
62