|
23 | 23 | from ...util import _sanity_check_params, set_module
|
24 | 24 | from ...context import current_context
|
25 | 25 | from . import _internal as _npi
|
| 26 | +from ..ndarray import NDArray |
26 | 27 |
|
27 | 28 | __all__ = ['zeros', 'ones', 'maximum', 'minimum', 'stack', 'arange', 'argmax',
|
28 | 29 | 'add', 'subtract', 'multiply', 'divide', 'mod', 'power', 'concatenate',
|
29 |
| - 'clip', 'split', 'swapaxes', 'expand_dims', 'tile'] |
| 30 | + 'clip', 'split', 'swapaxes', 'expand_dims', 'tile', 'linspace'] |
30 | 31 |
|
31 | 32 |
|
32 | 33 | @set_module('mxnet.ndarray.numpy')
|
@@ -629,3 +630,63 @@ def tile(A, reps):
|
629 | 630 | The tiled output array.
|
630 | 631 | """
|
631 | 632 | return _npi.tile(A, reps)
|
| 633 | + |
| 634 | + |
| 635 | +@set_module('mxnet.ndarray.numpy') |
| 636 | +def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0, **kwargs): #pylint: disable=too-many-arguments |
| 637 | + """Return evenly spaced numbers over a specified interval. |
| 638 | +
|
| 639 | + Returns num evenly spaced samples, calculated over the interval [start, stop]. |
| 640 | + The endpoint of the interval can optionally be excluded. |
| 641 | +
|
| 642 | + Parameters |
| 643 | + ---------- |
| 644 | + start : array_like |
| 645 | + The starting value of the sequence. |
| 646 | + stop : array_like |
| 647 | + The end value of the sequence, unless endpoint is set to False. In |
| 648 | + that case, the sequence consists of all but the last of num + 1 |
| 649 | + evenly spaced samples, so that stop is excluded. Note that the step |
| 650 | + size changes when endpoint is False. |
| 651 | + num : int, optional |
| 652 | + Number of samples to generate. Default is 50. Must be non-negative. |
| 653 | + endpoint : bool, optional |
| 654 | + If True, stop is the last sample. Otherwise, it is not included. |
| 655 | + Default is True. |
| 656 | + retstep: bool, optional |
| 657 | + If True, return (samples, step), where step is the spacing between samples. |
| 658 | + dtype: dtype, optional |
| 659 | + The type of the output array. If dtype is not given, infer the data |
| 660 | + type from the other input arguments. |
| 661 | + axis : int, optional |
| 662 | + The axis in the result to store the samples. Relevant only if start or |
| 663 | + stop are array-like. By default (0), the samples will be along a new |
| 664 | + axis inserted at the beginning. Use -1 to get an axis at the end. |
| 665 | + Returns |
| 666 | + ------- |
| 667 | + samples : ndarray |
| 668 | + There are num equally spaced samples in the closed interval |
| 669 | + `[start, stop]` or the half-open interval `[start, stop)` |
| 670 | + (depending on whether endpoint is True or False). |
| 671 | + step : float, optional |
| 672 | + Only returned if retstep is True |
| 673 | + Size of spacing between samples. |
| 674 | +
|
| 675 | + Notes |
| 676 | + ----- |
| 677 | + This function currently does not support ``start`` and ``stop`` as ndarrays and |
| 678 | + axis could only be 0 now. |
| 679 | + """ |
| 680 | + if isinstance(start, (list, _np.ndarray, NDArray)) or \ |
| 681 | + isinstance(stop, (list, _np.ndarray, NDArray)): |
| 682 | + raise NotImplementedError('start and stop only support int') |
| 683 | + if axis != 0: |
| 684 | + raise NotImplementedError("the function only support axis 0") |
| 685 | + ctx = kwargs.pop('ctx', current_context()) |
| 686 | + if ctx is None: |
| 687 | + ctx = current_context() |
| 688 | + if retstep: |
| 689 | + step = (stop - start) / (num - 1) |
| 690 | + return (_npi.linspace(start=start, stop=stop, num=num, endpoint=endpoint, ctx=ctx, dtype=dtype), step) |
| 691 | + else: |
| 692 | + return _npi.linspace(start=start, stop=stop, num=num, endpoint=endpoint, ctx=ctx, dtype=dtype) |
0 commit comments