- Scriptcontext debugged to be working
- Added a drivable adapter to scriptcontext nodes - Added subsampling to simulated histograms (and as a general option) in order to support Gumtree testing.
This commit is contained in:
135
nxdataset.c
135
nxdataset.c
@ -7,6 +7,7 @@
|
||||
Mark Koennecke, October 2002
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nxdataset.h"
|
||||
|
||||
@ -306,6 +307,140 @@ int putNXDatasetValueAt(pNXDS dataset, int address, double value){
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------
|
||||
This is working recursively through the dimensions. When at the last:
|
||||
actual copying takes place.
|
||||
-----------------------------------------------------------------------*/
|
||||
static void copyCutData(pNXDS source, pNXDS target, int sourceDim[],
|
||||
int targetDim[], int start[], int end[],
|
||||
int dim){
|
||||
int i, length;
|
||||
double val;
|
||||
|
||||
targetDim[dim] = 0;
|
||||
length = end[dim] - start[dim];
|
||||
if(dim == source->rank -1){
|
||||
for(i = 0; i < length; i++){
|
||||
sourceDim[dim] = start[dim] + i;
|
||||
val = getNXDatasetValue(source,sourceDim);
|
||||
targetDim[dim] = i;
|
||||
putNXDatasetValue(target, targetDim, val);
|
||||
}
|
||||
} else {
|
||||
for(i = 0; i < length; i++){
|
||||
sourceDim[dim] = start[dim] + i;
|
||||
targetDim[dim] = i;
|
||||
copyCutData(source,target, sourceDim, targetDim, start, end, dim+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
pNXDS cutNXDataset(pNXDS source, int start[], int end[]){
|
||||
pNXDS result = NULL;
|
||||
int newDim[NX_MAXRANK], i;
|
||||
int sourceDim[NX_MAXRANK], targetDim[NX_MAXRANK];
|
||||
|
||||
for(i = 0; i < source->rank; i++){
|
||||
if(start[i] < 0 || end[i] > source->dim[i]){
|
||||
fprintf(stderr,"ERROR: invalid boundaries specified for cutting");
|
||||
return NULL;
|
||||
}
|
||||
newDim[i] = end[i] - start[i];
|
||||
if(newDim[i] <= 0){
|
||||
fprintf(stderr,"ERROR: invalid cut limits specified for cutting dataset");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
result = createNXDataset(source->rank, source->type, newDim);
|
||||
if(result == NULL){
|
||||
fprintf(stderr,"ERROR: out of memory creating result dataset");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
copyCutData(source, result, sourceDim, targetDim, start, end, 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*----------------------------------------------------------------------
|
||||
This recurses through all dimesnions, thereby skipping the summed one.
|
||||
At the end of the rescusion the actual summing is performed.
|
||||
----------------------------------------------------------------------*/
|
||||
static void sumData(pNXDS source, pNXDS target, int sourceDim[],
|
||||
int targetDim[], int targetDimCount, int dimNo,
|
||||
int start, int end, int currentDim){
|
||||
int i, length;
|
||||
double val, sumVal;
|
||||
|
||||
/*
|
||||
when we have recursed through all dimensions
|
||||
we actually do the sums...
|
||||
*/
|
||||
if(currentDim == source->rank){
|
||||
length = end - start;
|
||||
sumVal = getNXDatasetValue(target, targetDim);
|
||||
for(i = 0; i < length; i++){
|
||||
sourceDim[dimNo] = start + i;
|
||||
val = getNXDatasetValue(source,sourceDim);
|
||||
sumVal += val;
|
||||
}
|
||||
putNXDatasetValue(target, targetDim, sumVal);
|
||||
} else {
|
||||
/*
|
||||
jump over the summed dimension while recursing
|
||||
through the dimensions
|
||||
*/
|
||||
if(currentDim == dimNo){
|
||||
sumData(source,target,sourceDim,
|
||||
targetDim,targetDimCount,
|
||||
dimNo,start,end,currentDim+1);
|
||||
} else {
|
||||
/*
|
||||
loop over all values of the non summed dimension
|
||||
*/
|
||||
for(i = 0; i < source->dim[currentDim]; i++){
|
||||
/*
|
||||
the problem here is that we have to jump over the summed
|
||||
dimension here. This why we have to maintain a separate
|
||||
dimension count for the target array. Jumping is done
|
||||
above.
|
||||
*/
|
||||
targetDim[targetDimCount] = i;
|
||||
targetDimCount++;
|
||||
|
||||
sourceDim[currentDim] = i;
|
||||
sumData(source,target,sourceDim,targetDim,targetDimCount,
|
||||
dimNo,start,end,currentDim+1);
|
||||
targetDimCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
pNXDS sumNXDataset(pNXDS source, int dimNo, int start, int end){
|
||||
int newDim[NX_MAXRANK], targetDim[NX_MAXRANK], sourceDim[NX_MAXRANK];
|
||||
pNXDS result = NULL;
|
||||
int i, count;
|
||||
|
||||
if(dimNo < 0 || dimNo > source->rank-1) {
|
||||
fprintf(stderr,"ERROR: invalid dimension for summing requested");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
make result dataset with missing summed dimension
|
||||
*/
|
||||
for(i = 0, count = 0; i < source->rank; i++){
|
||||
if(i != dimNo){
|
||||
newDim[count] = source->dim[i];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
result = createNXDataset(source->rank-1, source->type, newDim);
|
||||
if(result == NULL){
|
||||
fprintf(stderr,"ERROR: out of memory creating result dataset");
|
||||
return NULL;
|
||||
}
|
||||
sumData(source,result,sourceDim,targetDim,0,
|
||||
dimNo, start, end, 0);
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user