Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ benchmarks/numpy
cythonize.dat
numpy/random/mtrand/mtrand.c
numpy/random/mtrand/randint_helpers.pxi
numpy/random_intel/mklrand/mklrand.c
3 changes: 2 additions & 1 deletion numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def pkgload(*packages, **options):
from . import fft
from . import polynomial
from . import random
from . import random_intel
from . import ctypeslib
from . import ma
from . import matrixlib as _mat
Expand All @@ -185,7 +186,7 @@ def pkgload(*packages, **options):
__all__.extend(core.__all__)
__all__.extend(_mat.__all__)
__all__.extend(lib.__all__)
__all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
__all__.extend(['linalg', 'fft', 'random', 'random_intel', 'ctypeslib', 'ma'])


# Filter annoying Cython warnings that serve no good purpose.
Expand Down
125 changes: 125 additions & 0 deletions numpy/random_intel/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""
========================
Random Number Generation
========================

==================== =========================================================
Utility functions
==============================================================================
random Uniformly distributed values of a given shape.
bytes Uniformly distributed random bytes.
random_integers Uniformly distributed integers in a given range.
random_sample Uniformly distributed floats in a given range.
random Alias for random_sample
ranf Alias for random_sample
sample Alias for random_sample
choice Generate a weighted random sample from a given array-like
permutation Randomly permute a sequence / generate a random sequence.
shuffle Randomly permute a sequence in place.
seed Seed the random number generator.
==================== =========================================================

==================== =========================================================
Compatibility functions
==============================================================================
rand Uniformly distributed values.
randn Normally distributed values.
ranf Uniformly distributed floating point numbers.
randint Uniformly distributed integers in a given range.
==================== =========================================================

==================== =========================================================
Univariate distributions
==============================================================================
beta Beta distribution over ``[0, 1]``.
binomial Binomial distribution.
chisquare :math:`\\chi^2` distribution.
exponential Exponential distribution.
f F (Fisher-Snedecor) distribution.
gamma Gamma distribution.
geometric Geometric distribution.
gumbel Gumbel distribution.
hypergeometric Hypergeometric distribution.
laplace Laplace distribution.
logistic Logistic distribution.
lognormal Log-normal distribution.
logseries Logarithmic series distribution.
negative_binomial Negative binomial distribution.
noncentral_chisquare Non-central chi-square distribution.
noncentral_f Non-central F distribution.
normal Normal / Gaussian distribution.
pareto Pareto distribution.
poisson Poisson distribution.
power Power distribution.
rayleigh Rayleigh distribution.
triangular Triangular distribution.
uniform Uniform distribution.
vonmises Von Mises circular distribution.
wald Wald (inverse Gaussian) distribution.
weibull Weibull distribution.
zipf Zipf's distribution over ranked data.
==================== =========================================================

==================== =========================================================
Multivariate distributions
==============================================================================
dirichlet Multivariate generalization of Beta distribution.
multinomial Multivariate generalization of the binomial distribution.
multivariate_normal Multivariate generalization of the normal distribution.
==================== =========================================================

==================== =========================================================
Standard distributions
==============================================================================
standard_cauchy Standard Cauchy-Lorentz distribution.
standard_exponential Standard exponential distribution.
standard_gamma Standard Gamma distribution.
standard_normal Standard normal distribution.
standard_t Standard Student's t-distribution.
==================== =========================================================

==================== =========================================================
Internal functions
==============================================================================
get_state Get tuple representing internal state of generator.
set_state Set state of generator.
==================== =========================================================

"""
from __future__ import division, absolute_import, print_function

from numpy.distutils.system_info import get_info

if get_info('mkl'):
import warnings

# To get sub-modules
from .info import __doc__, __all__

with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
from .mklrand import *

# Some aliases:
ranf = random = sample = random_sample
__all__.extend(['ranf', 'random', 'sample'])


def __RandomState_ctor():
"""Return a RandomState instance.

This function exists solely to assist (un)pickling.

Note that the state of the RandomState returned here is irrelevant, as this function's
entire purpose is to return a newly allocated RandomState whose state pickle can set.
Consequently the RandomState returned by this function is a freshly allocated copy
with a seed=0.

See https://github.com/numpy/numpy/issues/4763 for a detailed discussion

