Skip to content

Commit

Permalink
Simplify reductions
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Dec 18, 2024
1 parent 58ac472 commit 833b7ea
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions src/xstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,7 @@ static int xUnwrapField(XField *f) {
* @return X_SUCCESS (0) if successful, or else an xchange.h error code <0.
*/
int xReduceField(XField *f) {
static const char *fn = "xReduceField";

int status = X_SUCCESS;

if(!f) return x_error(X_NULL, EINVAL, fn, "input field is NULL");
if(!f) return x_error(X_NULL, EINVAL, "xReduceField", "input field is NULL");

xReduceDims(&f->ndim, f->sizes);

Expand All @@ -1002,16 +998,10 @@ int xReduceField(XField *f) {
XStructure *sub = (XStructure *) f->value;
int i = xGetFieldCount(f);

while(--i >= 0) {
int stat = xReduceStruct(&sub[i]);
if(stat < 0) {
x_trace(fn, f->name, status);
if(!status) status = stat;
}
}
while(--i >= 0) xReduceStruct(&sub[i]);
}

return status;
return X_SUCCESS;
}

/**
Expand All @@ -1026,12 +1016,9 @@ int xReduceField(XField *f) {
* @see xReduceDims()
*/
int xReduceStruct(XStructure *s) {
static const char *fn = "xReduceStruct";

XField *f;
int status = X_SUCCESS;

if(!s) return x_error(X_STRUCT_INVALID, EINVAL, fn, "input structure is NULL");
if(!s) return x_error(X_STRUCT_INVALID, EINVAL, "xReduceStruct", "input structure is NULL");

f = s->firstField;
if(!f) return X_SUCCESS;
Expand All @@ -1042,7 +1029,6 @@ int xReduceStruct(XStructure *s) {

XStructure *sub = (XStructure *) f->value;
XField *sf;
int stat;

s->firstField = sub->firstField;

Expand All @@ -1052,22 +1038,15 @@ int xReduceStruct(XStructure *s) {
while(--i >= 0) ss[i].parent = s;
}

stat = xReduceStruct(s);
if(stat < 0) {
x_trace(fn, f->name, stat);
if(!status) status = stat;
}
xReduceStruct(s);

free(f);
return status;
return X_SUCCESS;
}

for(; f != NULL; f = f->next) {
int st = xReduceField(f);
if(!status) status = st;
}
for(; f != NULL; f = f->next) xReduceField(f);

return status;
return X_SUCCESS;
}


Expand Down

0 comments on commit 833b7ea

Please sign in to comment.