A high-performance general-purpose compute library
data.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
13#ifdef __cplusplus
14#include <af/dim4.hpp>
15#include <af/traits.hpp>
16namespace af
17{
18 class array;
19
29 template<typename T>
30 array constant(T val, const dim4 &dims, const dtype ty=(af_dtype)dtype_traits<T>::ctype);
31
41 template<typename T>
43
54 template<typename T>
55 array constant(T val, const dim_t d0, const dim_t d1, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
56
68 template<typename T>
69 array constant(T val, const dim_t d0, const dim_t d1, const dim_t d2, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
70
83 template<typename T>
84 array constant(T val, const dim_t d0, const dim_t d1, const dim_t d2, const dim_t d3, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
85
93 AFAPI array identity(const dim4 &dims, const dtype ty=f32);
94
102 AFAPI array identity(const dim_t d0, const dtype ty=f32);
103
112 AFAPI array identity(const dim_t d0, const dim_t d1, const dtype ty=f32);
113
123 AFAPI array identity(const dim_t d0, const dim_t d1,
124 const dim_t d2, const dtype ty=f32);
125
136 AFAPI array identity(const dim_t d0, const dim_t d1,
137 const dim_t d2, const dim_t d3, const dtype ty=f32);
138
148 AFAPI array range(const dim4 &dims, const int seq_dim = -1, const dtype ty=f32);
149
163 AFAPI array range(const dim_t d0, const dim_t d1 = 1, const dim_t d2 = 1,
164 const dim_t d3 = 1, const int seq_dim = -1, const dtype ty=f32);
165
175 AFAPI array iota(const dim4 &dims, const dim4 &tile_dims = dim4(1), const dtype ty=f32);
176
186 AFAPI array diag(const array &in, const int num = 0, const bool extract = true);
187
198 AFAPI array join(const int dim, const array &first, const array &second);
199
211 AFAPI array join(const int dim, const array &first, const array &second, const array &third);
212
225 AFAPI array join(const int dim, const array &first, const array &second,
226 const array &third, const array &fourth);
227
240 AFAPI array tile(const array &in, const unsigned x, const unsigned y=1,
241 const unsigned z=1, const unsigned w=1);
242
254 AFAPI array tile(const array &in, const dim4 &dims);
255
266 AFAPI array reorder(const array& in, const unsigned x,
267 const unsigned y=1, const unsigned z=2, const unsigned w=3);
268
279 AFAPI array shift(const array& in, const int x, const int y=0, const int z=0, const int w=0);
280
289 AFAPI array moddims(const array& in, const dim4& dims);
290
302 AFAPI array moddims(const array& in, const dim_t d0, const dim_t d1=1, const dim_t d2=1, const dim_t d3=1);
303
313 AFAPI array moddims(const array& in, const unsigned ndims, const dim_t* const dims);
314
321 AFAPI array flat(const array &in);
322
330 AFAPI array flip(const array &in, const unsigned dim);
331
339 AFAPI array lower(const array &in, bool is_unit_diag=false);
340
348 AFAPI array upper(const array &in, bool is_unit_diag=false);
349
350#if AF_API_VERSION >= 31
359 AFAPI array select(const array &cond, const array &a, const array &b);
360#endif
361
362#if AF_API_VERSION >= 31
371 AFAPI array select(const array &cond, const array &a, const double &b);
372#endif
373
374#if AF_API_VERSION >= 31
383 AFAPI array select(const array &cond, const double &a, const array &b);
384#endif
385
386#if AF_API_VERSION >= 31
398 AFAPI void replace(array &a, const array &cond, const array &b);
399#endif
400
401#if AF_API_VERSION >= 31
411 AFAPI void replace(array &a, const array &cond, const double &b);
412#endif
413
414#if AF_API_VERSION >= 37
426 AFAPI array pad(const array &in, const dim4 &beginPadding,
427 const dim4 &endPadding, const borderType padFillType);
428#endif
429
430#if AF_API_VERSION >= 39
440 AFAPI void replace(array &a, const array &cond, const long long b);
441
451 AFAPI void replace(array &a, const array &cond,
452 const unsigned long long b);
453
462 AFAPI array select(const array &cond, const array &a, const long long b);
463
472 AFAPI array select(const array &cond, const array &a,
473 const unsigned long long b);
474
483 AFAPI array select(const array &cond, const long long a, const array &b);
484
493 AFAPI array select(const array &cond, const unsigned long long a,
494 const array &b);
495#endif
496}
497#endif
498
499#ifdef __cplusplus
500extern "C" {
501#endif
515 AFAPI af_err af_constant(af_array *arr, const double val, const unsigned ndims, const dim_t * const dims, const af_dtype type);
516
532 AFAPI af_err af_constant_complex(af_array *arr, const double real, const double imag,
533 const unsigned ndims, const dim_t * const dims, const af_dtype type);
534
549 AFAPI af_err af_constant_long (af_array *arr, const long long val, const unsigned ndims, const dim_t * const dims);
550
566 AFAPI af_err af_constant_ulong(af_array *arr, const unsigned long long val, const unsigned ndims, const dim_t * const dims);
567
580 AFAPI af_err af_identity(af_array* out, const unsigned ndims, const dim_t* const dims, const af_dtype type);
581
596 AFAPI af_err af_range(af_array *out, const unsigned ndims, const dim_t * const dims,
597 const int seq_dim, const af_dtype type);
598
614 AFAPI af_err af_iota(af_array *out, const unsigned ndims, const dim_t * const dims,
615 const unsigned t_ndims, const dim_t * const tdims, const af_dtype type);
616
631 AFAPI af_err af_diag_create(af_array *out, const af_array in, const int num);
632
646 AFAPI af_err af_diag_extract(af_array *out, const af_array in, const int num);
647
662 AFAPI af_err af_join(af_array *out, const int dim, const af_array first, const af_array second);
663
679 AFAPI af_err af_join_many(af_array *out, const int dim, const unsigned n_arrays, const af_array *inputs);
680
698 const unsigned x, const unsigned y, const unsigned z, const unsigned w);
699
715 const unsigned x, const unsigned y, const unsigned z, const unsigned w);
716
731 AFAPI af_err af_shift(af_array *out, const af_array in, const int x, const int y, const int z, const int w);
732
746 AFAPI af_err af_moddims(af_array *out, const af_array in, const unsigned ndims, const dim_t * const dims);
747
759
771 AFAPI af_err af_flip(af_array *out, const af_array in, const unsigned dim);
772
784 AFAPI af_err af_lower(af_array *out, const af_array in, bool is_unit_diag);
785
797 AFAPI af_err af_upper(af_array *out, const af_array in, bool is_unit_diag);
798
799#if AF_API_VERSION >= 31
812 AFAPI af_err af_select(af_array *out, const af_array cond, const af_array a, const af_array b);
813#endif
814
815#if AF_API_VERSION >= 31
828 AFAPI af_err af_select_scalar_r(af_array *out, const af_array cond, const af_array a, const double b);
829#endif
830
831#if AF_API_VERSION >= 31
844 AFAPI af_err af_select_scalar_l(af_array *out, const af_array cond, const double a, const af_array b);
845#endif
846
847#if AF_API_VERSION >= 31
864#endif
865
866#if AF_API_VERSION >= 31
880 AFAPI af_err af_replace_scalar(af_array a, const af_array cond, const double b);
881#endif
882
883#if AF_API_VERSION >= 37
902 const unsigned begin_ndims,
903 const dim_t *const begin_dims, const unsigned end_ndims,
904 const dim_t *const end_dims,
905 const af_border_type pad_fill_type);
906#endif
907
908#if AF_API_VERSION >= 39
923 const long long b);
924
939 const unsigned long long b);
940
954 const af_array a, const long long b);
955
969 const af_array a,
970 const unsigned long long b);
971
985 const long long a, const af_array b);
986
1000 const unsigned long long a,
1001 const af_array b);
1002#endif
1003
1004#ifdef __cplusplus
1005}
1006#endif
A multi dimensional data container.
Definition: array.h:37
Generic object that represents size and shape.
Definition: dim4.hpp:26
af_dtype
Definition: defines.h:210
@ f32
32-bit floating point values
Definition: defines.h:211
af_border_type
Definition: defines.h:266
long long dim_t
Definition: defines.h:56
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:240
#define AFAPI
Definition: defines.h:38
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
AFAPI af_err af_constant_long(af_array *arr, const long long val, const unsigned ndims, const dim_t *const dims)
C Interface to generate an array with elements set to a specified value.
AFAPI af_err af_constant_complex(af_array *arr, const double real, const double imag, const unsigned ndims, const dim_t *const dims, const af_dtype type)
C Interface to generate a complex array with elements set to a specified value.
AFAPI af_err af_constant_ulong(af_array *arr, const unsigned long long val, const unsigned ndims, const dim_t *const dims)
C Interface to generate an array with elements set to a specified value.
AFAPI af_err af_constant(af_array *arr, const double val, const unsigned ndims, const dim_t *const dims, const af_dtype type)
C Interface to generate an array with elements set to a specified value.
AFAPI af_err af_diag_extract(af_array *out, const af_array in, const int num)
C Interface to extract the diagonal from an array.
AFAPI array diag(const array &in, const int num=0, const bool extract=true)
C++ Interface to extract the diagonal from an array.
AFAPI af_err af_diag_create(af_array *out, const af_array in, const int num)
C Interface to create a diagonal matrix from an extracted diagonal array.
AFAPI array identity(const dim4 &dims, const dtype ty=f32)
C++ Interface to generate an identity array.
AFAPI af_err af_identity(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
C Interface to generate an identity array.
AFAPI af_err af_iota(af_array *out, const unsigned ndims, const dim_t *const dims, const unsigned t_ndims, const dim_t *const tdims, const af_dtype type)
C Interface to generate an array with [0, n-1] values modified to specified dimensions and tiling.
AFAPI array iota(const dim4 &dims, const dim4 &tile_dims=dim4(1), const dtype ty=f32)
C++ Interface to generate an array with [0, n-1] values modified to specified dimensions and tiling.
AFAPI af_err af_lower(af_array *out, const af_array in, bool is_unit_diag)
C Interface to return the lower triangle array.
AFAPI array lower(const array &in, bool is_unit_diag=false)
C++ Interface to return the lower triangle array.
AFAPI af_err af_pad(af_array *out, const af_array in, const unsigned begin_ndims, const dim_t *const begin_dims, const unsigned end_ndims, const dim_t *const end_dims, const af_border_type pad_fill_type)
C Interface to pad an array.
AFAPI array pad(const array &in, const dim4 &beginPadding, const dim4 &endPadding, const borderType padFillType)
C++ Interface to pad an array.
AFAPI array range(const dim4 &dims, const int seq_dim=-1, const dtype ty=f32)
C++ Interface to generate an array with [0, n-1] values along the seq_dim dimension and tiled across ...
AFAPI af_err af_range(af_array *out, const unsigned ndims, const dim_t *const dims, const int seq_dim, const af_dtype type)
C Interface to generate an array with [0, n-1] values along the seq_dim dimension and tiled across ot...
AFAPI void replace(array &a, const array &cond, const array &b)
C++ Interface to replace elements of an array with elements of another array.
AFAPI af_err af_replace_scalar_long(af_array a, const af_array cond, const long long b)
C Interface to replace elements of an array with a scalar value.
AFAPI af_err af_replace_scalar(af_array a, const af_array cond, const double b)
C Interface to replace elements of an array with a scalar value.
AFAPI af_err af_replace(af_array a, const af_array cond, const af_array b)
C Interface to replace elements of an array with elements of another array.
AFAPI af_err af_replace_scalar_ulong(af_array a, const af_array cond, const unsigned long long b)
C Interface to replace elements of an array with a scalar value.
AFAPI af_err af_select_scalar_l_long(af_array *out, const af_array cond, const long long a, const af_array b)
C Interface to select elements based on a conditional array.
AFAPI af_err af_select_scalar_l(af_array *out, const af_array cond, const double a, const af_array b)
C Interface to select elements based on a conditional array.
AFAPI array select(const array &cond, const array &a, const array &b)
C++ Interface to select elements based on a conditional array.
AFAPI af_err af_select_scalar_l_ulong(af_array *out, const af_array cond, const unsigned long long a, const af_array b)
C Interface to select elements based on a conditional array.
AFAPI af_err af_select_scalar_r_ulong(af_array *out, const af_array cond, const af_array a, const unsigned long long b)
C Interface to select elements based on a conditional array.
AFAPI af_err af_select_scalar_r_long(af_array *out, const af_array cond, const af_array a, const long long b)
C Interface to select elements based on a conditional array.
AFAPI af_err af_select_scalar_r(af_array *out, const af_array cond, const af_array a, const double b)
C Interface to select elements based on a conditional array.
AFAPI af_err af_select(af_array *out, const af_array cond, const af_array a, const af_array b)
C Interface to select elements based on a conditional array.
AFAPI af_err af_upper(af_array *out, const af_array in, bool is_unit_diag)
C Interface to return the upper triangle array.
AFAPI array upper(const array &in, bool is_unit_diag=false)
C++ Interface to return the upper triangle array.
AFAPI array flat(const array &in)
C++ Interface to flatten an array.
AFAPI af_err af_flat(af_array *out, const af_array in)
C Interface to flatten an array.
AFAPI array flip(const array &in, const unsigned dim)
C++ Interface to flip an array.
AFAPI af_err af_flip(af_array *out, const af_array in, const unsigned dim)
C Interface to flip an array.
AFAPI af_err af_join(af_array *out, const int dim, const af_array first, const af_array second)
C Interface to join 2 arrays along a dimension.
AFAPI af_err af_join_many(af_array *out, const int dim, const unsigned n_arrays, const af_array *inputs)
C Interface to join many arrays along a dimension.
AFAPI array join(const int dim, const array &first, const array &second)
C++ Interface to join 2 arrays along a dimension.
AFAPI array moddims(const array &in, const dim4 &dims)
C++ Interface to modify the dimensions of an input array to a specified shape.
AFAPI af_err af_moddims(af_array *out, const af_array in, const unsigned ndims, const dim_t *const dims)
C Interface to modify the dimensions of an input array to a specified shape.
AFAPI af_err af_reorder(af_array *out, const af_array in, const unsigned x, const unsigned y, const unsigned z, const unsigned w)
C Interface to reorder an array.
AFAPI array reorder(const array &in, const unsigned x, const unsigned y=1, const unsigned z=2, const unsigned w=3)
C++ Interface to reorder an array.
AFAPI af_err af_shift(af_array *out, const af_array in, const int x, const int y, const int z, const int w)
C Interface to shift an array.
AFAPI array shift(const array &in, const int x, const int y=0, const int z=0, const int w=0)
C++ Interface to shift an array.
AFAPI af_err af_tile(af_array *out, const af_array in, const unsigned x, const unsigned y, const unsigned z, const unsigned w)
C Interface to generate a tiled array.
AFAPI array tile(const array &in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)
C++ Interface to generate a tiled array.
Definition: algorithm.h:15