How is the at (@) sign used in c source code for numpy?

I was looking at part of the source code for numpy, and I noticed that most of the c sources use a construct @variablename@. For example, in the file "npy_math_complex.c.src" (located here ):

/*==========================================================
* Constants
*=========================================================*/
static const @ctype@ c_1@c@ = {1.0@C@, 0.0};
static const @ctype@ c_half@c@ = {0.5@C@, 0.0};
static const @ctype@ c_i@c@ = {0.0, 1.0@C@};
static const @ctype@ c_ihalf@c@ = {0.0, 0.5@C@};

What do @ctype@u mean @c@? Are these some macros? I assume that they are not normal C-macros since I looked at the corresponding header files listed in the file and they do not seem to define any macros using "@".

Is @name@some kind of macro used distutilswhen compiling c-code into a python module?

I have never seen the character @used in c code before, and so I'm a bit confused ...

+4
source share
1 answer

This is because these files are templates. If I remember correctly, NumPy uses several template engines (thanks @ user2357112 for help finding the right one):

and the second is responsible for converting them into "regular" C files - before they are compiled.

Basically, these functions will be cloned many times, and for each function a special placeholder tag is inserted between %.

For example, in this case begins with :

/**begin repeat
 * #type = npy_float, npy_double, npy_longdouble#
 * #ctype = npy_cfloat,npy_cdouble,npy_clongdouble#
 * #c = f, , l#
 * #C = F, , L#
 * ....
 */

, @ctype@ npy_cfloat @c@ f @c@ f:

static const npy_cfloat c_1f = {1.0F, 0.0};
static const npy_cfloat c_halff = {0.5F, 0.0};
static const npy_cfloat c_if = {0.0, 1.0F};
static const npy_cfloat c_ihalff = {0.0, 0.5F};

@ctype@ npy_cdouble,...

static const npy_cdouble c_1 = {1.0, 0.0};
static const npy_cdouble c_half = {0.5, 0.0};
static const npy_cdouble c_i = {0.0, 1.0};
static const npy_cdouble c_ihalf = {0.0, 0.5};

:

static const npy_clongdouble c_1l = {1.0L, 0.0};
static const npy_clongdouble c_halfl = {0.5L, 0.0};
static const npy_clongdouble c_il = {0.0, 1.0L};
static const npy_clongdouble c_ihalfl = {0.0, 0.5L};

C.

+5

Source: https://habr.com/ru/post/1684418/


All Articles