23 #define REST af_source_t src=afHost, unsigned ngfor=0
24 #define GROUP(...) __VA_ARGS__
407 #define afDevicePointer afDevice
408 #define afHostPointer afHost
430 #define CONSTR(what, dims, ...) \
431 template<typename ty> array(dims, const ty __VA_ARGS__); \
472 array(
const dim4& dims,
dtype ty =
f32);
496 array(
int d0,
int d1,
dtype ty =
f32);
521 array(
int d0,
int d1,
int d2,
dtype ty =
f32);
546 array(
int d0,
int d1,
int d2,
int d3,
dtype ty =
f32);
613 CONSTR(column vector,
unsigned dim0, *pointer,
REST)
692 CONSTR(4D array,
GROUP(
unsigned dim0,
unsigned dim1,
unsigned dim2,
unsigned dim3), *pointer,
REST)
723 CONSTR(array, const dim4& dims, *pointer,
REST)
756 template<typename ty> static array scalar(const ty value);
793 array(
const array& input,
const dim4& dims);
826 array(
const array& input,
int dim0,
int dim1 = 1,
int dim2 = 1,
int dim3 = 1);
866 int dims(
unsigned dim)
const;
899 int elements()
const;
923 int nonzeros()
const;
941 unsigned ngfor()
const;
959 size_t bytes()
const;
989 bool isempty()
const;
1015 bool isscalar()
const;
1042 bool isvector()
const;
1095 bool iscolumn()
const;
1152 bool iscomplex()
const;
1180 inline bool isreal()
const {
return iscomplex() ==
false; }
1197 bool issparse()
const;
1232 void unlock()
const;
1450 array operator()(
const seq& s)
const;
1471 array operator()(array indices)
const;
1493 array operator()(
const seq& rows,
const seq& cols)
const;
1581 array operator()(
const seq& rows, array columns)
const;
1601 array operator()(array rows,
const seq& columns)
const;
1611 array operator()(array rows, array columns)
const;
1703 array operator()(
const seq& x,
const seq& y,
const seq& z)
const;
1714 array operator()(array rows, array cols,
const seq& slices)
const;
1738 array operator()(array rows,
const seq& cols,
const seq& slices)
const;
1786 array operator()(
const seq& rows, array cols,
const seq& slices)
const;
1797 array operator()(
const seq& rows,
const seq& cols, array slices)
const;
1810 array operator()(
const seq& w,
const seq& x,
const seq& y, array& z)
const;
1821 array operator()(
const seq& w,
const seq& x,
const seq& y,
const seq& z)
const;
1919 template<
typename T> T scalar()
const;
1968 template<
typename T> T* device()
const;
2000 template<
typename T> T* host()
const;
2015 void host(
void* ptr)
const;
2041 template<
typename T>
static T* alloc(
size_t elements);
2052 static void *alloc(
size_t elements,
dtype type);
2079 template<
typename T>
static T* pinned(
size_t elements);
2089 static void free(
const void*);
2096 array& operator op(const array&); \
2097 array& operator op(const double&); \
2098 array& operator op(const cfloat&); \
2099 array& operator op(const cdouble&)
2103 array operator op(const array&) const; \
2104 array operator op(const double&) const; \
2105 array operator op(const cfloat&) const; \
2106 array operator op(const cdouble&) const; \
2107 AFAPI friend array operator op(const double&, const array&); \
2108 AFAPI friend array operator op(const cfloat&, const array&); \
2109 AFAPI friend array operator op(const cdouble&, const array&)
2114 array operator op(const array&) const; \
2115 array operator op##op(const array&) const; \
2116 array operator op##op(const bool&) const; \
2117 array operator op##op(const int&) const; \
2118 array operator op##op(const unsigned&) const; \
2119 array operator op##op(const double&) const; \
2120 array operator op##op(const cfloat&) const; \
2121 array operator op##op(const cdouble&) const; \
2122 AFAPI friend array operator op##op(const bool&, const array&); \
2123 AFAPI friend array operator op##op(const int&, const array&); \
2124 AFAPI friend array operator op##op(const unsigned&, const array&); \
2125 AFAPI friend array operator op##op(const cfloat&, const array&); \
2126 AFAPI friend array operator op##op(const cdouble&, const array&)
2129 #define COMPARISON(op) \
2130 array operator op(const array&) const; \
2131 array operator op(const bool&) const; \
2132 array operator op(const int&) const; \
2133 array operator op(const double&) const; \
2134 array operator op(const cfloat&) const; \
2135 array operator op(const cdouble&) const; \
2136 AFAPI friend array operator op(const bool&, const array&); \
2137 AFAPI friend array operator op(const int&, const array&); \
2138 AFAPI friend array operator op(const double&, const array&); \
2139 AFAPI friend array operator op(const cfloat&, const array&); \
2140 AFAPI friend array operator op(const cdouble&, const array&)
2150 array operator-()
const;
2162 array operator!()
const;
2222 array operator %(
const array&)
const;
2223 array operator %(
const double&)
const;
2224 AFAPI friend array operator %(
const double&,
const array&);
2281 array& operator %=(
const array&);
2282 array& operator %=(
const double&);
2294 array& operator++();
2305 array& operator--();
2339 array operator ^(
const array&)
const;
2443 template<
typename ty> array& operator=(
const ty value);
2461 array& operator=(
const array& a);
2546 array as(
dtype type)
const;
2554 array asfloat()
const;
2568 AFAPI friend std::ostream& operator<<(std::ostream&,
const array&);
2574 friend class ginternal;
2585 array(
dtype ty,
const dim4& dims,
const void* pointer,
2590 #define GEN(what, ...) \
2593 AFAPI array constant(float,__VA_ARGS__, dtype ty=f32); \
2594 AFAPI array identity(__VA_ARGS__, dtype ty=f32); \
2595 AFAPI array randu(__VA_ARGS__, dtype ty=f32); \
2596 AFAPI array randn(__VA_ARGS__, dtype ty=f32); \
2597 AFAPI array rand(__VA_ARGS__, dtype ty=u32); \
2676 GEN(column vector, unsigned nx)
2677 GEN(matrix,
unsigned nx,
unsigned ny)
2678 GEN(
volume,
unsigned nx,
unsigned ny,
unsigned nz)
2679 GEN(4D array,
unsigned d0,
unsigned d1,
unsigned d2,
unsigned d3)
2680 GEN(array,
const dim4& dims)
2687 #define UNARY(fn) AFAPI array fn(const array& x);
2697 #define UNARY_REAL(fn) \
2699 AFAPI array fn(const array& x, bool isreal=STATE);
2702 #define BINARY_EXTRA(fn, a, b, comment, ...) \
2704 AFAPI array fn(const array &a, const array &b __VA_ARGS__); \
2706 AFAPI array fn(const array &a, const double b __VA_ARGS__); \
2708 AFAPI array fn(const double a, const array &b __VA_ARGS__)
2709 #define BINARY_NAMED(fn,a,b,comment) BINARY_EXTRA(fn,a,b,comment,) // HACK
2712 #define BINARY(fn,comment) \
2714 AFAPI array fn(const array &, const array &); \
2716 AFAPI array fn(const array &, const double); \
2718 AFAPI array fn(const double, const array &)
2721 #define EXTREMUM(fn, OP) \
2723 AFAPI array fn(const array &x, const array &y); \
2725 AFAPI array fn(const double x, const array &y)
2932 BINARY_EXTRA(
pow, base, power, \p base raised to \p power(exponent). If \p isreal is true then bypass checks for complexity(faster)., ,
bool isreal = false);
3214 BINARY_NAMED(complex, real, imaginary, Form a complex result from \p real and \p imaginary parts);
3224 BINARY(
atan2, arc tangent function of two variables);
3234 BINARY(
hypot, Euclidean distance function without undue overflow or underflow during intermediate steps);
3254 BINARY_NAMED(
mod, x, y, Compute <tt>x - n * y</tt>
where \c n is quotient of <tt>x / y</tt>. Round toward zero.);
3271 AFAPI array
lower(const array& input,
int diagonal = 0);
3287 AFAPI array
upper(const array& input,
int diagonal = 0);
3337 AFAPI array
join(
int dim, const array& A, const array& B);
3338 AFAPI array
join(
int dim, const array& A, const array& B, const array& C);
3339 AFAPI array
join(
int dim, const array& A, const array& B, const array& C, const array& D);
3371 AFAPI array
flip(const array& in,
unsigned dim);
3377 #undef REAL_CONSTRUCTOR
3378 #undef ROOT_CONSTRUCTOR
3380 #undef UNARY_OPERATION
3381 #undef BINARY_OPERATION
3412 inline array
eval(array a) { a.
eval();
return a; }
array operator()(const seq &w, const int x, const seq &y, const seq &z) const
Access volume.
Definition: array.h:1869
array complex(const array &x)
dtype m_type
Data type.
Definition: array.h:2580
#define REST
Definition: array.h:23
#define GEN(what,...)
Definition: array.h:2590
array operator()(const seq &x, int column) const
Access linear sequence of elements at location row and column.
Definition: array.h:1568
array operator()(const seq &w, const seq &x, const int y, const seq &z) const
Access volume.
Definition: array.h:1881
array operator()(const seq &x, int y, const seq &z) const
Access elements at sequence of rows x, column y, and sequence of slices z.
Definition: array.h:1691
#define CONSTR(what, dims,...)
Create what from pointer (column-major order like Fortran)
Definition: array.h:430
handle volume(const af::array &X)
array operator()(int x, int y, const seq &z) const
Access elements at row x, column y, and sequence of slices z.
Definition: array.h:1655
array cosh(const array &x)
array pow2(const array &x)
array operator()(const seq &w, const seq &x, const seq &y, int z) const
Access volume.
Definition: array.h:1833
floating point (32-bit single-precision)
Definition: array.h:392
array mod(const array &x, const array &y)
Compute x - n * y where n is quotient of x / y.
array diag(const array &input)
Extract or form diagonal matrix.
array sign(const array &x)
#define BINARY_NAMED(fn, a, b, comment)
Definition: array.h:2709
#define UNARY_REAL(fn)
Definition: array.h:2697
array operator()(int index) const
Access linear element at index.
Definition: array.h:1430
array exp(const array &x)
array where(const array &input)
Indices where nonzero (zero-based indexing).
array isInf(const array &x)
array sqrt(const array &x, bool isreal=false)
Assume output will be real if isreal==true (faster), otherwise produce complex values if necessary (s...
array hypot(const array &, const array &)
Euclidean distance function without undue overflow or underflow during intermediate steps...
array log1p(const array &x)
array erfc(const array &x)
#define BINARY(fn, comment)
Definition: array.h:2712
ginternal * m_internal
Pointer to internal data-structures.
Definition: array.h:2576
array col(int index) const
Access column index to form column vector.
Definition: array.h:1296
array real(const array &x)
array ceil(const array &x)
array operator()(array rows, int column) const
Access elements along index array rows and location column.
Definition: array.h:1591
array root(const array &radicand, const array &n)
Calculate n - th root of real - valued radicand.
array atan2(const array &, const array &)
arc tangent function of two variables
array operator()(const int w, const int x, const int y, const int z) const
Access volume.
Definition: array.h:1893
array tan(const array &x)
array upper(const array &input, int diagonal=0)
Extract upper triangular matrix.
complex-valued floating point (32-bit single-precision real and imaginary components) ...
Definition: array.h:393
array trunc(const array &x)
array rows(int first, int last) const
Access rows first through last to form a matrix (inclusive).
Definition: array.h:1356
array operator()(int x, const seq &y, const seq &z) const
Access elements at row x, sequence of columns y, and sequence of slices z.
Definition: array.h:1667
array isFinite(const array &x)
Host-memory pointer.
Definition: array.h:404
void eval()
Evaluate all expressions associated with the variable.
array erf(const array &x)
#define UNARY(fn)
Definition: array.h:2687
GPU array container.
Definition: array.h:411
array flip(const array &in, unsigned dim)
Flip array along a given dimension (base-zero index).
array acosh(const array &x)
array erfcinv(const array &x)
array expm1(const array &x)
#define COMPARISON(op)
Definition: array.h:2129
array min(const array &x, const array &y)
Minimum between x and y at every position.
bool isreal() const
Definition: array.h:1180
signed 32-bit integer
Definition: array.h:397
array lower(const array &input, int diagonal=0)
Extract lower triangular matrix.
sequential index generator
Definition: index.h:156
af_source_t
Specify which address-space pointer belongs.
Definition: array.h:402
#define LOGIC(op)
Definition: array.h:2113
dtype
Definition: array.h:391
array floor(const array &x)
array acos(const array &x)
array join(int dim, const array &A, const array &B)
Join two arrays along dimension dim.
array operator()(const seq &x, int y, int z) const
Access elements at sequence of rows x, column y and slice z.
Definition: array.h:1633
#define BIN(op)
Definition: array.h:2102
boolean (8-bit: nonzero=true, zero=false)
Definition: array.h:396
array asinh(const array &x)
array round(const array &x)
array operator()(int row, int col) const
Access the element at location (row, col).
Definition: array.h:1513
array slices(int first, int last) const
Access slices first through last to form a matrix (inclusive)
Definition: array.h:1404
array epsilon(const array &x)
array operator()(array rows, int cols, int slice) const
Access elements at array of row indices rows, column cols, and slice.
Definition: array.h:1762
complex-valued floating point (64-bit double-precision real and imaginary components) ...
Definition: array.h:395
#define AFAPI
Definition: defines.h:45
array operator()(int x, int y, int z) const
Access elements at location row x, column y and slice z.
Definition: array.h:1622
seq span
Reference entire dimension.
array rem(const array &, const array &)
remainder
#define EXTREMUM(fn, OP)
Definition: array.h:2721
array operator()(int row, const seq &y) const
Access linear sequence of elements at location row and y seq of columns.
Definition: array.h:1534
unsigned 32-bit integer
Definition: array.h:398
array max(const array &x, const array &y)
Maximum between x and y at every position.
array arg(const array &x)
array tanh(const array &x)
array cols(int first, int last) const
Access columns first through last to form a matrix (inclusive)
Definition: array.h:1384
#define BINARY_EXTRA(fn, a, b, comment,...)
Definition: array.h:2702
array operator()(const seq &rows, array cols, int slice) const
Access elements at sequence of row indices rows, array of column indicies cols, and slice...
Definition: array.h:1750
unsigned m_ngfor
Number of gfor tiles (zero or one indicates one tile)
Definition: array.h:2582
array erfinv(const array &x)
#define SELF(op)
Definition: array.h:2095
array operator()(const seq &w, const seq &x, int y, int z) const
Access volume.
Definition: array.h:1845
#define GROUP(...)
Definition: array.h:25
array operator()(array rows, const seq &cols, int slice) const
Access elements at array of row indices rows, sequence of column indices cols, and slice...
Definition: array.h:1774
array sinh(const array &x)
array operator()(int row, array columns) const
Access linear sequence of elements at location row and columns array of indices of columns...
Definition: array.h:1547
array pow(const array &base, const array &power, bool isreal=false)
base raised to power(exponent).
array log(const array &x, bool isreal=false)
Assume output will be real if isreal==true (faster), otherwise produce complex values if necessary (s...
array operator()(int x, const seq &y, int z) const
Access elements at row x, sequence of columns y and slice z.
Definition: array.h:1644
array operator()(const int w, const seq &x, const seq &y, const seq &z) const
Access volume.
Definition: array.h:1857
array row(int index) const
Access row index to form row vector.
Definition: array.h:1265
array conjg(const array &x)
array factorial(const array &x)
array log10(const array &x)
array log2(const array &x)
array abs(const array &x)
array gamma(const array &x)
array slice(int index) const
Access slice index to form a matrix (plane of a volume, channel in an image)
Definition: array.h:1328
array gammaln(const array &x)
array dimensions descriptor
Definition: dims.h:16
array operator()(array rows, array cols, int slice) const
Access elements at array of row indices rows, array of column indices cols, and slice.
Definition: array.h:1726
floating point (64-bit double-precision)
Definition: array.h:394
array atan(const array &x)
array asin(const array &x)
array operator()(const seq &x, const seq &y, int z) const
Access elements at sequence of rows x, sequence of columns y, and slice z.
Definition: array.h:1679
array imag(const array &x)
array eval(array a)
Evaluate an expression (nonblocking).
Definition: array.h:3413
Device-memory pointer.
Definition: array.h:403
array cos(const array &x)
array atanh(const array &x)
array isNaN(const array &x)
dim4 m_dims
Dimensions.
Definition: array.h:2578
array sin(const array &x)