A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

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
56 class AFAPI array_proxy
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
195 array(array &&other) AF_NOEXCEPT;
196
207 array &operator=(array &&other) AF_NOEXCEPT;
208#endif
209#endif
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
533 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
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
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;
893
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;
920
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;
946
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
1103 array operator ~() const;
1104#endif
1105
1110 int nonzeros() const;
1111
1112
1118 void lock() const;
1119
1120
1121#if AF_API_VERSION >= 34
1127 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
1473 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
1580 AFAPI void setManualEvalFlag(bool flag);
1581#endif
1582
1583#if AF_API_VERSION >= 34
1585 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
1656 AFAPI af_err af_release_array(af_array arr);
1657
1661 AFAPI af_err af_retain_array(af_array *out, const af_array in);
1662
1663#if AF_API_VERSION >= 31
1667 AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
1668#endif
1669
1673 AFAPI af_err af_eval(af_array in);
1674
1675#if AF_API_VERSION >= 34
1679 AFAPI af_err af_eval_multiple(const int num, af_array *arrays);
1680#endif
1681
1682#if AF_API_VERSION >= 34
1686 AFAPI af_err af_set_manual_eval_flag(bool flag);
1687#endif
1688
1689#if AF_API_VERSION >= 34
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
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
1898 AFAPI af_err af_is_sparse (bool *result, const af_array arr);
1899#endif
1900
1901#if AF_API_VERSION >= 35
1909 AFAPI af_err af_get_scalar(void* output_value, const af_array arr);
1910#endif
1911
1916#ifdef __cplusplus
1917}
1918#endif
BIN_OP
#define BIN_OP(OP)
Definition array.h:1170
ASSIGN
#define ASSIGN(OP)
Definition array.h:74
af::array::array_proxy
Intermediate data class.
Definition array.h:57
af::array::array_proxy::isempty
bool isempty() const
af::array::array_proxy::scalar
T scalar() const
af::array::array_proxy::lock
void lock() const
af::array::array_proxy::dims
dim4 dims() const
af::array::array_proxy::type
dtype type() const
af::array::array_proxy::slices
array::array_proxy slices(int first, int last)
af::array::array_proxy::H
array H() const
af::array::array_proxy::isvector
bool isvector() const
af::array::array_proxy::isrealfloating
bool isrealfloating() const
af::array::array_proxy::iscomplex
bool iscomplex() const
af::array::array_proxy::as
array as(dtype type) const
af::array::array_proxy::bytes
size_t bytes() const
af::array::array_proxy::ishalf
bool ishalf() const
af::array::array_proxy::isscalar
bool isscalar() const
af::array::array_proxy::isLocked
bool isLocked() const
af::array::array_proxy::host
T * host() const
af::array::array_proxy::isinteger
bool isinteger() const
af::array::array_proxy::issparse
bool issparse() const
af::array::array_proxy::slice
const array::array_proxy slice(int index) const
af::array::array_proxy::host
void host(void *ptr) const
af::array::array_proxy::device
T * device() const
af::array::array_proxy::eval
void eval() const
af::array::array_proxy::slice
array::array_proxy slice(int index)
af::array::array_proxy::array_proxy
array_proxy(const array_proxy &other)
af::array::array_proxy::isbool
bool isbool() const
af::array::array_proxy::T
array T() const
af::array::array_proxy::issingle
bool issingle() const
af::array::array_proxy::dims
dim_t dims(unsigned dim) const
af::array::array_proxy::elements
dim_t elements() const
af::array::array_proxy::allocated
size_t allocated() const
af::array::array_proxy::array_proxy
array_proxy(array &par, af_index_t *ssss, bool linear=false)
af::array::array_proxy::isrow
bool isrow() const
af::array::array_proxy::rows
const array::array_proxy rows(int first, int last) const
af::array::array_proxy::row
const array::array_proxy row(int index) const
af::array::array_proxy::copy
array copy() const
af::array::array_proxy::cols
const array::array_proxy cols(int first, int last) const
af::array::array_proxy::get
af_array get()
af::array::array_proxy::isfloating
bool isfloating() const
af::array::array_proxy::row
array::array_proxy row(int index)
af::array::array_proxy::cols
array::array_proxy cols(int first, int last)
af::array::array_proxy::unlock
void unlock() const
af::array::array_proxy::~array_proxy
~array_proxy()
af::array::array_proxy::rows
array::array_proxy rows(int first, int last)
af::array::array_proxy::slices
const array::array_proxy slices(int first, int last) const
af::array::array_proxy::isdouble
bool isdouble() const
af::array::array_proxy::get
af_array get() const
af::array::array_proxy::col
array::array_proxy col(int index)
af::array::array_proxy::isreal
bool isreal() const
Definition array.h:130
af::array::array_proxy::col
const array::array_proxy col(int index) const
af::array::array_proxy::numdims
unsigned numdims() const
af::array::array_proxy::iscolumn
bool iscolumn() const
af::array
A multi dimensional data container.
Definition array.h:37
af::array::isempty
bool isempty() const
Returns true of the array is empty.
af::array::scalar
T scalar() const
Get the first element of the array as a scalar.
af::array::lock
void lock() const
Locks the device buffer in the memory manager.
af::array::dims
dim4 dims() const
Get dimensions of the array.
af::array::array
array(const dim4 &dims, const T *pointer, af::source src=afHost)
Create an array of specified size on the device using a host/device pointer.
af::array::type
dtype type() const
Get array data type.
af::array::array
array(dim_t dim0, dim_t dim1, dtype ty=f32)
Allocate a two-dimensional array of a specified size with undefined contents.
af::array::H
array H() const
Get the conjugate-transpose of the current array.
af::array::isvector
bool isvector() const
Returns true if only one of the array dimensions has more than one element.
af::array::isrealfloating
bool isrealfloating() const
Returns true if the array type is f16 f32 or f64.
af::array::iscomplex
bool iscomplex() const
Returns true if the array type is c32 or c64.
af::array::bytes
size_t bytes() const
Get the size of the array in bytes.
af::array::ishalf
bool ishalf() const
Returns true if the array type is f16.
af::array::isscalar
bool isscalar() const
Returns true of the array contains only one value.
af::array::isLocked
bool isLocked() const
Query if the array has been locked by the user.
af::array::host
T * host() const
Copy array data to host and return host pointer.
af::array::set
void set(af_array tmp)
Updates the internal af_array object.
af::array::array
array(const array &input, const dim_t dim0, const dim_t dim1=1, const dim_t dim2=1, const dim_t dim3=1)
Adjust the dimensions of an N-D array (fast).
af::array::isinteger
bool isinteger() const
Returns true if the array type is u8, b8, s32 u32, s64, u64, s16, u16.
af::array::issparse
bool issparse() const
Returns true if the array is a sparse array.
af::array::array
array(const dim4 &dims, dtype ty=f32)
Allocate an array of a specified size with undefined contents.
af::array::as
const array as(dtype type) const
Casts the array into another data type.
af::array::host
void host(void *ptr) const
Copy array data to existing host pointer.
af::array::device
T * device() const
Get the device pointer from the array and lock the buffer in memory manager.
af::array::array
array(dim_t dim0, dim_t dim1, dim_t dim2, dtype ty=f32)
Allocate a three-dimensional (3D) array of a specified size with undefined contents.
af::array::eval
void eval() const
Evaluate any JIT expressions to generate data for the array.
af::array::array
array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, dtype ty=f32)
Allocate a four-dimensional (4D) array of a specified size with undefined contents.
af::array::array
array(dim_t dim0, dtype ty=f32)
Allocate a one-dimensional array of a specified size with undefined contents.
af::array::isbool
bool isbool() const
Returns true if the array type is b8.
af::array::T
array T() const
Get the transposed the array.
af::array::issingle
bool issingle() const
Returns true if the array type is either f32 nor c32.
af::array::dims
dim_t dims(unsigned dim) const
Get dimensions of the array.
af::array::elements
dim_t elements() const
Get the total number of elements across all dimensions of the array.
af::array::allocated
size_t allocated() const
Get the size of the array in memory.
af::array::array
array(dim_t dim0, const T *pointer, af::source src=afHost)
Create a column vector on the device using a host/device pointer.
af::array::~array
~array()
af::array::isrow
bool isrow() const
Returns true if only the second dimension has more than one element.
af::array::array
array()
Create an uninitialized array (no data, undefined size)
af::array::array
array(dim_t dim0, dim_t dim1, const T *pointer, af::source src=afHost)
Create a 2D array on the device using a host/device pointer.
af::array::write
void write(const T *ptr, const size_t bytes, af::source src=afHost)
Perform deep copy from host/device pointer to an existing array.
af::array::copy
array copy() const
Perform deep copy of the array.
af::array::array
array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, const T *pointer, af::source src=afHost)
Create a 4D array on the device using a host/device pointer.
af::array::get
af_array get()
get the af_array handle
af::array::isfloating
bool isfloating() const
Returns true if the array type is f16 f32, f64, c32 or c64.
af::array::array
array(const array &input, const dim4 &dims)
Adjust the dimensions of an N-D array (fast).
af::array::unlock
void unlock() const
Unlocks the device buffer in the memory manager.
af::array::array
array(dim_t dim0, dim_t dim1, dim_t dim2, const T *pointer, af::source src=afHost)
Create a 3D array on the device using a host/device pointer.
af::array::array
array(const array &in)
Creates a copy to the in array.
af::array::array
array(const af_array handle)
Creates an array from an af_array handle.
af::array::isdouble
bool isdouble() const
Returns true if the array type is f64 or c64.
af::array::get
af_array get() const
get the af_array handle
af::array::isreal
bool isreal() const
Returns true if the array type is neither c32 nor c64.
Definition array.h:733
af::array::nonzeros
int nonzeros() const
Get the count of non-zero elements in the array.
af::array::numdims
unsigned numdims() const
Get the number of dimensions of the array.
af::array::iscolumn
bool iscolumn() const
Returns true if only the first dimension has more than one element.
af::dim4
Generic object that represents size and shape.
Definition dim4.hpp:26
af::dim4::get
dim_t * get()
Returns the underlying pointer to the dim4 object.
Definition dim4.hpp:103
af::exception
An ArrayFire exception class.
Definition exception.h:22
af::index
Wrapper for af_index.
Definition index.h:52
defines.h
af_dtype
af_dtype
Definition defines.h:210
f32
@ f32
32-bit floating point values
Definition defines.h:211
dim_t
long long dim_t
Definition defines.h:56
af_err
af_err
Definition defines.h:71
af_array
void * af_array
Definition defines.h:240
AFAPI
#define AFAPI
Definition defines.h:38
af_source
af_source
Definition defines.h:232
afHost
@ afHost
Host pointer.
Definition defines.h:234
AF_MAX_DIMS
#define AF_MAX_DIMS
Definition defines.h:237
device.h
dim4.hpp
exception.h
af_get_last_error
AFAPI void af_get_last_error(char **msg, dim_t *len)
Returns the last error message that occurred and its error message.
af::operator&&
AFAPI array operator&&(const array &lhs, const array &rhs)
Performs a logical AND operation on two arrays or an array and a value.
af::operator&
AFAPI array operator&(const array &lhs, const array &rhs)
Performs an bitwise AND operation on two arrays or an array and a value.
af::array::cols
const array::array_proxy cols(int first, int last) const
Returns a reference to sequence of columns.
af::array::cols
array::array_proxy cols(int first, int last)
Returns a reference to sequence of columns.
af::array::col
array::array_proxy col(int index)
Returns a reference to a col.
af::array::col
const array::array_proxy col(int index) const
Returns a reference to a col.
af::array::operator()
array::array_proxy operator()(const index &s0)
This operator returns a reference of the original array at a given coordinate.
af::array::operator()
const array::array_proxy operator()(const index &s0, const index &s1, const index &s2=span, const index &s3=span) const
This operator returns a reference of the original array at a given coordinate.
af::array::operator()
const array::array_proxy operator()(const index &s0) const
This operator returns a reference of the original array at a given coordinate.
af::array::operator()
array::array_proxy operator()(const index &s0, const index &s1, const index &s2=span, const index &s3=span)
This operator returns a reference of the original array at a given coordinate.
af::array::rows
const array::array_proxy rows(int first, int last) const
Returns a reference to sequence of rows.
af::array::row
const array::array_proxy row(int index) const
Returns a reference to a row.
af::array::row
array::array_proxy row(int index)
Returns a reference to a row.
af::array::rows
array::array_proxy rows(int first, int last)
Returns a reference to sequence of rows.
af::array::slices
array::array_proxy slices(int first, int last)
Returns a reference to a matrix in a volume.
af::array::slice
const array::array_proxy slice(int index) const
Returns a reference to a matrix in a volume.
af::array::slice
array::array_proxy slice(int index)
Returns a reference to a matrix in a volume.
af::array::slices
const array::array_proxy slices(int first, int last) const
Returns a reference to a matrix in a volume.
af_is_vector
AFAPI af_err af_is_vector(bool *result, const af_array arr)
Check if an array is a vector.
af_get_type
AFAPI af_err af_get_type(af_dtype *type, const af_array arr)
Gets the type of an array.
af_copy_array
AFAPI af_err af_copy_array(af_array *arr, const af_array in)
Deep copy an array to another.
af_is_column
AFAPI af_err af_is_column(bool *result, const af_array arr)
Check if an array is a column vector.
af_is_empty
AFAPI af_err af_is_empty(bool *result, const af_array arr)
Check if an array is empty.
af_is_single
AFAPI af_err af_is_single(bool *result, const af_array arr)
Check if an array is single precision type.
af_is_half
AFAPI af_err af_is_half(bool *result, const af_array arr)
Check if an array is 16 bit floating point type.
af_get_data_ref_count
AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in)
Get the reference count of af_array.
af_create_handle
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.
af_is_floating
AFAPI af_err af_is_floating(bool *result, const af_array arr)
Check if an array is floating precision type.
af_get_data_ptr
AFAPI af_err af_get_data_ptr(void *data, const af_array arr)
Copy data from an af_array to a C pointer.
af_get_elements
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.
af_is_realfloating
AFAPI af_err af_is_realfloating(bool *result, const af_array arr)
Check if an array is real floating point type.
af_is_integer
AFAPI af_err af_is_integer(bool *result, const af_array arr)
Check if an array is integer type.
af_retain_array
AFAPI af_err af_retain_array(af_array *out, const af_array in)
Increments an af_array reference count.
af_create_array
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.
af_set_manual_eval_flag
AFAPI af_err af_set_manual_eval_flag(bool flag)
Turn the manual eval flag on or off.
af_get_manual_eval_flag
AFAPI af_err af_get_manual_eval_flag(bool *flag)
Get the manual eval flag.
af_get_dims
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.
af_eval
AFAPI af_err af_eval(af_array in)
Evaluate any expressions in the Array.
af_eval_multiple
AFAPI af_err af_eval_multiple(const int num, af_array *arrays)
Evaluate multiple arrays together.
af_is_row
AFAPI af_err af_is_row(bool *result, const af_array arr)
Check if an array is row vector.
af_is_sparse
AFAPI af_err af_is_sparse(bool *result, const af_array arr)
Check if an array is sparse.
af_is_complex
AFAPI af_err af_is_complex(bool *result, const af_array arr)
Check if an array is complex type.
af_release_array
AFAPI af_err af_release_array(af_array arr)
Reduce the reference count of the af_array.
af_is_double
AFAPI af_err af_is_double(bool *result, const af_array arr)
Check if an array is double precision type.
af_is_scalar
AFAPI af_err af_is_scalar(bool *result, const af_array arr)
Check if an array is scalar, ie.
af_get_numdims
AFAPI af_err af_get_numdims(unsigned *result, const af_array arr)
Gets the number of dimensions of an array.
af_get_scalar
AFAPI af_err af_get_scalar(void *output_value, const af_array arr)
Get first element from an array.
af_is_real
AFAPI af_err af_is_real(bool *result, const af_array arr)
Check if an array is real type.
af_is_bool
AFAPI af_err af_is_bool(bool *result, const af_array arr)
Check if an array is bool type.
af_write_array
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.
af::getManualEvalFlag
AFAPI bool getManualEvalFlag()
Get the manual eval flag.
af::setManualEvalFlag
AFAPI void setManualEvalFlag(bool flag)
Turn the manual eval flag on or off.
af::eval
array & eval(array &a)
Evaluate an expression (nonblocking).
Definition array.h:1467
af_free_host
AFAPI af_err af_free_host(void *ptr)
index.h
af
Definition algorithm.h:15
seq.h
af::af_cdouble
Definition complex.h:32
af::af_cfloat
Definition complex.h:24
af::dtype_traits
Definition traits.hpp:21
af_index_t
Struct used to index an af_array.
Definition index.h:22
traits.hpp
util.h