| 21 | static array b; |
| 22 | |
| 23 | void 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 | |
| 54 | void sparseConjugateGradient(void) { |
| 55 | array x = constant(0, b.dims(), f32); |
no test coverage detected