Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 0e5368e

Browse files
authored
Merge pull request #43 from PyMoDAQ/bugfix/linspace_step_with_quantity
allow using quantities in linspace step
2 parents 9ae6443 + 9b9772c commit 0e5368e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/pymodaq_utils/math_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import List, Union, Tuple
88
from pymodaq_utils.logger import get_module_name, set_logger
99
from collections.abc import Iterable
10+
from pint import Quantity
1011

1112
logger = set_logger(get_module_name(__file__))
1213

@@ -123,7 +124,11 @@ def linspace_step(start, stop, step):
123124
raise ValueError('Invalid value for one parameter')
124125
Nsteps = int(np.ceil((stop - start) / step))
125126
new_stop = start + (Nsteps - 1) * step
126-
if np.abs(new_stop + step - stop) < 1e-12:
127+
if isinstance(new_stop, Quantity):
128+
tol = (new_stop + step - stop).magnitude
129+
else:
130+
tol = (new_stop + step - stop)
131+
if np.abs(tol) < 1e-12:
127132
Nsteps += 1
128133
new_stop = start + (Nsteps - 1) * step
129134
return np.linspace(start, new_stop, Nsteps)

0 commit comments

Comments
 (0)