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
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
108#undef ASSIGN
109#endif
110
111 // af::array member functions. same behavior as those below
113 af_array get() 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
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
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
171
172 array::array_proxy slices(int first, int last);
173 const array::array_proxy slices(int first, int last) const;
174 };
175
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 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>
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
525 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
624
628 af_array get() const;
629
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
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
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
814
820 const array::array_proxy operator()(const index &s0) const;
821
822
841 const index &s1,
842 const index &s2 = span,
843 const index &s3 = span);
844
851 const index &s1,
852 const index &s2 = span,
853 const index &s3 = span) const;
854
855
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;
882
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;
909
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;
935
965 const array as(dtype type) const;
966
967
969
973 array T() const;
977 array H() const;
978
979#define ASSIGN_(OP2) \
980 array& OP2(const array &val); \
981 array& OP2(const double &val); \
982 array& OP2(const cdouble &val); \
983 array& OP2(const cfloat &val); \
984 array& OP2(const float &val); \
985 array& OP2(const int &val); \
986 array& OP2(const unsigned &val); \
987 array& OP2(const bool &val); \
988 array& OP2(const char &val); \
989 array& OP2(const unsigned char &val); \
990 array& OP2(const long &val); \
991 array& OP2(const unsigned long &val); \
992 array& OP2(const long long &val); \
993 array& OP2(const unsigned long long &val);
994
995
996#if AF_API_VERSION >= 32
997#define ASSIGN(OP) \
998 ASSIGN_(OP) \
999 array& OP(const short &val); \
1000 array& OP(const unsigned short &val);
1001
1002#else
1003#define ASSIGN(OP) ASSIGN_(OP)
1004#endif
1005
1006
1016 ASSIGN(operator=)
1018
1028 ASSIGN(operator+=)
1030
1040 ASSIGN(operator-=)
1042
1052 ASSIGN(operator*=)
1054
1065 ASSIGN(operator/=)
1067
1068
1069#undef ASSIGN
1070#undef ASSIGN_
1071
1078
1084 array operator !() const;
1085
1086#if AF_API_VERSION >= 38
1092 array operator ~() const;
1093#endif
1094
1099 int nonzeros() const;
1100
1101
1107 void lock() const;
1108
1109
1110#if AF_API_VERSION >= 34
1116 bool isLocked() const;
1117#endif
1118
1119
1125 void unlock() const;
1126 };
1127 // end of class array
1128
1129#define BIN_OP_(OP) \
1130 AFAPI array OP (const array& lhs, const array& rhs); \
1131 AFAPI array OP (const bool& lhs, const array& rhs); \
1132 AFAPI array OP (const int& lhs, const array& rhs); \
1133 AFAPI array OP (const unsigned& lhs, const array& rhs); \
1134 AFAPI array OP (const char& lhs, const array& rhs); \
1135 AFAPI array OP (const unsigned char& lhs, const array& rhs); \
1136 AFAPI array OP (const long& lhs, const array& rhs); \
1137 AFAPI array OP (const unsigned long& lhs, const array& rhs); \
1138 AFAPI array OP (const long long& lhs, const array& rhs); \
1139 AFAPI array OP (const unsigned long long& lhs, const array& rhs); \
1140 AFAPI array OP (const double& lhs, const array& rhs); \
1141 AFAPI array OP (const float& lhs, const array& rhs); \
1142 AFAPI array OP (const cfloat& lhs, const array& rhs); \
1143 AFAPI array OP (const cdouble& lhs, const array& rhs); \
1144 AFAPI array OP (const array& lhs, const bool& rhs); \
1145 AFAPI array OP (const array& lhs, const int& rhs); \
1146 AFAPI array OP (const array& lhs, const unsigned& rhs); \
1147 AFAPI array OP (const array& lhs, const char& rhs); \
1148 AFAPI array OP (const array& lhs, const unsigned char& rhs); \
1149 AFAPI array OP (const array& lhs, const long& rhs); \
1150 AFAPI array OP (const array& lhs, const unsigned long& rhs); \
1151 AFAPI array OP (const array& lhs, const long long& rhs); \
1152 AFAPI array OP (const array& lhs, const unsigned long long& rhs); \
1153 AFAPI array OP (const array& lhs, const double& rhs); \
1154 AFAPI array OP (const array& lhs, const float& rhs); \
1155 AFAPI array OP (const array& lhs, const cfloat& rhs); \
1156 AFAPI array OP (const array& lhs, const cdouble& rhs);
1157
1158#if AF_API_VERSION >= 32
1159#define BIN_OP(OP) \
1160 BIN_OP_(OP) \
1161 AFAPI array OP (const short& lhs, const array& rhs); \
1162 AFAPI array OP (const unsigned short& lhs, const array& rhs); \
1163 AFAPI array OP (const array& lhs, const short& rhs); \
1164 AFAPI array OP (const array& lhs, const unsigned short& rhs);
1165
1166#else
1167#define BIN_OP(OP) BIN_OP_(OP)
1168#endif
1169
1178 BIN_OP(operator+ )
1180
1189 BIN_OP(operator- )
1191
1200 BIN_OP(operator* )
1202
1211 BIN_OP(operator/ )
1213
1222 BIN_OP(operator==)
1224
1234 BIN_OP(operator!=)
1236
1246 BIN_OP(operator< )
1248
1257 BIN_OP(operator<=)
1259
1269 BIN_OP(operator> )
1271
1281 BIN_OP(operator>=)
1283
1294 BIN_OP(operator||)
1296
1306 BIN_OP(operator% )
1308
1319 BIN_OP(operator| )
1321
1332 BIN_OP(operator^ )
1334
1345 BIN_OP(operator<<)
1347
1358 BIN_OP(operator>>)
1360
1361#undef BIN_OP
1362#undef BIN_OP_
1363
1374 AFAPI array operator&(const array& lhs, const array& rhs);
1375 AFAPI array operator&(const array& lhs, const bool& rhs);
1376 AFAPI array operator&(const array& lhs, const cdouble& rhs);
1377 AFAPI array operator&(const array& lhs, const cfloat& rhs);
1378 AFAPI array operator&(const array& lhs, const char& rhs);
1379 AFAPI array operator&(const array& lhs, const double& rhs);
1380 AFAPI array operator&(const array& lhs, const float& rhs);
1381 AFAPI array operator&(const array& lhs, const int& rhs);
1382 AFAPI array operator&(const array& lhs, const long long& rhs);
1383 AFAPI array operator&(const array& lhs, const long& rhs);
1384 AFAPI array operator&(const array& lhs, const short& rhs);
1385 AFAPI array operator&(const array& lhs, const unsigned char& rhs);
1386 AFAPI array operator&(const array& lhs, const unsigned long long& rhs);
1387 AFAPI array operator&(const array& lhs, const unsigned long& rhs);
1388 AFAPI array operator&(const array& lhs, const unsigned short& rhs);
1389 AFAPI array operator&(const array& lhs, const unsigned& rhs);
1390 AFAPI array operator&(const bool& lhs, const array& rhs);
1391 AFAPI array operator&(const cdouble& lhs, const array& rhs);
1392 AFAPI array operator&(const cfloat& lhs, const array& rhs);
1393 AFAPI array operator&(const char& lhs, const array& rhs);
1394 AFAPI array operator&(const double& lhs, const array& rhs);
1395 AFAPI array operator&(const float& lhs, const array& rhs);
1396 AFAPI array operator&(const int& lhs, const array& rhs);
1397 AFAPI array operator&(const long long& lhs, const array& rhs);
1398 AFAPI array operator&(const long& lhs, const array& rhs);
1399 AFAPI array operator&(const short& lhs, const array& rhs);
1400 AFAPI array operator&(const unsigned char& lhs, const array& rhs);
1401 AFAPI array operator&(const unsigned long long& lhs, const array& rhs);
1402 AFAPI array operator&(const unsigned long& lhs, const array& rhs);
1403 AFAPI array operator&(const unsigned short& lhs, const array& rhs);
1404 AFAPI array operator&(const unsigned& lhs, const array& rhs);
1406
1417 AFAPI array operator&&(const array& lhs, const array& rhs);
1418 AFAPI array operator&&(const array& lhs, const bool& rhs);
1419 AFAPI array operator&&(const array& lhs, const cdouble& rhs);
1420 AFAPI array operator&&(const array& lhs, const cfloat& rhs);
1421 AFAPI array operator&&(const array& lhs, const char& rhs);
1422 AFAPI array operator&&(const array& lhs, const double& rhs);
1423 AFAPI array operator&&(const array& lhs, const float& rhs);
1424 AFAPI array operator&&(const array& lhs, const int& rhs);
1425 AFAPI array operator&&(const array& lhs, const long long& rhs);
1426 AFAPI array operator&&(const array& lhs, const long& rhs);
1427 AFAPI array operator&&(const array& lhs, const short& rhs);
1428 AFAPI array operator&&(const array& lhs, const unsigned char& rhs);
1429 AFAPI array operator&&(const array& lhs, const unsigned long long& rhs);
1430 AFAPI array operator&&(const array& lhs, const unsigned long& rhs);
1431 AFAPI array operator&&(const array& lhs, const unsigned short& rhs);
1432 AFAPI array operator&&(const array& lhs, const unsigned& rhs);
1433 AFAPI array operator&&(const bool& lhs, const array& rhs);
1434 AFAPI array operator&&(const cdouble& lhs, const array& rhs);
1435 AFAPI array operator&&(const cfloat& lhs, const array& rhs);
1436 AFAPI array operator&&(const char& lhs, const array& rhs);
1437 AFAPI array operator&&(const double& lhs, const array& rhs);
1438 AFAPI array operator&&(const float& lhs, const array& rhs);
1439 AFAPI array operator&&(const int& lhs, const array& rhs);
1440 AFAPI array operator&&(const long long& lhs, const array& rhs);
1441 AFAPI array operator&&(const long& lhs, const array& rhs);
1442 AFAPI array operator&&(const short& lhs, const array& rhs);
1443 AFAPI array operator&&(const unsigned char& lhs, const array& rhs);
1444 AFAPI array operator&&(const unsigned long long& lhs, const array& rhs);
1445 AFAPI array operator&&(const unsigned long& lhs, const array& rhs);
1446 AFAPI array operator&&(const unsigned short& lhs, const array& rhs);
1447 AFAPI array operator&&(const unsigned& lhs, const array& rhs);
1449
1450
1452
1456 inline array &eval(array &a) { a.eval(); return a; }
1457
1458#if AF_API_VERSION >= 34
1462 AFAPI void eval(int num, array **arrays);
1463#endif
1464
1465 inline void eval(array &a, array &b)
1466 {
1467#if AF_API_VERSION >= 34
1468 array *arrays[] = {&a, &b};
1469 return eval(2, arrays);
1470#else
1471 eval(a); b.eval();
1472#endif
1473 }
1474
1475 inline void eval(array &a, array &b, array &c)
1476 {
1477#if AF_API_VERSION >= 34
1478 array *arrays[] = {&a, &b, &c};
1479 return eval(3, arrays);
1480#else
1481 eval(a, b); c.eval();
1482#endif
1483 }
1484
1485 inline void eval(array &a, array &b, array &c, array &d)
1486 {
1487#if AF_API_VERSION >= 34
1488 array *arrays[] = {&a, &b, &c, &d};
1489 return eval(4, arrays);
1490#else
1491 eval(a, b, c); d.eval();
1492#endif
1493
1494 }
1495
1496 inline void eval(array &a, array &b, array &c, array &d, array &e)
1497 {
1498#if AF_API_VERSION >= 34
1499 array *arrays[] = {&a, &b, &c, &d, &e};
1500 return eval(5, arrays);
1501#else
1502 eval(a, b, c, d); e.eval();
1503#endif
1504 }
1505
1506 inline void eval(array &a, array &b, array &c, array &d, array &e, array &f)
1507 {
1508#if AF_API_VERSION >= 34
1509 array *arrays[] = {&a, &b, &c, &d, &e, &f};
1510 return eval(6, arrays);
1511#else
1512 eval(a, b, c, d, e); f.eval();
1513#endif
1514 }
1515
1516#if AF_API_VERSION >= 37
1517
1519 inline const array &eval(const array &a) { a.eval(); return a; }
1520
1521#if AF_COMPILER_CXX_VARIADIC_TEMPLATES
1522 template <typename... ARRAYS>
1523 inline void eval(ARRAYS... in) {
1524 array *arrays[] = {const_cast<array *>(&in)...};
1525 eval((int)sizeof...(in), arrays);
1526 }
1527
1528#else
1529
1530 inline void eval(const array &a, const array &b)
1531 {
1532 const array *arrays[] = {&a, &b};
1533 return eval(2, const_cast<array **>(arrays));
1534 }
1535
1536 inline void eval(const array &a, const array &b, const array &c)
1537 {
1538 const array *arrays[] = {&a, &b, &c};
1539 return eval(3, const_cast<array **>(arrays));
1540 }
1541
1542 inline void eval(const array &a, const array &b, const array &c,
1543 const array &d)
1544 {
1545 const array *arrays[] = {&a, &b, &c, &d};
1546 return eval(4, const_cast<array **>(arrays));
1547 }
1548
1549 inline void eval(const array &a, const array &b, const array &c,
1550 const array &d, const array &e)
1551 {
1552 const array *arrays[] = {&a, &b, &c, &d, &e};
1553 return eval(5, const_cast<array **>(arrays));
1554 }
1555
1556 inline void eval(const array &a, const array &b, const array &c,
1557 const array &d, const array &e, const array &f)
1558 {
1559 const array *arrays[] = {&a, &b, &c, &d, &e, &f};
1560 return eval(6, const_cast<array **>(arrays));
1561 }
1562#endif // AF_COMPILER_CXX_VARIADIC_TEMPLATES
1563#endif
1564
1565#if AF_API_VERSION >= 34
1569 AFAPI void setManualEvalFlag(bool flag);
1570#endif
1571
1572#if AF_API_VERSION >= 34
1575#endif
1576
1581}
1582#endif
1583
1584#ifdef __cplusplus
1585extern "C" {
1586#endif
1587
1606 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);
1607
1621 AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t * const dims, const af_dtype type);
1622
1627
1631 AFAPI af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src);
1632
1638 AFAPI af_err af_get_data_ptr(void *data, const af_array arr);
1639
1646
1651
1652#if AF_API_VERSION >= 31
1656 AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
1657#endif
1658
1663
1664#if AF_API_VERSION >= 34
1668 AFAPI af_err af_eval_multiple(const int num, af_array *arrays);
1669#endif
1670
1671#if AF_API_VERSION >= 34
1676#endif
1677
1678#if AF_API_VERSION >= 34
1683#endif
1684
1694
1704
1717 const af_array arr);
1718
1727 AFAPI af_err af_get_numdims(unsigned *result, const af_array arr);
1728
1737 AFAPI af_err af_is_empty (bool *result, const af_array arr);
1738
1747 AFAPI af_err af_is_scalar (bool *result, const af_array arr);
1748
1757 AFAPI af_err af_is_row (bool *result, const af_array arr);
1758
1767 AFAPI af_err af_is_column (bool *result, const af_array arr);
1768
1779 AFAPI af_err af_is_vector (bool *result, const af_array arr);
1780
1789 AFAPI af_err af_is_complex (bool *result, const af_array arr);
1790
1801 AFAPI af_err af_is_real (bool *result, const af_array arr);
1802
1811 AFAPI af_err af_is_double (bool *result, const af_array arr);
1812
1821 AFAPI af_err af_is_single (bool *result, const af_array arr);
1822
1823#if AF_API_VERSION >= 37
1832 AFAPI af_err af_is_half(bool *result, const af_array arr);
1833#endif
1834
1843 AFAPI af_err af_is_realfloating (bool *result, const af_array arr);
1844
1856 AFAPI af_err af_is_floating (bool *result, const af_array arr);
1857
1866 AFAPI af_err af_is_integer (bool *result, const af_array arr);
1867
1876 AFAPI af_err af_is_bool (bool *result, const af_array arr);
1877
1878#if AF_API_VERSION >= 34
1887 AFAPI af_err af_is_sparse (bool *result, const af_array arr);
1888#endif
1889
1890#if AF_API_VERSION >= 35
1898 AFAPI af_err af_get_scalar(void* output_value, const af_array arr);
1899#endif
1900
1905#ifdef __cplusplus
1906}
1907#endif
#define BIN_OP(OP)
Definition: array.h:1159
#define ASSIGN(OP)
Definition: array.h:997
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:130
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.
void lock() const
Locks the device buffer in the memory manager.
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.
bool isLocked() const
Query if the array has been locked by the user.
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 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).
void unlock() const
Unlocks the device buffer in the memory manager.
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:722
int nonzeros() const
Get the count of non-zero elements in the array.
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:240
#define AFAPI
Definition: defines.h:38
af_source
Definition: defines.h:232
@ afHost
Host pointer.
Definition: defines.h:234
#define AF_MAX_DIMS
Definition: defines.h:237
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.
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts 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:1456
AFAPI af_err af_free_host(void *ptr)
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
Definition: algorithm.h:15
AFAPI seq span
A special value representing the entire axis of an af::array.
Struct used to index an af_array.
Definition: index.h:22