Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / include / R_ext / Itermacros.h @ 2486

History | View | Annotate | Download (4.8 kB)

1 2486 sjacqu01
/*
2 2486 sjacqu01
 *  R : A Computer Language for Statistical Data Analysis
3 2486 sjacqu01
 *  Copyright (C) 2001-12  The R Core Team.
4 2486 sjacqu01
 *
5 2486 sjacqu01
 *  This program is free software; you can redistribute it and/or modify
6 2486 sjacqu01
 *  it under the terms of the GNU Lesser General Public License as published by
7 2486 sjacqu01
 *  the Free Software Foundation; either version 2.1 of the License, or
8 2486 sjacqu01
 *  (at your option) any later version.
9 2486 sjacqu01
 *
10 2486 sjacqu01
 *  This program is distributed in the hope that it will be useful,
11 2486 sjacqu01
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 2486 sjacqu01
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 2486 sjacqu01
 *  GNU Lesser General Public License for more details.
14 2486 sjacqu01
 *
15 2486 sjacqu01
 *  You should have received a copy of the GNU Lesser General Public License
16 2486 sjacqu01
 *  along with this program; if not, a copy is available at
17 2486 sjacqu01
 *  http://www.r-project.org/Licenses/
18 2486 sjacqu01
 */
19 2486 sjacqu01
20 2486 sjacqu01
/*
21 2486 sjacqu01
  Macros to help defining vectorized functions with proper recycling
22 2486 sjacqu01
  and periodic interrupt checks.
23 2486 sjacqu01
 */
24 2486 sjacqu01
25 2486 sjacqu01
#ifndef  R_EXT_ITERMACROS_H_
26 2486 sjacqu01
#define  R_EXT_ITERMACROS_H_
27 2486 sjacqu01
28 2486 sjacqu01
#define LOOP_WITH_INTERRUPT_CHECK(LOOP, ncheck, n, ...) do {                \
29 2486 sjacqu01
        for (size_t __intr_threshold__ = ncheck;                        \
30 2486 sjacqu01
             TRUE;                                                        \
31 2486 sjacqu01
             __intr_threshold__ += ncheck) {                                \
32 2486 sjacqu01
            size_t __intr_end__ = n < __intr_threshold__ ?                \
33 2486 sjacqu01
                n : __intr_threshold__;                                        \
34 2486 sjacqu01
            LOOP(__intr_end__, __VA_ARGS__);                                \
35 2486 sjacqu01
            if (__intr_end__ == n) break;                                \
36 2486 sjacqu01
            else R_CheckUserInterrupt();                                \
37 2486 sjacqu01
        }                                                                \
38 2486 sjacqu01
    } while (0)
39 2486 sjacqu01
40 2486 sjacqu01
#define R_ITERATE_CORE(n, i, loop_body) do {        \
41 2486 sjacqu01
        for (; i < n; ++i) { loop_body }        \
42 2486 sjacqu01
    } while (0)
43 2486 sjacqu01
44 2486 sjacqu01
#define R_ITERATE(n, i, loop_body) do {                \
45 2486 sjacqu01
        i = 0;                                        \
46 2486 sjacqu01
        R_ITERATE_CORE(n, i, loop_body);                \
47 2486 sjacqu01
    } while (0)
48 2486 sjacqu01
49 2486 sjacqu01
#define R_ITERATE_CHECK(ncheck, n, i, loop_body) do {                        \
50 2486 sjacqu01
        i = 0;                                                                \
51 2486 sjacqu01
        LOOP_WITH_INTERRUPT_CHECK(R_ITERATE_CORE, ncheck, n, i, loop_body); \
52 2486 sjacqu01
    } while (0)
