11from typing import Optional , Sequence
22
33from .core import UltraFastList
4- from .ulist import BooleanList , FloatList , IntegerList , StringList
5- from .ulist import arange as _arange
64from .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 :
1123 """Return evenly spaced values within a given interval, which is similar
1224 to the Python built-in range function, but returns an ulist rather than
1325 a list.
@@ -21,6 +33,8 @@ def arange(start: int, stop: Optional[int] = None, step: int = 1
2133 Defaults to None.
2234 step (int, optional):
2335 Spacing between values. Defaults to 1.
36+ dtype (str, optional):
37+ The type of the output ulist. 'int', 'int32', 'int64'.
2438
2539 Returns:
2640 UltraFastList: A ulist object.
@@ -43,7 +57,13 @@ def arange(start: int, stop: Optional[int] = None, step: int = 1
4357 if stop is None :
4458 stop = start
4559 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'!" )
4767
4868
4969def cycle (obj : Sequence , size : int , dtype : str ) -> UltraFastList :
@@ -55,11 +75,13 @@ def cycle(obj: Sequence, size: int, dtype: str) -> UltraFastList:
5575 size (int):
5676 size (int): Size of the new ulist.
5777 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'.
5980
6081 Raises:
6182 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'!
6385
6486 Returns:
6587 UltraFastList: A ulist object.
@@ -83,17 +105,23 @@ def cycle(obj: Sequence, size: int, dtype: str) -> UltraFastList:
83105 >>> arr4
84106 UltraFastList(['foo', 'foo', 'foo'])
85107 """
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 ))
90116 elif dtype == "bool" :
91117 result = UltraFastList (BooleanList .cycle (obj , size ))
92118 elif dtype == "string" :
93119 result = UltraFastList (StringList .cycle (obj , size ))
94120 else :
95121 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+ )
97125 return result
98126
99127
@@ -104,11 +132,13 @@ def from_seq(obj: Sequence, dtype: str) -> UltraFastList:
104132 obj (Sequence):
105133 Sequence object such as list, tuple and range.
106134 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'.
108137
109138 Raises:
110139 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'!
112142
113143 Returns:
114144 UltraFastList: A ulist object.
@@ -132,17 +162,23 @@ def from_seq(obj: Sequence, dtype: str) -> UltraFastList:
132162 >>> arr4
133163 UltraFastList(['foo', 'bar', 'baz'])
134164 """
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 ))
139173 elif dtype == "bool" :
140174 result = UltraFastList (BooleanList (obj ))
141175 elif dtype == "string" :
142176 result = UltraFastList (StringList (obj ))
143177 else :
144178 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+ )
146182 return result
147183
148184
@@ -181,9 +217,9 @@ def repeat(elem: ELEM, size: int) -> UltraFastList:
181217 if isinstance (elem , bool ):
182218 return UltraFastList (BooleanList .repeat (elem , size ))
183219 elif isinstance (elem , float ):
184- return UltraFastList (FloatList .repeat (elem , size ))
220+ return UltraFastList (FloatList64 .repeat (elem , size ))
185221 elif isinstance (elem , int ):
186- return UltraFastList (IntegerList .repeat (elem , size ))
222+ return UltraFastList (IntegerList64 .repeat (elem , size ))
187223 elif isinstance (elem , str ):
188224 return UltraFastList (StringList .repeat (elem , size ))
189225 else :
0 commit comments