Debian Codegraph @

pypy/module/micronumpy/app_numpy.py

raw symbols SCIP
1 from __future__ import absolute_import
2
3 import math
4
5 import _numpypy
6 from _numpypy.multiarray import set_docstring
7
8 def arange(start, stop=None, step=1, dtype=None):
9 '''arange([start], stop[, step], dtype=None)
10 Generate values in the half-interval [start, stop).
11 '''
12 if stop is None:
13 stop = start
14 start = 0
15 if dtype is None:
16 # find minimal acceptable dtype but not less than int
17 dtype = _numpypy.multiarray.result_type(start, stop, step, int)
18 length = math.ceil((float(stop) - start) / step)
19 length = int(length)
20 arr = _numpypy.multiarray.empty(length, dtype=dtype)
21 i = start
22 for j in range(arr.size):
23 arr[j] = i
24 i += step
25 return arr
26
27
28 def add_docstring(obj, docstring):
29 old_doc = getattr(obj, '__doc__', None)
30 if old_doc is not None:
31 raise RuntimeError("%s already has a docstring" % obj)
32 try:
33 set_docstring(obj, docstring)
34 except:
35 raise TypeError("Cannot set a docstring for %s" % obj)