53 2486 sjacqu01
54 2486 sjacqu01
#define MOD_ITERATE_CORE(n, n1, n2, i, i1, i2, loop_body) do {        \
55 2486 sjacqu01
        for (; i < n;                                                        \
56 2486 sjacqu01
             i1 = (++i1 == n1) ? 0 : i1,                                \
57 2486 sjacqu01
                 i2 = (++i2 == n2) ? 0 : i2,                                \
58 2486 sjacqu01
                 ++i) {                                                        \
59 2486 sjacqu01
            loop_body                                                        \
60 2486 sjacqu01
                }                                                        \
61 2486 sjacqu01
    } while (0)
62 2486 sjacqu01
63 2486 sjacqu01
#define MOD_ITERATE(n, n1, n2, i, i1, i2, loop_body) do {        \
64 2486 sjacqu01
        i = i1 = i2 = 0;                                        \
65 2486 sjacqu01
        MOD_ITERATE_CORE(n, n1, n2, i, i1, i2, loop_body);        \
66 2486 sjacqu01
    } while (0)
67 2486 sjacqu01
68 2486 sjacqu01
#define MOD_ITERATE_CHECK(ncheck, n, n1, n2, i, i1, i2, loop_body) do {        \
69 2486 sjacqu01
        i = i1 = i2 = 0;                                                \
70 2486 sjacqu01
        LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE_CORE, ncheck, n,                \
71 2486 sjacqu01
                                  n1, n2, i, i1, i2, loop_body);        \
72 2486 sjacqu01
    } while (0)
73 2486 sjacqu01
74 2486 sjacqu01
#define MOD_ITERATE3_CORE(n, n1, n2, n3, i, i1, i2, i3, loop_body) do {        \
75 2486 sjacqu01
        for (; i < n;                                                        \
76 2486 sjacqu01
             i1 = (++i1 == n1) ? 0 : i1,                                \
77 2486 sjacqu01
                 i2 = (++i2 == n2) ? 0 : i2,                                \
78 2486 sjacqu01
                 i3 = (++i3 == n3) ? 0 : i3,                                \
79 2486 sjacqu01
                 ++i) {                                                        \
80 2486 sjacqu01
            loop_body                                                        \
81 2486 sjacqu01
                }                                                        \
82 2486 sjacqu01
    } while (0)
83 2486 sjacqu01
84 2486 sjacqu01
#define MOD_ITERATE3(n, n1, n2, n3, i, i1, i2, i3, loop_body) do {        \
85 2486 sjacqu01
        i = i1 = i2 = i3 = 0;                                                \
86 2486 sjacqu01
        MOD_ITERATE3_CORE(n, n1, n2, n3, i, i1, i2, i3, loop_body);        \
87 2486 sjacqu01
    } while (0)
88 2486 sjacqu01
89 2486 sjacqu01
#define MOD_ITERATE3_CHECK(ncheck, n, n1, n2, n3, i, i1, i2, i3, loop_body) \
90 2486 sjacqu01
    do {                                                                \
91 2486 sjacqu01
        i = i1 = i2 = i3 = 0;                                                \
92 2486 sjacqu01
        LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE3_CORE, ncheck, n,                \
93 2486 sjacqu01
                                  n1, n2, n3, i, i1, i2, i3, loop_body); \
94 2486 sjacqu01
    } while (0)
95 2486 sjacqu01
96 2486 sjacqu01
#define MOD_ITERATE4_CORE(n, n1, n2, n3, n4, i, i1, i2, i3, i4, loop_body) \
97 2486 sjacqu01
    do {                                                                \
98 2486 sjacqu01
        for (; i < n;                                                        \
99 2486 sjacqu01
             i1 = (++i1 == n1) ? 0 : i1,                                \
100 2486 sjacqu01
                 i2 = (++i2 == n2) ? 0 : i2,                                \
101 2486 sjacqu01
                 i3 = (++i3 == n3) ? 0 : i3,                                \
102 2486 sjacqu01
                 i4 = (++i4 == n4) ? 0 : i4,                                \
103 2486 sjacqu01
                 ++i) {                                                        \
104 2486 sjacqu01
            loop_body                                                        \
105 2486 sjacqu01
                }                                                        \
106 2486 sjacqu01
    } while (0)
