This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b72d195
commit 275d961
Showing
12 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Namespace for operators used in Gluon dispatched by F=ndarray.""" | ||
from __future__ import absolute_import | ||
import numpy as _np | ||
from ...util import set_module | ||
from . import _internal as _npi | ||
|
||
|
||
__all__ = ['polyval'] | ||
|
||
|
||
@set_module('mxnet.ndarray.numpy') | ||
def polyval(p, x): | ||
""" | ||
Evaluate a polynomial at specific values. | ||
If p is of length N, this function returns the value: | ||
p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1] | ||
If x is a sequence, then p(x) is returned for each element of x. | ||
If x is another polynomial then the composite polynomial p(x(t)) is returned. | ||
Parameters | ||
---------- | ||
p : ndarray | ||
1D array of polynomial coefficients (including coefficients equal to zero) | ||
from highest degree to the constant term. | ||
x : ndarray | ||
An array of numbers, at which to evaluate p. | ||
Returns | ||
------- | ||
values : ndarray | ||
Result array of polynomials | ||
Notes | ||
----- | ||
This function differs from the original `numpy.polyval | ||
<https://numpy.org/devdocs/reference/generated/numpy.polyval.html>`_ in | ||
the following way(s): | ||
- Does not support poly1d. | ||
- X should be ndarray type even if it contains only one element. | ||
Examples | ||
-------- | ||
>>> p = np.array([3, 0, 1]) | ||
array([3., 0., 1.]) | ||
>>> x = np.array([5]) | ||
array([5.]) | ||
>>> np.polyval(p, x) # 3 * 5**2 + 0 * 5**1 + 1 | ||
array([76.]) | ||
>>> x = np.array([5, 4]) | ||
array([5., 4.]) | ||
>>> np.polyval(p, x) | ||
array([76., 49.]) | ||
""" | ||
from ...numpy import ndarray | ||
if isinstance(p, ndarray) and isinstance(x, ndarray): | ||
return _npi.polyval(p, x) | ||
elif not isinstance(p, ndarray) and not isinstance(x, ndarray): | ||
return _np.polyval(p, x) | ||
else: | ||
raise TypeError('type not supported') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Namespace for ops used in imperative programming.""" | ||
|
||
from __future__ import absolute_import | ||
from ..ndarray import numpy as _mx_nd_np | ||
from ..util import set_module | ||
|
||
|
||
__all__ = ['polyval'] | ||
|
||
|
||
@set_module('mxnet.numpy') | ||
def polyval(p, x): | ||
""" | ||
Evaluate a polynomial at specific values. | ||
If p is of length N, this function returns the value: | ||
p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1] | ||
If x is a sequence, then p(x) is returned for each element of x. | ||
If x is another polynomial then the composite polynomial p(x(t)) is returned. | ||
Parameters | ||
---------- | ||
p : ndarray | ||
1D array of polynomial coefficients (including coefficients equal to zero) | ||
from highest degree to the constant term. | ||
x : ndarray | ||
An array of numbers, at which to evaluate p. | ||
Returns | ||
------- | ||
values : ndarray | ||
Result array of polynomials | ||
Notes | ||
----- | ||
This function differs from the original `numpy.polyval | ||
<https://numpy.org/devdocs/reference/generated/numpy.polyval.html>`_ in | ||
the following way(s): | ||
- Does not support poly1d. | ||
- X should be ndarray type even if it contains only one element. | ||
Examples | ||
-------- | ||
>>> p = np.array([3, 0, 1]) | ||
array([3., 0., 1.]) | ||
>>> x = np.array([5]) | ||
array([5.]) | ||
>>> np.polyval(p, x) # 3 * 5**2 + 0 * 5**1 + 1 | ||
array([76.]) | ||
>>> x = np.array([5, 4]) | ||
array([5., 4.]) | ||
>>> np.polyval(p, x) | ||
array([76., 49.]) | ||
""" | ||
return _mx_nd_np.polyval(p, x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Namespace for operators used in Gluon dispatched by F=symbol.""" | ||
|
||
from __future__ import absolute_import | ||
import numpy as _np | ||
from ...util import set_module | ||
from . import _internal as _npi | ||
from ..symbol import Symbol | ||
|
||
|
||
__all__ = ['polyval'] | ||
|
||
@set_module('mxnet.symbol.numpy') | ||
def polyval(p, x): | ||
""" | ||
Evaluate a polynomial at specific values. | ||
If p is of length N, this function returns the value: | ||
p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1] | ||
If x is a sequence, then p(x) is returned for each element of x. | ||
If x is another polynomial then the composite polynomial p(x(t)) is returned. | ||
Parameters | ||
---------- | ||
p : _Symbol | ||
1D array of polynomial coefficients (including coefficients equal to zero) | ||
from highest degree to the constant term. | ||
x : _Symbol | ||
An array of numbers, at which to evaluate p. | ||
Returns | ||
------- | ||
values : _Symbol | ||
Result array of polynomials | ||
Notes | ||
----- | ||
This function differs from the original `numpy.polyval | ||
<https://numpy.org/devdocs/reference/generated/numpy.polyval.html>`_ in | ||
the following way(s): | ||
- Does not support poly1d. | ||
- X should be ndarray type even if it contains only one element. | ||
""" | ||
if isinstance(p, Symbol) and isinstance(x, Symbol): | ||
return _npi.polyval(p, x) | ||
elif not isinstance(p, Symbol) and not isinstance(x, Symbol): | ||
return _np.polyval(p, x) | ||
else: | ||
raise TypeError('type not supported') |
Oops, something went wrong.