Skip to content

Commit

Permalink
Fixed bug where instance-reduce expressions on non-instanced maps did…
Browse files Browse the repository at this point in the history
… not result in updating all active instances of the destination signal.
  • Loading branch information
malloch committed May 24, 2024
1 parent 3804518 commit bbfd2c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,17 +807,26 @@ void mpr_map_receive(mpr_local_map m, mpr_time time)
}
types = alloca(mpr_sig_get_len((mpr_sig)dst_sig) * sizeof(char));
for (i = 0; i < m->num_inst; i++) {
void *value;
if (!mpr_bitflags_get(m->updated_inst, i))
continue;
status = mpr_expr_eval(mpr_graph_get_expr_stack(m->obj.graph), m->expr, src_vals,
&m->vars, dst_val, &time, types, i);
if (!status)
continue;

mpr_local_sig_set_inst_value(dst_sig, dst_val, i, id_map, status, map_manages_inst, time);
value = mpr_value_get_samp(dst_val, i);
mpr_local_sig_set_inst_value(dst_sig, value, i, id_map, status, map_manages_inst, time);

if ((status & EXPR_EVAL_DONE) && !m->use_inst)
if ((status & EXPR_EVAL_DONE) && !m->use_inst) {
/* Don't need to re-evaluate, but need to apply update to remaining active instances */
for (++i; i < m->num_inst; i++) {
if (!mpr_bitflags_get(m->updated_inst, i))
continue;
mpr_local_sig_set_inst_value(dst_sig, value, i, id_map, status, map_manages_inst, time);
}
break;
}
}
mpr_bitflags_clear(m->updated_inst, m->num_inst);
m->updated = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mpr_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int mpr_sig_get_num_inst_internal(mpr_sig sig);

int mpr_sig_get_use_inst(mpr_sig sig);

void mpr_local_sig_set_inst_value(mpr_local_sig sig, mpr_value val, int inst_idx, mpr_id_map id_map,
void mpr_local_sig_set_inst_value(mpr_local_sig sig, void *value, int inst_idx, mpr_id_map id_map,
int status, int map_manages_inst, mpr_time time);

/* Functions below are only used by testinstance.c for printing instance indices */
Expand Down
3 changes: 1 addition & 2 deletions src/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ void mpr_sig_copy_props(mpr_sig to, mpr_sig from)
mpr_obj_set_id((mpr_obj)dev, mpr_obj_get_id((mpr_obj)from->dev));
}

void mpr_local_sig_set_inst_value(mpr_local_sig sig, mpr_value val, int inst_idx, mpr_id_map id_map,
void mpr_local_sig_set_inst_value(mpr_local_sig sig, void *value, int inst_idx, mpr_id_map id_map,
int status, int map_manages_inst, mpr_time time)
{
mpr_sig_inst si;
Expand All @@ -1769,7 +1769,6 @@ void mpr_local_sig_set_inst_value(mpr_local_sig sig, mpr_value val, int inst_idx
}

if (status & EXPR_UPDATE) {
void *value = mpr_value_get_samp(val, inst_idx);
/* TODO: create new map->id_map */
/*
if (map_manages_inst) {
Expand Down
10 changes: 10 additions & 0 deletions test/testinstance.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct _test_config {
} test_config;

#define EXPR1 "alive=n>=5;y=x;n=(n+1)%10;"
#define EXPR2 "y=x.instance.mean()"

/* TODO: test received values */
/* TODO: these should work with count_epsilon=0.0 */
Expand Down Expand Up @@ -161,6 +162,15 @@ test_config test_configs[] = {
{ 33, SINGLETON, INSTANCED, INSTANCED, MPR_LOC_SRC, NONE, EXPR1, 0.5, 0.5, 0.0, 0 },
{ 34, SINGLETON, INSTANCED, INSTANCED, MPR_LOC_DST, NONE, EXPR1, 0.5, 0.5, 0.0, 0 },

/* instanced ––> instanced; instance reduce expression */
/* result of expression should update all active destination instances */
{ 35, INSTANCED, INSTANCED, SINGLETON, MPR_LOC_SRC, NONE, EXPR2, 3.0, 3.0, 0.0, 1 },
{ 36, INSTANCED, INSTANCED, SINGLETON, MPR_LOC_DST, NONE, EXPR2, 3.0, 3.0, 0.0, 1 },

/* instanced ==> instanced; instance reduce expression */
{ 37, INSTANCED, INSTANCED, INSTANCED, MPR_LOC_SRC, NONE, EXPR2, 1.0, 1.0, 0.0, 1 },
{ 38, INSTANCED, INSTANCED, INSTANCED, MPR_LOC_DST, NONE, EXPR2, 4.0, 1.0, 0.0, 1 },

/* work in progress:
* instanced ––> instanced; in-map instance management (late start, early release, ad hoc)
* instanced ==> instanced; in-map instance management (late start, early release, ad hoc)
Expand Down

0 comments on commit bbfd2c1

Please sign in to comment.