@@ -2053,9 +2053,190 @@ void stdlib_strided_z_as_u( uint8_t *arrays[], int64_t *shape, int64_t *strides,
2053
2053
2054
2054
* * *
2055
2055
2056
- #### TODO
2056
+ #### STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE
2057
2057
2058
- TODO: document macros
2058
+ Macro containing the preamble for a loop which updates a strided output array.
2059
+
2060
+ ```c
2061
+ STDLIB_STRIDED_NULLARY_LOOP_PREMABLE {
2062
+ // Loop body...
2063
+ }
2064
+ ```
2065
+
2066
+ The macro expects the following variables to be defined:
2067
+
2068
+ - ** arrays** : ` uint8_t** ` array whose only element is a pointer to a strided output array.
2069
+ - ** shape** : ` int64_t* ` array whose only element is the number of elements over which to iterate.
2070
+ - ** strides** : ` int64_t* ` array containing strides (in bytes) for each strided array.
2071
+
2072
+ The macro defines the following variables:
2073
+
2074
+ - ** op1** : ` uint8_t* ` pointer to the first indexed element of the output strided array.
2075
+ - ** os1** : ` int64_t ` index increment for the output strided array.
2076
+ - ** n** : ` int64_t ` number of indexed elements.
2077
+ - ** i** : ` int64_t ` loop counter.
2078
+
2079
+ ``` c
2080
+ #define STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE \
2081
+ uint8_t *op1 = arrays[ 0 ]; \
2082
+ int64_t os1 = strides[ 0 ]; \
2083
+ int64_t n = shape[ 0 ]; \
2084
+ int64_t i; \
2085
+ if ( n <= 0 ) { \
2086
+ return; \
2087
+ } \
2088
+ if ( os1 < 0 ) { \
2089
+ op1 += (1-n) * os1; \
2090
+ } \
2091
+ for ( i = 0; i < n; i++, op1 += os1 )
2092
+ ```
2093
+
2094
+ #### STDLIB_STRIDED_NULLARY_LOOP_TWO_OUT_PREAMBLE
2095
+
2096
+ Macro containing the preamble for a loop which updates two strided output arrays.
2097
+
2098
+ ```c
2099
+ STDLIB_STRIDED_NULLARY_LOOP_TWO_OUT_PREMABLE {
2100
+ // Loop body...
2101
+ }
2102
+ ```
2103
+
2104
+ The macro expects the following variables to be defined:
2105
+
2106
+ - ** arrays** : ` uint8_t** ` array whose only element is a pointer to a strided output array.
2107
+ - ** shape** : ` int64_t* ` array whose only element is the number of elements over which to iterate.
2108
+ - ** strides** : ` int64_t* ` array containing strides (in bytes) for each strided array.
2109
+
2110
+ The macro defines the following variables:
2111
+
2112
+ - ** op1** : ` uint8_t* ` pointer to the first indexed element of the first output strided array.
2113
+ - ** op2** : ` uint8_t* ` pointer to the first indexed element of the second output strided array.
2114
+ - ** os1** : ` int64_t ` index increment for the first output strided array.
2115
+ - ** os2** : ` int64_t ` index increment for the second output strided array.
2116
+ - ** n** : ` int64_t ` number of indexed elements.
2117
+ - ** i** : ` int64_t ` loop counter.
2118
+
2119
+ ``` c
2120
+ #define STDLIB_STRIDED_NULLARY_LOOP_TWO_OUT_PREAMBLE \
2121
+ uint8_t *op1 = arrays[ 0 ]; \
2122
+ uint8_t *op2 = arrays[ 1 ]; \
2123
+ int64_t os1 = strides[ 0 ]; \
2124
+ int64_t os2 = strides[ 1 ]; \
2125
+ int64_t n = shape[ 0 ]; \
2126
+ int64_t i; \
2127
+ if ( n <= 0 ) { \
2128
+ return; \
2129
+ } \
2130
+ if ( os1 < 0 ) { \
2131
+ op1 += (1-n) * os1; \
2132
+ } \
2133
+ if ( os2 < 0 ) { \
2134
+ op2 += (1-n) * os2; \
2135
+ } \
2136
+ for ( i = 0; i < n; i++, op1 += os1, op2 += os2 )
2137
+ ```
2138
+
2139
+ #### STDLIB_STRIDED_NULLARY_LOOP_INLINE( tout, expr )
2140
+
2141
+ Macro for a nullary loop which inlines an expression.
2142
+
2143
+ ```c
2144
+ STDLIB_STRIDED_NULLARY_LOOP_INLINE( double, *out = (double)1.0 )
2145
+ ```
2146
+
2147
+ The macro expects the following arguments:
2148
+
2149
+ - ** tout** : output strided array element type.
2150
+ - ** expr** : expression to inline.
2151
+
2152
+ In addition to the variables defined by the ` STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE ` macro, the macro defines the following variables:
2153
+
2154
+ - ** out** : ` <tout>* ` pointer to an output strided array element.
2155
+
2156
+ The macro expects a provided expression to store the result via ` *out ` .
2157
+
2158
+ ``` c
2159
+ #define STDLIB_STRIDED_NULLARY_LOOP_INLINE ( tout, expr ) \
2160
+ STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE { \
2161
+ tout * out = (tout * )op1; \
2162
+ expr; \
2163
+ }
2164
+ ```
2165
+
2166
+ #### STDLIB_STRIDED_NULLARY_LOOP_CLBK( tout )
2167
+
2168
+ Macro for a nullary loop which invokes a callback.
2169
+
2170
+ ```c
2171
+ STDLIB_STRIDED_NULLARY_LOOP_CLBK( double )
2172
+ ```
2173
+
2174
+ The macro expects the following arguments:
2175
+
2176
+ - **tout**: output strided array element data type.
2177
+
2178
+ In addition to the variables expected by `STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE`, the macro expects the following variables to be defined:
2179
+
2180
+ - **f**: nullary callback.
2181
+
2182
+ ```c
2183
+ #define STDLIB_STRIDED_NULLARY_LOOP_CLBK ( tout ) \
2184
+ STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE { \
2185
+ *(tout *)op1 = (tout)f(); \
2186
+ }
2187
+ ```
2188
+
2189
+ #### STDLIB_STRIDED_NULLARY_LOOP_CLBK_RET_NONSCALAR( tout )
2190
+
2191
+ Macro for a nullary loop which invokes a callback which returns a non-scalar value (e.g., a `struct`).
2192
+
2193
+ ```c
2194
+ #include "stdlib/complex/float64.h"
2195
+
2196
+ STDLIB_STRIDED_NULLARY_LOOP_CLBK_RET_NONSCALAR( stdlib_complex128_t )
2197
+ ```
2198
+
2199
+ The macro expects the following arguments:
2200
+
2201
+ - ** tout** : output strided array element data type.
2202
+
2203
+ In addition to the variables expected by ` STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE ` , the macro expects the following variables to be defined:
2204
+
2205
+ - ** f** : nullary callback.
2206
+
2207
+ ``` c
2208
+ #define STDLIB_STRIDED_NULLARY_LOOP_CLBK_RET_NONSCALAR ( tout ) \
2209
+ STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE { \
2210
+ *(tout *)op1 = f(); \
2211
+ }
2212
+ ```
2213
+
2214
+ #### STDLIB_STRIDED_NULLARY_LOOP_CLBK_RET_CAST_FCN( tout, cout )
2215
+
2216
+ Macro for a nullary loop which invokes a callback whose return values should be cast to a different type via casting functions.
2217
+
2218
+ ```c
2219
+ #include "stdlib/complex/float32.h"
2220
+ #include "stdlib/complex/float64.h"
2221
+
2222
+ STDLIB_STRIDED_NULLARY_LOOP_CLBK_RET_CAST_FCN( stdlib_complex64_t, stdlib_complex128_to_complex64 )
2223
+ ```
2224
+
2225
+ The macro expects the following arguments:
2226
+
2227
+ - ** tout** : output strided array element data type.
2228
+ - ** cout** : function for casting an callback's return value to the output array data type.
2229
+
2230
+ In addition to the variables expected by ` STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE ` , the macro expects the following variables to be defined:
2231
+
2232
+ - ** f** : nullary callback.
2233
+
2234
+ ``` c
2235
+ #define STDLIB_STRIDED_NULLARY_LOOP_CLBK_RET_CAST_FCN ( tout, cout ) \
2236
+ STDLIB_STRIDED_NULLARY_LOOP_PREAMBLE { \
2237
+ *(tout *)op1 = cout( f() ); \
2238
+ }
2239
+ ```
2059
2240
2060
2241
<!-- ./macros -->
2061
2242
0 commit comments