summaryrefslogtreecommitdiff
path: root/numpy/core/function_base.py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2018-12-01 11:56:29 -0800
committerStephan Hoyer <shoyer@google.com>2018-12-01 11:56:31 -0800
commit8356edf5985c26284435379b50508aa4ddb11b6f (patch)
tree3aadabe8ae2ec6dbbade9bf904cd7358559be585 /numpy/core/function_base.py
parentb3a435305082699c26445630d9c79587d51ba9f1 (diff)
downloadnumpy-8356edf5985c26284435379b50508aa4ddb11b6f.tar.gz
ENH: override support for np.linspace and friends
Fixes gh-12379
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r--numpy/core/function_base.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py
index b3dd313cf..0fc56e70e 100644
--- a/numpy/core/function_base.py
+++ b/numpy/core/function_base.py
@@ -1,17 +1,22 @@
from __future__ import division, absolute_import, print_function
+import functools
import warnings
import operator
from . import numeric as _nx
from .numeric import (result_type, NaN, shares_memory, MAY_SHARE_BOUNDS,
- TooHardError,asanyarray)
+ TooHardError, asanyarray)
from numpy.core.multiarray import add_docstring
-from numpy.core.overrides import set_module
+from numpy.core import overrides
__all__ = ['logspace', 'linspace', 'geomspace']
+array_function_dispatch = functools.partial(
+ overrides.array_function_dispatch, module='numpy')
+
+
def _index_deprecate(i, stacklevel=2):
try:
i = operator.index(i)
@@ -24,7 +29,12 @@ def _index_deprecate(i, stacklevel=2):
return i
-@set_module('numpy')
+def _linspace_dispatcher(
+ start, stop, num=None, endpoint=None, retstep=None, dtype=None):
+ return (start, stop)
+
+
+@array_function_dispatch(_linspace_dispatcher)
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
"""
Return evenly spaced numbers over a specified interval.
@@ -156,7 +166,12 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
return y.astype(dtype, copy=False)
-@set_module('numpy')
+def _logspace_dispatcher(
+ start, stop, num=None, endpoint=None, base=None, dtype=None):
+ return (start, stop)
+
+
+@array_function_dispatch(_logspace_dispatcher)
def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None):
"""
Return numbers spaced evenly on a log scale.
@@ -241,7 +256,11 @@ def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None):
return _nx.power(base, y).astype(dtype)
-@set_module('numpy')
+def _geomspace_dispatcher(start, stop, num=None, endpoint=None, dtype=None):
+ return (start, stop)
+
+
+@array_function_dispatch(_geomspace_dispatcher)
def geomspace(start, stop, num=50, endpoint=True, dtype=None):
"""
Return numbers spaced evenly on a log scale (a geometric progression).