$darkmode
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 
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
27  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
121 
132  AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r);
133 #endif
134 
135 #if AF_API_VERSION >= 34
136 
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
288 
296 #endif
297 
298 #if AF_API_VERSION >= 34
299 
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
335 
347  af_random_engine_type rtype,
348  unsigned long long seed);
349 #endif
350 
351 #if AF_API_VERSION >= 34
352 
363  const af_random_engine engine);
364 #endif
365 
366 #if AF_API_VERSION >= 34
367 
378  const af_random_engine_type rtype);
379 #endif
380 
381 #if AF_API_VERSION >= 34
382 
393  const af_random_engine engine);
394 #endif
395 
396 #if AF_API_VERSION >= 34
397 
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
417 
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
437 
448  const unsigned long long seed);
449 #endif
450 
451 #if AF_API_VERSION >= 34
452 
462 #endif
463 
464 #if AF_API_VERSION >= 34
465 
475 #endif
476 
477 #if AF_API_VERSION >= 34
478 
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
493 
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
AFAPI af_err af_randu(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
af_random_engine_type
Definition: defines.h:439
AFAPI void setSeed(const unsigned long long seed)
C++ Interface to set the seed of the default random number generator.
Definition: algorithm.h:14
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
AFAPI af_err af_set_seed(const unsigned long long seed)
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_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_type randomEngineType
Definition: defines.h:589
AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype 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.
void * af_random_engine
Handle for a random engine object.
Definition: random.h:19
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_err
Definition: defines.h:71
AFAPI af_err af_get_seed(unsigned long long *seed)
long long dim_t
Definition: defines.h:56
AFAPI af_err af_release_random_engine(af_random_engine engine)
C Interface to release a random engine.
#define AFAPI
Definition: defines.h:38
AFAPI unsigned long long getSeed()
C++ Interface to get the seed of the default random number generator.
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_random_engine_set_type(af_random_engine *engine, const af_random_engine_type rtype)
C Interface to change random engine type.
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:330
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 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_get_default_random_engine(af_random_engine *engine)
C Interface to get the default random engine.
void * af_array
Definition: defines.h:240
AFAPI randomEngine getDefaultRandomEngine(void)
C++ Interface to get the default random engine type.
32-bit floating point values
Definition: defines.h:211
AFAPI void setDefaultRandomEngineType(randomEngineType rtype)
C++ Interface to set the default random engine type.
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_dtype
Definition: defines.h:210
af_dtype dtype
Definition: defines.h:553