1#include <ae2f/Ann/Conv.h>
8#define EPSILON 0.000001
13size_t test_mMMapFieldIdx(
const ae2f_mMMap *
const mmap,
const size_t dim,
const size_t *
const idxs)
20uint64_t Conv1dTestNoPad() {
28 size_t inputsz = 10, kernelsz = 3, outsz = 8, stride = 1, padding = 0;
36 for(
i = 0;
i < inputsz;
i++) {
66 for(
i = 0;
i < outsz;
i++)
81 (targets[
i] - matchbuff)
82 * (targets[
i] - matchbuff)
97uint64_t Conv1dTestWithPad() {
105 size_t inputsz = 6, kernelsz = 3, outsz = 8, stride = 1, padding = 2;
113 for(
i = 0;
i < inputsz;
i++) {
129 , NULL
, stride
, padding
135 0.2, 0.7, 1.7, 2.7, 3.7, 4.7, 4.3, 3
137 for(
i = 0;
i < outsz;
i++)
149 (targets[
i] - matchbuff)
150 * (targets[
i] - matchbuff)
165uint64_t Conv2DTest() {
166 puts(
"Conv2DTest start");
175 kernelsz[2] = {3, 3},
177 stride[2] = { 1, 1 };
179 size_t idxbuff[2] = {0, 0};
187 puts(
"obj has made");
189 for(
i = 0,
el = 1;
i < 4;
i++)
190 for(
j = 0;
j < 4;
j++) {
202 kernelelbuff[2] = -1;
208 puts(
"buff has made");
225 kernelelbuff[2] = -2;
234 for(
i = 0,
el = 1;
i < 3;
i++) {
235 for(
j = 0;
j < 3;
j++) {
241 , test_mMMapFieldIdx(
260 puts(
"__ae2f_AnnConv");
274 for(a = 0; a <
sizeof(target) /
sizeof(**target); a++) {
281 { puts(
"Match None"); assert(
"Match None"); }
304 outv_expected[4][2] = {
314 ae2f_eAnnCnnPool types[] = {
320 const char* type_names[] = {
321 "MAX",
"MIN",
"ADD",
"AVG",
"MIDDLE"
323 int num_types =
sizeof(types) /
sizeof(types[0]);
326 for (
i = 0;
i < num_types;
i++) {
337 printf(
"%s Pooling: outc = %zu, outv = [%f, %f]\n",
338 type_names[
i], outc, outv[0], outv[1]);
341 ((outv[0] - outv_expected[
i][0])
342 * (outv[0] - outv_expected[
i][0])
345 || ((outv[1] - outv_expected[
i][1])
346 * (outv[1] - outv_expected[
i][1])
350 printf(
"Mismatch: Expected value: %f, %f\n"
351 , outv_expected[
i][0]
352 , outv_expected[
i][1]
357 printf(
"%s Pooling: Error occurred: %d\n", type_names[
i], e);
365uint64_t Pool2dTest() {
366 puts(
"Pool2dTest START");
377 size_t inc[2] = {4, 4};
380 size_t window_opt[2] = {2, 2};
383 size_t stride_opt[2] = {2, 2};
395 err =
ae2f_AnnCnnPool(2
, inv
, inc
, 0
, outv
, 0
, 0
, window_opt
, 0
, stride_opt
, ae2f_eAnnCnnPool_MAX);
397 printf(
"MAX Pooling: outc = %zu, outv = [%f, %f, %f, %f]\n",
398 outc, outv[0], outv[1], outv[2], outv[3]);
402 for(
i = 0;
i <
sizeof(tar)/
sizeof(tar[0]);
i++)
404 printf(
"Match test %lu\n",
i);
405 if((tar[
i] - outv[
i]) * (tar[
i] - outv[
i]) > EPSILON)
407 printf(
"Mismatch: %f, %f\n", tar[
i], outv[
i]);
413 printf(
"MAX Pooling Error: %d\n", err);
417 outv[0] = outv[1] = outv[2] = outv[3] = 0;
420 err =
ae2f_AnnCnnPool(2
, inv
, inc
, 0
, outv
, 0
, 0
, window_opt
, 0
, stride_opt
, ae2f_eAnnCnnPool_AVG);
422 printf(
"AVG Pooling: outc = %zu, outv = [%f, %f, %f, %f]\n",
423 outc, outv[0], outv[1], outv[2], outv[3]);
427 for(
i = 0;
i <
sizeof(tar)/
sizeof(tar[0]);
i++)
429 if((tar[
i] - outv[
i]) * (tar[
i] - outv[
i]) > EPSILON)
431 printf(
"Mismatch: %f, %f\n", tar[
i], outv[
i]);
437 printf(
"AVG Pooling Error: %d\n", err);
448 | Conv1dTestWithPad()
455 printf(
"Check 0: %lu\n", a);
462int main() {
return 0; }
@ ae2f_eAnnCnnPool_MAX
Max.
@ ae2f_eAnnCnnPool_MIN
Min.
@ ae2f_eAnnCnnPool_ADD
Add.
@ ae2f_eAnnCnnPool_AVG
Average.
ae2f_extern ae2f_SHAREDEXPORT ae2f_err_t ae2f_AnnCnnPool1d(const ae2f_float_t *inv, const size_t inc, ae2f_float_t *outv, size_t *opt_outc, const size_t window, const size_t stride, ae2f_eAnnCnnPool type) noexcept
ae2f_extern ae2f_SHAREDEXPORT ae2f_err_t ae2f_AnnCnnPool(size_t dim, const ae2f_float_t *inv, const size_t *inc, size_t incc, ae2f_float_t *outv, size_t *opt_outc, size_t outcc, const size_t *window_opt, size_t windowcc, const size_t *stride_opt, ae2f_eAnnCnnPool type)
ae2f_SHAREDEXPORT ae2f_err_t ae2f_AnnCnnConv1d(const ae2f_float_t *infv, size_t infc, const ae2f_float_t *ingv, size_t ingc, ae2f_float_t *outv, size_t *opt_outc, size_t stride, size_t pad)
all vectors are suggested initiated as 0.
ae2f_SHAREDEXPORT ae2f_err_t ae2f_AnnCnnConv(size_t dim, const ae2f_float_t *infv, const size_t *infc, size_t infcc, const ae2f_float_t *ingv, const size_t *ingc, size_t ingcc, ae2f_float_t *outv, size_t *outc_opt, size_t outcc, const size_t *stride_opt, const size_t *pad_opt)
dim must be the dimension of mmaps, lengths of lists. This function is meant to be recursive....
#define ae2f_mMMapDimLen(mmap,...)
Length vector for every dimension index.
#define ae2f_mMMapField(mmap,...)
ae2f_extern ae2f_SHAREDCALL void ae2f_mMMapMk(const size_t dim, const size_t *const lens, ae2f_err_t *const opt_ret_err, ae2f_FREE(free, ae2f_mMMapDel) ae2f_mMMap **const ret_mmap) noexcept
ae2f_extern ae2f_SHAREDCALL void ae2f_mMMapDel(ae2f_mMMap *mmap)
ae2f_extern ae2f_SHAREDCALL void ae2f_mMMapFieldIdx(const ae2f_mMMap *const mmap, const size_t dim, const size_t *const idxs, size_t *const ret)
uint8_t ae2f_err_t
Informs that this number represents the error.