A high-performance general-purpose compute library
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:
* http://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");
af_print(sum(A));
printf("\n--Product along columns\n");
af_print(product(A));
printf("\n--Minimum along columns\n");
af_print(min(A));
printf("\n--Maximum along columns\n");
af_print(max(A));
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;
}
A multi dimensional data container.
Definition: array.h:37
array T() const
Get the transposed the array.
An ArrayFire exception class.
Definition: exception.h:22
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:46
array::array_proxy col(int index)
Returns a reference to a col.
array::array_proxy row(int index)
Returns a reference to a row.
AFAPI void info()
AFAPI void setDevice(const int device)
Sets the current device.
Definition: algorithm.h:15
#define af_print(...)
Definition: util.h:148