A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

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
19 typedef void * af_random_engine;
20
21#ifdef __cplusplus
22 namespace af
23{
24 class array;
25 class dim4;
26#if AF_API_VERSION >= 34
34 class AFAPI randomEngine {
35 private:
38 af_random_engine engine;
39
40 public:
50 explicit randomEngine(randomEngineType typeIn = AF_RANDOM_ENGINE_DEFAULT,
51 unsigned long long seedIn = 0);
52
58 randomEngine(const randomEngine &other);
59
66 randomEngine(af_random_engine engine);
67
71 ~randomEngine();
72
80 randomEngine &operator=(const randomEngine &other);
81
87 void setType(const randomEngineType type);
88
94 randomEngineType getType(void);
95
101 void setSeed(const unsigned long long seed);
102
108 unsigned long long getSeed(void) const;
109
116 af_random_engine get(void) const;
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
184 AFAPI array randu(const dim_t d0,
185 const dim_t d1, const dtype ty=f32);
186
199 AFAPI array randu(const dim_t d0,
200 const dim_t d1, const dim_t d2, const dtype ty=f32);
201
215 AFAPI array randu(const dim_t d0,
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);
253 AFAPI array randn(const dim_t d0,
254 const dim_t d1, const dtype ty=f32);
267 AFAPI array randn(const dim_t d0,
268 const dim_t d1, const dim_t d2, const dtype ty=f32);
269
283 AFAPI array randn(const dim_t d0,
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
295 AFAPI void setDefaultRandomEngineType(randomEngineType rtype);
296#endif
297
298#if AF_API_VERSION >= 34
306 AFAPI randomEngine getDefaultRandomEngine(void);
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
331 extern "C" {
332#endif
333
334#if AF_API_VERSION >= 34
346 AFAPI af_err af_create_random_engine(af_random_engine *engine,
347 af_random_engine_type rtype,
348 unsigned long long seed);
349#endif
350
351#if AF_API_VERSION >= 34
362 AFAPI af_err af_retain_random_engine(af_random_engine *out,
363 const af_random_engine engine);
364#endif
365
366#if AF_API_VERSION >= 34
377 AFAPI af_err af_random_engine_set_type(af_random_engine *engine,
378 const af_random_engine_type rtype);
379#endif
380
381#if AF_API_VERSION >= 34
392 AFAPI af_err af_random_engine_get_type(af_random_engine_type *rtype,
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
447 AFAPI af_err af_random_engine_set_seed(af_random_engine *engine,
448 const unsigned long long seed);
449#endif
450
451#if AF_API_VERSION >= 34
461 AFAPI af_err af_get_default_random_engine(af_random_engine *engine);
462#endif
463
464#if AF_API_VERSION >= 34
474 AFAPI af_err af_set_default_random_engine_type(const af_random_engine_type rtype);
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
502 AFAPI af_err af_release_random_engine(af_random_engine engine);
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
af::array
A multi dimensional data container.
Definition array.h:37
af::dim4
Generic object that represents size and shape.
Definition dim4.hpp:26
af::randomEngine
C++ Interface - Random Number Generation Engine Class.
Definition random.h:34
af::randomEngine::getType
randomEngineType getType(void)
C++ Interface to get the random type of the random engine.
af::randomEngine::setSeed
void setSeed(const unsigned long long seed)
C++ Interface to set the seed of the random engine.
af::randomEngine::getSeed
unsigned long long getSeed(void) const
C++ Interface to return the seed of the random engine.
af::randomEngine::setType
void setType(const randomEngineType type)
C++ Interface to set the random type of the random engine.
af::randomEngine::operator=
randomEngine & operator=(const randomEngine &other)
C++ Interface to assign the internal state of randome engine.
af::randomEngine::randomEngine
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.
af::randomEngine::randomEngine
randomEngine(af_random_engine engine)
C++ Interface to create a copy of the random engine object from a af_random_engine handle.
af::randomEngine::randomEngine
randomEngine(const randomEngine &other)
C++ Interface copy constructor for a af::randomEngine.
af::randomEngine::get
af_random_engine get(void) const
C++ Interface to return the af_random_engine handle of this object.
af::randomEngine::~randomEngine
~randomEngine()
C++ Interface destructor for a af::randomEngine.
defines.h
af_dtype
af_dtype
Definition defines.h:210
f32
@ f32
32-bit floating point values
Definition defines.h:211
dim_t
long long dim_t
Definition defines.h:56
af_random_engine_type
af_random_engine_type
Definition defines.h:439
AF_RANDOM_ENGINE_DEFAULT
@ AF_RANDOM_ENGINE_DEFAULT
Definition defines.h:446
af_err
af_err
Definition defines.h:71
af_array
void * af_array
Definition defines.h:240
AFAPI
#define AFAPI
Definition defines.h:38
af::getDefaultRandomEngine
AFAPI randomEngine getDefaultRandomEngine(void)
C++ Interface to get the default random engine type.
af_get_default_random_engine
AFAPI af_err af_get_default_random_engine(af_random_engine *engine)
C Interface to get the default random engine.
af::getSeed
AFAPI unsigned long long getSeed()
C++ Interface to get the seed of the default random number generator.
af_get_seed
AFAPI af_err af_get_seed(unsigned long long *seed)
af_random_normal
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.
af_randn
AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
af::randn
AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers normally distributed.
af_retain_random_engine
AFAPI af_err af_retain_random_engine(af_random_engine *out, const af_random_engine engine)
C Interface to retain a random engine.
af_random_engine_get_seed
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.
af_random_engine_set_type
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.
af_release_random_engine
AFAPI af_err af_release_random_engine(af_random_engine engine)
C Interface to release a random engine.
af_create_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.
af_random_engine_get_type
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.
af_random_engine_set_seed
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.
af_random_uniform
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.
af_randu
AFAPI af_err af_randu(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
af::randu
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
af::setDefaultRandomEngineType
AFAPI void setDefaultRandomEngineType(randomEngineType rtype)
C++ Interface to set the default random engine type.
af_set_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.
af::setSeed
AFAPI void setSeed(const unsigned long long seed)
C++ Interface to set the seed of the default random number generator.
af_set_seed
AFAPI af_err af_set_seed(const unsigned long long seed)
af_random_engine
void * af_random_engine
Handle for a random engine object.
Definition random.h:19
af
Definition algorithm.h:15