"""
return RandomState(seed=0)

from numpy.testing.nosetester import _numpy_tester
test = _numpy_tester().test
bench = _numpy_tester().bench
140 changes: 140 additions & 0 deletions numpy/random_intel/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
========================
Random Number Generation
========================

==================== =========================================================
Utility functions
==============================================================================
random_sample Uniformly distributed floats over ``[0, 1)``.
random Alias for `random_sample`.
bytes Uniformly distributed random bytes.
random_integers Uniformly distributed integers in a given range.
permutation Randomly permute a sequence / generate a random sequence.
shuffle Randomly permute a sequence in place.
seed Seed the random number generator.
choice Random sample from 1-D array.

==================== =========================================================

==================== =========================================================
Compatibility functions
==============================================================================
rand Uniformly distributed values.
randn Normally distributed values.
ranf Uniformly distributed floating point numbers.
randint Uniformly distributed integers in a given range.
==================== =========================================================

==================== =========================================================
Univariate distributions
==============================================================================
beta Beta distribution over ``[0, 1]``.
binomial Binomial distribution.
chisquare :math:`\\chi^2` distribution.
exponential Exponential distribution.
f F (Fisher-Snedecor) distribution.
gamma Gamma distribution.
geometric Geometric distribution.
gumbel Gumbel distribution.
hypergeometric Hypergeometric distribution.
laplace Laplace distribution.
logistic Logistic distribution.
lognormal Log-normal distribution.
logseries Logarithmic series distribution.
negative_binomial Negative binomial distribution.
noncentral_chisquare Non-central chi-square distribution.
noncentral_f Non-central F distribution.
normal Normal / Gaussian distribution.
pareto Pareto distribution.
poisson Poisson distribution.
power Power distribution.
rayleigh Rayleigh distribution.
triangular Triangular distribution.
uniform Uniform distribution.
vonmises Von Mises circular distribution.
wald Wald (inverse Gaussian) distribution.
weibull Weibull distribution.
zipf Zipf's distribution over ranked data.
==================== =========================================================

==================== =========================================================
Multivariate distributions
==============================================================================
dirichlet Multivariate generalization of Beta distribution.
multinomial Multivariate generalization of the binomial distribution.
multivariate_normal Multivariate generalization of the normal distribution.
multinormal_cholesky Multivariate generalization of the normal distribution.
==================== =========================================================

==================== =========================================================
Standard distributions
==============================================================================
standard_cauchy Standard Cauchy-Lorentz distribution.
standard_exponential Standard exponential distribution.
standard_gamma Standard Gamma distribution.
standard_normal Standard normal distribution.
standard_t Standard Student's t-distribution.
==================== =========================================================

==================== =========================================================
Internal functions
==============================================================================
get_state Get tuple representing internal state of generator.
set_state Set state of generator.
==================== =========================================================

"""
from __future__ import division, absolute_import, print_function

depends = ['core']

__all__ = [
'beta',
'binomial',
'bytes',
'chisquare',
'choice',
'dirichlet',
'exponential',
'f',
'gamma',
'geometric',
'get_state',
'gumbel',
'hypergeometric',
'laplace',
'logistic',
'lognormal',
'logseries',
'multinomial',
'multivariate_normal',
'negative_binomial',
'noncentral_chisquare',
'noncentral_f',
'normal',
'pareto',
'permutation',
'poisson',
'power',
'rand',
'randint',
'randn',
'random_integers',
'random_sample',
'rayleigh',
'seed',
'set_state',
'shuffle',
'standard_cauchy',
'standard_exponential',
'standard_gamma',
'standard_normal',
'standard_t',
'triangular',
'uniform',
'vonmises',
'wald',
'weibull',
'zipf'
]
43 changes: 43 additions & 0 deletions numpy/random_intel/mklrand/Python.pxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# :Author: Robert Kern
# :Copyright: 2004, Enthought, Inc.
# :License: BSD Style


cdef extern from "Python.h":
# Not part of the Python API, but we might as well define it here.
# Note that the exact type doesn't actually matter for Pyrex.
ctypedef int size_t

# String API
char* PyString_AsString(object string)
char* PyString_AS_STRING(object string)
object PyString_FromString(char* c_string)
object PyString_FromStringAndSize(char* c_string, int length)

# Float API
double PyFloat_AsDouble(object ob)
long PyInt_AsLong(object ob)

# Memory API
void* PyMem_Malloc(size_t n)
void* PyMem_Realloc(void* buf, size_t n)
void PyMem_Free(void* buf)

void Py_DECREF(object obj)
void Py_XDECREF(object obj)
void Py_INCREF(object obj)
void Py_XINCREF(object obj)

# TypeCheck API
int PyFloat_Check(object obj)
int PyInt_Check(object obj)

# Error API
int PyErr_Occurred()
void PyErr_Clear()

cdef extern from "string.h":
void *memcpy(void *s1, void *s2, int n)

cdef extern from "math.h":
double fabs(double x)
42 changes: 42 additions & 0 deletions numpy/random_intel/mklrand/generate_mklrand_c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
from __future__ import division, absolute_import, print_function

import sys
import re
import os

unused_internal_funcs = ['__Pyx_PrintItem',
'__Pyx_PrintNewline',
'__Pyx_ReRaise',
#'__Pyx_GetExcValue',
'__Pyx_ArgTypeTest',
'__Pyx_SetVtable',
'__Pyx_GetVtable',
'__Pyx_CreateClass']

if __name__ == '__main__':
# Use cython here so that long docstrings are broken up.
# This is needed for some VC++ compilers.
os.system('cython mklrand.pyx')
mklrand_c = open('mklrand.c', 'r')
processed = open('mklrand_pp.c', 'w')
unused_funcs_str = '(' + '|'.join(unused_internal_funcs) + ')'
uifpat = re.compile(r'static \w+ \*?'+unused_funcs_str+r'.*/\*proto\*/')
linepat = re.compile(r'/\* ".*/mklrand.pyx":')
for linenum, line in enumerate(mklrand_c):
m = re.match(r'^(\s+arrayObject\w*\s*=\s*[(])[(]PyObject\s*[*][)]',
line)
if m:
line = '%s(PyArrayObject *)%s' % (m.group(1), line[m.end():])
m = uifpat.match(line)
if m:
line = ''
m = re.search(unused_funcs_str, line)
if m:
print("%s was declared unused, but is used at line %d" % (m.group(),
linenum+1), file=sys.stderr)
line = linepat.sub(r'/* "mklrand.pyx":', line)
processed.write(line)
mklrand_c.close()
processed.close()
os.rename('mklrand_pp.c', 'mklrand.c')
Loading