A high-performance general-purpose compute library
array.h (2023-01-24 18:32:46 -0500, (build 987d5675a))
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, typename = typename std::enable_if<
526 std::is_fundamental<T>::value, void>::type>
527 array(std::initializer_list<T> list)
528 : arr(nullptr) {
529 dim_t size = list.size();
530 if (af_err __aferr = af_create_array(&arr, list.begin(), 1, &size,
531 static_cast<af_dtype>(af::dtype_traits<T>::af_type))) {
532 char *msg = NULL;
533 af_get_last_error(&msg, NULL);
534 af::exception ex(msg, __PRETTY_FUNCTION__, "include/af/array.h",
535 __LINE__, __aferr);
536 af_free_host(msg);
537 throw std::move(ex);
538 }
539 }
540
542 template <typename T, typename = typename std::enable_if<
543 std::is_fundamental<T>::value, void>::type>
544 array(const af::dim4 &dims, std::initializer_list<T> list)
545 : arr(nullptr) {
546 const dim_t *size = dims.get();
547 if (af_err __aferr = af_create_array(
548 &arr, list.begin(), AF_MAX_DIMS, 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#endif
559#endif
560
587 array(const array& input, const dim4& dims);
588
619 array( const array& input,
620 const dim_t dim0, const dim_t dim1 = 1,
621 const dim_t dim2 = 1, const dim_t dim3 = 1);
622
627
631 af_array get() const;
632
637
641 template<typename T> T* host() const;
642
646 void host(void *ptr) const;
647
651 template<typename T> void write(const T *ptr, const size_t bytes, af::source src = afHost);
652
656 dtype type() const;
657
661 dim4 dims() const;
662
666 dim_t dims(unsigned dim) const;
667
671 unsigned numdims() const;
672
676 size_t bytes() const;
677
682 size_t allocated() const;
683
687 array copy() const;
688
692 bool isempty() const;
693
697 bool isscalar() const;
698
703 bool isvector() const;
704
709 bool isrow() const;
710
715 bool iscolumn() const;
716
720 bool iscomplex() const;
721
725 inline bool isreal() const { return !iscomplex(); }
726
730 bool isdouble() const;
731
735 bool issingle() const;
736
737#if AF_API_VERSION >= 37
741 bool ishalf() const;
742#endif
743
747 bool isrealfloating() const;
748
753 bool isfloating() const;
754
759 bool isinteger() const;
760
764 bool isbool() const;
765
766#if AF_API_VERSION >= 34
770 bool issparse() const;
771#endif
772
776 void eval() const;
777
784 template<typename T> T scalar() const;
785
794 template<typename T> T* device() const;
795
796 // INDEXING
797 // Single arguments
798
817
823 const array::array_proxy operator()(const index &s0) const;
824
825
844 const index &s1,
845 const index &s2 = span,
846 const index &s3 = span);
847
854 const index &s1,
855 const index &s2 = span,
856 const index &s3 = span) const;
857
858
871 const array::array_proxy row(int index) const;
872
882 array::array_proxy rows(int first, int last);
883 const array::array_proxy rows(int first, int last) const;
885
898 const array::array_proxy col(int index) const;
899
909 array::array_proxy cols(int first, int last);
910 const array::array_proxy cols(int first, int last) const;
912
925 const array::array_proxy slice(int index) const;
926
935 array::array_proxy slices(int first, int last);
936 const array::array_proxy slices(int first, int last) const;
938
968 const array as(dtype type) const;
969
970
972
976 array T() const;
980 array H() const;
981
982#define ASSIGN_(OP2) \
983 array& OP2(const array &val); \
984 array& OP2(const double &val); \
985 array& OP2(const cdouble &val); \
986 array& OP2(const cfloat &val); \
987 array& OP2(const float &val); \
988 array& OP2(const int &val); \
989 array& OP2(const unsigned &val); \
990 array& OP2(const bool &val); \
991 array& OP2(const char &val); \
992 array& OP2(const unsigned char &val); \
993 array& OP2(const long &val); \
994 array& OP2(const unsigned long &val); \
995 array& OP2(const long long &val); \
996 array& OP2(const unsigned long long &val);
997
998
999#if AF_API_VERSION >= 32
1000#define ASSIGN(OP) \
1001 ASSIGN_(OP) \
1002 array& OP(const short &val); \
1003 array& OP(const unsigned short &val);
1004
1005#else
1006#define ASSIGN(OP) ASSIGN_(OP)
1007#endif
1008
1009
1019 ASSIGN(operator=)
1021
1031 ASSIGN(operator+=)
1033
1043 ASSIGN(operator-=)
1045
1055 ASSIGN(operator*=)
1057
1068 ASSIGN(operator/=)
1070
1071
1072#undef ASSIGN
1073#undef ASSIGN_
1074
1080 array operator -() const;
1081
1087 array operator !() const;
1088
1089#if AF_API_VERSION >= 38
1095 array operator ~() const;
1096#endif
1097
1102 int nonzeros() const;
1103
1104
1110 void lock() const;
1111
1112
1113#if AF_API_VERSION >= 34
1119 bool isLocked() const;
1120#endif
1121
1122
1128 void unlock() const;
1129 };
1130 // end of class array
1131
1132#define BIN_OP_(OP) \
1133 AFAPI array OP (const array& lhs, const array& rhs); \
1134 AFAPI array OP (const bool& lhs, const array& rhs); \
1135 AFAPI array OP (const int& lhs, const array& rhs); \
1136 AFAPI array OP (const unsigned& lhs, const array& rhs); \
1137 AFAPI array OP (const char& lhs, const array& rhs); \
1138 AFAPI array OP (const unsigned char& lhs, const array& rhs); \
1139 AFAPI array OP (const long& lhs, const array& rhs); \
1140 AFAPI array OP (const unsigned long& lhs, const array& rhs); \
1141 AFAPI array OP (const long long& lhs, const array& rhs); \
1142 AFAPI array OP (const unsigned long long& lhs, const array& rhs); \
1143 AFAPI array OP (const double& lhs, const array& rhs); \
1144 AFAPI array OP (const float& lhs, const array& rhs); \
1145 AFAPI array OP (const cfloat& lhs, const array& rhs); \
1146 AFAPI array OP (const cdouble& lhs, const array& rhs); \
1147 AFAPI array OP (const array& lhs, const bool& rhs); \
1148 AFAPI array OP (const array& lhs, const int& rhs); \
1149 AFAPI array OP (const array& lhs, const unsigned& rhs); \
1150 AFAPI array OP (const array& lhs, const char& rhs); \
1151 AFAPI array OP (const array& lhs, const unsigned char& rhs); \
1152 AFAPI array OP (const array& lhs, const long& rhs); \
1153 AFAPI array OP (const array& lhs, const unsigned long& rhs); \
1154 AFAPI array OP (const array& lhs, const long long& rhs); \
1155 AFAPI array OP (const array& lhs, const unsigned long long& rhs); \
1156 AFAPI array OP (const array& lhs, const double& rhs); \
1157 AFAPI array OP (const array& lhs, const float& rhs); \
1158 AFAPI array OP (const array& lhs, const cfloat& rhs); \
1159 AFAPI array OP (const array& lhs, const cdouble& rhs);
1160
1161#if AF_API_VERSION >= 32
1162#define BIN_OP(OP) \
1163 BIN_OP_(OP) \
1164 AFAPI array OP (const short& lhs, const array& rhs); \
1165 AFAPI array OP (const unsigned short& lhs, const array& rhs); \
1166 AFAPI array OP (const array& lhs, const short& rhs); \
1167 AFAPI array OP (const array& lhs, const unsigned short& rhs);
1168
1169#else
1170#define BIN_OP(OP) BIN_OP_(OP)
1171#endif
1172
1181 BIN_OP(operator+ )
1183
1192 BIN_OP(operator- )
1194
1203 BIN_OP(operator* )
1205
1214 BIN_OP(operator/ )
1216
1225 BIN_OP(operator==)
1227
1237 BIN_OP(operator!=)
1239
1249 BIN_OP(operator< )
1251
1260 BIN_OP(operator<=)
1262
1272 BIN_OP(operator> )
1274
1284 BIN_OP(operator>=)
1286
1297 BIN_OP(operator||)
1299
1309 BIN_OP(operator% )
1311
1322 BIN_OP(operator| )
1324
1335 BIN_OP(operator^ )
1337
1348 BIN_OP(operator<<)
1350
1361 BIN_OP(operator>>)
1363
1364#undef BIN_OP
1365#undef BIN_OP_
1366
1377 AFAPI array operator&(const array& lhs, const array& rhs);
1378 AFAPI array operator&(const array& lhs, const bool& rhs);
1379 AFAPI array operator&(const array& lhs, const cdouble& rhs);
1380 AFAPI array operator&(const array& lhs, const cfloat& rhs);
1381 AFAPI array operator&(const array& lhs, const char& rhs);
1382 AFAPI array operator&(const array& lhs, const double& rhs);
1383 AFAPI array operator&(const array& lhs, const float& rhs);
1384 AFAPI array operator&(const array& lhs, const int& rhs);
1385 AFAPI array operator&(const array& lhs, const long long& rhs);
1386 AFAPI array operator&(const array& lhs, const long& rhs);
1387 AFAPI array operator&(const array& lhs, const short& rhs);
1388 AFAPI array operator&(const array& lhs, const unsigned char& rhs);
1389 AFAPI array operator&(const array& lhs, const unsigned long long& rhs);
1390 AFAPI array operator&(const array& lhs, const unsigned long& rhs);
1391 AFAPI array operator&(const array& lhs, const unsigned short& rhs);
1392 AFAPI array operator&(const array& lhs, const unsigned& rhs);
1393 AFAPI array operator&(const bool& lhs, const array& rhs);
1394 AFAPI array operator&(const cdouble& lhs, const array& rhs);
1395 AFAPI array operator&(const cfloat& lhs, const array& rhs);
1396 AFAPI array operator&(const char& lhs, const array& rhs);
1397 AFAPI array operator&(const double& lhs, const array& rhs);
1398 AFAPI array operator&(const float& lhs, const array& rhs);
1399 AFAPI array operator&(const int& lhs, const array& rhs);
1400 AFAPI array operator&(const long long& lhs, const array& rhs);
1401 AFAPI array operator&(const long& lhs, const array& rhs);
1402 AFAPI array operator&(const short& lhs, const array& rhs);
1403 AFAPI array operator&(const unsigned char& lhs, const array& rhs);
1404 AFAPI array operator&(const unsigned long long& lhs, const array& rhs);
1405 AFAPI array operator&(const unsigned long& lhs, const array& rhs);
1406 AFAPI array operator&(const unsigned short& lhs, const array& rhs);
1407 AFAPI array operator&(const unsigned& lhs, const array& rhs);
1409
1420 AFAPI array operator&&(const array& lhs, const array& rhs);
1421 AFAPI array operator&&(const array& lhs, const bool& rhs);
1422 AFAPI array operator&&(const array& lhs, const cdouble& rhs);
1423 AFAPI array operator&&(const array& lhs, const cfloat& rhs);
1424 AFAPI array operator&&(const array& lhs, const char& rhs);
1425 AFAPI array operator&&(const array& lhs, const double& rhs);
1426 AFAPI array operator&&(const array& lhs, const float& rhs);
1427 AFAPI array operator&&(const array& lhs, const int& rhs);
1428 AFAPI array operator&&(const array& lhs, const long long& rhs);
1429 AFAPI array operator&&(const array& lhs, const long& rhs);
1430 AFAPI array operator&&(const array& lhs, const short& rhs);
1431 AFAPI array operator&&(const array& lhs, const unsigned char& rhs);
1432 AFAPI array operator&&(const array& lhs, const unsigned long long& rhs);
1433 AFAPI array operator&&(const array& lhs, const unsigned long& rhs);
1434 AFAPI array operator&&(const array& lhs, const unsigned short& rhs);
1435 AFAPI array operator&&(const array& lhs, const unsigned& rhs);
1436 AFAPI array operator&&(const bool& lhs, const array& rhs);
1437 AFAPI array operator&&(const cdouble& lhs, const array& rhs);
1438 AFAPI array operator&&(const cfloat& lhs, const array& rhs);
1439 AFAPI array operator&&(const char& lhs, const array& rhs);
1440 AFAPI array operator&&(const double& lhs, const array& rhs);
1441 AFAPI array operator&&(const float& lhs, const array& rhs);
1442 AFAPI array operator&&(const int& lhs, const array& rhs);
1443 AFAPI array operator&&(const long long& lhs, const array& rhs);
1444 AFAPI array operator&&(const long& lhs, const array& rhs);
1445 AFAPI array operator&&(const short& lhs, const array& rhs);
1446 AFAPI array operator&&(const unsigned char& lhs, const array& rhs);
1447 AFAPI array operator&&(const unsigned long long& lhs, const array& rhs);
1448 AFAPI array operator&&(const unsigned long& lhs, const array& rhs);
1449 AFAPI array operator&&(const unsigned short& lhs, const array& rhs);
1450 AFAPI array operator&&(const unsigned& lhs, const array& rhs);
1452
1453
1455
1459 inline array &eval(array &a) { a.eval(); return a; }
1460
1461#if AF_API_VERSION >= 34
1465 AFAPI void eval(int num, array **arrays);
1466#endif
1467
1468 inline void eval(array &a, array &b)
1469 {
1470#if AF_API_VERSION >= 34
1471 array *arrays[] = {&a, &b};
1472 return eval(2, arrays);
1473#else
1474 eval(a); b.eval();
1475#endif
1476 }
1477
1478 inline void eval(array &a, array &b, array &c)
1479 {
1480#if AF_API_VERSION >= 34
1481 array *arrays[] = {&a, &b, &c};
1482 return eval(3, arrays);
1483#else
1484 eval(a, b); c.eval();
1485#endif
1486 }
1487
1488 inline void eval(array &a, array &b, array &c, array &d)
1489 {
1490#if AF_API_VERSION >= 34
1491 array *arrays[] = {&a, &b, &c, &d};
1492 return eval(4, arrays);
1493#else
1494 eval(a, b, c); d.eval();
1495#endif
1496
1497 }
1498
1499 inline void eval(array &a, array &b, array &c, array &d, array &e)
1500 {
1501#if AF_API_VERSION >= 34
1502 array *arrays[] = {&a, &b, &c, &d, &e};
1503 return eval(5, arrays);
1504#else
1505 eval(a, b, c, d); e.eval();
1506#endif
1507 }
1508
1509 inline void eval(array &a, array &b, array &c, array &d, array &e, array &f)
1510 {
1511#if AF_API_VERSION >= 34
1512 array *arrays[] = {&a, &b, &c, &d, &e, &f};
1513 return eval(6, arrays);
1514#else
1515 eval(a, b, c, d, e); f.eval();
1516#endif
1517 }
1518
1519#if AF_API_VERSION >= 37
1520
1522 inline const array &eval(const array &a) { a.eval(); return a; }
1523
1524#if AF_COMPILER_CXX_VARIADIC_TEMPLATES
1525 template <typename... ARRAYS>
1526 inline void eval(ARRAYS... in) {
1527 array *arrays[] = {const_cast<array *>(&in)...};
1528 eval((int)sizeof...(in), arrays);
1529 }
1530
1531#else
1532
1533 inline void eval(const array &a, const array &b)
1534 {
1535 const array *arrays[] = {&a, &b};
1536 return eval(2, const_cast<array **>(arrays));
1537 }
1538
1539 inline void eval(const array &a, const array &b, const array &c)
1540 {
1541 const array *arrays[] = {&a, &b, &c};
1542 return eval(3, const_cast<array **>(arrays));
1543 }
1544
1545 inline void eval(const array &a, const array &b, const array &c,
1546 const array &d)
1547 {
1548 const array *arrays[] = {&a, &b, &c, &d};
1549 return eval(4, const_cast<array **>(arrays));
1550 }
1551
1552 inline void eval(const array &a, const array &b, const array &c,
1553 const array &d, const array &e)
1554 {
1555 const array *arrays[] = {&a, &b, &c, &d, &e};
1556 return eval(5, const_cast<array **>(arrays));
1557 }
1558
1559 inline void eval(const array &a, const array &b, const array &c,
1560 const array &d, const array &e, const array &f)
1561 {
1562 const array *arrays[] = {&a, &b, &c, &d, &e, &f};
1563 return eval(6, const_cast<array **>(arrays));
1564 }
1565#endif // AF_COMPILER_CXX_VARIADIC_TEMPLATES
1566#endif
1567
1568#if AF_API_VERSION >= 34
1572 AFAPI void setManualEvalFlag(bool flag);
1573#endif
1574
1575#if AF_API_VERSION >= 34
1578#endif
1579
1584}
1585#endif
1586
1587#ifdef __cplusplus
1588extern "C" {
1589#endif
1590
1609 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);
1610
1624 AFAPI af_err af_create_handle(af_array *arr, const unsigned ndims, const dim_t * const dims, const af_dtype type);
1625
1630
1634 AFAPI af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src);
1635
1641 AFAPI af_err af_get_data_ptr(void *data, const af_array arr);
1642
1649
1654
1655#if AF_API_VERSION >= 31
1659 AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
1660#endif
1661
1666
1667#if AF_API_VERSION >= 34
1671 AFAPI af_err af_eval_multiple(const int num, af_array *arrays);
1672#endif
1673
1674#if AF_API_VERSION >= 34
1679#endif
1680
1681#if AF_API_VERSION >= 34
1686#endif
1687
1697
1707
1720 const af_array arr);
1721
1730 AFAPI af_err af_get_numdims(unsigned *result, const af_array arr);
1731
1740 AFAPI af_err af_is_empty (bool *result, const af_array arr);
1741
1750 AFAPI af_err af_is_scalar (bool *result, const af_array arr);
1751
1760 AFAPI af_err af_is_row (bool *result, const af_array arr);
1761
1770 AFAPI af_err af_is_column (bool *result, const af_array arr);
1771
1782 AFAPI af_err af_is_vector (bool *result, const af_array arr);
1783
1792 AFAPI af_err af_is_complex (bool *result, const af_array arr);
1793
1804 AFAPI af_err af_is_real (bool *result, const af_array arr);
1805
1814 AFAPI af_err af_is_double (bool *result, const af_array arr);
1815
1824 AFAPI af_err af_is_single (bool *result, const af_array arr);
1825
1826#if AF_API_VERSION >= 37
1835 AFAPI af_err af_is_half(bool *result, const af_array arr);
1836#endif
1837
1846 AFAPI af_err af_is_realfloating (bool *result, const af_array arr);
1847
1859 AFAPI af_err af_is_floating (bool *result, const af_array arr);
1860
1869 AFAPI af_err af_is_integer (bool *result, const af_array arr);
1870
1879 AFAPI af_err af_is_bool (bool *result, const af_array arr);
1880
1881#if AF_API_VERSION >= 34
1890 AFAPI af_err af_is_sparse (bool *result, const af_array arr);
1891#endif
1892
1893#if AF_API_VERSION >= 35
1901 AFAPI af_err af_get_scalar(void* output_value, const af_array arr);
1902#endif
1903
1908#ifdef __cplusplus
1909}
1910#endif
#define BIN_OP(OP)
Definition: array.h:1162
#define ASSIGN(OP)
Definition: array.h:1000
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:725
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.
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:1459
AFAPI af_err af_free_host(void *ptr)
Definition: algorithm.h:15
Struct used to index an af_array.
Definition: index.h:22