random.h Source File

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
18 typedef void * af_random_engine;
19
20 #ifdef __cplusplus
21 namespace af
22 {
23 class array;
24 class dim4;
25 #if AF_API_VERSION >= 34
26 class AFAPI randomEngine
31 {
32 private:
38 af_random_engine engine;
39 public:
50 explicit
51 randomEngine(randomEngineType typeIn = AF_RANDOM_ENGINE_DEFAULT, uintl seedIn = 0);
52
60 randomEngine(const randomEngine& in);
61
69 randomEngine(af_random_engine engine);
70
78 ~randomEngine();
79
91 randomEngine& operator= (const randomEngine& in);
92
102 void setType(const randomEngineType type);
103
113 randomEngineType getType(void);
114
124 void setSeed(const uintl seed);
125
135 uintl getSeed(void) const;
136
146 af_random_engine get(void) const;
147 };
148 #endif
149
150 #if AF_API_VERSION >= 34
151
160 AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r);
161 #endif
162
163 #if AF_API_VERSION >= 34
164
173 AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r);
174 #endif
175
184 AFAPI array randu(const dim4 &dims, const dtype ty=f32);
185
194 AFAPI array randu(const dim_t d0, const dtype ty=f32);
195
205 AFAPI array randu(const dim_t d0,
206 const dim_t d1, const dtype ty=f32);
207
218 AFAPI array randu(const dim_t d0,
219 const dim_t d1, const dim_t d2, const dtype ty=f32);
220
232 AFAPI array randu(const dim_t d0,
233 const dim_t d1, const dim_t d2,
234 const dim_t d3, const dtype ty=f32);
235
244 AFAPI array randn(const dim4 &dims, const dtype ty=f32);
245
254 AFAPI array randn(const dim_t d0, const dtype ty=f32);
264 AFAPI array randn(const dim_t d0,
265 const dim_t d1, const dtype ty=f32);
276 AFAPI array randn(const dim_t d0,
277 const dim_t d1, const dim_t d2, const dtype ty=f32);
278
290 AFAPI array randn(const dim_t d0,
291 const dim_t d1, const dim_t d2,
292 const dim_t d3, const dtype ty=f32);
293
294 #if AF_API_VERSION >= 34
295
300 AFAPI void setDefaultRandomEngineType(randomEngineType rtype);
301 #endif
302
303 #if AF_API_VERSION >= 34
304
309 AFAPI randomEngine getDefaultRandomEngine(void);
310 #endif
311
317 AFAPI void setSeed(const uintl seed);
318
324 AFAPI uintl getSeed();
325
326 }
327 #endif
328
329 #ifdef __cplusplus
330 extern "C" {
331 #endif
332
333 #if AF_API_VERSION >= 34
334
345 AFAPI af_err af_create_random_engine(af_random_engine *engine, af_random_engine_type rtype, uintl seed);
346 #endif
347
348 #if AF_API_VERSION >= 34
349
359 AFAPI af_err af_retain_random_engine(af_random_engine *out, const af_random_engine engine);
360 #endif
361
362 #if AF_API_VERSION >= 34
363
373 AFAPI af_err af_random_engine_set_type(af_random_engine *engine, const af_random_engine_type rtype);
374 #endif
375
376 #if AF_API_VERSION >= 34
377
387 AFAPI af_err af_random_engine_get_type(af_random_engine_type *rtype, const af_random_engine engine);
388 #endif
389
390 #if AF_API_VERSION >= 34
391
404 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);
405 #endif
406
407 #if AF_API_VERSION >= 34
408
421 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);
422 #endif
423
424 #if AF_API_VERSION >= 34
425
435 AFAPI af_err af_random_engine_set_seed(af_random_engine *engine, const uintl seed);
436 #endif
437
438 #if AF_API_VERSION >= 34
439
448 AFAPI af_err af_get_default_random_engine(af_random_engine *engine);
449 #endif
450
451 #if AF_API_VERSION >= 34
452
461 AFAPI af_err af_set_default_random_engine_type(const af_random_engine_type rtype);
462 #endif
463
464 #if AF_API_VERSION >= 34
465
475 AFAPI af_err af_random_engine_get_seed(uintl * const seed, af_random_engine engine);
476 #endif
477
478 #if AF_API_VERSION >= 34
479
487 AFAPI af_err af_release_random_engine(af_random_engine engine);
488 #endif
489
498 AFAPI af_err af_randu(af_array *out, const unsigned ndims, const dim_t * const dims, const af_dtype type);
499
508 AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t * const dims, const af_dtype type);
509
515 AFAPI af_err af_set_seed(const uintl seed);
516
522 AFAPI af_err af_get_seed(uintl *seed);
523
524 #ifdef __cplusplus
525 }
526 #endif
af_randu
AFAPI af_err af_randu(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
af_random_engine_type
af_random_engine_type
Definition: defines.h:410
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 for changing random engine type.
af
Definition: algorithm.h:14
af_random_engine_get_seed
AFAPI af_err af_random_engine_get_seed(uintl *const seed, af_random_engine engine)
C Interface for getting the seed of a random engine.
af::getSeed
AFAPI uintl getSeed()
af_release_random_engine
AFAPI af_err af_release_random_engine(af_random_engine engine)
C Interface for releasing random engine.
af::randu
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
af_random_engine_set_seed
AFAPI af_err af_random_engine_set_seed(af_random_engine *engine, const uintl seed)
C Interface for setting the seed of a random engine.
af::randomEngineType
af_random_engine_type randomEngineType
Definition: defines.h:504
af_randn
AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
af_err
af_err
Definition: defines.h:63
defines.h
af_create_random_engine
AFAPI af_err af_create_random_engine(af_random_engine *engine, af_random_engine_type rtype, uintl seed)
C Interface for creating random engine.
af_set_seed
AFAPI af_err af_set_seed(const uintl seed)
dim_t
long long dim_t
Definition: defines.h:50
af::setDefaultRandomEngineType
AFAPI void setDefaultRandomEngineType(randomEngineType rtype)
af_get_seed
AFAPI af_err af_get_seed(uintl *seed)
AFAPI
#define AFAPI
Definition: defines.h:31
af_set_default_random_engine_type
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.
af::randn
AFAPI array randn(const dim4 &dims, const dtype ty, randomEngine &r)
AF_RANDOM_ENGINE_DEFAULT
Definition: defines.h:417
afcl::array
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
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 for creating an array of normal numbers using a random engine.
uintl
unsigned long long uintl
Definition: defines.h:56
af_get_default_random_engine
AFAPI af_err af_get_default_random_engine(af_random_engine *engine)
C Interface for getting the default random engine.
af_retain_random_engine
AFAPI af_err af_retain_random_engine(af_random_engine *out, const af_random_engine engine)
C Interface for retaining random engine.
af_array
void * af_array
Definition: defines.h:222
af::getDefaultRandomEngine
AFAPI randomEngine getDefaultRandomEngine(void)
af::setSeed
AFAPI void setSeed(const uintl seed)
f32
32-bit floating point values
Definition: defines.h:196
af_random_engine
void * af_random_engine
Handle for random engine.
Definition: random.h:18
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 for creating an array of uniform numbers using a random engine.
af_dtype
af_dtype
Definition: defines.h:195
af::dtype
af_dtype dtype
Definition: defines.h:468
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 for getting random engine type.