@@ -55,27 +55,32 @@ class MultiIndexUIntEngine(libindex.BaseMultiIndexCodesEngine,
55
55
56
56
def _codes_to_ints (self , codes ):
57
57
"""
58
- Transform each row of a 2d array of uint64 in a uint64, in a strictly
58
+ Transform combination(s) of uint64 in one uint64 (each) , in a strictly
59
59
monotonic way (i.e. respecting the lexicographic order of integer
60
60
combinations): see BaseMultiIndexCodesEngine documentation.
61
61
62
62
Parameters
63
63
----------
64
- codes : 2-dimensional array of dtype uint64
64
+ codes : 1- or 2-dimensional array of dtype uint64
65
65
Combinations of integers (one per row)
66
66
67
67
Returns
68
68
------
69
- int_keys : 1-dimensional array of dtype uint64
70
- Integers representing one combination each
69
+ int_keys : scalar or 1-dimensional array, of dtype uint64
70
+ Integer(s) representing one combination ( each)
71
71
"""
72
72
# Shift the representation of each level by the pre-calculated number
73
73
# of bits:
74
74
codes <<= self .offsets
75
75
76
76
# Now sum and OR are in fact interchangeable. This is a simple
77
77
# composition of the (disjunct) significant bits of each level (i.e.
78
- # each column in "codes") in a single positive integer (per row):
78
+ # each column in "codes") in a single positive integer:
79
+ if codes .ndim == 1 :
80
+ # Single key
81
+ return np .bitwise_or .reduce (codes )
82
+
83
+ # Multiple keys
79
84
return np .bitwise_or .reduce (codes , axis = 1 )
80
85
81
86
@@ -90,19 +95,19 @@ class MultiIndexPyIntEngine(libindex.BaseMultiIndexCodesEngine,
90
95
91
96
def _codes_to_ints (self , codes ):
92
97
"""
93
- Transform each row of a 2d array of uint64 in a Python integer, in a
98
+ Transform combination(s) of uint64 in one Python integer (each) , in a
94
99
strictly monotonic way (i.e. respecting the lexicographic order of
95
100
integer combinations): see BaseMultiIndexCodesEngine documentation.
96
101
97
102
Parameters
98
103
----------
99
- codes : 2-dimensional array of dtype uint64
104
+ codes : 1- or 2-dimensional array of dtype uint64
100
105
Combinations of integers (one per row)
101
106
102
107
Returns
103
108
------
104
- int_keys : 1-dimensional array of dtype object
105
- Integers representing one combination each
109
+ int_keys : int, or 1-dimensional array of dtype object
110
+ Integer(s) representing one combination ( each)
106
111
"""
107
112
108
113
# Shift the representation of each level by the pre-calculated number
@@ -113,6 +118,11 @@ def _codes_to_ints(self, codes):
113
118
# Now sum and OR are in fact interchangeable. This is a simple
114
119
# composition of the (disjunct) significant bits of each level (i.e.
115
120
# each column in "codes") in a single positive integer (per row):
121
+ if codes .ndim == 1 :
122
+ # Single key
123
+ return np .bitwise_or .reduce (codes )
124
+
125
+ # Multiple keys
116
126
return np .bitwise_or .reduce (codes , axis = 1 )
117
127
118
128
0 commit comments