mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
[Fix] Fix conflicts ._.
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
#include "modpyplot.h"
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modpyplot___init___obj, modpyplot___init__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_arrow_obj, 4, 4, modpyplot_arrow);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_axis_obj, 0, 1, modpyplot_axis);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_bar_obj, 2, 4, modpyplot_bar);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_grid_obj, 0, 1, modpyplot_grid);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_hist_obj, 1, 2, modpyplot_hist);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_plot_obj, 1, 2, modpyplot_plot);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(modpyplot_scatter_obj, modpyplot_scatter);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modpyplot_show_obj, modpyplot_show);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(modpyplot_text_obj, modpyplot_text);
|
||||
|
||||
STATIC const mp_rom_map_elem_t modpyplot_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_matplotlib_dot_pyplot) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&modpyplot___init___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_arrow), MP_ROM_PTR(&modpyplot_arrow_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_axis), MP_ROM_PTR(&modpyplot_axis_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&modpyplot_bar_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_grid), MP_ROM_PTR(&modpyplot_grid_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_hist), MP_ROM_PTR(&modpyplot_hist_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_plot), MP_ROM_PTR(&modpyplot_plot_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_scatter), MP_ROM_PTR(&modpyplot_scatter_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&modpyplot_show_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&modpyplot_text_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(modpyplot_module_globals, modpyplot_module_globals_table);
|
||||
|
||||
const mp_obj_module_t modpyplot_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&modpyplot_module_globals,
|
||||
};
|
||||
@@ -88,8 +88,7 @@ mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args) {
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
sPlotStore->addSegment(args[0], args[1], mp_obj_new_float(mp_obj_get_float(args[0])+mp_obj_get_float(args[2])), mp_obj_new_float(mp_obj_get_float(args[1])+mp_obj_get_float(args[3])), color, true); // TODO: use float_binary_op
|
||||
|
||||
sPlotStore->addSegment(args[0], args[1], mp_obj_float_binary_op(MP_BINARY_OP_INPLACE_ADD, mp_obj_get_float(args[0]), args[2]), mp_obj_float_binary_op(MP_BINARY_OP_INPLACE_ADD, mp_obj_get_float(args[1]), args[3]), color, true);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@@ -183,13 +182,23 @@ mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
for (size_t i=0; i<xLength; i++) {
|
||||
mp_float_t iH = mp_obj_get_float(hItems[hLength > 1 ? i : 0]);
|
||||
mp_float_t iW = mp_obj_get_float(wItems[wLength > 1 ? i : 0]);
|
||||
mp_float_t iB = mp_obj_get_float(bItems[bLength > 1 ? i : 0]);
|
||||
mp_float_t iX = mp_obj_get_float(xItems[i])-iW/2.0;
|
||||
mp_float_t iYStart = iH < 0.0 ? iB : iB + iH;
|
||||
mp_float_t iYEnd = iH < 0.0 ? iB + iH : iB;
|
||||
sPlotStore->addRect(mp_obj_new_float(iX), mp_obj_new_float(iX+iW), mp_obj_new_float(iYStart), mp_obj_new_float(iYEnd), color); // TODO: use float_binary_op?
|
||||
mp_obj_t iH = hItems[hLength > 1 ? i : 0];
|
||||
mp_obj_t iW = wItems[wLength > 1 ? i : 0];
|
||||
mp_obj_t iB = bItems[bLength > 1 ? i : 0];
|
||||
mp_obj_t iX = xItems[i];
|
||||
|
||||
float iWf = mp_obj_get_float(iW);
|
||||
float iXf = mp_obj_get_float(iX);
|
||||
mp_obj_t rectLeft = mp_obj_new_float(iXf - iWf/2.0f);
|
||||
mp_obj_t rectRight = mp_obj_new_float(iXf + iWf/2.0f);
|
||||
mp_obj_t rectBottom = iB;
|
||||
mp_obj_t rectTop = mp_obj_float_binary_op(MP_BINARY_OP_INPLACE_ADD, mp_obj_get_float(iH), iB);
|
||||
if (mp_obj_get_float(iH) < 0.0) {
|
||||
mp_obj_t temp = rectTop;
|
||||
rectTop = rectBottom;
|
||||
rectBottom = temp;
|
||||
}
|
||||
sPlotStore->addRect(rectLeft, rectRight, rectTop, rectBottom, color);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@@ -229,6 +238,8 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args) {
|
||||
mp_float_t min = mp_obj_get_float(xItems[0]);
|
||||
mp_float_t max = mp_obj_get_float(xItems[xLength - 1]);
|
||||
|
||||
// TODO: memory optimization
|
||||
// Don't create a list of edges, compute the edge on the go if not present?
|
||||
mp_obj_t * edgeItems;
|
||||
size_t nBins;
|
||||
// bin arg
|
||||
@@ -252,7 +263,7 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
// Fill the bin edges list
|
||||
for (int i = 0; i < nBins+1; i++) {
|
||||
for (size_t i = 0; i < nBins+1; i++) {
|
||||
edgeItems[i] = mp_obj_new_float(min+i*binWidth);
|
||||
}
|
||||
}
|
||||
@@ -323,7 +334,7 @@ mp_obj_t modpyplot_plot(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
// Create the default xItems: [0, 1, 2,...]
|
||||
xItems = m_new(mp_obj_t, length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
xItems[i] = mp_obj_new_float((float)i);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -62,7 +62,7 @@ T PlotStore::ListIterator<T>::operator*() {
|
||||
};
|
||||
|
||||
void checkFloatType(mp_obj_t * elements, size_t nbOfElements) {
|
||||
for (int i = 0; i < nbOfElements; i++) {
|
||||
for (size_t i = 0; i < nbOfElements; i++) {
|
||||
// TODO: we don't take advantage of the fact that we extracted the value at the sametime... Maybe change the way things are done, build the c objects in addItem instead of allocating them on the python heap? Or use float array in python?
|
||||
mp_float_t value;
|
||||
if (!mp_obj_get_float_maybe(elements[i], &value)) {
|
||||
|
||||
Reference in New Issue
Block a user