Skip to content

Commit

Permalink
add offset for multi hist
Browse files Browse the repository at this point in the history
  • Loading branch information
diemoschwarz committed Jul 18, 2024
1 parent a22cb32 commit dbd4312
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
58 changes: 37 additions & 21 deletions src/statistics/rta_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void rta_histogram_init (rta_histogram_params_t *params)

/* Calculate histogram */
void rta_histogram_stride (rta_histogram_params_t *params,
rta_real_t *input, const unsigned int i_stride, const unsigned int i_size,
rta_real_t *output, const unsigned int out_stride,
rta_real_t *bpfout, const unsigned int bpf_stride)
rta_real_t *input, const int i_stride, const unsigned int i_size,
rta_real_t *output, const int out_stride,
rta_real_t *bpfout, const int bpf_stride)
{
rta_real_t one = 1;

Expand All @@ -67,9 +67,9 @@ void rta_histogram_stride (rta_histogram_params_t *params,
}

void rta_histogram_stride_multi (rta_histogram_params_t *params, int num_input,
rta_real_t *input[], const unsigned int i_stride, const unsigned int i_size[],
rta_real_t *output, const unsigned int out_stride,
rta_real_t *bpfout, const unsigned int bpf_stride)
rta_real_t *input[], const int i_offset, const int i_stride, const unsigned int i_size[],
rta_real_t *output, const int out_stride,
rta_real_t *bpfout, const int bpf_stride)
{
rta_real_t one = 1;
rta_real_t *ones[num_input]; // array of pointers to weights data
Expand All @@ -78,31 +78,31 @@ void rta_histogram_stride_multi (rta_histogram_params_t *params, int num_input,
ones[i] = &one; // make then all point to 1, zero stride assures we stay there

rta_histogram_weighted_stride_multi(params, num_input,
input, i_stride, i_size,
input, i_offset, i_stride, i_size,
ones, 0, // unweighted: all weights == 1
output, out_stride,
bpfout, bpf_stride);
}

/* Calculate weighted histogram */
void rta_histogram_weighted_stride (rta_histogram_params_t *params,
rta_real_t *input, const unsigned int i_stride, const unsigned int i_size,
rta_real_t *weights, const unsigned int w_stride,
rta_real_t *output, const unsigned int out_stride,
rta_real_t *bpfout, const unsigned int bpf_stride)
rta_real_t *input, const int i_stride, const unsigned int i_size,
rta_real_t *weights, const int w_stride,
rta_real_t *output, const int out_stride,
rta_real_t *bpfout, const int bpf_stride)
{
rta_histogram_weighted_stride_multi(params, 1,
&input, i_stride, &i_size,
&input, 0, i_stride, &i_size,
&weights, w_stride, // unweighted: all weights == 1
output, out_stride,
bpfout, bpf_stride);
}

