$darkmode
A high-performance general-purpose compute library
array.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/compilers.h>
12 #include <af/defines.h>
13 #include <af/device.h>
14 #include <af/dim4.hpp>
15 #include <af/exception.h>
16 #include <af/index.h>
17 #include <af/seq.h>
18 #include <af/util.h>
19 
20 #ifdef __cplusplus
21 #include <af/traits.hpp>
22 
23 #if AF_API_VERSION >= 38
24 #if AF_COMPILER_CXX_GENERALIZED_INITIALIZERS
25 #include <initializer_list>
26 #endif
27 #endif
28 
29 namespace af
30 {
31 
32  class dim4;
33 
37  class AFAPI array {
38  af_array arr;
39 
40 
41  public:
48  void set(af_array tmp);
49 
57  {
58  struct array_proxy_impl; //forward declaration
59  array_proxy_impl *impl; // implementation
60 
61  public:
62  array_proxy(array& par, af_index_t *ssss, bool linear = false);
63  array_proxy(const array_proxy &other);
64 #if AF_COMPILER_CXX_RVALUE_REFERENCES
65  array_proxy(array_proxy &&other);
66  array_proxy & operator=(array_proxy &&other);
67 #endif
68  ~array_proxy();
69 
70  // Implicit conversion operators
71  operator array() const;
72  operator array();
73 
74 #define ASSIGN(OP) \
75  array_proxy& operator OP(const array_proxy &a); \
76  array_proxy& operator OP(const array &a); \
77  array_proxy& operator OP(const double &a); \
78  array_proxy& operator OP(const cdouble &a); \
79  array_proxy& operator OP(const cfloat &a); \
80  array_proxy& operator OP(const float &a); \
81  array_proxy& operator OP(const int &a); \
82  array_proxy& operator OP(const unsigned &a); \
83  array_proxy& operator OP(const bool &a); \
84  array_proxy& operator OP(const char &a); \
85  array_proxy& operator OP(const unsigned char &a); \
86  array_proxy& operator OP(const long &a); \
87  array_proxy& operator OP(const unsigned long &a); \
88  array_proxy& operator OP(const long long &a); \
89  array_proxy& operator OP(const unsigned long long &a);
90 
91  ASSIGN(=)
92  ASSIGN(+=)
93  ASSIGN(-=)
94  ASSIGN(*=)
95  ASSIGN(/=)
96 #undef ASSIGN
97 
98 #if AF_API_VERSION >= 32
99 #define ASSIGN(OP) \
100  array_proxy& operator OP(const short &a); \
101  array_proxy& operator OP(const unsigned short &a);
102 
103  ASSIGN(=)
104  ASSIGN(+=)
105  ASSIGN(-=)
106  ASSIGN(*=)
107  ASSIGN(/=)
108 #undef ASSIGN
109 #endif
110 
111  // af::array member functions. same behavior as those below
112  af_array get();
113  af_array get() const;
114  dim_t elements() const;
115  template<typename T> T* host() const;
116  void host(void *ptr) const;
117  dtype type() const;
118  dim4 dims() const;
119  dim_t dims(unsigned dim) const;
120  unsigned numdims() const;
121  size_t bytes() const;
122  size_t allocated() const;
123  array copy() const;
124  bool isempty() const;
125  bool isscalar() const;
126  bool isvector() const;
127  bool isrow() const;
128  bool iscolumn() const;
129  bool iscomplex() const;
130  inline bool isreal() const { return !iscomplex(); }
131  bool isdouble() const;
132  bool issingle() const;
133 #if AF_API_VERSION >= 37
134  bool ishalf() const;
135 #endif
136  bool isrealfloating() const;
137  bool isfloating() const;
138  bool isinteger() const;
139  bool isbool() const;
140 #if AF_API_VERSION >= 34
141  bool issparse() const;
142 #endif
143  void eval() const;
144  array as(dtype type) const;
145  array T() const;
146  array H() const;
147  template<typename T> T scalar() const;
148  template<typename T> T* device() const;
149  void unlock() const;
150 #if AF_API_VERSION >= 31
151  void lock() const;
152 #endif
153 
154 #if AF_API_VERSION >= 34
155  bool isLocked() const;
156 #endif
157 
158  array::array_proxy row(int index);
159  const array::array_proxy row(int index) const;
160 
161  array::array_proxy rows(int first, int last);
162  const array::array_proxy rows(int first, int last) const;
163 
164  array::array_proxy col(int index);
165  const array::array_proxy col(int index) const;
166  array::array_proxy cols(int first, int last);
167  const array::array_proxy cols(int first, int last) const;
168 
169  array::array_proxy slice(int index);
170  const array::array_proxy slice(int index) const;
171 
172  array::array_proxy slices(int first, int last);
173  const array::array_proxy slices(int first, int last) const;
174  };
175 
183  array();
184 
185 #if AF_API_VERSION >= 37
186 #if AF_COMPILER_CXX_RVALUE_REFERENCES
187 
195  array(array &&other) AF_NOEXCEPT;
196 
207  array &operator=(array &&other) AF_NOEXCEPT;
208 #endif
209 #endif
210 
217  explicit
218  array(const af_array handle);
219 
225  array(const array& in);
226 
249  explicit
250  array(dim_t dim0, dtype ty = f32);
251 
275  explicit
276  array(dim_t dim0, dim_t dim1, dtype ty = f32);
277 
302  explicit
303  array(dim_t dim0, dim_t dim1, dim_t dim2, dtype ty = f32);
304 
330  explicit
331  array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, dtype ty = f32);
332 
358  explicit
359  array(const dim4& dims, dtype ty = f32);
360 
388  template<typename T>
389  explicit
390  array(dim_t dim0,
391  const T *pointer, af::source src=afHost);
392 
393 
416  template<typename T>
417  explicit
418  array(dim_t dim0, dim_t dim1,
419  const T *pointer, af::source src=afHost);
420 
421 
448  template<typename T>
449  explicit
450  array(dim_t dim0, dim_t dim1, dim_t dim2,
451  const T *pointer, af::source src=afHost);
452 
453 
482  template<typename T>
483  explicit
484  array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3,
485  const T *pointer, af::source src=afHost);
486 
525  template<typename T>
526  explicit
527  array(const dim4& dims,
528  const T *pointer, af::source src=afHost);
529 
530 #if AF_API_VERSION >= 38
531 #if AF_COMPILER_CXX_GENERALIZED_INITIALIZERS
532  template <typename T, typename = typename std::enable_if<
534  std::is_fundamental<T>::value, void>::type>
535  array(std::initializer_list<T> list)
536  : arr(nullptr) {
537  dim_t size = list.size();
538  if (af_err __aferr = af_create_array(&arr, list.begin(), 1, &size,
539  static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
540  char *msg = NULL;
541  af_get_last_error(&msg, NULL);
542  af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
543  __LINE__, __aferr);
544  af_free_host(msg);
545  throw std::move(ex);
546  }
547  }
548 
550  template <typename T, typename = typename std::enable_if<
551  std::is_fundamental<T>::value, void>::type>
552  array(const af::dim4 &dims, std::initializer_list<T> list)
553  : arr(nullptr) {
554  const dim_t *size = dims.get();
555  if (af_err __aferr = af_create_array(
556  &arr, list.begin(), AF_MAX_DIMS, size,
557  static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
558  char *msg = NULL;
559  af_get_last_error(&msg, NULL);
560  af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
561  __LINE__, __aferr);
562  af_free_host(msg);
563  throw std::move(ex);
564  }
565  }
566 #endif
567 #endif
568 
595  array(const array& input, const dim4& dims);
596 
627  array( const array& input,
628  const dim_t dim0, const dim_t dim1 = 1,
629  const dim_t dim2 = 1, const dim_t dim3 = 1);
630 
634  af_array get();
635 
639  af_array get() const;
640 
644  dim_t elements() const;
645 
649  template<typename T> T* host() const;
650 
654  void host(void *ptr) const;
655 
659  template<typename T> void write(const T *ptr, const size_t bytes, af::source src = afHost);
660 
664  dtype type() const;
665 
669  dim4 dims() const;
670 
674  dim_t dims(unsigned dim) const;
675 
679  unsigned numdims() const;
680 
684  size_t bytes() const;
685 
690  size_t allocated() const;
691 
695  array copy() const;
696 
700  bool isempty() const;
701 
705  bool isscalar() const;
706 
711  bool isvector() const;
712 
717  bool isrow() const;
718 
723  bool iscolumn() const;
724 
728  bool iscomplex() const;
729 
733  inline bool isreal() const { return !iscomplex(); }
734 
738  bool isdouble() const;
739 
743  bool issingle() const;
744 
745 #if AF_API_VERSION >= 37
746 
749  bool ishalf() const;
750 #endif
751 
755  bool isrealfloating() const;
756 
761  bool isfloating() const;
762 
767  bool isinteger() const;
768 
772  bool isbool() const;
773 
774 #if AF_API_VERSION >= 34
775 
778  bool issparse() const;
779 #endif
780 
784  void eval() const;
785 
792  template<typename T> T scalar() const;
793 
802  template<typename T> T* device() const;
803 
804  // INDEXING
805  // Single arguments
806 
824  array::array_proxy operator()(const index &s0);
825 
831  const array::array_proxy operator()(const index &s0) const;
832 
833 
851  array::array_proxy operator()(const index &s0,
852  const index &s1,
853  const index &s2 = span,
854  const index &s3 = span);
855 
861  const array::array_proxy operator()(const index &s0,
862  const index &s1,
863  const index &s2 = span,
864  const index &s3 = span) const;
865 
866 
878  array::array_proxy row(int index);
879  const array::array_proxy row(int index) const;
880 
890  array::array_proxy rows(int first, int last);
891  const array::array_proxy rows(int first, int last) const;
892 
905  array::array_proxy col(int index);
906  const array::array_proxy col(int index) const;
907 
917  array::array_proxy cols(int first, int last);
918  const array::array_proxy cols(int first, int last) const;
919 
932  array::array_proxy slice(int index);
933  const array::array_proxy slice(int index) const;
934 
943  array::array_proxy slices(int first, int last);
944  const array::array_proxy slices(int first, int last) const;
945 
976  const array as(dtype type) const;
977 
978 
979  ~array();
980 
984  array T() const;
988  array H() const;
989 
990 #define ASSIGN_(OP2) \
991  array& OP2(const array &val); \
992  array& OP2(const double &val); \
993  array& OP2(const cdouble &val); \
994  array& OP2(const cfloat &val); \
995  array& OP2(const float &val); \
996  array& OP2(const int &val); \
997  array& OP2(const unsigned &val); \
998  array& OP2(const bool &val); \
999  array& OP2(const char &val); \
1000  array& OP2(const unsigned char &val); \
1001  array& OP2(const long &val); \
1002  array& OP2(const unsigned long &val); \
1003  array& OP2(const long long &val); \
1004  array& OP2(const unsigned long long &val);
1005 
1006 
1007 #if AF_API_VERSION >= 32
1008 #define ASSIGN(OP) \
1009  ASSIGN_(OP) \
1010  array& OP(const short &val); \
1011  array& OP(const unsigned short &val);
1012 
1013 #else
1014 #define ASSIGN(OP) ASSIGN_(OP)
1015 #endif
1016 
1017 
1027  ASSIGN(operator=)
1029 
1039  ASSIGN(operator+=)
1041 
1051  ASSIGN(operator-=)
1053 
1063  ASSIGN(operator*=)
1065 
1076  ASSIGN(operator/=)
1078 
1079 
1080 #undef ASSIGN
1081 #undef ASSIGN_
1082 
1088  array operator -() const;
1089 
1095  array operator !() const;
1096 
1097 #if AF_API_VERSION >= 38
1098  array operator ~() const;
1104 #endif
1105 
1110  int nonzeros() const;
1111 
1112 
1118  void lock() const;
1119 
1120 
1121 #if AF_API_VERSION >= 34
1122  bool isLocked() const;
1128 #endif
1129 
1130 
1136  void unlock() const;
1137  };
1138  // end of class array
1139 
1140 #define BIN_OP_(OP) \
1141  AFAPI array OP (const array& lhs, const array& rhs); \
1142  AFAPI array OP (const bool& lhs, const array& rhs); \
1143  AFAPI array OP (const int& lhs, const array& rhs); \
1144  AFAPI array OP (const unsigned& lhs, const array& rhs); \
1145  AFAPI array OP (const char& lhs, const array& rhs); \
1146  AFAPI array OP (const unsigned char& lhs, const array& rhs); \
1147  AFAPI array OP (const long& lhs, const array& rhs); \
1148  AFAPI array OP (const unsigned long& lhs, const array& rhs); \
1149  AFAPI array OP (const long long& lhs, const array& rhs); \
1150  AFAPI array OP (const unsigned long long& lhs, const array& rhs); \
1151  AFAPI array OP (const double& lhs, const array& rhs); \
1152  AFAPI array OP (const float& lhs, const array& rhs); \
1153  AFAPI array OP (const cfloat& lhs, const array& rhs); \
1154  AFAPI array OP (const cdouble& lhs, const array& rhs); \
1155  AFAPI array OP (const array& lhs, const bool& rhs); \
1156  AFAPI array OP (const array& lhs, const int& rhs); \
1157  AFAPI array OP (const array& lhs, const unsigned& rhs); \
1158  AFAPI array OP (const array& lhs, const char& rhs); \
1159  AFAPI array OP (const array& lhs, const unsigned char& rhs); \
1160  AFAPI array OP (const array& lhs, const long& rhs); \
1161  AFAPI array OP (const array& lhs, const unsigned long& rhs); \
1162  AFAPI array OP (const array& lhs, const long long& rhs); \
1163  AFAPI array OP (const array& lhs, const unsigned long long& rhs); \
1164  AFAPI array OP (const array& lhs, const double& rhs); \
1165  AFAPI array OP (const array& lhs, const float& rhs); \
1166  AFAPI array OP (const array& lhs, const cfloat& rhs); \
1167  AFAPI array OP (const array& lhs, const cdouble& rhs);
1168 
1169 #if AF_API_VERSION >= 32
1170 #define BIN_OP(OP) \
1171  BIN_OP_(OP) \
1172  AFAPI array OP (const short& lhs, const array& rhs); \
1173  AFAPI array OP (const unsigned short& lhs, const array& rhs); \
1174  AFAPI array OP (const array& lhs, const short& rhs); \
1175  AFAPI array OP (const array& lhs, const unsigned short& rhs);
1176 
1177 #else
1178 #define BIN_OP(OP) BIN_OP_(OP)
1179 #endif
1180 
1189  BIN_OP(operator+ )
1191 
1200  BIN_OP(operator- )
1202 
1211  BIN_OP(operator* )
1213 
1222  BIN_OP(operator/ )
1224 
1233  BIN_OP(operator==)
1235 
1245  BIN_OP(operator!=)
1247 
1257  BIN_OP(operator< )
1259 
1268  BIN_OP(operator<=)
1270 
1280  BIN_OP(operator> )
1282 
1292  BIN_OP(operator>=)
1294 
1305  BIN_OP(operator||)
1307 
1317  BIN_OP(operator% )
1319 
1330  BIN_OP(operator| )
1332 
1343  BIN_OP(operator^ )
1345 
1356  BIN_OP(operator<<)
1358 
1369  BIN_OP(operator>>)
1371 
1372 #undef BIN_OP
1373 #undef BIN_OP_
1374 
1385  AFAPI array operator&(const array& lhs, const array& rhs);
1386  AFAPI array operator&(const array& lhs, const bool& rhs);
1387  AFAPI array operator&(const array& lhs, const cdouble& rhs);
1388  AFAPI array operator&(const array& lhs, const cfloat& rhs);
1389  AFAPI array operator&(const array& lhs, const char& rhs);
1390  AFAPI array operator&(const array& lhs, const double& rhs);
1391  AFAPI array operator&(const array& lhs, const float& rhs);
1392  AFAPI array operator&(const array& lhs, const int& rhs);
1393  AFAPI array operator&(const array& lhs, const long long& rhs);
1394  AFAPI array operator&(const array& lhs, const long& rhs);
1395  AFAPI array operator&(const array& lhs, const short& rhs);
1396  AFAPI array operator&(const array& lhs, const unsigned char& rhs);
1397  AFAPI array operator&(const array& lhs, const unsigned long long& rhs);
1398  AFAPI array operator&(const array& lhs, const unsigned long& rhs);
1399  AFAPI array operator&(const array& lhs, const unsigned short& rhs);
1400  AFAPI array operator&(const array& lhs, const unsigned& rhs);
1401  AFAPI array operator&(const bool& lhs, const array& rhs);
1402  AFAPI array operator&(const cdouble& lhs, const array& rhs);
1403  AFAPI array operator&(const cfloat& lhs, const array& rhs);
1404  AFAPI array operator&(const char& lhs, const array& rhs);
1405  AFAPI array operator&(const double& lhs, const array& rhs);
1406  AFAPI array operator&(const float& lhs, const array& rhs);
1407  AFAPI array operator&(const int& lhs, const array& rhs);
1408  AFAPI array operator&(const long long& lhs, const array& rhs);
1409  AFAPI array operator&(const long& lhs, const array& rhs);
1410  AFAPI array operator&(const short& lhs, const array& rhs);
1411  AFAPI array operator&(const unsigned char& lhs, const array& rhs);
1412  AFAPI array operator&(const unsigned long long& lhs, const array& rhs);
1413  AFAPI array operator&(const unsigned long& lhs, const array& rhs);
1414  AFAPI array operator&(const unsigned short& lhs, const array& rhs);
1415  AFAPI array operator&(const unsigned& lhs, const array& rhs);
1417 
1428  AFAPI array operator&&(const array& lhs, const array& rhs);
1429  AFAPI array operator&&(const array& lhs, const bool& rhs);
1430  AFAPI array operator&&(const array& lhs, const cdouble& rhs);
1431  AFAPI array operator&&(const array& lhs, const cfloat& rhs);
1432  AFAPI array operator&&(const array& lhs, const char& rhs);
1433  AFAPI array operator&&(const array& lhs, const double& rhs);
1434  AFAPI array operator&&(const array& lhs, const float& rhs);
1435  AFAPI array operator&&(const array& lhs, const int& rhs);
1436  AFAPI array operator&&(const array& lhs, const long long& rhs);
1437  AFAPI array operator&&(const array& lhs, const long& rhs);
1438  AFAPI array operator&&(const array& lhs, const short& rhs);
1439  AFAPI array operator&&(const array& lhs, const unsigned char& rhs);
1440  AFAPI array operator&&(const array& lhs, const unsigned long long& rhs);
1441  AFAPI array operator&&(const array& lhs, const unsigned long& rhs);
1442  AFAPI array operator&&(const array& lhs, const unsigned short& rhs);
1443  AFAPI array operator&&(const array& lhs, const unsigned& rhs);
1444  AFAPI array operator&&(const bool& lhs, const array& rhs);
1445  AFAPI array operator&&(const cdouble& lhs, const array& rhs);
1446  AFAPI array operator&&(const cfloat& lhs, const array& rhs);
1447  AFAPI array operator&&(const char& lhs, const array& rhs);
1448  AFAPI array operator&&(const double& lhs, const array& rhs);
1449  AFAPI array operator&&(const float& lhs, const array& rhs);
1450  AFAPI array operator&&(const int& lhs, const array& rhs);
1451  AFAPI array operator&&(const long long& lhs, const array& rhs);
1452  AFAPI array operator&&(const long& lhs, const array& rhs);
1453  AFAPI array operator&&(const short& lhs, const array& rhs);
1454  AFAPI array operator&&(const unsigned char& lhs, const array& rhs);
1455  AFAPI array operator&&(const unsigned long long& lhs, const array& rhs);
1456  AFAPI array operator&&(const unsigned long& lhs, const array& rhs);
1457  AFAPI array operator&&(const unsigned short& lhs, const array& rhs);
1458  AFAPI array operator&&(const unsigned& lhs, const array& rhs);
1460 
1461 
1463 
1467  inline array &eval(array &a) { a.eval(); return a; }
1468 
1469 #if AF_API_VERSION >= 34
1470  AFAPI void eval(int num, array **arrays);
1474 #endif
1475 
1476  inline void eval(array &a, array &b)
1477  {
1478 #if AF_API_VERSION >= 34
1479  array *arrays[] = {&a, &b};
1480  return eval(2, arrays);
1481 #else
1482  eval(a); b.eval();
1483 #endif
1484  }
1485 
1486  inline void eval(array &a, array &b, array &c)
1487  {
1488 #if AF_API_VERSION >= 34
1489  array *arrays[] = {&a, &b, &c};
1490  return eval(3, arrays);
1491 #else
1492  eval(a, b); c.eval();
1493 #endif
1494  }
1495 
1496  inline void eval(array &a, array &b, array &c, array &d)
1497  {
1498 #if AF_API_VERSION >= 34
1499  array *arrays[] = {&a, &b, &c, &d};
1500  return eval(4, arrays);
1501 #else
1502  eval(a, b, c); d.eval();
1503 #endif
1504 
1505  }
1506 
1507  inline void eval(array &a, array &b, array &c, array &d, array &e)
1508  {
1509 #if AF_API_VERSION >= 34
1510  array *arrays[] = {&a, &b, &c, &d, &e};
1511  return eval(5, arrays);
1512 #else
1513  eval(a, b, c, d); e.eval();
1514 #endif
1515  }
1516 
1517  inline void eval(array &a, array &b, array &c, array &d, array &e, array &f)
1518  {
1519 #if AF_API_VERSION >= 34
1520  array *arrays[] = {&a, &b, &c, &d, &e, &f};
1521  return eval(6, arrays);
1522 #else
1523  eval(a, b, c, d, e); f.eval();
1524 #endif
1525  }
1526 
1527 #if AF_API_VERSION >= 37
1528 
1530  inline const array &eval(const array &a) { a.eval(); return a; }
1531 
1532 #if AF_COMPILER_CXX_VARIADIC_TEMPLATES
1533  template <typename... ARRAYS>
1534  inline void eval(ARRAYS... in) {
1535  array *arrays[] = {const_cast<array *>(&in)...};
1536  eval((int)sizeof...(in), arrays);
1537  }
1538 
1539 #else
1540 
1541  inline void eval(const array &a, const array &b)
1542  {
1543  const array *arrays[] = {&a, &b};
1544  return eval(2, const_cast<array **>(arrays));
1545  }
1546 
1547  inline void eval(const array &a, const array &b, const array &c)
1548  {
1549  const array *arrays[] = {&a, &b, &c};
1550  return eval(3, const_cast<array **>(arrays));
1551  }
1552 
1553  inline void eval(const array &a, const array &b, const array &c,
1554  const array &d)
1555  {
1556  const array *arrays[] = {&a, &b, &c, &d};
1557  return eval(4, const_cast<array **>(arrays));
1558  }
1559 
1560  inline void eval(const array &a, const array &b, const array &c,
1561  const array &d, const array &e)
1562  {
1563  const array *arrays[] = {&a, &b, &c, &d, &e};
1564  return eval(5, const_cast<array **>(arrays));
1565  }
1566 
1567  inline void eval(const array &a, const array &b, const array &c,
1568  const array &d, const array &e, const array &f)
1569  {
1570  const array *arrays[] = {&a, &b, &c, &d, &e, &f};
1571  return eval(6, const_cast<array **>(arrays));
1572  }
1573 #endif // AF_COMPILER_CXX_VARIADIC_TEMPLATES
1574 #endif
1575 
1576 #if AF_API_VERSION >= 34
1577  AFAPI void setManualEvalFlag(bool flag);
1581 #endif
1582 
1583 #if AF_API_VERSION >= 34
1584  AFAPI bool getManualEvalFlag();
1586 #endif
1587 
1592 }
1593 #endif
1594 
1595 #ifdef __cplusplus
1596 extern "C" {
1597 #endif
1598 
1617  AFAPI af_err af_create_array(af_array *arr, const void * const data, const unsigned ndims, const dim_t * const dims, const af_dtype type);
1618 
1632  AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t * const dims, const af_dtype type);
1633 
1637  AFAPI af_err af_copy_array(af_array *arr, const af_array in);
1638 
1642  AFAPI af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src);
1643 
1649  AFAPI af_err af_get_data_ptr(void *data, const af_array arr);
1650 
1657 
1661  AFAPI af_err af_retain_array(af_array *out, const af_array in);
1662 
1663 #if AF_API_VERSION >= 31
1664 
1667  AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
1668 #endif
1669 
1674 
1675 #if AF_API_VERSION >= 34
1676 
1679  AFAPI af_err af_eval_multiple(const int num, af_array *arrays);
1680 #endif
1681 
1682 #if AF_API_VERSION >= 34
1683 
1687 #endif
1688 
1689 #if AF_API_VERSION >= 34
1690 
1693  AFAPI af_err af_get_manual_eval_flag(bool *flag);
1694 #endif
1695 
1704  AFAPI af_err af_get_elements(dim_t *elems, const af_array arr);
1705 
1714  AFAPI af_err af_get_type(af_dtype *type, const af_array arr);
1715 
1727  AFAPI af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3,
1728  const af_array arr);
1729 
1738  AFAPI af_err af_get_numdims(unsigned *result, const af_array arr);
1739 
1748  AFAPI af_err af_is_empty (bool *result, const af_array arr);
1749 
1758  AFAPI af_err af_is_scalar (bool *result, const af_array arr);
1759 
1768  AFAPI af_err af_is_row (bool *result, const af_array arr);
1769 
1778  AFAPI af_err af_is_column (bool *result, const af_array arr);
1779 
1790  AFAPI af_err af_is_vector (bool *result, const af_array arr);
1791 
1800  AFAPI af_err af_is_complex (bool *result, const af_array arr);
1801 
1812  AFAPI af_err af_is_real (bool *result, const af_array arr);
1813 
1822  AFAPI af_err af_is_double (bool *result, const af_array arr);
1823 
1832  AFAPI af_err af_is_single (bool *result, const af_array arr);
1833 
1834 #if AF_API_VERSION >= 37
1835 
1843  AFAPI af_err af_is_half(bool *result, const af_array arr);
1844 #endif
1845 
1854  AFAPI af_err af_is_realfloating (bool *result, const af_array arr);
1855 
1867  AFAPI af_err af_is_floating (bool *result, const af_array arr);
1868 
1877  AFAPI af_err af_is_integer (bool *result, const af_array arr);
1878 
1887  AFAPI af_err af_is_bool (bool *result, const af_array arr);
1888 
1889 #if AF_API_VERSION >= 34
1890 
1898  AFAPI af_err af_is_sparse (bool *result, const af_array arr);
1899 #endif
1900 
1901 #if AF_API_VERSION >= 35
1902 
1909  AFAPI af_err af_get_scalar(void* output_value, const af_array arr);
1910 #endif
1911 
1916 #ifdef __cplusplus
1917 }
1918 #endif
An ArrayFire exception class.
Definition: exception.h:21
bool isreal() const
Definition: array.h:130
Definition: algorithm.h:14
AFAPI af_err af_is_vector(bool *result, const af_array arr)
Check if an array is a vector.
AFAPI af_err af_is_half(bool *result, const af_array arr)
Check if an array is 16 bit floating point type.
AFAPI af_err af_get_numdims(unsigned *result, const af_array arr)
Gets the number of dimensions of an array.
AFAPI void af_get_last_error(char **msg, dim_t *len)
Returns the last error message that occurred and its error message.
AFAPI af_err af_is_column(bool *result, const af_array arr)
Check if an array is a column vector.
#define ASSIGN(OP)
Definition: array.h:1008
AFAPI af_err af_get_scalar(void *output_value, const af_array arr)
Get first element from an array.
AFAPI af_err af_get_type(af_dtype *type, const af_array arr)
Gets the type of an array.
AFAPI array operator &&(const array &lhs, const array &rhs)
Performs a logical AND operation on two arrays or an array and a value.
AFAPI af_err af_is_complex(bool *result, const af_array arr)
Check if an array is complex type.
af::af_cfloat cfloat
Definition: complex.h:44
AFAPI af_err af_retain_array(af_array *out, const af_array in)
Increments an af_array reference count.
AFAPI af_err af_is_scalar(bool *result, const af_array arr)
Check if an array is scalar, ie.
AFAPI af_err af_eval(af_array in)
Evaluate any expressions in the Array.
A multi dimensional data container.
Definition: array.h:37
AFAPI af_err af_is_integer(bool *result, const af_array arr)
Check if an array is integer type.
AFAPI af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3, const af_array arr)
Gets the dimensions of an array.
AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in)
Get the reference count of af_array.
#define AF_MAX_DIMS
Definition: defines.h:237
AFAPI af_err af_get_elements(dim_t *elems, const af_array arr)
Get the total number of elements across all dimensions of the array.
AFAPI af_err af_is_double(bool *result, const af_array arr)
Check if an array is double precision type.
Struct used to index an af_array.
Definition: index.h:22
af_err
Definition: defines.h:71
AFAPI seq span
A special value representing the entire axis of an af::array.
AFAPI af_err af_free_host(void *ptr)
af_source
Definition: defines.h:232
AFAPI af_err af_get_data_ptr(void *data, const af_array arr)
Copy data from an af_array to a C pointer.
dim_t * get()
Returns the underlying pointer to the dim4 object.
Definition: dim4.hpp:103
long long dim_t
Definition: defines.h:56
#define BIN_OP(OP)
Definition: array.h:1170
AFAPI af_err af_get_manual_eval_flag(bool *flag)
Get the manual eval flag.
AFAPI af_err af_set_manual_eval_flag(bool flag)
Turn the manual eval flag on or off.
AFAPI array operator &(const array &lhs, const array &rhs)
Performs an bitwise AND operation on two arrays or an array and a value.
AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t *const dims, const af_dtype type)
Create af_array handle.
Wrapper for af_index.
Definition: index.h:52
#define AFAPI
Definition: defines.h:38
AFAPI af_err af_is_row(bool *result, const af_array arr)
Check if an array is row vector.
AFAPI void copy(array &dst, const array &src, const index &idx0, const index &idx1=span, const index &idx2=span, const index &idx3=span)
Copy the values of an input array based on index.
AFAPI af_err af_is_single(bool *result, const af_array arr)
Check if an array is single precision type.
AFAPI af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src)
Copy data from a C pointer (host/device) to an existing array.
array & eval(array &a)
Evaluate an expression (nonblocking).
Definition: array.h:1467
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 void setManualEvalFlag(bool flag)
Turn the manual eval flag on or off.
AFAPI af_err af_eval_multiple(const int num, af_array *arrays)
Evaluate multiple arrays together.
af::af_cdouble cdouble
Definition: complex.h:45
AFAPI af_err af_is_empty(bool *result, const af_array arr)
Check if an array is empty.
AFAPI af_err af_copy_array(af_array *arr, const af_array in)
Deep copy an array to another.
bool isreal() const
Returns true if the array type is neither c32 nor c64.
Definition: array.h:733
AFAPI af_err af_create_array(af_array *arr, const void *const data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
Create an af_array handle initialized with user defined data.
void * af_array
Definition: defines.h:240
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts two arrays or an array and a value.
void eval() const
Evaluate any JIT expressions to generate data for the array.
32-bit floating point values
Definition: defines.h:211
AFAPI af_err af_is_real(bool *result, const af_array arr)
Check if an array is real type.
AFAPI af_err af_is_sparse(bool *result, const af_array arr)
Check if an array is sparse.
Generic object that represents size and shape.
Definition: dim4.hpp:25
Intermediate data class.
Definition: array.h:56
Host pointer.
Definition: defines.h:234
af_dtype
Definition: defines.h:210
AFAPI af_err af_is_bool(bool *result, const af_array arr)
Check if an array is bool type.
AFAPI af_err af_is_floating(bool *result, const af_array arr)
Check if an array is floating precision type.
af_dtype dtype
Definition: defines.h:553
AFAPI af_err af_is_realfloating(bool *result, const af_array arr)
Check if an array is real floating point type.
AFAPI bool getManualEvalFlag()
Get the manual eval flag.
AFAPI af_err af_release_array(af_array arr)
Reduce the reference count of the af_array.