Subversion Repositories CharLCD

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef _MATRIX_TEMPLATES_H_
  2. #define _MATRIX_TEMPLATES_H_
  3.  
  4. /*--------------------------------------------------------------------------------*/
  5. /* Includes */
  6. /*--------------------------------------------------------------------------------*/
  7. #include "test_templates.h"
  8.  
  9. /*--------------------------------------------------------------------------------*/
  10. /* Group Specific Templates */
  11. /*--------------------------------------------------------------------------------*/
  12.  
  13. /**
  14.  *  Compare the outputs from the function under test and the reference
  15.  *  function.
  16.  */
  17. #define MATRIX_COMPARE_INTERFACE(output_type, output_content_type)  \
  18.     TEST_ASSERT_BUFFERS_EQUAL(                                      \
  19.         ((output_type *) &matrix_output_ref)->pData,                \
  20.         ((output_type *) &matrix_output_fut)->pData,                \
  21.         ((output_type *) &matrix_output_fut)->numRows *             \
  22.         ((output_type *) &matrix_output_ref)->numCols *             \
  23.         sizeof(output_content_type))
  24.  
  25. /**
  26.  * Comparison SNR thresholds for the data types used in matrix_tests.
  27.  */
  28. #define MATRIX_SNR_THRESHOLD 120
  29.  
  30. /**
  31.  *  Compare the outputs from the function under test and the reference
  32.  *  function using SNR.
  33.  */
  34. #define MATRIX_SNR_COMPARE_INTERFACE(output_type, output_content_type)  \
  35.     do                                                                  \
  36.     {                                                                   \
  37.         TEST_CONVERT_AND_ASSERT_SNR(                                    \
  38.             (float32_t *)matrix_output_f32_ref,                         \
  39.             ((output_type *) &matrix_output_ref)->pData,                \
  40.             (float32_t *)matrix_output_f32_fut,                         \
  41.             ((output_type *) &matrix_output_ref)->pData,                \
  42.             ((output_type *) &matrix_output_fut)->numRows *             \
  43.             ((output_type *) &matrix_output_ref)->numCols,              \
  44.             output_content_type,                                        \
  45.             MATRIX_SNR_THRESHOLD                                        \
  46.             );                                                          \
  47.     } while (0)
  48.  
  49. /**
  50.  *  Compare the outputs from the function under test and the reference
  51.  *  function using SNR. This is special for float64_t
  52.  */
  53. #define MATRIX_DBL_SNR_COMPARE_INTERFACE(output_type)                   \
  54.     do                                                                  \
  55.     {                                                                   \
  56.         TEST_ASSERT_DBL_SNR(                                            \
  57.             (float64_t *)matrix_output_f32_ref,                         \
  58.             (float64_t *)matrix_output_f32_fut,                         \
  59.             ((output_type *) &matrix_output_fut)->numRows *             \
  60.             ((output_type *) &matrix_output_ref)->numCols,              \
  61.             MATRIX_SNR_THRESHOLD                                        \
  62.             );                                                          \
  63.     } while (0)
  64.  
  65. /*--------------------------------------------------------------------------------*/
  66. /* Input Interfaces */
  67. /*--------------------------------------------------------------------------------*/
  68. /*
  69.  *  General:
  70.  *  Input interfaces provide inputs to functions inside test templates.  They
  71.  *  ONLY provide the inputs.  The output variables should be hard coded.
  72.  *
  73.  *  The input interfaces must have the following format:
  74.  *
  75.  *  ARM_xxx_INPUT_INTERFACE() or
  76.  *  REF_xxx_INPUT_INTERFACE()
  77.  *
  78.  *  The xxx must be lowercase, and is intended to be the indentifying substring
  79.  *  in the function's name.  Acceptable values are 'sub' or 'add' from the
  80.  *  functions arm_add_q31.
  81.  */
  82.  
  83. #define ARM_mat_add_INPUT_INTERFACE(input_a_ptr, input_b_ptr)    \
  84.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_fut)
  85.  
  86. #define REF_mat_add_INPUT_INTERFACE(input_a_ptr, input_b_ptr)    \
  87.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_ref)
  88.  
  89. #define ARM_mat_cmplx_mult_INPUT_INTERFACE(input_a_ptr, input_b_ptr)    \
  90.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_fut)
  91.  
  92. #define REF_mat_cmplx_mult_INPUT_INTERFACE(input_a_ptr, input_b_ptr)    \
  93.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_ref)
  94.  
  95. #define ARM_mat_inverse_INPUT_INTERFACE(input_ptr)  \
  96.     PAREN(input_ptr, (void *) &matrix_output_fut)
  97.  
  98. #define REF_mat_inverse_INPUT_INTERFACE(input_ptr)  \
  99.     PAREN(input_ptr, (void *) &matrix_output_ref)
  100.  
  101. #define ARM_mat_mult_INPUT_INTERFACE(input_a_ptr, input_b_ptr)      \
  102.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_fut)
  103.  
  104. #define REF_mat_mult_INPUT_INTERFACE(input_a_ptr, input_b_ptr)      \
  105.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_ref)
  106.  
  107. #define ARM_mat_mult_fast_INPUT_INTERFACE(input_a_ptr, input_b_ptr) \
  108.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_fut)
  109.  
  110. #define REF_mat_mult_fast_INPUT_INTERFACE(input_a_ptr, input_b_ptr) \
  111.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_ref)
  112.  
  113. #define ARM_mat_sub_INPUT_INTERFACE(input_a_ptr, input_b_ptr)    \
  114.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_fut)
  115.  
  116. #define REF_mat_sub_INPUT_INTERFACE(input_a_ptr, input_b_ptr)    \
  117.     PAREN(input_a_ptr, input_b_ptr, (void *) &matrix_output_ref)
  118.  
  119. #define ARM_mat_trans_INPUT_INTERFACE(input_ptr)    \
  120.     PAREN(input_ptr, (void *) &matrix_output_fut)
  121.  
  122. #define REF_mat_trans_INPUT_INTERFACE(input_ptr)    \
  123.     PAREN(input_ptr, (void *) &matrix_output_ref)
  124.  
  125. /*--------------------------------------------------------------------------------*/
  126. /* Dimension Validation Interfaces */
  127. /*--------------------------------------------------------------------------------*/
  128.  
  129. #define MATRIX_TEST_VALID_ADDITIVE_DIMENSIONS(input_type,   \
  130.                                               matrix_a_ptr, \
  131.                                               matrix_b_ptr) \
  132.     ((((input_type) (matrix_a_ptr))->numRows ==             \
  133.       ((input_type) (matrix_b_ptr))->numRows) &&            \
  134.      (((input_type) (matrix_a_ptr))->numCols ==             \
  135.       ((input_type) (matrix_b_ptr))->numCols))
  136.  
  137. #define MATRIX_TEST_VALID_MULTIPLICATIVE_DIMENSIONS(input_type,     \
  138.                                                     matrix_a_ptr,   \
  139.                                                     matrix_b_ptr)   \
  140.     (((input_type) (matrix_a_ptr))->numCols ==                      \
  141.      ((input_type) (matrix_b_ptr))->numRows)
  142.  
  143. #define MATRIX_TEST_VALID_SQUARE_DIMENSIONS(input_type, \
  144.                                             matrix_ptr) \
  145.     (((input_type)(matrix_ptr))->numRows ==             \
  146.      ((input_type)(matrix_ptr))->numCols)
  147.  
  148. #define MATRIX_TEST_VALID_DIMENSIONS_ALWAYS(input_type, \
  149.                                             matrix_ptr) \
  150.     (1 == 1)                                            \
  151.  
  152. /*--------------------------------------------------------------------------------*/
  153. /* Output Configuration Interfaces */
  154. /*--------------------------------------------------------------------------------*/
  155. /* The matrix tests assume the output matrix is always the correct size.  These
  156.  * interfaces size the properly size the output matrices according to the input
  157.  * matrices and the operation at hand.*/
  158.  
  159. #define MATRIX_TEST_CONFIG_ADDITIVE_OUTPUT(input_type,      \
  160.                                            matrix_a_ptr,    \
  161.                                            matrix_b_ptr)    \
  162.     do                                                      \
  163.     {                                                       \
  164.         ((input_type) &matrix_output_fut)->numRows =        \
  165.             ((input_type)(matrix_a_ptr))->numRows;          \
  166.         ((input_type) &matrix_output_fut)->numCols =        \
  167.             ((input_type)(matrix_a_ptr))->numCols;          \
  168.         ((input_type) &matrix_output_ref)->numRows =        \
  169.             ((input_type)(matrix_a_ptr))->numRows;          \
  170.         ((input_type) &matrix_output_ref)->numCols =        \
  171.             ((input_type)(matrix_a_ptr))->numCols;          \
  172.     } while (0)
  173.  
  174. #define MATRIX_TEST_CONFIG_MULTIPLICATIVE_OUTPUT(input_type,    \
  175.                                                  matrix_a_ptr,  \
  176.                                                  matrix_b_ptr)  \
  177.     do                                                          \
  178.     {                                                           \
  179.         ((input_type) &matrix_output_fut)->numRows =            \
  180.             ((input_type)(matrix_a_ptr))->numRows;              \
  181.         ((input_type) &matrix_output_fut)->numCols =            \
  182.             ((input_type)(matrix_b_ptr))->numCols;              \
  183.         ((input_type) &matrix_output_ref)->numRows =            \
  184.             ((input_type)(matrix_a_ptr))->numRows;              \
  185.         ((input_type) &matrix_output_ref)->numCols =            \
  186.             ((input_type)(matrix_b_ptr))->numCols;              \
  187.     } while (0)
  188.  
  189. #define MATRIX_TEST_CONFIG_SAMESIZE_OUTPUT(input_type,  \
  190.                                            matrix_ptr)  \
  191.     do                                                  \
  192.     {                                                   \
  193.         ((input_type) &matrix_output_fut)->numRows =    \
  194.             ((input_type)(matrix_ptr))->numRows;        \
  195.         ((input_type) &matrix_output_fut)->numCols =    \
  196.             ((input_type)(matrix_ptr))->numCols;        \
  197.         ((input_type) &matrix_output_ref)->numRows =    \
  198.             ((input_type)(matrix_ptr))->numRows;        \
  199.         ((input_type) &matrix_output_ref)->numCols =    \
  200.             ((input_type)(matrix_ptr))->numCols;        \
  201.     } while (0)
  202.  
  203. #define MATRIX_TEST_CONFIG_TRANSPOSE_OUTPUT(input_type,     \
  204.                                             matrix_ptr)     \
  205.         do                                                  \
  206.         {                                                   \
  207.             ((input_type) &matrix_output_fut)->numRows =    \
  208.                 ((input_type)(matrix_ptr))->numCols;        \
  209.             ((input_type) &matrix_output_fut)->numCols =    \
  210.                 ((input_type)(matrix_ptr))->numRows;        \
  211.             ((input_type) &matrix_output_ref)->numRows =    \
  212.                 ((input_type)(matrix_ptr))->numCols;        \
  213.             ((input_type) &matrix_output_ref)->numCols =    \
  214.                 ((input_type)(matrix_ptr))->numRows;        \
  215.         } while (0)
  216.  
  217. /*--------------------------------------------------------------------------------*/
  218. /* TEST Templates */
  219. /*--------------------------------------------------------------------------------*/
  220.  
  221. #define MATRIX_TEST_TEMPLATE_ELT1(arr_desc_inputs,                      \
  222.                                   input_type,                           \
  223.                                   output_type, output_content_type,     \
  224.                                   fut, fut_arg_interface,               \
  225.                                   ref, ref_arg_interface,               \
  226.                                   output_config_interface,              \
  227.                                   dim_validation_interface,             \
  228.                                   compare_interface)                    \
  229.     do                                                                  \
  230.     {                                                                   \
  231.         TEMPLATE_DO_ARR_DESC(                                           \
  232.             input_idx, input_type, input, arr_desc_inputs               \
  233.             ,                                                           \
  234.             JTEST_DUMP_STRF("Matrix Dimensions: %dx%d\n",               \
  235.                          (int)input->numRows,                           \
  236.                          (int)input->numCols);                          \
  237.                                                                         \
  238.             if (dim_validation_interface(input_type,                     \
  239.                                         input)) {                       \
  240.                 output_config_interface(input_type,                     \
  241.                                         input);                         \
  242.                 TEST_CALL_FUT_AND_REF(                                  \
  243.                     fut, fut_arg_interface(input),                      \
  244.                     ref, ref_arg_interface(input));                     \
  245.                 compare_interface(output_type,                          \
  246.                                   output_content_type);                 \
  247.             } else {                                                    \
  248.                 arm_status matrix_test_retval;                          \
  249.                 TEST_CALL_FUT(                                          \
  250.                     matrix_test_retval = fut,                           \
  251.                     fut_arg_interface(input));                          \
  252.                                                                         \
  253.                 /* If dimensions are known bad, the fut should */       \
  254.                 /* detect it. */                                        \
  255.                 if ( matrix_test_retval != ARM_MATH_SIZE_MISMATCH) {     \
  256.                     return JTEST_TEST_FAILED;                           \
  257.                 }                                                       \
  258.             });                                                         \
  259.         return JTEST_TEST_PASSED;                                       \
  260.     } while (0)
  261.  
  262.  
  263. #define MATRIX_TEST_TEMPLATE_ELT2(arr_desc_inputs_a,                    \
  264.                                   arr_desc_inputs_b,                    \
  265.                                   input_type,                           \
  266.                                   output_type, output_content_type,     \
  267.                                   fut, fut_arg_interface,               \
  268.                                   ref, ref_arg_interface,               \
  269.                                   output_config_interface,              \
  270.                                   dim_validation_interface,             \
  271.                                   compare_interface)                    \
  272.     do                                                                  \
  273.     {                                                                   \
  274.         TEMPLATE_DO_ARR_DESC(                                           \
  275.             input_a_idx, input_type, input_a, arr_desc_inputs_a         \
  276.             ,                                                           \
  277.             input_type input_b = ARR_DESC_ELT(                          \
  278.                 input_type, input_a_idx,                                \
  279.                 &(arr_desc_inputs_b));                                  \
  280.                                                                         \
  281.             JTEST_DUMP_STRF("Matrix Dimensions: A %dx%d  B %dx%d\n",    \
  282.                      (int)input_a->numRows,                             \
  283.                      (int)input_a->numCols,                             \
  284.                      (int)input_b->numRows,                             \
  285.                      (int)input_b->numCols);                            \
  286.                                                                         \
  287.             if (dim_validation_interface(input_type,                     \
  288.                                         input_a,                        \
  289.                                         input_b)) {                     \
  290.                                                                         \
  291.                 output_config_interface(input_type,                     \
  292.                                         input_a,                        \
  293.                                         input_b);                       \
  294.                                                                         \
  295.                 TEST_CALL_FUT_AND_REF(                                  \
  296.                     fut, fut_arg_interface(input_a, input_b),           \
  297.                     ref, ref_arg_interface(input_a, input_b));          \
  298.                                                                         \
  299.                 compare_interface(output_type, output_content_type);    \
  300.                                                                         \
  301.             } else {                                                    \
  302.                 arm_status matrix_test_retval;                          \
  303.                 TEST_CALL_FUT(                                          \
  304.                     matrix_test_retval = fut, fut_arg_interface(input_a, input_b)); \
  305.                                                                         \
  306.                 /* If dimensions are known bad, the fut should */       \
  307.                 /* detect it. */                                        \
  308.                 if ( matrix_test_retval != ARM_MATH_SIZE_MISMATCH) {     \
  309.                     return JTEST_TEST_FAILED;                           \
  310.                 }                                                       \
  311.             });                                                         \
  312.         return JTEST_TEST_PASSED;                                       \
  313.     } while (0)
  314.  
  315. /**
  316.  *  Specialization of #MATRIX_TEST_TEMPLATE_ELT2() for matrix tests.
  317.  *
  318.  *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
  319.  *  REF_xxx_INPUT_INTERFACEs.
  320.  */
  321. #define MATRIX_DEFINE_TEST_TEMPLATE_ELT2(fn_name, suffix,           \
  322.                                          output_config_interface,   \
  323.                                          dim_validation_interface,  \
  324.                                          comparison_interface)      \
  325.         JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,          \
  326.                           arm_##fn_name##_##suffix)                 \
  327.         {                                                           \
  328.             MATRIX_TEST_TEMPLATE_ELT2(                              \
  329.                 matrix_##suffix##_a_inputs,                         \
  330.                 matrix_##suffix##_b_inputs,                         \
  331.                 arm_matrix_instance_##suffix * ,                    \
  332.                 arm_matrix_instance_##suffix,                       \
  333.                 TYPE_FROM_ABBREV(suffix),                           \
  334.                 arm_##fn_name##_##suffix,                           \
  335.                 ARM_##fn_name##_INPUT_INTERFACE,                    \
  336.                 ref_##fn_name##_##suffix,                           \
  337.                 REF_##fn_name##_INPUT_INTERFACE,                    \
  338.                 output_config_interface,                            \
  339.                 dim_validation_interface,                           \
  340.                 comparison_interface);                              \
  341.         }                                                           \
  342.  
  343. /**
  344.  *  Specialization of #MATRIX_TEST_TEMPLATE_ELT1() for matrix tests.
  345.  *
  346.  *  @note This macro relies on the existance of ARM_xxx_INPUT_INTERFACE and
  347.  *  REF_xxx_INPUT_INTERFACEs.
  348.  */
  349. #define MATRIX_DEFINE_TEST_TEMPLATE_ELT1(fn_name, suffix,           \
  350.                                          output_config_interface,   \
  351.                                          dim_validation_interface)  \
  352.         JTEST_DEFINE_TEST(arm_##fn_name##_##suffix##_test,          \
  353.                           arm_##fn_name##_##suffix)                 \
  354.         {                                                           \
  355.             MATRIX_TEST_TEMPLATE_ELT1(                              \
  356.                 matrix_##suffix##_a_inputs,                         \
  357.                 arm_matrix_instance_##suffix * ,                    \
  358.                 arm_matrix_instance_##suffix,                       \
  359.                 TYPE_FROM_ABBREV(suffix),                           \
  360.                 arm_##fn_name##_##suffix,                           \
  361.                 ARM_##fn_name##_INPUT_INTERFACE,                    \
  362.                 ref_##fn_name##_##suffix,                           \
  363.                 REF_##fn_name##_INPUT_INTERFACE,                    \
  364.                 output_config_interface,                            \
  365.                 dim_validation_interface,                           \
  366.                 MATRIX_COMPARE_INTERFACE);                          \
  367.         }                                                           \
  368.  
  369.  
  370. #endif /* _MATRIX_TEMPLATES_H_ */
  371.