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
29namespace 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
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#if AF_API_VERSION >= 32
92#define ASSIGN_32(OP) \
93 array_proxy& operator OP(const short &a); \
94 array_proxy& operator OP(const unsigned short &a);
95#else
96#define ASSIGN_32(OP)
97#endif
98
99#if AF_API_VERSION >= 310
100#define ASSIGN_310(OP) \
101 array_proxy& operator OP(const signed char &a);
102#else
103#define ASSIGN_310(OP)
104#endif
105
106#define ASSIGN(OP) \
107 ASSIGN_(OP) \
108 ASSIGN_32(OP) \
109 ASSIGN_310(OP)
110
116#undef ASSIGN
117#undef ASSIGN_
118#undef ASSIGN_32
119#undef ASSIGN_310
120
121 // af::array member functions. same behavior as those below
123 af_array get() const;
125 template<typename T> T* host() const;
126 void host(void *ptr) const;
127 dtype type() const;
128 dim4 dims() const;
129 dim_t dims(unsigned dim) const;
130 unsigned numdims() const;
131 size_t bytes() const;
132 size_t allocated() const;
133 array copy() const;
134 bool isempty() const;
135 bool isscalar() const;
136 bool isvector() const;
137 bool isrow() const;
138 bool iscolumn() const;
139 bool iscomplex() const;
140 inline bool isreal() const { return !iscomplex(); }
141 bool isdouble() const;
142 bool issingle() const;
143#if AF_API_VERSION >= 37
144 bool ishalf() const;
145#endif
146 bool isrealfloating() const;
147 bool isfloating() const;
148 bool isinteger() const;
149 bool isbool() const;
150#if AF_API_VERSION >= 34
151 bool issparse() const;
152#endif
153 void eval() const;
154 array as(dtype type) const;
155 array T() const;
156 array H() const;
157 template<typename T> T scalar() const;
158 template<typename T> T* device() const;
159 void unlock() const;
160#if AF_API_VERSION >= 31
161 void lock() const;
162#endif
163
164#if AF_API_VERSION >= 34
165 bool isLocked() const;
166#endif
167
169 const array::array_proxy row(int index) const;
170
171 array::array_proxy rows(int first, int last);
172 const array::array_proxy rows(int first, int last) const;
173
175 const array::array_proxy col(int index) const;
176 array::array_proxy cols(int first, int last);
177 const array::array_proxy cols(int first, int last) const;
178
181
182 array::array_proxy slices(int first, int last);
183 const array::array_proxy slices(int first, int last) const;
184 };
185
194
195#if AF_API_VERSION >= 37
196#if AF_COMPILER_CXX_RVALUE_REFERENCES
205 array(array &&other) AF_NOEXCEPT;
206
217 array &operator=(array &&other) AF_NOEXCEPT;
218#endif
219#endif
227 explicit
228 array(const af_array handle);
229
235 array(const array& in);
236
259 explicit
260 array(dim_t dim0, dtype ty = f32);
261
285 explicit
286 array(dim_t dim0, dim_t dim1, dtype ty = f32);
287
312 explicit
313 array(dim_t dim0, dim_t dim1, dim_t dim2, dtype ty = f32);
314
340 explicit
341 array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3, dtype ty = f32);
342
368 explicit
369 array(const dim4& dims, dtype ty = f32);
370
398 template<typename T>
399 explicit
401 const T *pointer, af::source src=afHost);
402
403
426 template<typename T>
427 explicit
428 array(dim_t dim0, dim_t dim1,
429 const T *pointer, af::source src=afHost);
430
431
458 template<typename T>
459 explicit
460 array(dim_t dim0, dim_t dim1, dim_t dim2,
461 const T *pointer, af::source src=afHost);
462
463
492 template<typename T>
493 explicit
494 array(dim_t dim0, dim_t dim1, dim_t dim2, dim_t dim3,
495 const T *pointer, af::source src=afHost);
496
535 template<typename T>
536 explicit
537 array(const dim4& dims,
538 const T *pointer, af::source src=afHost);
539
540#if AF_API_VERSION >= 38
541#if AF_COMPILER_CXX_GENERALIZED_INITIALIZERS
543 template <typename T, typename = typename std::enable_if<
544 std::is_fundamental<T>::value, void>::type>
545 array(std::initializer_list<T> list)
546 : arr(nullptr) {
547 dim_t size = list.size();
548 if (af_err __aferr = af_create_array(&arr, list.begin(), 1, &size,
549 static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
550 char *msg = NULL;
551 af_get_last_error(&msg, NULL);
552 af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
553 __LINE__, __aferr);
554 af_free_host(msg);
555 throw std::move(ex);
556 }
557 }
558
560 template <typename T, typename = typename std::enable_if<
561 std::is_fundamental<T>::value, void>::type>
562 array(const af::dim4 &dims, std::initializer_list<T> list)
563 : arr(nullptr) {
564 const dim_t *size = dims.get();
565 if (af_err __aferr = af_create_array(
566 &arr, list.begin(), AF_MAX_DIMS, size,
567 static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
568 char *msg = NULL;
569 af_get_last_error(&msg, NULL);
570 af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
571 __LINE__, __aferr);
572 af_free_host(msg);
573 throw std::move(ex);
574 }
575 }
576#endif
577#endif
578
605 array(const array& input, const dim4& dims);
606
637 array( const array& input,
638 const dim_t dim0, const dim_t dim1 = 1,
639 const dim_t dim2 = 1, const dim_t dim3 = 1);
640
645
649 af_array get() const;
650
655
659 template<typename T> T* host() const;
660
664 void host(void *ptr) const;
665
670 template<typename T> void write(const T *ptr, const size_t bytes, af::source src = afHost);
671
675 dtype type() const;
676
680 dim4 dims() const;
681
685 dim_t dims(unsigned dim) const;
686
690 unsigned numdims() const;
691
695 size_t bytes() const;
696
701 size_t allocated() const;
702
706 array copy() const;
707
711 bool isempty() const;
712
716 bool isscalar() const;
717
722 bool isvector() const;
723
728 bool isrow() const;
729
734 bool iscolumn() const;
735
739 bool iscomplex() const;
740
744 inline bool isreal() const { return !iscomplex(); }
745
749 bool isdouble() const;
750
754 bool issingle() const;
755
756#if AF_API_VERSION >= 37
760 bool ishalf() const;
761#endif
762
766 bool isrealfloating() const;
767
772 bool isfloating() const;
773
778 bool isinteger() const;
779
783 bool isbool() const;
784
785#if AF_API_VERSION >= 34
789 bool issparse() const;
790#endif
791
795 void eval() const;
796
803 template<typename T> T scalar() const;
804
813 template<typename T> T* device() const;
814
815 // INDEXING
816 // Single arguments
817
836
842 const array::array_proxy operator()(const index &s0) const;
843
844
863 const index &s1,
864 const index &s2 = span,
865 const index &s3 = span);
866
873 const index &s1,
874 const index &s2 = span,
875 const index &s3 = span) const;
876
877
890 const array::array_proxy row(int index) const;
891
901 array::array_proxy rows(int first, int last);
902 const array::array_proxy rows(int first, int last) const;
904
917 const array::array_proxy col(int index) const;
918
928 array::array_proxy cols(int first, int last);
929 const array::array_proxy cols(int first, int last) const;
931
944 const array::array_proxy slice(int index) const;
945
954 array::array_proxy slices(int first, int last);
955 const array::array_proxy slices(int first, int last) const;
957
988 const array as(dtype type) const;
989
990
992
996 array T() const;
1000 array H() const;
1001
1002#define ASSIGN_(OP2) \
1003 array& OP2(const array &val); \
1004 array& OP2(const double &val); \
1005 array& OP2(const cdouble &val); \
1006 array& OP2(const cfloat &val); \
1007 array& OP2(const float &val); \
1008 array& OP2(const int &val); \
1009 array& OP2(const unsigned &val); \
1010 array& OP2(const bool &val); \
1011 array& OP2(const char &val); \
1012 array& OP2(const unsigned char &val); \
1013 array& OP2(const long &val); \
1014 array& OP2(const unsigned long &val); \
1015 array& OP2(const long long &val); \
1016 array& OP2(const unsigned long long &val);
1017
1018#if AF_API_VERSION >= 32
1019#define ASSIGN_32(OP) \
1020 array& OP(const short &val); \
1021 array& OP(const unsigned short &val);
1022#else
1023#define ASSIGN_32(OP)
1024#endif
1025
1026#if AF_API_VERSION >= 310
1027#define ASSIGN_310(OP) \
1028 array& OP(const signed char &val);
1029#else
1030#define ASSIGN_310(OP)
1031#endif
1032
1033#define ASSIGN(OP) \
1034 ASSIGN_(OP) \
1035 ASSIGN_32(OP) \
1036 ASSIGN_310(OP)
1037
1047 ASSIGN(operator=)
1049
1059 ASSIGN(operator+=)
1061
1071 ASSIGN(operator-=)
1073
1083 ASSIGN(operator*=)
1085
1096 ASSIGN(operator/=)
1098
1099
1100#undef ASSIGN
1101#undef ASSIGN_
1102#undef ASSIGN_32
1103#undef ASSIGN_310
1104
1110 array operator -() const;
1117 array operator !() const;
1119#if AF_API_VERSION >= 38
1125 array operator ~() const;
1126#endif
1127
1132 int nonzeros() const;
1134
1140 void lock() const;
1142
1143#if AF_API_VERSION >= 34
1149 bool isLocked() const;
1150#endif
1151
1152
1158 void unlock() const;
1160 // end of class array
1161
1162#define BIN_OP_(OP) \
1163 AFAPI array OP (const array& lhs, const array& rhs); \
1164 AFAPI array OP (const bool& lhs, const array& rhs); \
1165 AFAPI array OP (const int& lhs, const array& rhs); \
1166 AFAPI array OP (const unsigned& lhs, const array& rhs); \
1167 AFAPI array OP (const char& lhs, const array& rhs); \
1168 AFAPI array OP (const unsigned char& lhs, const array& rhs); \
1169 AFAPI array OP (const long& lhs, const array& rhs); \
1170 AFAPI array OP (const unsigned long& lhs, const array& rhs); \
1171 AFAPI array OP (const long long& lhs, const array& rhs); \
1172 AFAPI array OP (const unsigned long long& lhs, const array& rhs); \
1173 AFAPI array OP (const double& lhs, const array& rhs); \
1174 AFAPI array OP (const float& lhs, const array& rhs); \
1175 AFAPI array OP (const cfloat& lhs, const array& rhs); \
1176 AFAPI array OP (const cdouble& lhs, const array& rhs); \
1177 AFAPI array OP (const array& lhs, const bool& rhs); \
1178 AFAPI array OP (const array& lhs, const int& rhs); \
1179 AFAPI array OP (const array& lhs, const unsigned& rhs); \
1180 AFAPI array OP (const array& lhs, const char& rhs); \
1181 AFAPI array OP (const array& lhs, const unsigned char& rhs); \
1182 AFAPI array OP (const array& lhs, const long& rhs); \
1183 AFAPI array OP (const array& lhs, const unsigned long& rhs); \
1184 AFAPI array OP (const array& lhs, const long long& rhs); \
1185 AFAPI array OP (const array& lhs, const unsigned long long& rhs); \
1186 AFAPI array OP (const array& lhs, const double& rhs); \
1187 AFAPI array OP (const array& lhs, const float& rhs); \
1188 AFAPI array OP (const array& lhs, const cfloat& rhs); \
1189 AFAPI array OP (const array& lhs, const cdouble& rhs);
1190
1191#if AF_API_VERSION >= 32
1192#define BIN_OP_32(OP) \
1193 AFAPI array OP (const short& lhs, const array& rhs); \
1194 AFAPI array OP (const unsigned short& lhs, const array& rhs); \
1195 AFAPI array OP (const array& lhs, const short& rhs); \
1196 AFAPI array OP (const array& lhs, const unsigned short& rhs);
1197
1198#else
1199#define BIN_OP_32(OP)
1200#endif
1201
1202#if AF_API_VERSION >= 310
1203#define BIN_OP_310(OP) \
1204 AFAPI array OP (const signed char& lhs, const array& rhs); \
1205 AFAPI array OP (const array& lhs, const signed char& rhs);
1206#else
1207#define BIN_OP_310(OP)
1208#endif
1209
1210#define BIN_OP(OP) \
1211 BIN_OP_(OP) \
1212 BIN_OP_32(OP) \
1213 BIN_OP_310(OP)
1214
1223 BIN_OP(operator+ )
1234 BIN_OP(operator- )
1245 BIN_OP(operator* )
1256 BIN_OP(operator/ )
1267 BIN_OP(operator==)
1279 BIN_OP(operator!=)
1291 BIN_OP(operator< )
1302 BIN_OP(operator<=)
1314 BIN_OP(operator> )
1326 BIN_OP(operator>=)
1339 BIN_OP(operator||)
1351 BIN_OP(operator% )
1364 BIN_OP(operator| )
1377 BIN_OP(operator^ )
1390 BIN_OP(operator<<)
1403 BIN_OP(operator>>)
1406#undef BIN_OP
1407#undef BIN_OP_
1408#undef BIN_OP_32
1409#undef BIN_OP_310
1410
1421 AFAPI array operator&(const array& lhs, const array& rhs);
1422 AFAPI array operator&(const array& lhs, const bool& rhs);
1423 AFAPI array operator&(const array& lhs, const cdouble& rhs);
1424 AFAPI array operator&(const array& lhs, const cfloat& rhs);
1425 AFAPI array operator&(const array& lhs, const char& rhs);
1426 AFAPI array operator&(const array& lhs, const double& rhs);
1427 AFAPI array operator&(const array& lhs, const float& rhs);
1428 AFAPI array operator&(const array& lhs, const int& rhs);
1429 AFAPI array operator&(const array& lhs, const long long& rhs);
1430 AFAPI array operator&(const array& lhs, const long& rhs);
1431 AFAPI array operator&(const array& lhs, const short& rhs);
1432 AFAPI array operator&(const array& lhs, const signed char& rhs);
1433 AFAPI array operator&(const array& lhs, const unsigned char& rhs);
1434 AFAPI array operator&(const array& lhs, const unsigned long long& rhs);
1435 AFAPI array operator&(const array& lhs, const unsigned long& rhs);
1436 AFAPI array operator&(const array& lhs, const unsigned short& rhs);
1437 AFAPI array operator&(const array& lhs, const unsigned& rhs);
1438 AFAPI array operator&(const bool& lhs, const array& rhs);
1439 AFAPI array operator&(const cdouble& lhs, const array& rhs);
1440 AFAPI array operator&(const cfloat& lhs, const array& rhs);
1441 AFAPI array operator&(const char& lhs, const array& rhs);
1442 AFAPI array operator&(const double& lhs, const array& rhs);
1443 AFAPI array operator&(const float& lhs, const array& rhs);
1444 AFAPI array operator&(const int& lhs, const array& rhs);
1445 AFAPI array operator&(const long long& lhs, const array& rhs);
1446 AFAPI array operator&(const long& lhs, const array& rhs);
1447 AFAPI array operator&(const short& lhs, const array& rhs);
1448 AFAPI array operator&(const signed char& lhs, const array& rhs);
1449 AFAPI array operator&(const unsigned char& lhs, const array& rhs);
1450 AFAPI array operator&(const unsigned long long& lhs, const array& rhs);
1451 AFAPI array operator&(const unsigned long& lhs, const array& rhs);
1452 AFAPI array operator&(const unsigned short& lhs, const array& rhs);
1453 AFAPI array operator&(const unsigned& lhs, const array& rhs);
1466 AFAPI array operator&&(const array& lhs, const array& rhs);
1467 AFAPI array operator&&(const array& lhs, const bool& rhs);
1468 AFAPI array operator&&(const array& lhs, const cdouble& rhs);
1469 AFAPI array operator&&(const array& lhs, const cfloat& rhs);
1470 AFAPI array operator&&(const array& lhs, const char& rhs);
1471 AFAPI array operator&&(const array& lhs, const double& rhs);
1472 AFAPI array operator&&(const array& lhs, const float& rhs);
1473 AFAPI array operator&&(const array& lhs, const int& rhs);
1474 AFAPI array operator&&(const array& lhs, const long long& rhs);
1475 AFAPI array operator&&(const array& lhs, const long& rhs);
1476 AFAPI array operator&&(const array& lhs, const short& rhs);
1477 AFAPI array operator&&(const array& lhs, const signed char& rhs);
1478 AFAPI array operator&&(const array& lhs, const unsigned char& rhs);
1479 AFAPI array operator&&(const array& lhs, const unsigned long long& rhs);
1480 AFAPI array operator&&(const array& lhs, const unsigned long& rhs);
1481 AFAPI array operator&&(const array& lhs, const unsigned short& rhs);
1482 AFAPI array operator&&(const array& lhs, const unsigned& rhs);
1483 AFAPI array operator&&(const bool& lhs, const array& rhs);
1484 AFAPI array operator&&(const cdouble& lhs, const array& rhs);
1485 AFAPI array operator&&(const cfloat& lhs, const array& rhs);
1486 AFAPI array operator&&(const char& lhs, const array& rhs);
1487 AFAPI array operator&&(const double& lhs, const array& rhs);
1488 AFAPI array operator&&(const float& lhs, const array& rhs);
1489 AFAPI array operator&&(const int& lhs, const array& rhs);
1490 AFAPI array operator&&(const long long& lhs, const array& rhs);
1491 AFAPI array operator&&(const long& lhs, const array& rhs);
1492 AFAPI array operator&&(const short& lhs, const array& rhs);
1493 AFAPI array operator&&(const signed char& lhs, const array& rhs);
1494 AFAPI array operator&&(const unsigned char& lhs, const array& rhs);
1495 AFAPI array operator&&(const unsigned long long& lhs, const array& rhs);
1496 AFAPI array operator&&(const unsigned long& lhs, const array& rhs);
1497 AFAPI array operator&&(const unsigned short& lhs, const array& rhs);
1498 AFAPI array operator&&(const unsigned& lhs, const array& rhs);
1501
1503
1507 inline array &eval(array &a) { a.eval(); return a; }
1508
1509#if AF_API_VERSION >= 34
1513 AFAPI void eval(int num, array **arrays);
1514#endif
1516 inline void eval(array &a, array &b)
1517 {
1518#if AF_API_VERSION >= 34
1519 array *arrays[] = {&a, &b};
1520 return eval(2, arrays);
1521#else
1522 eval(a); b.eval();
1523#endif
1524 }
1525
1526 inline void eval(array &a, array &b, array &c)
1527 {
1528#if AF_API_VERSION >= 34
1529 array *arrays[] = {&a, &b, &c};
1530 return eval(3, arrays);
1531#else
1532 eval(a, b); c.eval();
1533#endif
1534 }
1535
1536 inline void eval(array &a, array &b, array &c, array &d)
1537 {
1538#if AF_API_VERSION >= 34
1539 array *arrays[] = {&a, &b, &c, &d};
1540 return eval(4, arrays);
1541#else
1542 eval(a, b, c); d.eval();
1543#endif
1544
1545 }
1546
1547 inline void eval(array &a, array &b, array &c, array &d, array &e)
1548 {
1549#if AF_API_VERSION >= 34
1550 array *arrays[] = {&a, &b, &c, &d, &e};
1551 return eval(5, arrays);
1552#else
1553 eval(a, b, c, d); e.eval();
1554#endif
1555 }
1556
1557 inline void eval(array &a, array &b, array &c, array &d, array &e, array &f)
1558 {
1559#if AF_API_VERSION >= 34
1560 array *arrays[] = {&a, &b, &c, &d, &e, &f};
1561 return eval(6, arrays);
1562#else
1563 eval(a, b, c, d, e); f.eval();
1564#endif
1565 }
1566
1567#if AF_API_VERSION >= 37
1568
1570 inline const array &eval(const array &a) { a.eval(); return a; }
1571
1572#if AF_COMPILER_CXX_VARIADIC_TEMPLATES
1573 template <typename... ARRAYS>
1574 inline void eval(ARRAYS... in) {
1575 array *arrays[] = {const_cast<array *>(&in)...};
1576 eval((int)sizeof...(in), arrays);
1577 }
1578
1579#else
1580
1581 inline void eval(const array &a, const array &b)
1582 {
1583 const array *arrays[] = {&a, &b};
1584 return eval(2, const_cast<array **>(arrays));
1585 }
1586
1587 inline void eval(const array &a, const array &b, const array &c)
1588 {
1589 const array *arrays[] = {&a, &b, &c};
1590 return eval(3, const_cast<array **>(arrays));
1591 }
1592
1593 inline void eval(const array &a, const array &b, const array &c,
1594 const array &d)
1596 const array *arrays[] = {&a, &b, &c, &d};
1597 return eval(4, const_cast<array **>(arrays));
1598 }
1599
1600 inline void eval(const array &a, const array &b, const array &c,
1601 const array &d, const array &e)
1603 const array *arrays[] = {&a, &b, &c, &d, &e};
1604 return eval(5, const_cast<array **>(arrays));
1605 }
1606
1607 inline void eval(const array &a, const array &b, const array &c,
1608 const array &d, const array &e, const array &f)
1610 const array *arrays[] = {&a, &b, &c, &d, &e, &f};
1611 return eval(6, const_cast<array **>(arrays));
1612 }
1613#endif // AF_COMPILER_CXX_VARIADIC_TEMPLATES
1614#endif
1615
1616#if AF_API_VERSION >= 34
1620 AFAPI void setManualEvalFlag(bool flag);
1621#endif
1623#if AF_API_VERSION >= 34
1625 AFAPI bool getManualEvalFlag();
1626#endif
1632}
1633#endif
1634
1635#ifdef __cplusplus
1636extern "C" {
1637#endif
1638
1657 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);
1658
1672 AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t * const dims, const af_dtype type);
1673
1678
1682 AFAPI af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src);
1683
1689 AFAPI af_err af_get_data_ptr(void *data, const af_array arr);
1690
1697
1702
1703#if AF_API_VERSION >= 31
1707 AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
1708#endif
1709
1714
1715#if AF_API_VERSION >= 34
1719 AFAPI af_err af_eval_multiple(const int num, af_array *arrays);
1720#endif
1721
1722#if AF_API_VERSION >= 34
1727#endif
1728
1729#if AF_API_VERSION >= 34
1734#endif
1735
1745
1755
1768 const af_array arr);
1769
1778 AFAPI af_err af_get_numdims(unsigned *result, const af_array arr);
1779
1788 AFAPI af_err af_is_empty (bool *result, const af_array arr);
1789
1798 AFAPI af_err af_is_scalar (bool *result, const af_array arr);
1799
1808 AFAPI af_err af_is_row (bool *result, const af_array arr);
1809
1818 AFAPI af_err af_is_column (bool *result, const af_array arr);
1819
1830 AFAPI af_err af_is_vector (bool *result, const af_array arr);
1831
1840 AFAPI af_err af_is_complex (bool *result, const af_array arr);
1841
1852 AFAPI af_err af_is_real (bool *result, const af_array arr);
1853
1862 AFAPI af_err af_is_double (bool *result, const af_array arr);
1863
1872 AFAPI af_err af_is_single (bool *result, const af_array arr);
1873
1874#if AF_API_VERSION >= 37
1883 AFAPI af_err af_is_half(bool *result, const af_array arr);
1884#endif
1885
1894 AFAPI af_err af_is_realfloating (bool *result, const af_array arr);
1895
1907 AFAPI af_err af_is_floating (bool *result, const af_array arr);
1908
1917 AFAPI af_err af_is_integer (bool *result, const af_array arr);
1918
1927 AFAPI af_err af_is_bool (bool *result, const af_array arr);
1928
1929#if AF_API_VERSION >= 34
1938 AFAPI af_err af_is_sparse (bool *result, const af_array arr);
1939#endif
1940
1941#if AF_API_VERSION >= 35
1949 AFAPI af_err af_get_scalar(void* output_value, const af_array arr);
1950#endif
1951
1956#ifdef __cplusplus
1957}
1958#endif
#define BIN_OP(OP)
Definition: array.h:1212
#define ASSIGN(OP)
Definition: array.h:1034
Intermediate data class.
Definition: array.h:57
array::array_proxy slices(int first, int last)
bool isrealfloating() const
bool iscomplex() const
array as(dtype type) const
size_t bytes() const
bool isinteger() const
const array::array_proxy slice(int index) const
void host(void *ptr) const
array::array_proxy slice(int index)
array_proxy(const array_proxy &other)
dim_t dims(unsigned dim) const
dim_t elements() const
size_t allocated() const
array_proxy(array &par, af_index_t *ssss, bool linear=false)
const array::array_proxy rows(int first, int last) const
const array::array_proxy row(int index) const
const array::array_proxy cols(int first, int last) const
bool isfloating() const
array::array_proxy row(int index)
array::array_proxy cols(int first, int last)
array::array_proxy rows(int first, int last)
const array::array_proxy slices(int first, int last) const
af_array get() const
array::array_proxy col(int index)
bool isreal() const
Definition: array.h:140
const array::array_proxy col(int index) const
unsigned numdims() const
A multi dimensional data container.
Definition: array.h:37
bool isempty() const
Returns true of the array is empty.
T scalar() const
Get the first element of the array as a scalar.
dim4 dims() const
Get dimensions of the 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.
dtype type() const
Get array data type.
array(dim_t dim0, dim_t dim1, dtype ty=f32)
Allocate a two-dimensional array of a specified size with undefined contents.
array H() const
Get the conjugate-transpose of the current array.
bool isvector() const
Returns true if only one of the array dimensions has more than one element.
bool isrealfloating() const
Returns true if the array type is f16 f32 or f64.
bool iscomplex() const
Returns true if the array type is c32 or c64.
size_t bytes() const
Get the size of the array in bytes.
bool ishalf() const
Returns true if the array type is f16.
bool isscalar() const
Returns true of the array contains only one value.
T * host() const
Copy array data to host and return host pointer.
void set(af_array tmp)
Updates the internal af_array object.
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).
bool isinteger() const
Returns true if the array type is s8, u8, b8, s32, u32, s64, u64, s16, u16.
bool issparse() const
Returns true if the array is a sparse array.
array(const dim4 &dims, dtype ty=f32)
Allocate an array of a specified size with undefined contents.
const array as(dtype type) const
Casts the array into another data type.
void host(void *ptr) const
Copy array data to existing host pointer.
T * device() const
Get the device pointer from the array and lock the buffer in memory manager.
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.
void eval() const
Evaluate any JIT expressions to generate data for the 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.
array(dim_t dim0, dtype ty=f32)
Allocate a one-dimensional array of a specified size with undefined contents.
bool isbool() const
Returns true if the array type is b8.
array T() const
Get the transposed the array.
bool issingle() const
Returns true if the array type is either f32 nor c32.
dim_t dims(unsigned dim) const
Get dimensions of the array.
dim_t elements() const
Get the total number of elements across all dimensions of the array.
size_t allocated() const
Get the size of the array in memory.
array(dim_t dim0, const T *pointer, af::source src=afHost)
Create a column vector on the device using a host/device pointer.
bool isrow() const
Returns true if only the second dimension has more than one element.
array()
Create an uninitialized array (no data, undefined size)
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.
void write(const T *ptr, const size_t bytes, af::source src=afHost)
Perform deep copy from host/device pointer to an existing array.
array copy() const
Perform deep copy of the 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()
get the af_array handle
bool isfloating() const
Returns true if the array type is f16 f32, f64, c32 or c64.
array(const array &input, const dim4 &dims)
Adjust the dimensions of an N-D array (fast).
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.
array(const array &in)
Creates a copy to the in array.
array(const af_array handle)
Creates an array from an af_array handle.
bool isdouble() const
Returns true if the array type is f64 or c64.
af_array get() const
get the af_array handle
bool isreal() const
Returns true if the array type is neither c32 nor c64.
Definition: array.h:744
unsigned numdims() const
Get the number of dimensions of the array.
bool iscolumn() const
Returns true if only the first dimension has more than one element.
Generic object that represents size and shape.
Definition: dim4.hpp:26
dim_t * get()
Returns the underlying pointer to the dim4 object.
Definition: dim4.hpp:103
An ArrayFire exception class.
Definition: exception.h:22
Wrapper for af_index.
Definition: index.h:52
af_dtype
Definition: defines.h:210
@ f32
32-bit floating point values
Definition: defines.h:211
long long dim_t
Definition: defines.h:56
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:243
#define AFAPI
Definition: defines.h:38
af_source
Definition: defines.h:235
@ afHost
Host pointer.
Definition: defines.h:237
#define AF_MAX_DIMS
Definition: defines.h:240
AFAPI void af_get_last_error(char **msg, dim_t *len)
Returns the last error message that occurred and its error message.
AFAPI array operator&&(const array &lhs, const array &rhs)
Performs a logical AND operation on two arrays or an array and a value.
AFAPI array operator&(const array &lhs, const array &rhs)
Performs an bitwise AND operation on two arrays or an array and a value.
const array::array_proxy cols(int first, int last) const
Returns a reference to sequence of columns.
array::array_proxy cols(int first, int last)
Returns a reference to sequence of columns.
array::array_proxy col(int index)
Returns a reference to a col.
const array::array_proxy col(int index) const
Returns a reference to a col.
array::array_proxy operator()(const index &s0)
This operator returns a reference of the original array at a given coordinate.
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.
const array::array_proxy operator()(const index &s0) const
This operator returns a reference of the original array at a given coordinate.
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.
const array::array_proxy rows(int first, int last) const
Returns a reference to sequence of rows.
const array::array_proxy row(int index) const
Returns a reference to a row.
array::array_proxy row(int index)
Returns a reference to a row.
array::array_proxy rows(int first, int last)
Returns a reference to sequence of rows.
array::array_proxy slices(int first, int last)
Returns a reference to a matrix in a volume.
const array::array_proxy slice(int index) const
Returns a reference to a matrix in a volume.
array::array_proxy slice(int index)
Returns a reference to a matrix in a volume.
const array::array_proxy slices(int first, int last) const
Returns a reference to a matrix in a volume.
AFAPI af_err af_is_vector(bool *result, const af_array arr)
Check if an array is a vector.
AFAPI af_err af_get_type(af_dtype *type, const af_array arr)
Gets the type of an array.
AFAPI af_err af_copy_array(af_array *arr, const af_array in)
Deep copy an array to another.
AFAPI af_err af_is_column(bool *result, const af_array arr)
Check if an array is a column vector.
AFAPI af_err af_is_empty(bool *result, const af_array arr)
Check if an array is empty.
AFAPI af_err af_is_single(bool *result, const af_array arr)
Check if an array is single precision type.
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_data_ref_count(int *use_count, const af_array in)
Get the reference count of af_array.
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.
AFAPI af_err af_is_floating(bool *result, const af_array arr)
Check if an array is floating precision type.
AFAPI af_err af_get_data_ptr(void *data, const af_array arr)
Copy data from an af_array to a C pointer.
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_realfloating(bool *result, const af_array arr)
Check if an array is real floating point type.
AFAPI af_err af_is_integer(bool *result, const af_array arr)
Check if an array is integer type.
AFAPI af_err af_retain_array(af_array *out, const af_array in)
Increments an af_array reference count.
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.
AFAPI af_err af_set_manual_eval_flag(bool flag)
Turn the manual eval flag on or off.
AFAPI af_err af_get_manual_eval_flag(bool *flag)
Get the manual eval flag.
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_eval(af_array in)
Evaluate any expressions in the Array.
AFAPI af_err af_eval_multiple(const int num, af_array *arrays)
Evaluate multiple arrays together.
AFAPI af_err af_is_row(bool *result, const af_array arr)
Check if an array is row vector.
AFAPI af_err af_is_sparse(bool *result, const af_array arr)
Check if an array is sparse.
AFAPI af_err af_is_complex(bool *result, const af_array arr)
Check if an array is complex type.
AFAPI af_err af_release_array(af_array arr)
Reduce the reference count of the af_array.
AFAPI af_err af_is_double(bool *result, const af_array arr)
Check if an array is double precision type.
AFAPI af_err af_is_scalar(bool *result, const af_array arr)
Check if an array is scalar, ie.
AFAPI af_err af_get_numdims(unsigned *result, const af_array arr)
Gets the number of dimensions of an array.
AFAPI af_err af_get_scalar(void *output_value, const af_array arr)
Get first element from an array.
AFAPI af_err af_is_real(bool *result, const af_array arr)
Check if an array is real type.
AFAPI af_err af_is_bool(bool *result, const af_array arr)
Check if an array is bool 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.
AFAPI bool getManualEvalFlag()
Get the manual eval flag.
AFAPI void setManualEvalFlag(bool flag)
Turn the manual eval flag on or off.
array & eval(array &a)
Evaluate an expression (nonblocking).
Definition: array.h:1509
AFAPI af_err af_free_host(void *ptr)
Definition: algorithm.h:15
Struct used to index an af_array.
Definition: index.h:22