4 Commits

Author SHA1 Message Date
  Yann Weber a69926bd39 Commenting IF default flags and stuffs 4 years ago
  Yann Weber 045213a4cc Bugifx in Makefile's clean target 4 years ago
  Yann Weber 454173322a IFS weight update implementation 4 years ago
  Yann Weber 53e0d2cead Moved C tests 4 years ago
7 changed files with 116 additions and 29 deletions
  1. 7
    13
      Makefile
  2. 7
    2
      rpn_if.h
  3. 39
    12
      rpn_if_default.h
  4. 30
    1
      rpn_ifs.c
  5. 9
    1
      rpn_ifs.h
  6. 24
    0
      tests/Makefile
  7. 0
    0
      tests/test_rpn.c

+ 7
- 13
Makefile View File

51
 rpn_lib.o: rpn_lib.asm rpn_lib.h
51
 rpn_lib.o: rpn_lib.asm rpn_lib.h
52
 	$(NASM) $(NASMCFLAGS) -o $@ $<
52
 	$(NASM) $(NASMCFLAGS) -o $@ $<
53
 
53
 
54
-# Dirty & quick tests
55
-test: test.o rpn_lib.o rpn_jit.o rpn_parse.o
56
-	$(CC) $(CFLAGS) -o $@ $^
57
-
58
-test.o: test.c
59
-	$(CC) $(CFLAGS) -c -o $@ $<
60
-
61
 # Doxygen documentation
54
 # Doxygen documentation
62
 doc: doc/.doxygen.stamp
55
 doc: doc/.doxygen.stamp
63
 
56
 
84
 unittest: pyrpn.so
77
 unittest: pyrpn.so
85
 	PYTHONPATH=`pwd` $(PYTHON) -m unittest
78
 	PYTHONPATH=`pwd` $(PYTHON) -m unittest
86
 
79
 
87
-runtest: test
88
-	./test
80
+runtest:
81
+	make -C tests
89
 
82
 
90
 clean:
83
 clean:
91
-	-rm -fv *.o pyrpn.so test
92
-	-rm -fRv doc/.doxygen.stamp doc/* Doxyfile
84
+	-rm -fv *.o pyrpn.so test;\
85
+	rm -fRv doc/.doxygen.stamp doc/* Doxyfile;\
86
+	make -C tests clean
93
 
87
 
94
 distclean: clean
88
 distclean: clean
95
-	-rm -vf .deps
96
-	-rm -Rvf tests/__pycache__
89
+	-rm -vf .deps;\
90
+	rm -Rvf tests/__pycache__;
97
 
91
 

+ 7
- 2
rpn_if.h View File

23
 
23
 
24
 #include "rpn_jit.h"
24
 #include "rpn_jit.h"
25
 
25
 
26
+/**@file rpn_if.h
27
+ * @ingroup ifs_if
28
+ * @brief Iterated functions headers
29
+ *
30
+ * Iterated functions structure + API definition
31
+ */
32
+
26
 /**@defgroup ifs_if Iterated function
33
 /**@defgroup ifs_if Iterated function
27
  * @ingroup ifs
34
  * @ingroup ifs
28
  * @brief Iterated RPN expression
35
  * @brief Iterated RPN expression
95
  * @param rpn list of RPN expresions of params->rpn_sz size
102
  * @param rpn list of RPN expresions of params->rpn_sz size
96
  * @param memmap A suitable memory map. If NULL given, a new mmap is used
103
  * @param memmap A suitable memory map. If NULL given, a new mmap is used
97
  * @return A pointer on an allocated @ref rpn_if_s
104
  * @return A pointer on an allocated @ref rpn_if_s
98
- * @todo Delete rpn argument : rpn expressions are initialized and
99
- * have to be compiled later
100
  */
105
  */
101
 rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_value_t *memmap);
106
 rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_value_t *memmap);
102
 
107
 

+ 39
- 12
rpn_if_default.h View File

21
 
21
 
22
 /**@file rpn_if_default.h Defines default IF
22
 /**@file rpn_if_default.h Defines default IF
23
  * @ingroup ifs_if_default
23
  * @ingroup ifs_if_default
24
+ * @ingroup ifs_if
24
  * @brief Default IF definitions
25
  * @brief Default IF definitions
25
  */
26
  */
26
 
27
 
35
 #include "config.h"
36
 #include "config.h"
36
 #include "rpn_if.h"
37
 #include "rpn_if.h"
37
 
38
 
