-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement functions from np.random #46
Closed
Closed
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a5cc202
add numpy.random.rand
prasunanand 754e810
add more functions from Random module
prasunanand 6c0068b
Lint and adding random functions
prasunanand ed9e827
add to __ua_function__
prasunanand 92d3f50
Few tests passing: Import error fixed
prasunanand 97bdc75
More tests passing
prasunanand 36af3ec
All tests pass
prasunanand f24e867
Dask backend tests pass now
prasunanand File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,7 @@ | |
True | ||
""" | ||
from ._multimethods import * | ||
from .random import * | ||
|
||
from ._version import get_versions | ||
|
||
|
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 @@ | ||
from ._multimethods import * | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
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,306 @@ | ||
import functools | ||
import operator | ||
from uarray import create_multimethod, mark_as, all_of_type, Dispatchable | ||
import builtins | ||
|
||
create_numpy = functools.partial(create_multimethod, domain="numpy") | ||
|
||
from .._multimethods import ndarray, _self_argreplacer | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@all_of_type(ndarray) | ||
def rand(*tup): | ||
return tup | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@all_of_type(ndarray) | ||
def randn(*tup): | ||
return tup | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@all_of_type(ndarray) | ||
def randint(low, high=None, size=None, dtype="l"): | ||
return low | ||
prasunanand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def random_integers(low, high=None, size=None): | ||
return low | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def random_sample(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def random(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def ranf(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def sample(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def choice(a, size=None, replace=True, p=None): | ||
return (a, size, replace, p) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def bytes(length): | ||
return length | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def shuffle(x): | ||
return x | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def permutation(x): | ||
return x | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def beta(a, b, size=None): | ||
return (a, b, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def binomial(n, p, size=None): | ||
return (n, p, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def dirichlet(alpha, size=None): | ||
return (alpha, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def exponential(scale, size=None): | ||
return (scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def f(dfnum, dfden, size=None): | ||
return (dfnum, dfden, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def gamma(shape, scale=1.0, size=None): | ||
return (shape, scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def geometric(p, size=None): | ||
return (p, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def gumbel(loc=0.0, scale=1.0, size=None): | ||
return (loc, scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def hypergeometric(ngood, nbad, nsample, size=None): | ||
return (ngood, nbad, nsample, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def laplace(loc=0.0, scale=1.0, size=None): | ||
return (loc, scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def logistic(loc=0.0, scale=1.0, size=None): | ||
return (loc, scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def lognormal(mean=0.0, sigma=1.0, size=None): | ||
return (mean, sigma, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def logseries(p, size=None): | ||
return (p, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def multinomial(n, pvals, size=None): | ||
return (n, pvals, size) | ||
|
||
|
||
# check | ||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def multivariate_normal(mean, cov, size=None, check_valid=None, tol=None): | ||
return (mean, cov, size, check_valid, tol) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def negative_binomial(n, p, size=None): | ||
return (n, p, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def noncentral_chisquare(df, nonc, size=None): | ||
return (df, nonc, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def noncentral_f(dfnum, dfden, nonc, size=None): | ||
return (dfnum, dfden, nonc, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def normal(loc=0.0, scale=1.0, size=None): | ||
return (loc, scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def pareto(a, size=None): | ||
return (a, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def poisson(lam=1.0, size=None): | ||
return (lam, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def power(a, size=None): | ||
return (a, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def rayleigh(scale=1.0, size=None): | ||
return (scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def standard_cauchy(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def standard_exponential(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def standard_gamma(shape, size=None): | ||
return (shape, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def standard_normal(size=None): | ||
return size | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def standard_t(df, size=None): | ||
return (df, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def triangular(left, mode, right, size=None): | ||
return (left, mode, right, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def uniform(low=0.0, high=1.0, size=None): | ||
return (low, high, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def vonmises(mu, kappa, size=None): | ||
return (mu, kappa, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def wald(mean, scale, size=None): | ||
return (mean, scale, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def weibull(a, size=None): | ||
return (a, size) | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def zipf(a, size=None): | ||
return (a, size) | ||
|
||
|
||
# discuss: RandomState | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def seed(seed=None): | ||
return seed | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def get_state(): | ||
return | ||
|
||
|
||
@create_numpy(_self_argreplacer) | ||
@all_of_type(ndarray) | ||
def set_state(state): | ||
return state |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be replaced by checking the
__module__
of themethod
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to check
method.__module__
. It will be different depending on the submodule that the method is in.For simplicity, you can also move everything in
_multimethods.py
to__init__.py
.