random.h (2022-02-24 14:07:56 -0500, (build 8c2561559))
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
130 AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r);
131#endif
132
133#if AF_API_VERSION >= 34
143 AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r);
144#endif
145
154 AFAPI array randu(const dim4 &dims, const dtype ty=f32);
155
164 AFAPI array randu(const dim_t d0, const dtype ty=f32);
165
176 const dim_t d1, const dtype ty=f32);
177
189 const dim_t d1, const dim_t d2, const dtype ty=f32);
190
203 const dim_t d1, const dim_t d2,
204 const dim_t d3, const dtype ty=f32);
205
214 AFAPI array randn(const dim4 &dims, const dtype ty=f32);
215
224 AFAPI array randn(const dim_t d0, const dtype ty=f32);
235 const dim_t d1, const dtype ty=f32);
247 const dim_t d1, const dim_t d2, const dtype ty=f32);
248
261 const dim_t d1, const dim_t d2,
262 const dim_t d3, const dtype ty=f32);
263
264#if AF_API_VERSION >= 34
271#endif
272
273#if AF_API_VERSION >= 34
280#endif
281
288 AFAPI void setSeed(const unsigned long long seed);
289
296 AFAPI unsigned long long getSeed();
297
298}
299#endif
300
301#ifdef __cplusplus
302extern "C" {
303#endif
304
305#if AF_API_VERSION >= 34
319 unsigned long long seed);
320#endif
321
322#if AF_API_VERSION >= 34
334 const af_random_engine engine);
335#endif
336
337#if AF_API_VERSION >= 34
349 const af_random_engine_type rtype);
350#endif
351
352#if AF_API_VERSION >= 34
364 const af_random_engine engine);
365#endif
366
367#if AF_API_VERSION >= 34
384 AFAPI af_err af_random_uniform(af_array *out, const unsigned ndims,
385 const dim_t * const dims, const af_dtype type,
386 af_random_engine engine);
387#endif
388
389#if AF_API_VERSION >= 34
405 AFAPI af_err af_random_normal(af_array *out, const unsigned ndims,
406 const dim_t * const dims, const af_dtype type,
407 af_random_engine engine);
408#endif
409
410#if AF_API_VERSION >= 34
422 const unsigned long long seed);
423#endif
424
425#if AF_API_VERSION >= 34
436#endif
437
438#if AF_API_VERSION >= 34
449#endif
450
451#if AF_API_VERSION >= 34
462 AFAPI af_err af_random_engine_get_seed(unsigned long long * const seed,
463 af_random_engine engine);
464#endif
465
466#if AF_API_VERSION >= 34
476#endif
477
486 AFAPI af_err af_randu(af_array *out, const unsigned ndims,
487 const dim_t * const dims, const af_dtype type);
488
497 AFAPI af_err af_randn(af_array *out, const unsigned ndims,
498 const dim_t * const dims, const af_dtype type);
499
505 AFAPI af_err af_set_seed(const unsigned long long seed);
506
512 AFAPI af_err af_get_seed(unsigned long long *seed);
513
514#ifdef __cplusplus
515}
516#endif
A multi dimensional data container.
Definition: array.h:37
Generic object that represents size and shape.
Definition: dim4.hpp:26
Random Number Generation Engine Class.
Definition: random.h:34
randomEngineType getType(void)
Return the random type of the random engine.
void setSeed(const unsigned long long seed)
Sets the seed of the random engine.
unsigned long long getSeed(void) const
Returns the seed of the random engine.
void setType(const randomEngineType type)
Sets the random type of the random engine.
randomEngine & operator=(const randomEngine &other)
Assigns the internal state of randome engine.
randomEngine(randomEngineType typeIn=AF_RANDOM_ENGINE_DEFAULT, unsigned long long seedIn=0)
This function creates a af::randomEngine object with a af::randomEngineType and a seed.
randomEngine(af_random_engine engine)
Creates a copy of the random engine object from a af_random_engine handle.
randomEngine(const randomEngine &other)
Copy constructor for af::randomEngine.
af_random_engine get(void) const
Returns the af_random_engine handle of this object.
~randomEngine()
Destructor for 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:438
@ AF_RANDOM_ENGINE_DEFAULT
Definition: defines.h:445
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:240
#define AFAPI
Definition: defines.h:38
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
Definition: opencl.h:327
AFAPI af_err af_get_default_random_engine(af_random_engine *engine)
C Interface for getting the default random engine.
AFAPI randomEngine getDefaultRandomEngine(void)
AFAPI unsigned long long getSeed()
Gets 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 for creating an array of normal numbers using a random engine.
AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r)
AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
AFAPI af_err af_retain_random_engine(af_random_engine *out, const af_random_engine engine)
C Interface for retaining random engine.
AFAPI af_err af_random_engine_get_seed(unsigned long long *const seed, af_random_engine engine)
C Interface for getting 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 for changing random engine type.
AFAPI af_err af_release_random_engine(af_random_engine engine)
C Interface for releasing random engine.
AFAPI af_err af_create_random_engine(af_random_engine *engine, af_random_engine_type rtype, unsigned long long seed)
C Interface for creating random engine.
AFAPI af_err af_random_engine_get_type(af_random_engine_type *rtype, const af_random_engine engine)
C Interface for getting random engine type.
AFAPI af_err af_random_engine_set_seed(af_random_engine *engine, const unsigned long long seed)
C Interface for setting 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 for creating 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)
AFAPI af_err af_set_default_random_engine_type(const af_random_engine_type rtype)
C Interface for setting the type of the default random engine.
AFAPI void setDefaultRandomEngineType(randomEngineType rtype)
AFAPI af_err af_set_seed(const unsigned long long seed)
AFAPI void setSeed(const unsigned long long seed)
Sets the seed of the default random number generator.
void * af_random_engine
Handle for random engine.
Definition: random.h:19
Definition: algorithm.h:15