Alien-libhisto

 view release on metacpan or  search on metacpan

bundled/src/histo2d.c  view on Meta::CPAN

#include "simd.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

/* -------------------------------------------------------------------------
 * Internal Axis Validation & Setup Helpers
 * ------------------------------------------------------------------------- */

static bool validate_axis_spec(const histo2d_axis_t *axis) {
    if (!axis) return false;
    if (axis->nbins == 0 || axis->nbins > HISTO_MAX_NBINS) return false;

    if (axis->type == HISTO_BIN_UNIFORM) {
        if (!isfinite(axis->min) || !isfinite(axis->max)) return false;
        if (axis->min >= axis->max) return false;
    } else if (axis->type == HISTO_BIN_VARIABLE) {
        if (!axis->edges) return false;
        for (uint32_t i = 0; i <= axis->nbins; ++i) {
            if (!isfinite(axis->edges[i])) return false;

bundled/src/histo2d.c  view on Meta::CPAN

}

/* -------------------------------------------------------------------------
 * Lifecycle & Memory Management
 * ------------------------------------------------------------------------- */

histo2d_t* histo2d_create(const histo2d_axis_t *x_axis,
                          const histo2d_axis_t *y_axis,
                          uint32_t flags)
{
    if (!validate_axis_spec(x_axis) || !validate_axis_spec(y_axis)) {
        return NULL;
    }

    uint64_t total_cells = (uint64_t)x_axis->nbins * (uint64_t)y_axis->nbins;
    if (total_cells > HISTO_MAX_NBINS) {
        return NULL;
    }

    histo2d_t *h = (histo2d_t*)calloc(1, sizeof(histo2d_t));
    if (!h) return NULL;



( run in 1.292 second using v1.01-cache-2.11-cpan-d01c6094234 )