38
-#define RPN_IF_POSITION_LINEAR 0 // One expr for position
39
-#define RPN_IF_POSITION_XY 1 // two expr for poisition
40
-#define RPN_IF_POSITION_XDIM 2 // X expr for position
39
+/**@weakgroup ifs_if_default_posflag Default IF position flags
40
+ * @ingroup ifs_if_default
41
+ * @{ */
42
+#define RPN_IF_POSITION_LINEAR 0 ///< One expr for position
43
+#define RPN_IF_POSITION_XY 1 ///< two expr for position
44
+#define RPN_IF_POSITION_XDIM 2 ///< X expr for position
41
 
45
 
42
-#define RPN_IF_POSITION_OF_LOOP 0 // Loop on position overflow
43
-#define RPN_IF_POSITION_OF_ERR 16 // Trigger error on position overflow
46
+#define RPN_IF_POSITION_OF_LOOP 0 ///< Loop on position overflow
47
+#define RPN_IF_POSITION_OF_ERR 16 ///< Trigger error on position overflow
48
+/**@}*/
44
 
49
 
45
-#define RPN_IF_RES_BOOL 0 // Set to one when position occurs
46
-#define RPN_IF_RES_CONST 1 // Set to a constant value
47
-#define RPN_IF_RES_CONST_RGBA 2 // Set to a constant RGB using alpha channel
48
-#define RPN_IF_RES_COUNT 3 // Count number of time position occurs
49
-#define RPN_IF_RES_XFUN 4 // Set to result of rpn_expr
50
-#define RPN_IF_RES_RGB 5 // Set result to RGB color from rpn_expr
51
-#define RPN_IF_RES_RGBA 6 // Set result to RGB using alpha channel from rpn_expr
50
+/**@weakgroup ifs_if_default_resflag Default IF position flags
51
+ * @ingroup ifs_if_default
52
+ * @{ */
53
+#define RPN_IF_RES_BOOL 0 ///< Set to one when position occurs
54
+#define RPN_IF_RES_CONST 1 ///< Set to a constant value
55
+#define RPN_IF_RES_CONST_RGBA 2 ///< Set to a constant RGB using alpha channel
56
+#define RPN_IF_RES_COUNT 3 ///< Count number of time position occurs
57
+#define RPN_IF_RES_XFUN 4 ///< Set to result of rpn_expr
58
+#define RPN_IF_RES_RGB 5 ///< Set result to RGB color from rpn_expr
59
+#define RPN_IF_RES_RGBA 6 ///< Set result to RGB using alpha channel from rpn_expr
60
+/**@}*/
52
 
61
 
62
+/**@brief Alias for struct @ref rpn_if_default_data_s */
53
 typedef struct rpn_if_default_data_s rpn_if_default_data_t;
63
 typedef struct rpn_if_default_data_s rpn_if_default_data_t;
54
 
64
 
55
 /**@brief Stores default IF data
65
 /**@brief Stores default IF data
58
  */
68
  */
59
 struct rpn_if_default_data_s
69
 struct rpn_if_default_data_s
