source: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c @ 821

Last change on this file since 821 was 821, checked in by meunier, 8 years ago
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File size: 3.7 KB
Line 
1/* ------------------- */
2/* --- nralloc2X.c --- */
3/* ------------------- */
4
5/*
6 * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
7 * Univ Paris Sud XI, CNRS
8 *
9*/
10
11/*
12* 2002/06/11 ajout des fonctions endline
13*/
14#include <stdio.h>
15#include <stddef.h>
16#include <stdlib.h>
17#include <malloc.h>
18#include <math.h> // fabs
19
20#include "nrc_os_config.h"
21#include "mypredef.h"
22#include "nrtype.h"
23#include "nrdef.h"
24#include "nrmacro.h"
25#include "nrkernel.h"
26
27#include "nralloc2x.h"
28
29
30/* ----------------- */
31/* --- trimatrix --- */
32/* ----------------- */
33
34
35#undef type_trimatrix
36#define type_trimatrix(t) \
37t ** short_name(t,,trimatrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t step) \
38/* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */               \
39{                                                                                               \
40    int32_t nrow = nrh - nrl + 1;                                                               \
41    int32_t ncol = nch - ncl + 1;                                                               \
42    int n = nrow * ncol + (nrow * (nrow - 1) * step) / 2;                                       \
43    /* Attention, factorisation of n IS NOT PERMITTED : (nrow - 1) step / 2 is not even!!! */   \
44    t ** m;                                                                                     \
45    /* allocate pointers to rows */                                                             \
46    m = malloc((nrow + NR_END) * sizeof(t *));                                                  \
47    if (m == NULL) {                                                                            \
48        nrerror("*** Error: allocation failure in %s\n", __func__);                             \
49    }                                                                                           \
50    m += NR_END;                                                                                \
51    m -= nrl;                                                                                   \
52    /* allocate rows and set pointers to them */                                                \
53    m[nrl] = malloc(((n + NR_END) * sizeof(t)));                                                \
54    if (m[nrl] == NULL) {                                                                       \
55        nrerror("*** Error: allocation failure in %s\n", __func__);                             \
56    }                                                                                           \
57    m[nrl] += NR_END;                                                                           \
58    m[nrl] -= ncl;                                                                              \
59    for (int32_t i = nrl + 1; i <= nrh;i++) {                                                   \
60        m[i] = m[i - 1] + ncol;                                                                 \
61        ncol += step;                                                                           \
62    }                                                                                           \
63    /* return pointer to array of pointers to rows */                                           \
64    return m;                                                                                   \
65}
66
67
68type_trimatrix(int8_t);
69type_trimatrix(uint8_t);
70type_trimatrix(int16_t);
71type_trimatrix(uint16_t);
72type_trimatrix(int32_t);
73type_trimatrix(uint32_t);
74type_trimatrix(float);
75type_trimatrix(double);
76
77// Local Variables:
78// tab-width: 4
79// c-basic-offset: 4
80// c-file-offsets:((innamespace . 0)(inline-open . 0))
81// indent-tabs-mode: nil
82// End:
83// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
84
Note: See TracBrowser for help on using the repository browser.