getting_started/integer.cpp
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* https://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <arrayfire.h>
#include <stdio.h>
#include <af/util.h>
#include <cstdlib>
using namespace af;
int main(int argc, char** argv) {
try {
int device = argc > 1 ? atoi(argv[1]) : 0;
af::setDevice(device);
printf(
"\n=== ArrayFire signed(s32) / unsigned(u32) Integer Example "
"===\n");
int h_A[] = {1, 2, 4, -1, 2, 0, 4, 2, 3};
int h_B[] = {2, 3, -5, 6, 0, 10, -12, 0, 1};
array A = array(3, 3, h_A);
array B = array(3, 3, h_B);
printf("--\nSub-refencing and Sub-assignment\n");
af_print(A.col(0));
af_print(A.row(0));
A(0) = 11;
A(1) = 100;
A(1, span) = B(2, span);
printf("--Bit-wise operations\n");
// Returns an array of type s32
af_print(A & B);
af_print(A | B);
af_print(A ^ B);
printf("\n--Logical operations\n");
// Returns an array of type b8
af_print(A && B);
af_print(A || B);
printf("\n--Transpose\n");
af_print(A.T());
printf("\n--Flip Vertically / Horizontally\n");
af_print(flip(A, 0));
af_print(flip(A, 1));
printf("\n--Sum along columns\n");
printf("\n--Product along columns\n");
printf("\n--Minimum along columns\n");
printf("\n--Maximum along columns\n");
printf("\n--Minimum along columns with index\n");
array out, idx;
min(out, idx, A);
af_print(out);
af_print(idx);
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
util.h
af::info
AFAPI void info()
af::product
AFAPI array product(const array &in, const int dim=-1)
C++ Interface for product of elements in an array.
af::setDevice
AFAPI void setDevice(const int device)
Sets the current device.
af::array::col
array::array_proxy col(int index)
Returns a reference to a col.
af::flip
AFAPI array flip(const array &in, const unsigned dim)
af::array
A multi dimensional data container.
Definition: array.h:35
af
Definition: algorithm.h:15
af_print
#define af_print(...)
Definition: util.h:148
af::max
AFAPI array max(const array &in, const int dim=-1)
C++ Interface for maximum values in an array.
afcl::array
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
af::array::row
array::array_proxy row(int index)
Returns a reference to a row.
af::exception
An ArrayFire exception class.
Definition: exception.h:29
af::span
AFAPI seq span
A special value representing the entire axis of an af::array.
af::sum
AFAPI array sum(const array &in, const int dim=-1)
C++ Interface for sum of elements in an array.
arrayfire.h
af::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:60
af::array::T
array T() const
Get the transposed the array.
af::min
AFAPI array min(const array &in, const int dim=-1)
C++ Interface for minimum values in an array.