Skip to content

Commit 4cfd2c9

Browse files
DOC: Add a docstring to a function in gufuncgen.py that processes lists of type signatures
1 parent 7a550e7 commit 4cfd2c9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tools/cxxgen/gufuncgen.py

+47
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,53 @@
66

77

88
def classify_typenames(types):
9+
"""
10+
Identify unique types from a list of type signatures.
11+
12+
Given a list of ufunc type signatures, this function returns two
13+
values:
14+
15+
* A list of strings containing the unique character codes found in the
16+
signatures, but only those where the type in a given position is not
17+
the same in all the type signatures. These are the types that will be
18+
used to instantiate templated core functions.
19+
* a list with length `nin + nout`, where each element in the list is
20+
either an integer that is an index into the first return value (if
21+
there are varying types in the corresponding position in the input
22+
list of types), or the type code that was found in all types in that
23+
position.
24+
25+
Examples
26+
--------
27+
>>> types = ['ff?->fp',
28+
... 'dd?->dp',
29+
... 'gg?->gp']
30+
...
31+
>>> classify_typenames(types)
32+
(['fdg'], [0, 0, '?', 0, 'p'])
33+
34+
In the above example, note that in the columns of the aligned strings,
35+
the types are either all the same (`?` and `p`), or contain the sequence
36+
`'fdg'`. That is the only string in first return value. The integers
37+
in the second return value are all zero, so they refer to the first
38+
item in the first return value.
39+
40+
>>> types = ['ii?->fp',
41+
... 'ff?->fp',
42+
... 'dd?->dp',
43+
... 'gg?->gp']
44+
...
45+
>>> classify_typenames(types)
46+
(['ifdg', 'ffdg'], [0, 0, '?', 1, 'p'])
47+
48+
In this example, among the columns of types that are not constant, there
49+
are two distinct sequences: `'ifdg'` and `'ffdg'`. These are the values
50+
in the first return value. The first two integers in the second return
51+
value are 0, so they refer to the sequence `'ifdg'`. The third integer
52+
that occurs in the second return value is 1, so it refers to the sequence
53+
`'ffdg'`.
54+
55+
"""
956
types = np.array([list(t.replace('->', '')) for t in types])
1057
w = [''.join(c) for c in types.T]
1158
uts = []

0 commit comments

Comments
 (0)