107 2486 sjacqu01
108 2486 sjacqu01
#define MOD_ITERATE4(n, n1, n2, n3, n4, i, i1, i2, i3, i4, loop_body) do { \
109 2486 sjacqu01
        i = i1 = i2 = i3 = i4 = 0;                                        \
110 2486 sjacqu01
        MOD_ITERATE4_CORE(n, n1, n2, n3, n4, i, i1, i2, i3, i4, loop_body); \
111 2486 sjacqu01
    } while (0)
112 2486 sjacqu01
113 2486 sjacqu01
#define MOD_ITERATE4_CHECK(ncheck, n, n1, n2, n3, n4, i, i1, i2, i3, i4, \
114 2486 sjacqu01
                           loop_body)                                        \
115 2486 sjacqu01
    do {                                                                \
116 2486 sjacqu01
        i = i1 = i2 = i3 = i4 = 0;                                        \
117 2486 sjacqu01
        LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE4_CORE, ncheck, n,        \
118 2486 sjacqu01
                                  n1, n2, n3, n4,                        \
119 2486 sjacqu01
                                  i, i1, i2, i3, i4, loop_body);        \
120 2486 sjacqu01
    } while (0)
121 2486 sjacqu01
122 2486 sjacqu01
#define MOD_ITERATE5_CORE(n, n1, n2, n3, n4, n5, i, i1, i2, i3, i4, i5, \
123 2486 sjacqu01
                          loop_body)                                        \
124 2486 sjacqu01
    do {                                                                \
125 2486 sjacqu01
        for (; i < n;                                                        \
126 2486 sjacqu01
             i1 = (++i1 == n1) ? 0 : i1,                                \
127 2486 sjacqu01
                 i2 = (++i2 == n2) ? 0 : i2,                                \
128 2486 sjacqu01
                 i3 = (++i3 == n3) ? 0 : i3,                                \
129 2486 sjacqu01
                 i4 = (++i4 == n4) ? 0 : i4,                                \
130 2486 sjacqu01
                 i5 = (++i5 == n5) ? 0 : i5,                                \
131 2486 sjacqu01
                 ++i) {                                                        \
132 2486 sjacqu01
            loop_body                                                        \
133 2486 sjacqu01
                }                                                        \
134 2486 sjacqu01
    } while (0)
135 2486 sjacqu01
136 2486 sjacqu01
#define MOD_ITERATE5(n, n1, n2, n3, n4, n5, i, i1, i2, i3, i4, i5, loop_body) \
137 2486 sjacqu01
    do {                                                                \
138 2486 sjacqu01
        i = i1 = i2 = i3 = i4 = i5 = 0;                                        \
139 2486 sjacqu01
        MOD_ITERATE5_CORE(n, n1, n2, n3, n4, n5, i, i1, i2, i3, i4, i5, \
140 2486 sjacqu01
                          loop_body);                                        \
141 2486 sjacqu01
    } while (0)
142 2486 sjacqu01
143 2486 sjacqu01
#define MOD_ITERATE5_CHECK(ncheck, n, n1, n2, n3, n4, n5, \
144 2486 sjacqu01
                           i, i1, i2, i3, i4, i5,                        \
145 2486 sjacqu01
                           loop_body)                                        \
146 2486 sjacqu01
    do {                                                                \
147 2486 sjacqu01
        i = i1 = i2 = i3 = i4 = i5 = 0;                                        \
148 2486 sjacqu01
        LOOP_WITH_INTERRUPT_CHECK(MOD_ITERATE5_CORE, ncheck, n,        \
149 2486 sjacqu01
                                  n1, n2, n3, n4, n5,                        \
150 2486 sjacqu01
                                  i, i1, i2, i3, i4, i5, loop_body);        \
151 2486 sjacqu01
    } while (0)
152 2486 sjacqu01
153 2486 sjacqu01
#endif /* R_EXT_ITERMACROS_H_ */