A high-performance general-purpose compute library
random.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11#include <af/defines.h>
12
19typedef void * af_random_engine;
20
21#ifdef __cplusplus
22namespace af
23{
24 class array;
25 class dim4;
26#if AF_API_VERSION >= 34
35 private:
38 af_random_engine engine;
39
40 public:
51 unsigned long long seedIn = 0);
52
59
67
72
81
87 void setType(const randomEngineType type);
88
95
101 void setSeed(const unsigned long long seed);
102
108 unsigned long long getSeed(void) const;
109
117 };
118#endif
119
120#if AF_API_VERSION >= 34
132 AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r);
133#endif
134
135#if AF_API_VERSION >= 34
147 AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r);
148#endif
149
159 AFAPI array randu(const dim4 &dims, const dtype ty=f32);
160
171 AFAPI array randu(const dim_t d0, const dtype ty=f32);
172
185 const dim_t d1, const dtype ty=f32);
186
200 const dim_t d1, const dim_t d2, const dtype ty=f32);
201
216 const dim_t d1, const dim_t d2,
217 const dim_t d3, const dtype ty=f32);
218
229 AFAPI array randn(const dim4 &dims, const dtype ty=f32);
230
241 AFAPI array randn(const dim_t d0, const dtype ty=f32);
254 const dim_t d1, const dtype ty=f32);
268 const dim_t d1, const dim_t d2, const dtype ty=f32);
269
284 const dim_t d1, const dim_t d2,
285 const dim_t d3, const dtype ty=f32);
286
287#if AF_API_VERSION >= 34
296#endif
297
298#if AF_API_VERSION >= 34
307#endif
308
316 AFAPI void setSeed(const unsigned long long seed);
317
325 AFAPI unsigned long long getSeed();
326
327}
328#endif
329
330#ifdef __cplusplus
331extern "C" {
332#endif
333
334#if AF_API_VERSION >= 34
348 unsigned long long seed);
349#endif
350
351#if AF_API_VERSION >= 34
363 const af_random_engine engine);
364#endif
365
366#if AF_API_VERSION >= 34
378 const af_random_engine_type rtype);
379#endif
380
381#if AF_API_VERSION >= 34
393 const af_random_engine engine);
394#endif
395
396#if AF_API_VERSION >= 34
411 AFAPI af_err af_random_uniform(af_array *out, const unsigned ndims,
412 const dim_t * const dims, const af_dtype type,
413 af_random_engine engine);
414#endif
415
416#if AF_API_VERSION >= 34
431 AFAPI af_err af_random_normal(af_array *out, const unsigned ndims,
432 const dim_t * const dims, const af_dtype type,
433 af_random_engine engine);
434#endif
435
436#if AF_API_VERSION >= 34
448 const unsigned long long seed);
449#endif
450
451#if AF_API_VERSION >= 34
462#endif
463
464#if AF_API_VERSION >= 34
475#endif
476
477#if AF_API_VERSION >= 34
488 AFAPI af_err af_random_engine_get_seed(unsigned long long * const seed,
489 af_random_engine engine);
490#endif
491
492#if AF_API_VERSION >= 34
503#endif
504
515 AFAPI af_err af_randu(af_array *out, const unsigned ndims,
516 const dim_t * const dims, const af_dtype type);
517
528 AFAPI af_err af_randn(af_array *out, const unsigned ndims,
529 const dim_t * const dims, const af_dtype type);
530
538 AFAPI af_err af_set_seed(const unsigned long long seed);
539
547 AFAPI af_err af_get_seed(unsigned long long *seed);
548
549#ifdef __cplusplus
550}
551#endif
A multi dimensional data container.
Definition: array.h:37
Generic object that represents size and shape.
Definition: dim4.hpp:26
C++ Interface - Random Number Generation Engine Class.
Definition: random.h:34
randomEngineType getType(void)
C++ Interface to get the random type of the random engine.
void setSeed(const unsigned long long seed)
C++ Interface to set the seed of the random engine.
unsigned long long getSeed(void) const
C++ Interface to return the seed of the random engine.
void setType(const randomEngineType type)
C++ Interface to set the random type of the random engine.
randomEngine & operator=(const randomEngine &other)
C++ Interface to assign the internal state of randome engine.
randomEngine(randomEngineType typeIn=AF_RANDOM_ENGINE_DEFAULT, unsigned long long seedIn=0)
C++ Interface to create a af::randomEngine object with a af::randomEngineType and a seed.
randomEngine(af_random_engine engine)
C++ Interface to create a copy of the random engine object from a af_random_engine handle.
randomEngine(const randomEngine &other)
C++ Interface copy constructor for a af::randomEngine.
af_random_engine get(void) const
C++ Interface to return the af_random_engine handle of this object.
~randomEngine()
C++ Interface destructor for a af::randomEngine.
af_dtype
Definition: defines.h:210
@ f32
32-bit floating point values
Definition: defines.h:211
long long dim_t
Definition: defines.h:56
af_random_engine_type
Definition: defines.h:439
@ AF_RANDOM_ENGINE_DEFAULT
Definition: defines.h:446
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:240
#define AFAPI
Definition: defines.h:38
AFAPI randomEngine getDefaultRandomEngine(void)
C++ Interface to get the default random engine type.
AFAPI af_err af_get_default_random_engine(af_random_engine *engine)
C Interface to get the default random engine.
AFAPI unsigned long long getSeed()
C++ Interface to get the seed of the default random number generator.
AFAPI af_err af_get_seed(unsigned long long *seed)
AFAPI af_err af_random_normal(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type, af_random_engine engine)
C Interface to create an array of normal numbers using a random engine.
AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers normally distributed.
AFAPI af_err af_retain_random_engine(af_random_engine *out, const af_random_engine engine)
C Interface to retain a random engine.
AFAPI af_err af_random_engine_get_seed(unsigned long long *const seed, af_random_engine engine)
C Interface to get the seed of a random engine.
AFAPI af_err af_random_engine_set_type(af_random_engine *engine, const af_random_engine_type rtype)
C Interface to change random engine type.
AFAPI af_err af_release_random_engine(af_random_engine engine)
C Interface to release a random engine.
AFAPI af_err af_create_random_engine(af_random_engine *engine, af_random_engine_type rtype, unsigned long long seed)
C Interface to create a random engine.
AFAPI af_err af_random_engine_get_type(af_random_engine_type *rtype, const af_random_engine engine)
C Interface to get random engine type.
AFAPI af_err af_random_engine_set_seed(af_random_engine *engine, const unsigned long long seed)
C Interface to set the seed of a random engine.
AFAPI af_err af_random_uniform(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type, af_random_engine engine)
C Interface to create an array of uniform numbers using a random engine.
AFAPI af_err af_randu(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
AFAPI void setDefaultRandomEngineType(randomEngineType rtype)
C++ Interface to set the default random engine type.
AFAPI af_err af_set_default_random_engine_type(const af_random_engine_type rtype)
C Interface to set the type of the default random engine.
AFAPI void setSeed(const unsigned long long seed)
C++ Interface to set the seed of the default random number generator.
AFAPI af_err af_set_seed(const unsigned long long seed)
void * af_random_engine
Handle for a random engine object.
Definition: random.h:19
Definition: algorithm.h:15