Compare commits

...

4 commits

Author SHA1 Message Date
a69926bd39 Commenting IF default flags and stuffs 2020-04-21 14:12:17 +02:00
045213a4cc Bugifx in Makefile's clean target 2020-04-21 13:42:13 +02:00
454173322a IFS weight update implementation 2020-04-21 13:40:50 +02:00
53e0d2cead Moved C tests 2020-04-21 13:40:22 +02:00
7 changed files with 116 additions and 29 deletions

View file

@ -51,13 +51,6 @@ rpn_ifs.o: rpn_ifs.c rpn_ifs.h rpn_if.o
rpn_lib.o: rpn_lib.asm rpn_lib.h
$(NASM) $(NASMCFLAGS) -o $@ $<
# Dirty & quick tests
test: test.o rpn_lib.o rpn_jit.o rpn_parse.o
$(CC) $(CFLAGS) -o $@ $^
test.o: test.c
$(CC) $(CFLAGS) -c -o $@ $<
# Doxygen documentation
doc: doc/.doxygen.stamp
@ -84,14 +77,15 @@ benchmark: pyrpn.so
unittest: pyrpn.so
PYTHONPATH=`pwd` $(PYTHON) -m unittest
runtest: test
./test
runtest:
make -C tests
clean:
-rm -fv *.o pyrpn.so test
-rm -fRv doc/.doxygen.stamp doc/* Doxyfile
-rm -fv *.o pyrpn.so test;\
rm -fRv doc/.doxygen.stamp doc/* Doxyfile;\
make -C tests clean
distclean: clean
-rm -vf .deps
-rm -Rvf tests/__pycache__
-rm -vf .deps;\
rm -Rvf tests/__pycache__;

View file

@ -23,6 +23,13 @@
#include "rpn_jit.h"
/**@file rpn_if.h
* @ingroup ifs_if
* @brief Iterated functions headers
*
* Iterated functions structure + API definition
*/
/**@defgroup ifs_if Iterated function
* @ingroup ifs
* @brief Iterated RPN expression
@ -95,8 +102,6 @@ struct rpn_if_s
* @param rpn list of RPN expresions of params->rpn_sz size
* @param memmap A suitable memory map. If NULL given, a new mmap is used
* @return A pointer on an allocated @ref rpn_if_s
* @todo Delete rpn argument : rpn expressions are initialized and
* have to be compiled later
*/
rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_value_t *memmap);

View file

