CFI_type_float, 0, 1, NULL);
if (ind) return -1.0;
ind = CFI_section((CFI_cdesc_t *)§ion, source, lower, NULL, strides);
- assert (section.dim[0].lower_bound == lower[0]);
if (ind) return -2.0;
/* Sum over the section */
- for (idx[0] = lower[0]; idx[0] < section.dim[0].extent + lower[0]; idx[0]++)
+ for (idx[0] = section.dim[0].lower_bound;
+ idx[0] < section.dim[0].extent + section.dim[0].lower_bound;
+ idx[0]++)
ans += *(float*)CFI_address ((CFI_cdesc_t*)§ion, idx);
return ans;
}
ind = CFI_section((CFI_cdesc_t *)§ion, source,
lower, upper, strides);
assert (section.rank == 1);
- assert (section.dim[0].lower_bound == lower[0]);
if (ind) return -2.0;
/* Sum over the section */
- for (idx[0] = lower[0]; idx[0] < section.dim[0].extent + lower[0]; idx[0]++)
+ for (idx[0] = section.dim[0].lower_bound;
+ idx[0] < section.dim[0].extent + section.dim[0].lower_bound;
+ idx[0]++)
ans += *(float*)CFI_address ((CFI_cdesc_t*)§ion, idx);
return ans;
}
}
}
+ /* Set the base address. We have to compute this first in the case
+ where source == result, before we overwrite the dimension data. */
+ result->base_addr = CFI_address (source, lower);
+
/* Set the appropriate dimension information that gives us access to the
* data. */
- int aux = 0;
- for (int i = 0; i < source->rank; i++)
+ for (int i = 0, o = 0; i < source->rank; i++)
{
if (stride[i] == 0)
- {
- aux++;
- /* Adjust 'lower' for the base address offset. */
- lower[i] = lower[i] - source->dim[i].lower_bound;
- continue;
- }
- int idx = i - aux;
- result->dim[idx].lower_bound = lower[i];
- result->dim[idx].extent = 1 + (upper[i] - lower[i])/stride[i];
- result->dim[idx].sm = stride[i] * source->dim[i].sm;
- /* Adjust 'lower' for the base address offset. */
- lower[idx] = lower[idx] - source->dim[i].lower_bound;
+ continue;
+ result->dim[o].lower_bound = 0;
+ result->dim[o].extent = 1 + (upper[i] - lower[i])/stride[i];
+ result->dim[o].sm = stride[i] * source->dim[i].sm;
+ o++;
}
- /* Set the base address. */
- result->base_addr = CFI_address (source, lower);
-
return CFI_SUCCESS;
}