-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharange.py
49 lines (37 loc) · 1.14 KB
/
arange.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# SPDX-FileCopyrightText: Steven Ward
# SPDX-License-Identifier: OSL-3.0
# pylint: disable=invalid-name
# pylint: disable=missing-function-docstring
# pylint: disable=missing-module-docstring
__author__ = 'Steven Ward'
__license__ = 'OSL-3.0'
from decimal import Decimal as D
import numpy as np
# https://numpy.org/doc/stable/reference/generated/numpy.arange.html
def arange(start: D, stop: D = None, step: D = None, endpoint: bool = False):
start = D(start)
if stop is None:
stop = start
start = D(0) # default value in numpy.arange
else:
stop = D(stop)
if step is None:
step = D(1) # default value in numpy.arange
else:
step = D(step)
if step == 0:
raise ValueError(f'Step ({step}) must be non-zero')
a = np.arange(start, stop, step)
if endpoint:
if len(a) == 0 or a[-1] != stop:
# Make it a closed interval by appending the stop value.
a = np.append(a, stop)
# pylint: disable=pointless-string-statement
'''
while start < stop:
yield start
start += step
if endpoint:
yield stop
'''
return a