void rta_histogram_weighted_stride_multi (rta_histogram_params_t *params, int num_input,
rta_real_t *input[], const unsigned int i_stride, const unsigned int i_size[],
rta_real_t *weights[], const unsigned int w_stride,
rta_real_t *output, const unsigned int out_stride,
rta_real_t *bpfout, const unsigned int bpf_stride)
rta_real_t *input[], const int i_offset, const int i_stride, const unsigned int i_size[],
rta_real_t *weights[], const int w_stride,
rta_real_t *output, const int out_stride,
rta_real_t *bpfout, const int bpf_stride)
{
rta_real_t *ptr;
int i, j, k;
Expand Down Expand Up @@ -131,14 +131,18 @@ void rta_histogram_weighted_stride_multi (rta_histogram_params_t *params, int nu
params->hi = -FLT_MAX; /* upper histogram limit */

for (k = 0; k < num_input; k++)
for (i = 0; i < i_size[k] * i_stride; i += i_stride)
{
const int n = i_size[k] * i_stride + i_offset;

for (i = i_offset; i < n; i += i_stride)
{
float x = input[k][i];
if (x < params->lo)
params->lo = x;
if (x > params->hi)
params->hi = x;
}
}
}
else
{
Expand All @@ -147,25 +151,33 @@ void rta_histogram_weighted_stride_multi (rta_histogram_params_t *params, int nu
params->lo = FLT_MAX; /* lower histogram limit */

for (k = 0; k < num_input; k++)
for (i = 0; i < i_size[k] * i_stride; i += i_stride)
{
const int n = i_size[k] * i_stride + i_offset;

for (i = i_offset; i < n; i += i_stride)
{
float x = input[k][i];
if (x < params->lo)
params->lo = x;
}
}
}

if (!params->hi_given)
{
params->hi = -FLT_MAX; /* upper histogram limit */

for (k = 0; k < num_input; k++)
for (i = 0; i < i_size[k] * i_stride; i += i_stride)
{
const int n = i_size[k] * i_stride + i_offset;

for (i = i_offset; i < n; i += i_stride)
{
float x = input[k][i];
if (x > params->hi)
params->hi = x;
}
}
}
}

Expand All @@ -184,7 +196,10 @@ void rta_histogram_weighted_stride_multi (rta_histogram_params_t *params, int nu

/* calculate histogram */
for (k = 0; k < num_input; k++)
for (i = 0, j = 0; i < i_size[k] * i_stride; i += i_stride, j += w_stride)
{
const int n = i_size[k] * i_stride + i_offset;

for (i = i_offset, j = 0; i < n; i += i_stride, j += w_stride)
{
/* find bin index */
int ind = (input[k][i] - params->lo) * xfact;
Expand All @@ -197,7 +212,8 @@ void rta_histogram_weighted_stride_multi (rta_histogram_params_t *params, int nu

output[ind * out_stride] += weights[k][j];
}

}

// normalise histogram
if (params->norm > 0)
{
Expand Down
38 changes: 20 additions & 18 deletions src/statistics/rta_histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,28 @@ void rta_histogram_init (rta_histogram_params_t *self);
* @param bin_stride stride for bin index data
*/
void rta_histogram_stride (rta_histogram_params_t *params,
rta_real_t *input, const unsigned int i_stride, const unsigned int i_size,
rta_real_t *output, const unsigned int out_stride,
rta_real_t *binout, const unsigned int bin_stride);
rta_real_t *input, const int i_stride, const unsigned int i_size,
rta_real_t *output, const int out_stride,
rta_real_t *binout, const int bin_stride);

/**
* Calculate histogram over multiple blocks of data
*
* @param params pointer to histogram parameter struct
* @param num_input number of blocks of input data
* @param input array[num_input] of pointers to input data (at least i_size * i_stride elements)
* @param input array[num_input] of pointers to blocks of input data (at least i_size[i] * i_stride elements)
* @param i_offset offset into each block of input data
* @param i_stride stride for input data
* @param i_size array[num_input] of number of elements per block of input data
* @param i_size array[num_input] of number of elements for each block of input data
* @param output pointer to output data (at least params->nhist * out_stride elements)
* @param out_stride stride for output data
* @param binout NULL or pointer to bin index output data (at least params->nhist * bpf_stride elements)
* @param bin_stride stride for bin index data
*/
void rta_histogram_stride_multi (rta_histogram_params_t *params, int num_input,
rta_real_t *input[], const unsigned int i_stride, const unsigned int i_size[],
rta_real_t *output, const unsigned int out_stride,
rta_real_t *binout, const unsigned int bin_stride);
rta_real_t *input[], const int i_offset, const int i_stride, const unsigned int i_size[],
rta_real_t *output, const int out_stride,
rta_real_t *binout, const int bin_stride);

/**
* Calculate weighted histogram
Expand All @@ -113,10 +114,10 @@ void rta_histogram_stride_multi (rta_histogram_params_t *params, int num_input,
* @param bin_stride stride for bin index data
*/
void rta_histogram_weighted_stride (rta_histogram_params_t *params,
rta_real_t *input, const unsigned int i_stride, const unsigned int i_size,
rta_real_t *weights, const unsigned int w_stride,
rta_real_t *output, const unsigned int out_stride,
rta_real_t *binout, const unsigned int bin_stride);
rta_real_t *input, const int i_stride, const unsigned int i_size,
rta_real_t *weights, const int w_stride,
rta_real_t *output, const int out_stride,
rta_real_t *binout, const int bin_stride);


/**
Expand All @@ -125,9 +126,10 @@ void rta_histogram_weighted_stride (rta_histogram_params_t *params,
*
* @param params pointer to histogram parameter struct
* @param num_input number of blocks of input data
* @param input array[num_input] of pointers to input data (at least i_size * i_stride elements)
* @param input array[num_input] of pointers to blocks of input data (at least i_size[i] * i_stride elements)
* @param i_offset offset into each block of input data
* @param i_stride stride for input data
* @param i_size array[num_input] of number of input elements
* @param i_size array[num_input] of number of input elements for each block
* @param weights array[num_input] of pointers to weights data (at least i_size * w_stride elements)
* @param w_stride stride for weights data
* @param output pointer to output data (at least params->nhist * out_stride elements)
Expand All @@ -136,10 +138,10 @@ void rta_histogram_weighted_stride (rta_histogram_params_t *params,
* @param bin_stride stride for bin index data
*/
void rta_histogram_weighted_stride_multi (rta_histogram_params_t *params, int num_input,
rta_real_t *input[], const unsigned int i_stride, const unsigned int i_size[],
rta_real_t *weights[], const unsigned int w_stride,
rta_real_t *output, const unsigned int out_stride,
rta_real_t *binout, const unsigned int bin_stride);
rta_real_t *input[], const int i_offset, const int i_stride, const unsigned int i_size[],
rta_real_t *weights[], const int w_stride,
rta_real_t *output, const int out_stride,
rta_real_t *binout, const int bin_stride);

#ifdef __cplusplus
}
Expand Down

0 comments on commit dbd4312

Please sign in to comment.