60
 {
70
 {
71
+	/**@brief Flag defining position coordinate handling */
61
 	short pos_flag;
72
 	short pos_flag;
73
+	/**@brief Flag defining result handling */
62
 	short res_flag;
74
 	short res_flag;
63
 	/**@brief Stores size limits given pos_flag
75
 	/**@brief Stores size limits given pos_flag
64
 	 *
76
 	 *
76
 	rpn_value_t *const_val;
88
 	rpn_value_t *const_val;
77
 };
89
 };
78
 
90
 
91
+/**@brief Create a new @ref rpn_if_s corresponding to given flags
92
+ * @ingroup ifs_if_default
93
+ *
94
+ * @param pos_flag Binary OR combination of RPN_IF_POSITION_*
95
+ *     (@ref ifs_if_default_posflag )
96
+ * @param pos_flag Binary OR combination of RPN_IF_RES_*
97
+ *     (@ref ifs_if_default_posflag )
98
+ * @returns A new @ref rpn_if_t (see @ref rpn_if_new ) or NULL on
99
+ * error
100
+ * @todo Implementation/testing
101
+ */
102
+rpn_if_t* rpn_if_new_default(short pos_flag, short res_flag);
103
+
104
+/**@brief Default argf function ( see @ref rpn_if_param_s.arg_f ) */
79
 int rpn_if_argf_default(rpn_if_t *rif, size_t pos, rpn_value_t *args);
105
 int rpn_if_argf_default(rpn_if_t *rif, size_t pos, rpn_value_t *args);
106
+/**@brief Default result function ( see @ref rpn_if_param_s.res_f ) */
80
 int rpn_if_resf_default(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
107
 int rpn_if_resf_default(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
81
 
108
 
82
 /**@brief Set the first expression argument from position
109
 /**@brief Set the first expression argument from position

+ 30
- 1
rpn_ifs.c View File

132
 	return 0;
132
 	return 0;
133
 }
133
 }
134
 
134
 
135
+int rpn_ifs_run(rpn_ifs_t *rifs, size_t n)
136
+{
137
+	return 0;
138
+}
139
+
135
 int rpn_ifs_weight_update(rpn_ifs_t *rifs)
140
 int rpn_ifs_weight_update(rpn_ifs_t *rifs)
136
 {
141
 {
137
-	return 1;
142
+	unsigned long int weight_sum;
143
+	size_t i, j, max;
144
+	rpn_if_t **proba;
145
+
146
+	proba = rifs->if_proba;
147
+	bzero(rifs->if_proba, sizeof(rpn_if_t*)*255);
148
+
149
+	weight_sum = 0;
150
+
151
+	for(i=0; i < rifs->if_sz; i++)
152
+	{
153
+		weight_sum += rifs->weight[i];
154
+	}
155
+	j=0;
156
+	for(i=0; i < rifs->if_sz; i++)
157
+	{
158
+		max = rifs->weight[i] * 255 / weight_sum;
159
+		while(max)
160
+		{
161
+			*proba = rifs->rpn_if[i];
162
+			max--;
163
+			j++;
164
+		}
165
+	}
166
+	return 0;
138
 }
167
 }
139
 
168
 
140
 rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs)
169
 rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs)

+ 9
- 1
rpn_ifs.h View File

65
 	/**@brief Stores the original chance of choosing corresponding IF */
65
 	/**@brief Stores the original chance of choosing corresponding IF */
66
 	unsigned int *weight;
66
 	unsigned int *weight;
67
 	/** @brief Stores an array of 255 pointers on IF allowing fast
67
 	/** @brief Stores an array of 255 pointers on IF allowing fast
68
-	 * random choice */
68
+	 * random choice. Last ptr can be NULL*/
69
 	rpn_if_t *if_proba[255];
69
 	rpn_if_t *if_proba[255];
70
 
70
 
71
 	/**@brief Stores the RPN expressions pointer of the IF contained in
71
 	/**@brief Stores the RPN expressions pointer of the IF contained in
107
  */
107
  */
108
 int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
108
 int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
109
 
109
 
110
+/**@brief Call IFS n times
111
+ * @note Make n random choices and call corresponding IF
112
+ * @param rifs The iterated function system
113
+ * @param n consecutive IFS calls
114
+ * @return 1 if error else 0
115
+ */
116
+int rpn_ifs_run(rpn_ifs_t *rifs, size_t n);
117
+
110
 /**@brief Updates the @ref rpn_ifs_s.if_proba array using
118
 /**@brief Updates the @ref rpn_ifs_s.if_proba array using
111
  * @ref rpn_ifs_s.if_proba values
119
  * @ref rpn_ifs_s.if_proba values
112
  * @param rifs The iterated function system
120
  * @param rifs The iterated function system

+ 24
- 0
tests/Makefile View File

1
+CC=gcc
2
+LD=ld
3
+SOURCES=$(wildcard test_*.c)
4
+OBJS=$(patsubst %.c,%.o, $(SOURCES))
5
+BINARIES=$(patsubst %.o, %, $(OBJS))
6
+
7
+all: checks
8
+
9
+checks: $(BINARIES)
10
+	for test_bin in $(BINARIES); do echo "Running $${test_bin}.c"; ./$$test_bin && echo "OK" || echo "fail"; done
11
+
12
+../%.o:
13
+	make -C ..
14
+
15
+%.o: %.c
16
+	$(CC) -I.. $(CFLAGS) -c -o $@ $<
17
+
18
+test_%: test_%.o ../rpn_lib.o ../rpn_jit.o ../rpn_parse.o
19
+	$(CC) -I..  $(CFLAGS) -o $@ $^
20
+	
21
+.PHONY: clean
22
+
23
+clean:
24
+	-rm -v $(BINARIES) $(OBJS)

test.c → tests/test_rpn.c View File


Loading…
Cancel
Save