Fast IFS using RPN notation
python
c
x86-64
nasm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python_mutation.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2020 Weber Yann
  3. *
  4. * This file is part of pyrpn.
  5. *
  6. * pyrpn is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * pyrpn is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _PYTHON_MUTATION_H__
  20. #define _PYTHON_MUTATION_H__
  21. #include "config.h"
  22. #include <errno.h>
  23. #include <float.h>
  24. #define PY_SSIZE_T_CLEAN
  25. #include <Python.h>
  26. #include "structmember.h"
  27. #include "python_const.h"
  28. #include "rpn_mutate.h"
  29. #include "rpn_if_mutate.h"
  30. #include "rpn_ifs_mutate.h"
  31. /**@file python_mutation.h
  32. * @brief Python types (named tuple) & utility to manipulate mutation
  33. * parameters
  34. * @ingroup python_ext
  35. */
  36. /**@defgroup pymod_pyrpn_RPNMutationParams pyrpn.RPNMutationParams
  37. * @brief namedtuple storing mutation parameters
  38. * @ingroup pymod_pyrpn */
  39. /**@brief RPNMutationParams named tuple with mutation parameters */
  40. extern PyTypeObject rpn_mutation_params_SeqDesc;
  41. /**@brief @ref rpn_mutation_params_SeqDesc named tuple description */
  42. extern PyStructSequence_Desc rpn_mutation_params_desc;
  43. extern PyTypeObject ifs_mutation_weights_SeqDesc;
  44. extern PyStructSequence_Desc ifs_mutation_weights_desc;
  45. /**@brief Initialize mutation related types & stuff. Adds references
  46. * to pyrpn module given in argument
  47. * @param pyrpn_mod pyrpn python module instance
  48. * @return 0 if no error else -1 */
  49. int pyrpn_python_mutation_init(PyObject *pyrpn_mod);
  50. /**@brief Try to convert a python object into a rpn_mutation_params_t
  51. * @param py_params The python object
  52. * @param params A pointer on the parameters to initialize
  53. * @return -1 on failure and raise an exception
  54. * @ingroup pymod_pyrpn_RPNExpr
  55. */
  56. int pyrpn_pyobj_to_mutation_params(PyObject* py_params, rpn_mutation_params_t *params);
  57. int pyrpn_mutation_params_to_pyobj(const rpn_mutation_params_t *params,
  58. PyObject **res);
  59. int pyrpn_pyobj_to_ifs_mutation_weights(PyObject *py_params,
  60. ifs_mutation_weights_t *w);
  61. int pyrpn_ifs_mut_weight_to_pyobj(const ifs_mutation_weights_t *w,
  62. PyObject **mut_weights);
  63. /**@brief Set the mutation type weight from a PyObject* sequence
  64. * @param w The IFS mutation weight structure to edit
  65. * @param mut_type_weight Should be a sequence of 2 float values
  66. * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
  67. */
  68. int pyrpn_ifs_mut_params_mut_type_weight(ifs_mutation_weights_t *w,
  69. PyObject *mut_type_weight);
  70. /**@brief Set the mutation weight range from a PyObject* sequence
  71. * @param w The IFS mutation weight structure to edit
  72. * @param weight_range Should be a sequence of 2 float values
  73. * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
  74. */
  75. int pyrpn_ifs_mut_params_weight_range(ifs_mutation_weights_t *w,
  76. PyObject *weight_range);
  77. /**@brief Set the IF mutation weight from a PyObject* sequence
  78. * @note Check that the sequence length correspond to the if_count
  79. * in the ifs_mutation_weights_t struct
  80. * @note If current w_mut_if field is NULL allocate it
  81. * @param w The IFS mutation weight structure to edit
  82. * @param weight_range Should be a sequence of if_count float values
  83. * @param do_realloc If != 0 reallocate the w_mut_if field to correspond to
  84. * if_count
  85. * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
  86. */
  87. int pyrpn_ifs_mut_params_weight_mut_if(ifs_mutation_weights_t *w,
  88. PyObject *mut_if_weight, short do_realloc);
  89. /**@brief Set the IF component weights from a PyObject* sequence
  90. * @note The function cannot check the length validity of the given
  91. * sequence (except that empty sequence are invalid).
  92. * @param w The IFS mutation weight structure to edit
  93. * @param mut_type_weight Should be a sequence of 2 float values
  94. * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
  95. */
  96. int pyrpn_ifs_mut_params_if_comp_weight(ifs_mutation_weights_t *w,
  97. PyObject *if_comp_weight);
  98. /**@brief Set the RPN mutation parameters from a PyObject*
  99. * @param w The IFS mutation weight structure to edit
  100. * @param mutation_params Can be a valid value for a RPNMutationParams
  101. * or a sequence of valid values for a RPNMutationParams
  102. * of len w->if_count
  103. * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
  104. */
  105. int pyrpn_ifs_mut_params_mutation_params(ifs_mutation_weights_t *w,
  106. PyObject *mutation_params);
  107. #endif