Skip to content

Commit 9682ac0

Browse files
Support ARS5 counter-based basic random number generator provided by MKL
See: https://software.intel.com/content/www/us/en/develop/documentation/onemkl-vsnotes/top/testing-of-basic-random-number-generators/basic-random-generator-properties-and-testing-results/ars5.html In Python import mkl_random rs = mkl_random.RandomState(1234, brng="ARS5") rs.randn(5)
1 parent 425624c commit 9682ac0

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

mkl_random/mklrand.pyx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ cdef extern from "randomkit.h":
7070
MCG59 = 7
7171
PHILOX4X32X10 = 8
7272
NONDETERM = 9
73+
ARS5 = 10
7374

7475
void irk_fill(void *buffer, size_t size, irk_state *state) nogil
7576

@@ -873,6 +874,7 @@ _brng_dict = {
873874
'NONDETERM' : NONDETERM,
874875
'NONDETERMINISTIC' : NONDETERM,
875876
'NON_DETERMINISTIC' : NONDETERM,
877+
'ARS5' : ARS5
876878
}
877879

878880
_brng_dict_stream_max = {
@@ -886,6 +888,7 @@ _brng_dict_stream_max = {
886888
MCG59: 1,
887889
PHILOX4X32X10: 1,
888890
NONDETERM: 1,
891+
ARS5: 1,
889892
}
890893

891894
cdef irk_brng_t _default_fallback_brng_token_(brng):
@@ -973,8 +976,8 @@ cdef class RandomState:
973976
If `seed` is ``None``, then `RandomState` will try to read data from
974977
``/dev/urandom`` (or the Windows analogue) if available or seed from
975978
the clock otherwise.
976-
brng : {'MT19937', 'SFMT19937', 'MT2203', 'R250', 'WH', 'MCG31',
977-
'MCG59', 'MRG32K3A', 'PHILOX4X32X10', 'NONDETERM'}, optional
979+
brng : {'MT19937', 'SFMT19937', 'MT2203', 'R250', 'WH', 'MCG31', 'MCG59',
980+
'MRG32K3A', 'PHILOX4X32X10', 'NONDETERM', 'ARS5'}, optional
978981
Basic pseudo-random number generation algorithms, provided by
979982
Intel MKL. The default choice is 'MT19937' - the Mersenne Twister.
980983
@@ -1023,7 +1026,8 @@ cdef class RandomState:
10231026
Seed for `RandomState`.
10241027
Must be convertible to 32 bit unsigned integers.
10251028
brng : {'MT19937', 'SFMT19937', 'MT2203', 'R250', 'WH', 'MCG31',
1026-
'MCG59', 'MRG32K3A', 'PHILOX4X32X10', 'NONDETERM', None}, optional
1029+
'MCG59', 'MRG32K3A', 'PHILOX4X32X10', 'NONDETERM',
1030+
'ARS5', None}, optional
10271031
Basic pseudo-random number generation algorithms, provided by
10281032
Intel MKL. Use `brng==None` to keep the `brng` specified to construct
10291033
the class instance.

mkl_random/src/randomkit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
/*
27+
/*
2828
Adopted from NumPy's Random kit 1.3,
2929
Copyright (c) 2003-2005, Jean-Sebastien Roy (js@jeannot.org)
3030
*/
@@ -119,10 +119,11 @@ const MKL_INT brng_list[BRNG_KINDS] = {
119119
VSL_BRNG_MRG32K3A,
120120
VSL_BRNG_MCG59,
121121
VSL_BRNG_PHILOX4X32X10,
122-
VSL_BRNG_NONDETERM
122+
VSL_BRNG_NONDETERM,
123+
VSL_BRNG_ARS5
123124
};
124125

125-
/* Mersenne-Twister 2203 algorithm and Wichmann-Hill algorithm
126+
/* Mersenne-Twister 2203 algorithm and Wichmann-Hill algorithm
126127
* each have a parameter which produces a family of BRNG algorithms,
127128
* MKL identifies individual members of these families by VSL_BRNG_ALGO + family_id
128129
*/

mkl_random/src/randomkit.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef enum {
4545
} irk_error;
4646

4747
/* if changing this, also adjust brng_list[BRNG_KINDS] in randomkit.c */
48-
#define BRNG_KINDS 10
48+
#define BRNG_KINDS 11
4949

5050
typedef enum {
5151
MT19937 = 0,
@@ -57,7 +57,8 @@ typedef enum {
5757
MRG32K3A = 6,
5858
MCG59 = 7,
5959
PHILOX4X32X10 = 8,
60-
NONDETERM = 9
60+
NONDETERM = 9,
61+
ARS5 = 10
6162
} irk_brng_t;
6263

6364

0 commit comments

Comments
 (0)