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 
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 
346 #endif
347 
348 #if AF_API_VERSION >= 34
349 
360 #endif
361 
362 #if AF_API_VERSION >= 34
363 
374 #endif
375 
376 #if AF_API_VERSION >= 34
377 
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 
436 #endif
437 
438 #if AF_API_VERSION >= 34
439 
449 #endif
450 
451 #if AF_API_VERSION >= 34
452 
462 #endif
463 
464 #if AF_API_VERSION >= 34
465 
476 #endif
477 
478 #if AF_API_VERSION >= 34
479 
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
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:410
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.
Definition: algorithm.h:14
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.
AFAPI uintl getSeed()
AFAPI af_err af_release_random_engine(af_random_engine engine)
C Interface for releasing random engine.
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
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_random_engine_type randomEngineType
Definition: defines.h:497
AFAPI af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
af_err
Definition: defines.h:63
AFAPI af_err af_create_random_engine(af_random_engine *engine, af_random_engine_type rtype, uintl seed)
C Interface for creating random engine.
AFAPI af_err af_set_seed(const uintl seed)
long long dim_t
Definition: defines.h:50
AFAPI void setDefaultRandomEngineType(randomEngineType rtype)
AFAPI af_err af_get_seed(uintl *seed)
#define AFAPI
Definition: defines.h:31
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 array randn(const dim4 &dims, const dtype ty, randomEngine &r)
Definition: defines.h:417
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_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.
unsigned long long uintl
Definition: defines.h:56
AFAPI af_err af_get_default_random_engine(af_random_engine *engine)
C Interface for getting the default random engine.
AFAPI af_err af_retain_random_engine(af_random_engine *out, const af_random_engine engine)
C Interface for retaining random engine.
void * af_array
Definition: defines.h:222
AFAPI randomEngine getDefaultRandomEngine(void)
AFAPI void setSeed(const uintl seed)
32-bit floating point values
Definition: defines.h:196
void * af_random_engine
Handle for random engine.
Definition: random.h:18
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
Definition: defines.h:195
af_dtype dtype
Definition: defines.h:461
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.