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

Function setupInputs

examples/benchmarks/cg.cpp:23–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21static array b;
22
23void setupInputs() {
24 // Generate a random input: A
25 array T = randu(dimension, dimension, f32);
26 // Create 0s in input.
27 // Anything that is no divisible by sparsityFactor will become 0.
28 A = floor(T * 1000);
29 A = A * ((A % sparsityFactor) == 0) / 1000;
30 // Make it positive definite
31 A = transpose(A) + A + A.dims(0) * identity(A.dims(0), A.dims(0), f32);
32
33 // Make A sparse as spA
34 spA = sparse(A);
35
36 // Generate x0: Random guess
37 x0 = randu(A.dims(0), f32);
38
39 // Generate b
40 b = matmul(A, x0);
41
42 std::cout << "Sparsity of A = "
43 << 100.f * (float)sparseGetNNZ(spA) / (float)spA.elements() << "%"
44 << std::endl;
45 std::cout << "Memory Usage of A = " << A.bytes() / (1024.f * 1024.f)
46 << " MB" << std::endl;
47 std::cout << "Memory Usage of spA = "
48 << (sparseGetValues(spA).bytes() + sparseGetRowIdx(spA).bytes() +
49 sparseGetColIdx(spA).bytes()) /
50 (1024.f * 1024.f)
51 << " MB" << std::endl;
52}
53
54void sparseConjugateGradient(void) {
55 array x = constant(0, b.dims(), f32);

Callers 1

mainFunction · 0.85

Calls 13

randuFunction · 0.85
floorFunction · 0.85
sparseFunction · 0.85
sparseGetNNZFunction · 0.85
sparseGetValuesFunction · 0.85
sparseGetRowIdxFunction · 0.85
sparseGetColIdxFunction · 0.85
bytesMethod · 0.80
transposeFunction · 0.50
identityFunction · 0.50
matmulFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected