Kaynağa Gözat

Added human readable status reporting.

shkolnick-kun 4 ay önce
ebeveyn
işleme
c0e9faaeff
3 değiştirilmiş dosya ile 38 ekleme ve 5 silme
  1. 3 0
      src/yafl.c
  2. 30 0
      src/yafl_math.c
  3. 5 5
      src/yafl_math.h

+ 3 - 0
src/yafl.c

@@ -18,6 +18,9 @@
 
 #include "yafl.h"
 
+/*np.log(2. * np.pi)*/
+#define YAFL_L2PI (1.8378770664093453)
+
 #define _FX  (self->f)
 #define _HX  (self->h)
 #define _ZRF (self->zrf)

+ 30 - 0
src/yafl_math.c

@@ -17,6 +17,36 @@
 
 #include "yafl_math.h"
 
+/* We need some way of printing human readable statuses */
+char * yafl_fail_dsc(yaflStatusEn status)
+{
+    switch (status & 0xff0)
+    {
+#define _CASE_DSC(err) do { \
+    case err:               \
+    {                       \
+        return #err;        \
+    }                       \
+    } while (0)
+    _CASE_DSC(YAFL_ST_INV_ARG_1);
+    _CASE_DSC(YAFL_ST_INV_ARG_2);
+    _CASE_DSC(YAFL_ST_INV_ARG_3);
+    _CASE_DSC(YAFL_ST_INV_ARG_4);
+    _CASE_DSC(YAFL_ST_INV_ARG_5);
+    _CASE_DSC(YAFL_ST_INV_ARG_6);
+    _CASE_DSC(YAFL_ST_INV_ARG_7);
+    _CASE_DSC(YAFL_ST_INV_ARG_8);
+    _CASE_DSC(YAFL_ST_INV_ARG_9);
+    _CASE_DSC(YAFL_ST_INV_ARG_10);
+    _CASE_DSC(YAFL_ST_INV_ARG_11);
+    _CASE_DSC(YAFL_ST_INV_ARG_12);
+    default:
+    {
+        return "Internal error!!!";
+    }
+    }
+}
+
 #define _DO_VXN(name, op)                                                \
 yaflStatusEn name(yaflInt sz, yaflFloat *res, yaflFloat *v, yaflFloat n) \
 {                                                                        \

+ 5 - 5
src/yafl_math.h

@@ -35,9 +35,6 @@ do {                                                                       \
 
 #define YAFL_CHECK(cond, err) _YAFL_CHECK(cond, err, __FILE__, __func__, __LINE__)
 
-/*np.log(2. * np.pi)*/
-#define YAFL_L2PI (1.8378770664093453)
-
 typedef enum {
     /*Warning flag masks*/
     YAFL_ST_MSK_REGULARIZED  = 0x01,
@@ -79,6 +76,9 @@ typedef enum {
     YAFL_ST_INV_ARG_12   = 0x1b0
 } yaflStatusEn;
 
+/* We need some way of printing human readable statuses */
+char * yafl_fail_dsc(yaflStatusEn status);
+
 #define _YAFL_TRY(status, exp, file, func, line)                              \
 do {                                                                          \
     (status) |= (exp);                                                        \
@@ -86,8 +86,8 @@ do {                                                                          \
     {                                                                         \
         YAFL_DBG("YAFL:The expression (%s) gave an error in \n function: %s", \
                  #exp, func);                                                 \
-        YAFL_DBG("\n file: %s\n line: %d\n will return: %d\n",                \
-                 file, line, status);                                         \
+        YAFL_DBG("\n file: %s\n line: %d\n will return: %s\n",                \
+                 file, line, yafl_fail_dsc(status));                          \
         return status;                                                        \
     }                                                                         \
 } while (0)