1
1
from typing import Optional , Sequence
2
2
3
3
from .core import UltraFastList
4
- from .ulist import BooleanList , FloatList , IntegerList , StringList
5
- from .ulist import arange as _arange
6
4
from .typedef import ELEM
7
-
8
-
9
- def arange (start : int , stop : Optional [int ] = None , step : int = 1
10
- ) -> UltraFastList :
5
+ from .ulist import (
6
+ BooleanList ,
7
+ FloatList32 ,
8
+ FloatList64 ,
9
+ IntegerList32 ,
10
+ IntegerList64 ,
11
+ StringList ,
12
+ arange32 ,
13
+ arange64
14
+ )
15
+
16
+
17
+ def arange (
18
+ start : int ,
19
+ stop : Optional [int ] = None ,
20
+ step : int = 1 ,
21
+ dtype : str = 'int' ,
22
+ ) -> UltraFastList :
11
23
"""Return evenly spaced values within a given interval, which is similar
12
24
to the Python built-in range function, but returns an ulist rather than
13
25
a list.
@@ -21,6 +33,8 @@ def arange(start: int, stop: Optional[int] = None, step: int = 1
21
33
Defaults to None.
22
34
step (int, optional):
23
35
Spacing between values. Defaults to 1.
36
+ dtype (str, optional):
37
+ The type of the output ulist. 'int', 'int32', 'int64'.
24
38
25
39
Returns:
26
40
UltraFastList: A ulist object.
@@ -43,7 +57,13 @@ def arange(start: int, stop: Optional[int] = None, step: int = 1
43
57
if stop is None :
44
58
stop = start
45
59
start = 0
46
- return UltraFastList (_arange (start = start , stop = stop , step = step ))
60
+ if dtype == "int" or dtype == "int64" :
61
+ return UltraFastList (arange64 (start = start , stop = stop , step = step ))
62
+ elif dtype == "int32" :
63
+ return UltraFastList (arange32 (start = start , stop = stop , step = step ))
64
+ else :
65
+ raise ValueError (
66
+ "Parameter dtype should be 'int', 'int32' or 'int64'!" )
47
67
48
68
49
69
def cycle (obj : Sequence , size : int , dtype : str ) -> UltraFastList :
@@ -55,11 +75,13 @@ def cycle(obj: Sequence, size: int, dtype: str) -> UltraFastList:
55
75
size (int):
56
76
size (int): Size of the new ulist.
57
77
dtype (str):
58
- The type of the output ulist. 'int', 'float', 'bool' or 'string'.
78
+ The type of the output ulist. 'int', 'int32', 'int64',
79
+ 'float', 'float32', 'float64', 'bool' or 'string'.
59
80
60
81
Raises:
61
82
ValueError:
62
- Parameter dtype should be 'int', 'float', 'bool' or 'string'!
83
+ Parameter dtype should be 'int', 'int32', 'int64',
84
+ 'float', 'float32', 'float64', 'bool' or 'string'!
63
85
64
86
Returns:
65
87
UltraFastList: A ulist object.
@@ -83,17 +105,23 @@ def cycle(obj: Sequence, size: int, dtype: str) -> UltraFastList:
83
105
>>> arr4
84
106
UltraFastList(['foo', 'foo', 'foo'])
85
107
"""
86
- if dtype == "int" :
87
- result = UltraFastList (IntegerList .cycle (obj , size ))
88
- elif dtype == "float" :
89
- result = UltraFastList (FloatList .cycle (obj , size ))
108
+ if dtype == "int" or dtype == "int64" :
109
+ result = UltraFastList (IntegerList64 .cycle (obj , size ))
110
+ elif dtype == "int32" :
111
+ result = UltraFastList (IntegerList32 .cycle (obj , size ))
112
+ elif dtype == "float" or dtype == "float64" :
113
+ result = UltraFastList (FloatList64 .cycle (obj , size ))
114
+ elif dtype == "float32" :
115
+ result = UltraFastList (FloatList32 .cycle (obj , size ))
90
116
elif dtype == "bool" :
91
117
result = UltraFastList (BooleanList .cycle (obj , size ))
92
118
elif dtype == "string" :
93
119
result = UltraFastList (StringList .cycle (obj , size ))
94
120
else :
95
121
raise ValueError (
96
- "Parameter dtype should be 'int', 'float', 'bool' or 'string'!" )
122
+ "Parameter dtype should be 'int', 'int32', 'int64', " +
123
+ "'float', 'float32', 'float64', 'bool' or 'string'!"
124
+ )
97
125
return result
98
126
99
127
@@ -104,11 +132,13 @@ def from_seq(obj: Sequence, dtype: str) -> UltraFastList:
104
132
obj (Sequence):
105
133
Sequence object such as list, tuple and range.
106
134
dtype (str):
107
- The type of the output ulist. 'int', 'float', 'bool' or 'string'.
135
+ The type of the output ulist. 'int', 'int32', 'int64',
136
+ 'float', 'float32', 'float64', 'bool' or 'string'.
108
137
109
138
Raises:
110
139
ValueError:
111
- Parameter dtype should be 'int', 'float', 'bool' or 'string'!
140
+ Parameter dtype should be 'int', 'int32', 'int64',
141
+ 'float', 'float32', 'float64', 'bool' or 'string'!
112
142
113
143
Returns:
114
144
UltraFastList: A ulist object.
@@ -132,17 +162,23 @@ def from_seq(obj: Sequence, dtype: str) -> UltraFastList:
132
162
>>> arr4
133
163
UltraFastList(['foo', 'bar', 'baz'])
134
164
"""
135
- if dtype == "int" :
136
- result = UltraFastList (IntegerList (obj ))
137
- elif dtype == "float" :
138
- result = UltraFastList (FloatList (obj ))
165
+ if dtype == "int" or dtype == "int64" :
166
+ result = UltraFastList (IntegerList64 (obj ))
167
+ elif dtype == "int32" :
168
+ result = UltraFastList (IntegerList32 (obj ))
169
+ elif dtype == "float" or dtype == "float64" :
170
+ result = UltraFastList (FloatList64 (obj ))
171
+ elif dtype == "float32" :
172
+ result = UltraFastList (FloatList32 (obj ))
139
173
elif dtype == "bool" :
140
174
result = UltraFastList (BooleanList (obj ))
141
175
elif dtype == "string" :
142
176
result = UltraFastList (StringList (obj ))
143
177
else :
144
178
raise ValueError (
145
- "Parameter dtype should be 'int', 'float', 'bool' or 'string'!" )
179
+ "Parameter dtype should be 'int', 'int32', 'int64', " +
180
+ "'float', 'float32', 'float64', 'bool' or 'string'!"
181
+ )
146
182
return result
147
183
148
184
@@ -181,9 +217,9 @@ def repeat(elem: ELEM, size: int) -> UltraFastList:
181
217
if isinstance (elem , bool ):
182
218
return UltraFastList (BooleanList .repeat (elem , size ))
183
219
elif isinstance (elem , float ):
184
- return UltraFastList (FloatList .repeat (elem , size ))
220
+ return UltraFastList (FloatList64 .repeat (elem , size ))
185
221
elif isinstance (elem , int ):
186
- return UltraFastList (IntegerList .repeat (elem , size ))
222
+ return UltraFastList (IntegerList64 .repeat (elem , size ))
187
223
elif isinstance (elem , str ):
188
224
return UltraFastList (StringList .repeat (elem , size ))
189
225
else :
0 commit comments