MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / main

Function main

examples/helloworld/helloworld.cpp:16–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14using namespace af;
15
16int main(int argc, char* argv[]) {
17 try {
18 // Select a device and display arrayfire info
19 int device = argc > 1 ? atoi(argv[1]) : 0;
20 af::setDevice(device);
21 af::info();
22
23 printf("Create a 5-by-3 matrix of random floats on the GPU\n");
24 array A = randu(5, 3, f32);
25 af_print(A);
26
27 printf("Element-wise arithmetic\n");
28 array B = sin(A) + 1.5;
29 af_print(B);
30
31 printf("Negate the first three elements of second column\n");
32 B(seq(0, 2), 1) = B(seq(0, 2), 1) * -1;
33 af_print(B);
34
35 printf("Fourier transform the result\n");
36 array C = fft(B);
37 af_print(C);
38
39 printf("Grab last row\n");
40 array c = C.row(end);
41 af_print(c);
42
43 printf("Scan Test\n");
44 dim4 dims(16, 4, 1, 1);
45 array r = constant(2, dims);
46 af_print(r);
47
48 printf("Scan\n");
49 array S = af::scan(r, 0, AF_BINARY_MUL);
50 af_print(S);
51
52 printf("Create 2-by-3 matrix from host data\n");
53 float d[] = {1, 2, 3, 4, 5, 6};
54 array D(2, 3, d, afHost);
55 af_print(D);
56
57 printf("Copy last column onto first\n");
58 D.col(0) = D.col(end);
59 af_print(D);
60
61 // Sort A
62 printf("Sort A and print sorted array and corresponding indices\n");
63 array vals, inds;
64 sort(vals, inds, A);
65 af_print(vals);
66 af_print(inds);
67
68 } catch (af::exception& e) {
69 fprintf(stderr, "%s\n", e.what());
70 throw;
71 }
72
73 return 0;

Callers

nothing calls this directly

Calls 11

infoFunction · 0.85
randuFunction · 0.85
sinFunction · 0.85
seqClass · 0.85
constantFunction · 0.85
rowMethod · 0.80
colMethod · 0.80
setDeviceFunction · 0.50
fftFunction · 0.50
scanFunction · 0.50
sortFunction · 0.50

Tested by

no test coverage detected