@ -21,6 +21,7 @@
/**@file rpn_if_default.h Defines default IF
* @ingroup ifs_if_default
* @ingroup ifs_if
* @brief Default IF definitions
*/
@ -35,21 +36,30 @@
#include "config.h"
#include "rpn_if.h"
#define RPN_IF_POSITION_LINEAR 0 // One expr for position
#define RPN_IF_POSITION_XY 1 // two expr for poisition
#define RPN_IF_POSITION_XDIM 2 // X expr for position
/**@weakgroup ifs_if_default_posflag Default IF position flags
* @ingroup ifs_if_default
* @{ */
#define RPN_IF_POSITION_LINEAR 0 ///< One expr for position
#define RPN_IF_POSITION_XY 1 ///< two expr for position
#define RPN_IF_POSITION_XDIM 2 ///< X expr for position
#define RPN_IF_POSITION_OF_LOOP 0 // Loop on position overflow
#define RPN_IF_POSITION_OF_ERR 16 // Trigger error on position overflow
#define RPN_IF_POSITION_OF_LOOP 0 ///< Loop on position overflow
#define RPN_IF_POSITION_OF_ERR 16 ///< Trigger error on position overflow
/**@}*/
#define RPN_IF_RES_BOOL 0 // Set to one when position occurs
#define RPN_IF_RES_CONST 1 // Set to a constant value
#define RPN_IF_RES_CONST_RGBA 2 // Set to a constant RGB using alpha channel
#define RPN_IF_RES_COUNT 3 // Count number of time position occurs
#define RPN_IF_RES_XFUN 4 // Set to result of rpn_expr
#define RPN_IF_RES_RGB 5 // Set result to RGB color from rpn_expr
#define RPN_IF_RES_RGBA 6 // Set result to RGB using alpha channel from rpn_expr
/**@weakgroup ifs_if_default_resflag Default IF position flags
* @ingroup ifs_if_default
* @{ */
#define RPN_IF_RES_BOOL 0 ///< Set to one when position occurs
#define RPN_IF_RES_CONST 1 ///< Set to a constant value
#define RPN_IF_RES_CONST_RGBA 2 ///< Set to a constant RGB using alpha channel
#define RPN_IF_RES_COUNT 3 ///< Count number of time position occurs
#define RPN_IF_RES_XFUN 4 ///< Set to result of rpn_expr
#define RPN_IF_RES_RGB 5 ///< Set result to RGB color from rpn_expr
#define RPN_IF_RES_RGBA 6 ///< Set result to RGB using alpha channel from rpn_expr
/**@}*/
/**@brief Alias for struct @ref rpn_if_default_data_s */
typedef struct rpn_if_default_data_s rpn_if_default_data_t;
/**@brief Stores default IF data
@ -58,7 +68,9 @@ typedef struct rpn_if_default_data_s rpn_if_default_data_t;
*/
struct rpn_if_default_data_s
{
/**@brief Flag defining position coordinate handling */
short pos_flag;
/**@brief Flag defining result handling */
short res_flag;
/**@brief Stores size limits given pos_flag
*
@ -76,7 +88,22 @@ struct rpn_if_default_data_s
rpn_value_t *const_val;
};
/**@brief Create a new @ref rpn_if_s corresponding to given flags
* @ingroup ifs_if_default
*
* @param pos_flag Binary OR combination of RPN_IF_POSITION_*
* (@ref ifs_if_default_posflag )
* @param pos_flag Binary OR combination of RPN_IF_RES_*
* (@ref ifs_if_default_posflag )
* @returns A new @ref rpn_if_t (see @ref rpn_if_new ) or NULL on
* error
* @todo Implementation/testing
*/
rpn_if_t* rpn_if_new_default(short pos_flag, short res_flag);
/**@brief Default argf function ( see @ref rpn_if_param_s.arg_f ) */
int rpn_if_argf_default(rpn_if_t *rif, size_t pos, rpn_value_t *args);
/**@brief Default result function ( see @ref rpn_if_param_s.res_f ) */
int rpn_if_resf_default(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
/**@brief Set the first expression argument from position

View file

@ -132,9 +132,38 @@ int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx)
return 0;
}
int rpn_ifs_run(rpn_ifs_t *rifs, size_t n)
{
return 0;
}
int rpn_ifs_weight_update(rpn_ifs_t *rifs)
{
return 1;
unsigned long int weight_sum;
size_t i, j, max;
rpn_if_t **proba;
proba = rifs->if_proba;
bzero(rifs->if_proba, sizeof(rpn_if_t*)*255);
weight_sum = 0;
for(i=0; i < rifs->if_sz; i++)
{
weight_sum += rifs->weight[i];
}
j=0;
for(i=0; i < rifs->if_sz; i++)
{
max = rifs->weight[i] * 255 / weight_sum;
while(max)
{
*proba = rifs->rpn_if[i];
max--;
j++;
}
}
return 0;
}
rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs)

View file

@ -65,7 +65,7 @@ struct rpn_ifs_s
/**@brief Stores the original chance of choosing corresponding IF */
unsigned int *weight;
/** @brief Stores an array of 255 pointers on IF allowing fast
* random choice */
* random choice. Last ptr can be NULL*/
rpn_if_t *if_proba[255];
/**@brief Stores the RPN expressions pointer of the IF contained in
@ -107,6 +107,14 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight);
*/
int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
/**@brief Call IFS n times
* @note Make n random choices and call corresponding IF
* @param rifs The iterated function system
* @param n consecutive IFS calls
* @return 1 if error else 0
*/
int rpn_ifs_run(rpn_ifs_t *rifs, size_t n);
/**@brief Updates the @ref rpn_ifs_s.if_proba array using
* @ref rpn_ifs_s.if_proba values
* @param rifs The iterated function system

24
tests/Makefile Normal file
View file

@ -0,0 +1,24 @@
CC=gcc
LD=ld
SOURCES=$(wildcard test_*.c)
OBJS=$(patsubst %.c,%.o, $(SOURCES))
BINARIES=$(patsubst %.o, %, $(OBJS))
all: checks
checks: $(BINARIES)
for test_bin in $(BINARIES); do echo "Running $${test_bin}.c"; ./$$test_bin && echo "OK" || echo "fail"; done
../%.o:
make -C ..
%.o: %.c
$(CC) -I.. $(CFLAGS) -c -o $@ $<
test_%: test_%.o ../rpn_lib.o ../rpn_jit.o ../rpn_parse.o
$(CC) -I.. $(CFLAGS) -o $@ $^
.PHONY: clean
clean:
-rm -v $(BINARIES) $(OBJS)