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

Function TEST

test/getting_started.cpp:20–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using std::vector;
19
20TEST(GettingStarted, SNIPPET_getting_started_gen) {
21 //! [ex_getting_started_constructors]
22 // Arrays may be created using the array constructor and dimensioned
23 // as 1D, 2D, 3D; however, the values in these arrays will be undefined
24 array undefined_1D(100); // 1D array with 100 elements
25 array undefined_2D(10, 100); // 2D array of size 10 x 100
26 array undefined_3D(10, 10, 10); // 3D array of size 10 x 10 x 10
27 //! [ex_getting_started_constructors]
28
29 //! [ex_getting_started_gen]
30 // Generate an array of size three filled with zeros.
31 // If no data type is specified, ArrayFire defaults to f32.
32 // The constant function generates the data on the device.
33 array zeros = constant(0, 3);
34
35 // Generate a 1x4 array of uniformly distributed [0,1] random numbers
36 // The randu function generates the data on the device.
37 array rand1 = randu(1, 4);
38
39 // Generate a 2x2 array (or matrix, if you prefer) of random numbers
40 // sampled from a normal distribution.
41 // The randn function generates data on the device.
42 array rand2 = randn(2, 2);
43
44 // Generate a 3x3 identity matrix. The data is generated on the device.
45 array iden = identity(3, 3);
46
47 // Lastly, create a 2x1 array (column vector) of uniformly distributed
48 // 32-bit complex numbers (c32 data type):
49 array randcplx = randu(2, 1, c32);
50 //! [ex_getting_started_gen]
51
52 {
53 vector<float> output;
54 output.resize(zeros.elements());
55 zeros.host(&output.front());
56 ASSERT_EQ(f32, zeros.type());
57 for (dim_t i = 0; i < zeros.elements(); i++)
58 ASSERT_FLOAT_EQ(0, output[i]);
59 }
60
61 if (!noDoubleTests(f64)) {
62 array ones = constant(1, 3, 2, f64);
63 vector<double> output(ones.elements());
64 ones.host(&output.front());
65 ASSERT_EQ(f64, ones.type());
66 for (dim_t i = 0; i < ones.elements(); i++)
67 ASSERT_FLOAT_EQ(1, output[i]);
68 }
69
70 {
71 vector<float> output;
72 output.resize(iden.elements());
73 iden.host(&output.front());
74 for (dim_t i = 0; i < iden.dims(0); i++)
75 for (dim_t j = 0; j < iden.dims(1); j++)
76 if (i == j)
77 ASSERT_FLOAT_EQ(1, output[i * iden.dims(0) + j]);

Callers

nothing calls this directly

Calls 15

constantFunction · 0.85
randuFunction · 0.85
randnFunction · 0.85
noDoubleTestsFunction · 0.85
sinFunction · 0.85
sqrtFunction · 0.85
powFunction · 0.85
freeHostFunction · 0.85
hypotFunction · 0.85
fabsFunction · 0.85
hostMethod · 0.80
typeMethod · 0.80

Tested by

no test coverage detected