array.h (2020-10-27 00:11:00 -0400, (build d99887ae))
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  * https://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  array(dim_t dim0, dtype ty = f32);
250 
274  array(dim_t dim0, dim_t dim1, dtype ty = f32);
275 
300  array(dim_t dim0, dim_t dim1, dim_t dim2, dtype ty = f32);
301 
327  array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, dtype ty = f32);
328 
354  explicit
355  array(const dim4& dims, dtype ty = f32);
356 
384  template<typename T>
385  array(dim_t dim0,
386  const T *pointer, af::source src=afHost);
387 
388 
411  template<typename T>
412  array(dim_t dim0, dim_t dim1,
413  const T *pointer, af::source src=afHost);
414 
415 
442  template<typename T>
443  array(dim_t dim0, dim_t dim1, dim_t dim2,
444  const T *pointer, af::source src=afHost);
445 
446 
475  template<typename T>
476  array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3,
477  const T *pointer, af::source src=afHost);
478 
517  template<typename T>
518  explicit
519  array(const dim4& dims,
520  const T *pointer, af::source src=afHost);
521 
522 #if AF_API_VERSION >= 38
523 #if AF_COMPILER_CXX_GENERALIZED_INITIALIZERS
524  template <typename T> array(std::initializer_list<T> list)
526  : arr(nullptr) {
527  dim_t size = list.size();
528  if (af_err __aferr = af_create_array(&arr, list.begin(), 1, &size,
529  static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
530  char *msg = NULL;
531  af_get_last_error(&msg, NULL);
532  af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
533  __LINE__, __aferr);
534  af_free_host(msg);
535  throw std::move(ex);
536  }
537  }
538 
540  template <typename T>
541  array(const af::dim4 &dims, std::initializer_list<T> list)
542  : arr(nullptr) {
543  const dim_t *size = dims.get();
544  if (af_err __aferr = af_create_array(
545  &arr, list.begin(), AF_MAX_DIMS, size,
546  static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
547  char *msg = NULL;
548  af_get_last_error(&msg, NULL);
549  af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
550  __LINE__, __aferr);
551  af_free_host(msg);
552  throw std::move(ex);
553  }
554  }
555 #endif
556 #endif
557 
584  array(const array& input, const dim4& dims);
585 
616  array( const array& input,
617  const dim_t dim0, const dim_t dim1 = 1,
618  const dim_t dim2 = 1, const dim_t dim3 = 1);
619 
623  af_array get();
624 
628  af_array get() const;
629 
633  dim_t elements() const;
634 
638  template<typename T> T* host() const;
639 
643  void host(void *ptr) const;
644 
648  template<typename T> void write(const T *ptr, const size_t bytes, af::source src = afHost);
649 
653  dtype type() const;
654 
658  dim4 dims() const;
659 
663  dim_t dims(unsigned dim) const;
664 
668  unsigned numdims() const;
669 
673  size_t bytes() const;
674 
679  size_t allocated() const;
680 
684  array copy() const;
685 
689  bool isempty() const;
690 
694  bool isscalar() const;
695 
700  bool isvector() const;
701 
706  bool isrow() const;
707 
712  bool iscolumn() const;
713 
717  bool iscomplex() const;
718 
722  inline bool isreal() const { return !iscomplex(); }
723 
727  bool isdouble() const;
728 
732  bool issingle() const;
733 
734 #if AF_API_VERSION >= 37
735 
738  bool ishalf() const;
739 #endif
740 
744  bool isrealfloating() const;
745 
750  bool isfloating() const;
751 
756  bool isinteger() const;
757 
761  bool isbool() const;
762 
763 #if AF_API_VERSION >= 34
764 
767  bool issparse() const;
768 #endif
769 
773  void eval() const;
774 
781  template<typename T> T scalar() const;
782 
791  template<typename T> T* device() const;
792 
793  // INDEXING
794  // Single arguments
795 
813  array::array_proxy operator()(const index &s0);
814 
820  const array::array_proxy operator()(const index &s0) const;
821 
822 
840  array::array_proxy operator()(const index &s0,
841  const index &s1,
842  const index &s2 = span,
843  const index &s3 = span);
844 
850  const array::array_proxy operator()(const index &s0,
851  const index &s1,
852  const index &s2 = span,
853  const index &s3 = span) const;
854 
855 
867  array::array_proxy row(int index);
868  const array::array_proxy row(int index) const;
869 
879  array::array_proxy rows(int first, int last);
880  const array::array_proxy rows(int first, int last) const;
881 
894  array::array_proxy col(int index);
895  const array::array_proxy col(int index) const;
896 
906  array::array_proxy cols(int first, int last);
907  const array::array_proxy cols(int first, int last) const;
908 
921  array::array_proxy slice(int index);
922  const array::array_proxy slice(int index) const;
923 
932  array::array_proxy slices(int first, int last);
933  const array::array_proxy slices(int first, int last) const;
934 
940  const array as(dtype type) const;
941 
942 
943  ~array();
944 
948  array T() const;
952  array H() const;
953 
954 #define ASSIGN_(OP2) \
955  array& OP2(const array &val); \
956  array& OP2(const double &val); \
957  array& OP2(const cdouble &val); \
958  array& OP2(const cfloat &val); \
959  array& OP2(const float &val); \
960  array& OP2(const int &val); \
961  array& OP2(const unsigned &val); \
962  array& OP2(const bool &val); \
963  array& OP2(const char &val); \
964  array& OP2(const unsigned char &val); \
965  array& OP2(const long &val); \
966  array& OP2(const unsigned long &val); \
967  array& OP2(const long long &val); \
968  array& OP2(const unsigned long long &val);
969 
970 
971 #if AF_API_VERSION >= 32
972 #define ASSIGN(OP) \
973  ASSIGN_(OP) \
974  array& OP(const short &val); \
975  array& OP(const unsigned short &val);
976 
977 #else
978 #define ASSIGN(OP) ASSIGN_(OP)
979 #endif
980 
981 
991  ASSIGN(operator=)
993 
1003  ASSIGN(operator+=)
1005 
1015  ASSIGN(operator-=)
1017 
1027  ASSIGN(operator*=)
1029 
1040  ASSIGN(operator/=)
1042 
1043 
1044 #undef ASSIGN
1045 #undef ASSIGN_
1046 
1052  array operator -() const;
1053 
1059  array operator !() const;
1060 
1061 #if AF_API_VERSION >= 38
1062  array operator ~() const;
1068 #endif
1069 
1074  int nonzeros() const;
1075 
1076 
1082  void lock() const;
1083 
1084 
1085 #if AF_API_VERSION >= 34
1086  bool isLocked() const;
1092 #endif
1093 
1094 
1100  void unlock() const;
1101  };
1102  // end of class array
1103 
1104 #define BIN_OP_(OP) \
1105  AFAPI array OP (const array& lhs, const array& rhs); \
1106  AFAPI array OP (const bool& lhs, const array& rhs); \
1107  AFAPI array OP (const int& lhs, const array& rhs); \
1108  AFAPI array OP (const unsigned& lhs, const array& rhs); \
1109  AFAPI array OP (const char& lhs, const array& rhs); \
1110  AFAPI array OP (const unsigned char& lhs, const array& rhs); \
1111  AFAPI array OP (const long& lhs, const array& rhs); \
1112  AFAPI array OP (const unsigned long& lhs, const array& rhs); \
1113  AFAPI array OP (const long long& lhs, const array& rhs); \
1114  AFAPI array OP (const unsigned long long& lhs, const array& rhs); \
1115  AFAPI array OP (const double& lhs, const array& rhs); \
1116  AFAPI array OP (const float& lhs, const array& rhs); \
1117  AFAPI array OP (const cfloat& lhs, const array& rhs); \
1118  AFAPI array OP (const cdouble& lhs, const array& rhs); \
1119  AFAPI array OP (const array& lhs, const bool& rhs); \
1120  AFAPI array OP (const array& lhs, const int& rhs); \
1121  AFAPI array OP (const array& lhs, const unsigned& rhs); \
1122  AFAPI array OP (const array& lhs, const char& rhs); \
1123  AFAPI array OP (const array& lhs, const unsigned char& rhs); \
1124  AFAPI array OP (const array& lhs, const long& rhs); \
1125  AFAPI array OP (const array& lhs, const unsigned long& rhs); \
1126  AFAPI array OP (const array& lhs, const long long& rhs); \
1127  AFAPI array OP (const array& lhs, const unsigned long long& rhs); \
1128  AFAPI array OP (const array& lhs, const double& rhs); \
1129  AFAPI array OP (const array& lhs, const float& rhs); \
1130  AFAPI array OP (const array& lhs, const cfloat& rhs); \
1131  AFAPI array OP (const array& lhs, const cdouble& rhs);
1132 
1133 #if AF_API_VERSION >= 32
1134 #define BIN_OP(OP) \
1135  BIN_OP_(OP) \
1136  AFAPI array OP (const short& lhs, const array& rhs); \
1137  AFAPI array OP (const unsigned short& lhs, const array& rhs); \
1138  AFAPI array OP (const array& lhs, const short& rhs); \
1139  AFAPI array OP (const array& lhs, const unsigned short& rhs);
1140 
1141 #else
1142 #define BIN_OP(OP) BIN_OP_(OP)
1143 #endif
1144 
1153  BIN_OP(operator+ )
1155 
1164  BIN_OP(operator- )
1166 
1175  BIN_OP(operator* )
1177 
1186  BIN_OP(operator/ )
1188 
1197  BIN_OP(operator==)
1199 
1209  BIN_OP(operator!=)
1211 
1221  BIN_OP(operator< )
1223 
1232  BIN_OP(operator<=)
1234 
1244  BIN_OP(operator> )
1246 
1256  BIN_OP(operator>=)
1258 
1269  BIN_OP(operator||)
1271 
1281  BIN_OP(operator% )
1283 
1294  BIN_OP(operator| )
1296 
1307  BIN_OP(operator^ )
1309 
1320  BIN_OP(operator<<)
1322 
1333  BIN_OP(operator>>)
1335 
1336 #undef BIN_OP
1337 #undef BIN_OP_
1338 
1349  AFAPI array operator&(const array& lhs, const array& rhs);
1350  AFAPI array operator&(const array& lhs, const bool& rhs);
1351  AFAPI array operator&(const array& lhs, const cdouble& rhs);
1352  AFAPI array operator&(const array& lhs, const cfloat& rhs);
1353  AFAPI array operator&(const array& lhs, const char& rhs);
1354  AFAPI array operator&(const array& lhs, const double& rhs);
1355  AFAPI array operator&(const array& lhs, const float& rhs);
1356  AFAPI array operator&(const array& lhs, const int& rhs);
1357  AFAPI array operator&(const array& lhs, const long long& rhs);
1358  AFAPI array operator&(const array& lhs, const long& rhs);
1359  AFAPI array operator&(const array& lhs, const short& rhs);
1360  AFAPI array operator&(const array& lhs, const unsigned char& rhs);
1361  AFAPI array operator&(const array& lhs, const unsigned long long& rhs);
1362  AFAPI array operator&(const array& lhs, const unsigned long& rhs);
1363  AFAPI array operator&(const array& lhs, const unsigned short& rhs);
1364  AFAPI array operator&(const array& lhs, const unsigned& rhs);
1365  AFAPI array operator&(const bool& lhs, const array& rhs);
1366  AFAPI array operator&(const cdouble& lhs, const array& rhs);
1367  AFAPI array operator&(const cfloat& lhs, const array& rhs);
1368  AFAPI array operator&(const char& lhs, const array& rhs);
1369  AFAPI array operator&(const double& lhs, const array& rhs);
1370  AFAPI array operator&(const float& lhs, const array& rhs);
1371  AFAPI array operator&(const int& lhs, const array& rhs);
1372  AFAPI array operator&(const long long& lhs, const array& rhs);
1373  AFAPI array operator&(const long& lhs, const array& rhs);
1374  AFAPI array operator&(const short& lhs, const array& rhs);
1375  AFAPI array operator&(const unsigned char& lhs, const array& rhs);
1376  AFAPI array operator&(const unsigned long long& lhs, const array& rhs);
1377  AFAPI array operator&(const unsigned long& lhs, const array& rhs);
1378  AFAPI array operator&(const unsigned short& lhs, const array& rhs);
1379  AFAPI array operator&(const unsigned& lhs, const array& rhs);
1381 
1392  AFAPI array operator&&(const array& lhs, const array& rhs);
1393  AFAPI array operator&&(const array& lhs, const bool& rhs);
1394  AFAPI array operator&&(const array& lhs, const cdouble& rhs);
1395  AFAPI array operator&&(const array& lhs, const cfloat& rhs);
1396  AFAPI array operator&&(const array& lhs, const char& rhs);
1397  AFAPI array operator&&(const array& lhs, const double& rhs);
1398  AFAPI array operator&&(const array& lhs, const float& rhs);
1399  AFAPI array operator&&(const array& lhs, const int& rhs);
1400  AFAPI array operator&&(const array& lhs, const long long& rhs);
1401  AFAPI array operator&&(const array& lhs, const long& rhs);
1402  AFAPI array operator&&(const array& lhs, const short& rhs);
1403  AFAPI array operator&&(const array& lhs, const unsigned char& rhs);
1404  AFAPI array operator&&(const array& lhs, const unsigned long long& rhs);
1405  AFAPI array operator&&(const array& lhs, const unsigned long& rhs);
1406  AFAPI array operator&&(const array& lhs, const unsigned short& rhs);
1407  AFAPI array operator&&(const array& lhs, const unsigned& rhs);
1408  AFAPI array operator&&(const bool& lhs, const array& rhs);
1409  AFAPI array operator&&(const cdouble& lhs, const array& rhs);
1410  AFAPI array operator&&(const cfloat& lhs, const array& rhs);
1411  AFAPI array operator&&(const char& lhs, const array& rhs);
1412  AFAPI array operator&&(const double& lhs, const array& rhs);
1413  AFAPI array operator&&(const float& lhs, const array& rhs);
1414  AFAPI array operator&&(const int& lhs, const array& rhs);
1415  AFAPI array operator&&(const long long& lhs, const array& rhs);
1416  AFAPI array operator&&(const long& lhs, const array& rhs);
1417  AFAPI array operator&&(const short& lhs, const array& rhs);
1418  AFAPI array operator&&(const unsigned char& lhs, const array& rhs);
1419  AFAPI array operator&&(const unsigned long long& lhs, const array& rhs);
1420  AFAPI array operator&&(const unsigned long& lhs, const array& rhs);
1421  AFAPI array operator&&(const unsigned short& lhs, const array& rhs);
1422  AFAPI array operator&&(const unsigned& lhs, const array& rhs);
1424 
1425 
1427 
1431  inline array &eval(array &a) { a.eval(); return a; }
1432 
1433 #if AF_API_VERSION >= 34
1434  AFAPI void eval(int num, array **arrays);
1438 #endif
1439 
1440  inline void eval(array &a, array &b)
1441  {
1442 #if AF_API_VERSION >= 34
1443  array *arrays[] = {&a, &b};
1444  return eval(2, arrays);
1445 #else
1446  eval(a); b.eval();
1447 #endif
1448  }
1449 
1450  inline void eval(array &a, array &b, array &c)
1451  {
1452 #if AF_API_VERSION >= 34
1453  array *arrays[] = {&a, &b, &c};
1454  return eval(3, arrays);
1455 #else
1456  eval(a, b); c.eval();
1457 #endif
1458  }
1459 
1460  inline void eval(array &a, array &b, array &c, array &d)
1461  {
1462 #if AF_API_VERSION >= 34
1463  array *arrays[] = {&a, &b, &c, &d};
1464  return eval(4, arrays);
1465 #else
1466  eval(a, b, c); d.eval();
1467 #endif
1468 
1469  }
1470 
1471  inline void eval(array &a, array &b, array &c, array &d, array &e)
1472  {
1473 #if AF_API_VERSION >= 34
1474  array *arrays[] = {&a, &b, &c, &d, &e};
1475  return eval(5, arrays);
1476 #else
1477  eval(a, b, c, d); e.eval();
1478 #endif
1479  }
1480 
1481  inline void eval(array &a, array &b, array &c, array &d, array &e, array &f)
1482  {
1483 #if AF_API_VERSION >= 34
1484  array *arrays[] = {&a, &b, &c, &d, &e, &f};
1485  return eval(6, arrays);
1486 #else
1487  eval(a, b, c, d, e); f.eval();
1488 #endif
1489  }
1490 
1491 #if AF_API_VERSION >= 37
1492 
1494  inline const array &eval(const array &a) { a.eval(); return a; }
1495 
1496 #if AF_COMPILER_CXX_VARIADIC_TEMPLATES
1497  template <typename... ARRAYS>
1498  inline void eval(ARRAYS... in) {
1499  array *arrays[] = {const_cast<array *>(&in)...};
1500  eval((int)sizeof...(in), arrays);
1501  }
1502 
1503 #else
1504 
1505  inline void eval(const array &a, const array &b)
1506  {
1507  const array *arrays[] = {&a, &b};
1508  return eval(2, const_cast<array **>(arrays));
1509  }
1510 
1511  inline void eval(const array &a, const array &b, const array &c)
1512  {
1513  const array *arrays[] = {&a, &b, &c};
1514  return eval(3, const_cast<array **>(arrays));
1515  }
1516 
1517  inline void eval(const array &a, const array &b, const array &c,
1518  const array &d)
1519  {
1520  const array *arrays[] = {&a, &b, &c, &d};
1521  return eval(4, const_cast<array **>(arrays));
1522  }
1523 
1524  inline void eval(const array &a, const array &b, const array &c,
1525  const array &d, const array &e)
1526  {
1527  const array *arrays[] = {&a, &b, &c, &d, &e};
1528  return eval(5, const_cast<array **>(arrays));
1529  }
1530 
1531  inline void eval(const array &a, const array &b, const array &c,
1532  const array &d, const array &e, const array &f)
1533  {
1534  const array *arrays[] = {&a, &b, &c, &d, &e, &f};
1535  return eval(6, const_cast<array **>(arrays));
1536  }
1537 #endif // AF_COMPILER_CXX_VARIADIC_TEMPLATES
1538 #endif
1539 
1540 #if AF_API_VERSION >= 34
1541  AFAPI void setManualEvalFlag(bool flag);
1545 #endif
1546 
1547 #if AF_API_VERSION >= 34
1548  AFAPI bool getManualEvalFlag();
1550 #endif
1551 
1556 }
1557 #endif
1558 
1559 #ifdef __cplusplus
1560 extern "C" {
1561 #endif
1562 
1581  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);
1582 
1596  AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t * const dims, const af_dtype type);
1597 
1601  AFAPI af_err af_copy_array(af_array *arr, const af_array in);
1602 
1606  AFAPI af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src);
1607 
1613  AFAPI af_err af_get_data_ptr(void *data, const af_array arr);
1614 
1621 
1625  AFAPI af_err af_retain_array(af_array *out, const af_array in);
1626 
1627 #if AF_API_VERSION >= 31
1628 
1631  AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
1632 #endif
1633 
1638 
1639 #if AF_API_VERSION >= 34
1640 
1643  AFAPI af_err af_eval_multiple(const int num, af_array *arrays);
1644 #endif
1645 
1646 #if AF_API_VERSION >= 34
1647 
1651 #endif
1652 
1653 #if AF_API_VERSION >= 34
1654 
1657  AFAPI af_err af_get_manual_eval_flag(bool *flag);
1658 #endif
1659 
1668  AFAPI af_err af_get_elements(dim_t *elems, const af_array arr);
1669 
1678  AFAPI af_err af_get_type(af_dtype *type, const af_array arr);
1679 
1691  AFAPI af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3,
1692  const af_array arr);
1693 
1702  AFAPI af_err af_get_numdims(unsigned *result, const af_array arr);
1703 
1712  AFAPI af_err af_is_empty (bool *result, const af_array arr);
1713 
1722  AFAPI af_err af_is_scalar (bool *result, const af_array arr);
1723 
1732  AFAPI af_err af_is_row (bool *result, const af_array arr);
1733 
1742  AFAPI af_err af_is_column (bool *result, const af_array arr);
1743 
1754  AFAPI af_err af_is_vector (bool *result, const af_array arr);
1755 
1764  AFAPI af_err af_is_complex (bool *result, const af_array arr);
1765 
1776  AFAPI af_err af_is_real (bool *result, const af_array arr);
1777 
1786  AFAPI af_err af_is_double (bool *result, const af_array arr);
1787 
1796  AFAPI af_err af_is_single (bool *result, const af_array arr);
1797 
1798 #if AF_API_VERSION >= 37
1799 
1807  AFAPI af_err af_is_half(bool *result, const af_array arr);
1808 #endif
1809 
1818  AFAPI af_err af_is_realfloating (bool *result, const af_array arr);
1819 
1831  AFAPI af_err af_is_floating (bool *result, const af_array arr);
1832 
1841  AFAPI af_err af_is_integer (bool *result, const af_array arr);
1842 
1851  AFAPI af_err af_is_bool (bool *result, const af_array arr);
1852 
1853 #if AF_API_VERSION >= 34
1854 
1862  AFAPI af_err af_is_sparse (bool *result, const af_array arr);
1863 #endif
1864 
1865 #if AF_API_VERSION >= 35
1866 
1873  AFAPI af_err af_get_scalar(void* output_value, const af_array arr);
1874 #endif
1875 
1880 #ifdef __cplusplus
1881 }
1882 #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:972
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:1134
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:1431
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 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:722
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.
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.