Skip to content

Commit

Permalink
Fix boolean slice assignments in c runtime. Fix #3188
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24930 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Mar 5, 2015
1 parent 936719c commit c2593a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 42 deletions.
30 changes: 12 additions & 18 deletions SimulationRuntime/c/util/boolean_array.c
Expand Up @@ -303,16 +303,14 @@ void simple_indexed_assign_boolean_array2(const boolean_array_t* source,
boolean_set(dest, index, boolean_get(*source, index));
}

void indexed_assign_boolean_array(const boolean_array_t* source,
boolean_array_t* dest,
void indexed_assign_boolean_array(const boolean_array_t source, boolean_array_t* dest,
const index_spec_t* dest_spec)
{
_index_t* idx_vec1;
_index_t* idx_vec2;
_index_t* idx_size;
int i,j;

assert(base_array_ok(source));
assert(base_array_ok(&source));
assert(base_array_ok(dest));
assert(index_spec_ok(dest_spec));
assert(index_spec_fit_base_array(dest_spec, dest));
Expand All @@ -321,35 +319,31 @@ void indexed_assign_boolean_array(const boolean_array_t* source,
++j;
}
}
assert(j == source->ndims);
assert(j == source.ndims);

idx_vec1 = size_alloc(dest->ndims);
idx_vec2 = size_alloc(source->ndims);
idx_size = size_alloc(dest_spec->ndims);

for(i = 0; i < dest_spec->ndims; ++i) {
idx_vec1[i] = 0;

if(dest_spec->index[i] != NULL) {
if(dest_spec->index[i] != NULL) { /* is 'S' or 'A' */
idx_size[i] = imax(dest_spec->dim_size[i],1);
} else {
} else { /* is 'W' */
idx_size[i] = dest->dim_size[i];
}
}

j = 0;
do {
for(i = 0, j = 0; i < dest_spec->ndims; ++i) {
if(dest_spec->dim_size[i] != 0) {
idx_vec2[j] = idx_vec1[i];
++j;
}
}
boolean_set(dest, calc_base_index_spec(dest->ndims, idx_vec1,
dest, dest_spec),
boolean_get(*source, calc_base_index(source->ndims,
idx_vec2, source)));
boolean_set(dest,
calc_base_index_spec(dest->ndims, idx_vec1, dest, dest_spec),
boolean_get(source, j));
j++;

} while(0 == next_index(dest_spec->ndims, idx_vec1, idx_size));

assert(j == base_array_nr_of_elements(source));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/util/boolean_array.h
Expand Up @@ -111,7 +111,7 @@ extern char print_boolean(m_boolean value);
a[1:3] := b;
*/
extern void indexed_assign_boolean_array(const boolean_array_t* source,
extern void indexed_assign_boolean_array(const boolean_array_t source,
boolean_array_t* dest,
const index_spec_t* dest_spec);
extern void simple_indexed_assign_boolean_array1(const boolean_array_t* source,
Expand Down
8 changes: 3 additions & 5 deletions SimulationRuntime/c/util/integer_array.c
Expand Up @@ -297,8 +297,7 @@ void simple_indexed_assign_integer_array2(const integer_array_t * source,
integer_set(dest, index, integer_get(*source, index));
}

void indexed_assign_integer_array(const integer_array_t source,
integer_array_t* dest,
void indexed_assign_integer_array(const integer_array_t source, integer_array_t* dest,
const index_spec_t* dest_spec)
{
_index_t* idx_vec1;
Expand All @@ -317,15 +316,14 @@ void indexed_assign_integer_array(const integer_array_t source,
assert(j == source.ndims);

idx_vec1 = size_alloc(dest->ndims);
// idx_vec2 = size_alloc(source->ndims);
idx_size = size_alloc(dest_spec->ndims);

for(i = 0; i < dest_spec->ndims; ++i) {
idx_vec1[i] = 0;

if(dest_spec->index[i] != NULL) {
if(dest_spec->index[i] != NULL) { /* is 'S' or 'A' */
idx_size[i] = imax(dest_spec->dim_size[i],1);
} else {
} else { /* is 'W' */
idx_size[i] = dest->dim_size[i];
}
}
Expand Down
20 changes: 2 additions & 18 deletions SimulationRuntime/c/util/real_array.c
Expand Up @@ -276,7 +276,8 @@ void simple_indexed_assign_real_array2(const real_array_t * source,
real_set(dest, index, real_get(*source, index));
}

void indexed_assign_real_array(const real_array_t source, real_array_t* dest, const index_spec_t* dest_spec)
void indexed_assign_real_array(const real_array_t source, real_array_t* dest,
const index_spec_t* dest_spec)
{
_index_t* idx_vec1;
_index_t* idx_size;
Expand All @@ -294,7 +295,6 @@ void indexed_assign_real_array(const real_array_t source, real_array_t* dest, co
assert(j == source.ndims);

idx_vec1 = size_alloc(dest->ndims);
/* idx_vec2 = size_alloc(source.ndims); */
idx_size = size_alloc(dest_spec->ndims);

for(i = 0; i < dest_spec->ndims; ++i) {
Expand All @@ -309,26 +309,10 @@ void indexed_assign_real_array(const real_array_t source, real_array_t* dest, co

j = 0;
do {
/*for(i = 0, j = 0; i < dest_spec->ndims; ++i) {
if(dest_spec->dim_size[i] != 0) {
idx_vec2[j] = idx_vec1[i];
++j;
}
}*/
/*for(i = 0, j = 0; i < dest_spec->ndims; ++i) {
if((dest_spec->index_type[i] == 'W')
||
(dest_spec->index_type[i] == 'A')) {
idx_vec2[j] = idx_vec1[i];
++j;
}
}*/
real_set(dest,
calc_base_index_spec(dest->ndims, idx_vec1, dest, dest_spec),
real_get(source, j));
j++;
/* calc_base_index(source.ndims, idx_vec1, source)));*/
/* calc_base_index(source.ndims, idx_vec2, source)));*/

} while(0 == next_index(dest_spec->ndims, idx_vec1, idx_size));

Expand Down

0 comments on commit c2593a1

Please sign in to comment.