rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit dee28d7a2c3ced5958ac54a9957a6e07526ff66e
parent f164778b82c3af09722b22b0c19a6f54f698c311
Author: vaplv <vaplv@free.fr>
Date:   Wed, 20 Jul 2016 11:08:44 +0200

Add and test the fXY_set_dXY and dXY_set_fXY funcs (XY in [22, 33, 44])

Initialise a matrix of float from a matrix of double and vice versa.

Diffstat:
Msrc/realXY.h | 14++++++++++++++
Msrc/realXY_begin.h | 35++++++++++++++++++++---------------
Msrc/realXY_end.h | 7++++---
Msrc/test_real22.h | 97+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/test_real33.h | 24++++++++++++++++++++++++
Msrc/test_real44.h | 38++++++++++++++++++++++++++++++++++++++
6 files changed, 155 insertions(+), 60 deletions(-)

diff --git a/src/realXY.h b/src/realXY.h @@ -27,6 +27,20 @@ #endif static FINLINE REAL_TYPE__* +REALXY_CAST__(REAL_TYPE__* dst, const REAL_TYPE_COMPATIBLE__* src) +{ + int x, y, i; + ASSERT(dst && src); + i = 0; + FOR_EACH(x, 0, REALX_DIMENSION__) { + FOR_EACH(y, 0, REALY_DIMENSION__) { + dst[i] = (REAL_TYPE__)src[i]; + ++i; + }} + return dst; +} + +static FINLINE REAL_TYPE__* REALXY_FUNC__(splat)(REAL_TYPE__* dst, const REAL_TYPE__ val) { int i = 0; diff --git a/src/realXY_begin.h b/src/realXY_begin.h @@ -26,42 +26,47 @@ #error Missing arguments #endif -#if defined(REALXY_FUNC__) \ - || defined(REALY_FUNC__) \ +#if defined(REALX_REALXY_FUNC__) \ + || defined(REALXY_CAST__) \ || defined(REALXY_CTOR__) \ + || defined(REALXY_FUNC__) \ || defined(REALXY_REALX_FUNC__) \ - || defined(REALX_REALXY_FUNC__) \ || defined(REALXY_REALXY_FUNC__) \ + || defined(REALY_FUNC__) \ || defined(SIZEOF_REALXY__) #error Unexpected macro definition #endif +/* Define the name generator for the realX x realXY -> realXY functions */ +#define REALX_REALXY_FUNC__(Func) \ + REALX_FUNC__(CONCAT(CONCAT(CONCAT( \ + mul, REAL_LETTER__), REALX_DIMENSION__), REALY_DIMENSION__)) + +/* Define the realXY cast functions name */ +#define REALXY_CAST__ REALXY_FUNC__ (CONCAT(set_, CONCAT( \ + REAL_LETTER_TYPE_COMPATIBLE__, CONCAT(REALX_DIMENSION__, REALY_DIMENSION__)))) + +/* Define the realXY constructor name */ +#define REALXY_CTOR__ \ + CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), REALY_DIMENSION__) + /* Define the function name generators */ #define REALXY_FUNC__(Func) \ CONCAT(CONCAT(CONCAT(CONCAT \ (REAL_LETTER__, REALX_DIMENSION__), REALY_DIMENSION__), _), Func) -/* Define the function name generator for the realY functions */ -#define REALY_FUNC__(Func) \ - CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALY_DIMENSION__), _), Func) - /* Define the name generator for the realXY x realX -> realX functions */ #define REALXY_REALX_FUNC__(Func) \ REALXY_FUNC__(CONCAT(CONCAT(mul, REAL_LETTER__), REALX_DIMENSION__)) -/* Define the name generator for the realX x realXY -> realXY functions */ -#define REALX_REALXY_FUNC__(Func) \ - REALX_FUNC__(CONCAT(CONCAT(CONCAT( \ - mul, REAL_LETTER__), REALX_DIMENSION__), REALY_DIMENSION__)) - /* Define the name generator for the realXY x realXY -> realXY functions */ #define REALXY_REALXY_FUNC__(Func) \ REALXY_FUNC__(CONCAT(CONCAT(CONCAT( \ Func, REAL_LETTER__), REALX_DIMENSION__), REALY_DIMENSION__)) -/* Define the realXY constructor name */ -#define REALXY_CTOR__ \ - CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), REALY_DIMENSION__) +/* Define the function name generator for the realY functions */ +#define REALY_FUNC__(Func) \ + CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALY_DIMENSION__), _), Func) #define SIZEOF_REALXY__ sizeof(REAL_TYPE__[REALX_DIMENSION__*REALY_DIMENSION__]) diff --git a/src/realXY_end.h b/src/realXY_end.h @@ -19,12 +19,13 @@ #undef REALY_DIMENSION__ -#undef REALY_FUNC__ -#undef REALXY_FUNC__ -#undef REALXY_CTOR__ #undef REALX_REALXY_FUNC__ +#undef REALXY_CAST__ +#undef REALXY_CTOR__ +#undef REALXY_FUNC__ #undef REALXY_REALX_FUNC__ #undef REALXY_REALXY_FUNC__ +#undef REALY_FUNC__ #undef SIZEOF_REALXY__ #undef REALXY_BEGIN_H diff --git a/src/test_real22.h b/src/test_real22.h @@ -21,8 +21,9 @@ #include "realXY_begin.h" #define REAL REAL_TYPE__ +#define REAL_COMPATIBLE REAL_TYPE_COMPATIBLE__ -#define CHEK_REAL2(A, B) \ +#define CHECK_REAL2(A, B) \ { \ const REAL* a__ = (A); \ const REAL* b__ = (B); \ @@ -30,7 +31,7 @@ FOR_EACH(i__, 0, 2) \ CHECK(a__[i__], b__[i__]); \ } (void)0 -#define CHEK_REAL22(A, B) \ +#define CHECK_REAL22(A, B) \ { \ const REAL* a__ = (A); \ const REAL* b__ = (B); \ @@ -43,6 +44,7 @@ int main(int argc, char** argv) { REAL a[4], b[4], dst[4], c[4]; + REAL_COMPATIBLE d[4]; int i; (void)argc, (void)argv; @@ -55,74 +57,85 @@ main(int argc, char** argv) FOR_EACH(i, 0, 4) { CHECK(a[i], (REAL)i); } - CHEK_REAL22(REALXY_FUNC__(set_identity)(a), + CHECK_REAL22(REALXY_FUNC__(set_identity)(a), REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); + CHECK_REAL22(a, REALXY_CTOR__(c, 1.0, 0.0, 0.0, 1.0)); + + d[0] = (REAL_COMPATIBLE)0.1; + d[1] = (REAL_COMPATIBLE)(1.0/3.0); + d[2] = (REAL_COMPATIBLE)0.3; + d[3] = (REAL_COMPATIBLE)-0.7; + REALXY_CTOR__(c, + (REAL)(REAL_COMPATIBLE)0.1, + (REAL)(REAL_COMPATIBLE)(1.0/3.0), + (REAL)(REAL_COMPATIBLE)0.3, + (REAL)(REAL_COMPATIBLE)-0.7); + CHECK_REAL22(REALXY_CAST__(dst, d), c); REALXY_FUNC__(splat)(a, -1.0); - CHEK_REAL22(REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0), 0), + CHECK_REAL22(REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0), 0), REALXY_CTOR__(c, 0.0, -1.0, 1.0, -1.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, -1.0, 1.0, -1.0)); - CHEK_REAL22(REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 2.0, 3.0), 1), + CHECK_REAL22(a, REALXY_CTOR__(c, 0.0, -1.0, 1.0, -1.0)); + CHECK_REAL22(REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 2.0, 3.0), 1), REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); + CHECK_REAL22(a, REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); - CHEK_REAL22(REALXY_FUNC__(transpose)(a, a), + CHECK_REAL22(REALXY_FUNC__(transpose)(a, a), REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); - CHEK_REAL22(REALXY_FUNC__(transpose)(b, a), + CHECK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL22(REALXY_FUNC__(transpose)(b, a), REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); - CHEK_REAL22(b, REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); + CHECK_REAL22(b, REALXY_CTOR__(c, 0.0, 2.0, 1.0, 3.0)); REALXY_FUNC__(splat)(a, -1.0); - CHEK_REAL22(REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 0.0, 1.0), 0), + CHECK_REAL22(REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 0.0, 1.0), 0), REALXY_CTOR__(c, 0.0, 1.0, -1.0, -1.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, -1.0, -1.0)); - CHEK_REAL22(REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 2.0, 3.0), 1), + CHECK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, -1.0, -1.0)); + CHECK_REAL22(REALXY_FUNC__(set_col)(a, REALX_CTOR__(c, 2.0, 3.0), 1), REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL22(a, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); - CHEK_REAL2(REALXY_FUNC__(row)(b, a, 0), REALX_CTOR__(c, 0.0, 2.0)); - CHEK_REAL2(REALXY_FUNC__(row)(b, a, 1), REALX_CTOR__(c, 1.0, 3.0)); + CHECK_REAL2(REALXY_FUNC__(row)(b, a, 0), REALX_CTOR__(c, 0.0, 2.0)); + CHECK_REAL2(REALXY_FUNC__(row)(b, a, 1), REALX_CTOR__(c, 1.0, 3.0)); - CHEK_REAL2(REALXY_FUNC__(col)(b + 2, a, 0), REALX_CTOR__(c, 0.0, 1.0)); - CHEK_REAL2(REALXY_FUNC__(col)(b, a, 1), REALX_CTOR__(c, 2.0, 3.0)); + CHECK_REAL2(REALXY_FUNC__(col)(b + 2, a, 0), REALX_CTOR__(c, 0.0, 1.0)); + CHECK_REAL2(REALXY_FUNC__(col)(b, a, 1), REALX_CTOR__(c, 2.0, 3.0)); - CHEK_REAL2(REALXY_FUNC__(col_ptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0)); - CHEK_REAL2(REALXY_FUNC__(col_ptr)(a, 1), REALX_CTOR__(c, 2.0, 3.0)); - CHEK_REAL2(REALXY_FUNC__(col_cptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0)); - CHEK_REAL2(REALXY_FUNC__(col_cptr)(a, 1), REALX_CTOR__(c, 2.0, 3.0)); + CHECK_REAL2(REALXY_FUNC__(col_ptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0)); + CHECK_REAL2(REALXY_FUNC__(col_ptr)(a, 1), REALX_CTOR__(c, 2.0, 3.0)); + CHECK_REAL2(REALXY_FUNC__(col_cptr)(a, 0), REALX_CTOR__(c, 0.0, 1.0)); + CHECK_REAL2(REALXY_FUNC__(col_cptr)(a, 1), REALX_CTOR__(c, 2.0, 3.0)); REALXY_CTOR__(a, 1.0, 2.0, 3.0, 4.0); - CHEK_REAL2(REALXY_REALX_FUNC__(mul)(dst, a, REALX_CTOR__(c, 1.0, 2.0)), + CHECK_REAL2(REALXY_REALX_FUNC__(mul)(dst, a, REALX_CTOR__(c, 1.0, 2.0)), REALX_CTOR__(c, 7.0, 10.0)); - CHEK_REAL2(dst, REALX_CTOR__(c, 7.0, 10.0)); - CHEK_REAL2(REALX_REALXY_FUNC__(mul)(dst, REALX_CTOR__(c, 1.0, 2.0), a), + CHECK_REAL2(dst, REALX_CTOR__(c, 7.0, 10.0)); + CHECK_REAL2(REALX_REALXY_FUNC__(mul)(dst, REALX_CTOR__(c, 1.0, 2.0), a), REALX_CTOR__(c, 5.0, 11.0)); - CHEK_REAL2(dst, REALX_CTOR__(c, 5.0, 11.0)); - CHEK_REAL22(REALXY_FUNC__(mul)(dst, a, -1.0), + CHECK_REAL2(dst, REALX_CTOR__(c, 5.0, 11.0)); + CHECK_REAL22(REALXY_FUNC__(mul)(dst, a, -1.0), REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); - CHEK_REAL22(dst, REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); + CHECK_REAL22(dst, REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); REALXY_CTOR__(b, 2.0, 9.0, 8.0, 1.0); - CHEK_REAL22(REALXY_REALXY_FUNC__(mul)(dst, a, b), + CHECK_REAL22(REALXY_REALXY_FUNC__(mul)(dst, a, b), REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); - CHEK_REAL22(dst, REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); - CHEK_REAL22(REALXY_REALXY_FUNC__(mul)(b, a, b), + CHECK_REAL22(dst, REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); + CHECK_REAL22(REALXY_REALXY_FUNC__(mul)(b, a, b), REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); - CHEK_REAL22(b, REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); + CHECK_REAL22(b, REALXY_CTOR__(c, 29.0, 40.0, 11.0, 20.0)); REALXY_CTOR__(a, 0.0, 1.0, 2.0, 3.0); REALXY_CTOR__(b, 1.0, 2.0, 3.0, 4.0); - CHEK_REAL22(REALXY_FUNC__(add)(dst, a, b), + CHECK_REAL22(REALXY_FUNC__(add)(dst, a, b), REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0)); - CHEK_REAL22(dst, REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0)); - CHEK_REAL22(REALXY_FUNC__(sub)(dst, dst, b), + CHECK_REAL22(dst, REALXY_CTOR__(c, 1.0, 3.0, 5.0, 7.0)); + CHECK_REAL22(REALXY_FUNC__(sub)(dst, dst, b), REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); - CHEK_REAL22(dst, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); - CHEK_REAL22(REALXY_FUNC__(minus)(a, b), + CHECK_REAL22(dst, REALXY_CTOR__(c, 0.0, 1.0, 2.0, 3.0)); + CHECK_REAL22(REALXY_FUNC__(minus)(a, b), REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); - CHEK_REAL22(a, REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); + CHECK_REAL22(a, REALXY_CTOR__(c, -1.0, -2.0, -3.0, -4.0)); REALXY_FUNC__(set)(a, b); CHECK(REALXY_FUNC__(eq)(a, b), 1); @@ -134,9 +147,9 @@ main(int argc, char** argv) REALXY_FUNC__(set)(a, REALXY_CTOR__(c, 1, 3, 2, 4)); CHECK(REALXY_FUNC__(det)(a), -2.0); CHECK(REALXY_FUNC__(inverse)(b, a), -2.0); - CHEK_REAL22(b, REALXY_CTOR__(c, -2.0, 1.5, 1.0, -0.5)); + CHECK_REAL22(b, REALXY_CTOR__(c, -2.0, 1.5, 1.0, -0.5)); CHECK(REALXY_FUNC__(invtrans)(a, a), -2.0); - CHEK_REAL22(a, REALXY_CTOR__(c, -2.0, 1.0, 1.5, -0.5)); + CHECK_REAL22(a, REALXY_CTOR__(c, -2.0, 1.0, 1.5, -0.5)); return 0; } diff --git a/src/test_real33.h b/src/test_real33.h @@ -21,6 +21,7 @@ #include "realXY_begin.h" #define REAL REAL_TYPE__ +#define REAL_COMPATIBLE REAL_TYPE_COMPATIBLE__ #define CHECK_REAL3(A, B) \ { \ @@ -43,6 +44,7 @@ int main(int argc, char** argv) { REAL a[9], b[9], dst[9], c[9]; + REAL_COMPATIBLE d[9]; int i; (void)argc, (void)argv; @@ -60,6 +62,28 @@ main(int argc, char** argv) REALXY_CTOR__(c, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); CHECK_REAL33(a, REALXY_CTOR__(c, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); + d[0] = (REAL_COMPATIBLE)0.1; + d[1] = (REAL_COMPATIBLE)(1.0/3.0); + d[2] = (REAL_COMPATIBLE)0.3; + d[3] = (REAL_COMPATIBLE)-0.7; + d[4] = (REAL_COMPATIBLE)0.9; + d[5] = (REAL_COMPATIBLE)-0.41; + d[6] = (REAL_COMPATIBLE)0.22; + d[7] = (REAL_COMPATIBLE)-0.01; + d[8] = (REAL_COMPATIBLE)0.02; + + REALXY_CTOR__(c, + (REAL)(REAL_COMPATIBLE)0.1, + (REAL)(REAL_COMPATIBLE)(1.0/3.0), + (REAL)(REAL_COMPATIBLE)0.3, + (REAL)(REAL_COMPATIBLE)-0.7, + (REAL)(REAL_COMPATIBLE)0.9, + (REAL)(REAL_COMPATIBLE)-0.41, + (REAL)(REAL_COMPATIBLE)0.22, + (REAL)(REAL_COMPATIBLE)-0.01, + (REAL)(REAL_COMPATIBLE)0.02); + CHECK_REAL33(REALXY_CAST__(dst, d), c); + REALXY_FUNC__(splat)(a, -1.0); CHECK_REAL33 (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0, 2.0), 0), diff --git a/src/test_real44.h b/src/test_real44.h @@ -21,6 +21,7 @@ #include "realXY_begin.h" #define REAL REAL_TYPE__ +#define REAL_COMPATIBLE REAL_TYPE_COMPATIBLE__ #define CHECK_REAL4(A, B) \ { \ @@ -43,6 +44,7 @@ int main(int argc, char** argv) { REAL a[16], b[16], dst[16], c[16]; + REAL_COMPATIBLE d[16]; int i; (void)argc, (void)argv; @@ -73,6 +75,42 @@ main(int argc, char** argv) 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)); + d[0] = (REAL_COMPATIBLE)0.1; + d[1] = (REAL_COMPATIBLE)(1.0/3.0); + d[2] = (REAL_COMPATIBLE)0.3; + d[3] = (REAL_COMPATIBLE)-0.7; + d[4] = (REAL_COMPATIBLE)0.9; + d[5] = (REAL_COMPATIBLE)-0.41; + d[6] = (REAL_COMPATIBLE)0.22; + d[7] = (REAL_COMPATIBLE)-0.01; + d[8] = (REAL_COMPATIBLE)0.02; + d[9] = (REAL_COMPATIBLE)1.1; + d[10] = (REAL_COMPATIBLE)0.05; + d[11] = (REAL_COMPATIBLE)-0.0125; + d[12] = (REAL_COMPATIBLE)3.14; + d[13] = (REAL_COMPATIBLE)1.23; + d[14] = (REAL_COMPATIBLE)-4.56; + d[15] = (REAL_COMPATIBLE)2.02; + + REALXY_CTOR__(c, + (REAL)(REAL_COMPATIBLE)0.1, + (REAL)(REAL_COMPATIBLE)(1.0/3.0), + (REAL)(REAL_COMPATIBLE)0.3, + (REAL)(REAL_COMPATIBLE)-0.7, + (REAL)(REAL_COMPATIBLE)0.9, + (REAL)(REAL_COMPATIBLE)-0.41, + (REAL)(REAL_COMPATIBLE)0.22, + (REAL)(REAL_COMPATIBLE)-0.01, + (REAL)(REAL_COMPATIBLE)0.02, + (REAL)(REAL_COMPATIBLE)1.1, + (REAL)(REAL_COMPATIBLE)0.05, + (REAL)(REAL_COMPATIBLE)-0.0125, + (REAL)(REAL_COMPATIBLE)3.14, + (REAL)(REAL_COMPATIBLE)1.23, + (REAL)(REAL_COMPATIBLE)-4.56, + (REAL)(REAL_COMPATIBLE)2.02); + CHECK_REAL44(REALXY_CAST__(dst, d), c); + REALXY_FUNC__(splat)(a, -1.0); CHECK_REAL44 (REALXY_FUNC__(set_row)(a, REALX_CTOR__(c, 0.0, 1.0, 2.0, 3.0), 0),