Skip to content

Commit 7128623

Browse files
umar456pradeep
authored andcommitted
Update all source files based on clang-format rules
1 parent c2d0475 commit 7128623

File tree

1,394 files changed

+84876
-84573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,394 files changed

+84876
-84573
lines changed

examples/benchmarks/blas.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@
88
********************************************************/
99

1010
#include <arrayfire.h>
11-
#include <stdio.h>
1211
#include <math.h>
12+
#include <stdio.h>
1313
#include <cstdlib>
1414

1515
using namespace af;
1616

1717
// create a small wrapper to benchmark
18-
static array A; // populated before each timing
19-
static void fn()
20-
{
18+
static array A; // populated before each timing
19+
static void fn() {
2120
array B = matmul(A, A); // matrix multiply
2221
B.eval(); // ensure evaluated
2322
}
2423

25-
int main(int argc, char ** argv)
26-
{
24+
int main(int argc, char** argv) {
2725
double peak = 0;
2826
try {
2927
int device = argc > 1 ? atoi(argv[1]) : 0;
@@ -32,13 +30,11 @@ int main(int argc, char ** argv)
3230

3331
printf("Benchmark N-by-N matrix multiply\n");
3432
for (int n = 128; n <= 2048; n += 128) {
35-
3633
printf("%4d x %4d: ", n, n);
37-
A = constant(1,n,n);
38-
double time = timeit(fn); // time in seconds
39-
double gflops = 2.0 * powf(n,3) / (time * 1e9);
40-
if (gflops > peak)
41-
peak = gflops;
34+
A = constant(1, n, n);
35+
double time = timeit(fn); // time in seconds
36+
double gflops = 2.0 * powf(n, 3) / (time * 1e9);
37+
if (gflops > peak) peak = gflops;
4238

4339
printf(" %4.0f Gflops\n", gflops);
4440
fflush(stdout);
@@ -48,7 +44,6 @@ int main(int argc, char ** argv)
4844
throw;
4945
}
5046

51-
5247
printf(" ### peak %g GFLOPS\n", peak);
5348

5449
return 0;

examples/benchmarks/cg.cpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,111 +11,105 @@
1111

1212
using namespace af;
1313

14-
static size_t dimension = 4 * 1024;
15-
static const int maxIter = 10;
14+
static size_t dimension = 4 * 1024;
15+
static const int maxIter = 10;
1616
static const int sparsityFactor = 7;
1717

1818
static array A;
1919
static array spA; // Sparse A
2020
static array x0;
2121
static array b;
2222

23-
void setupInputs()
24-
{
23+
void setupInputs() {
2524
// Generate a random input: A
2625
array T = randu(dimension, dimension, f32);
2726
// Create 0s in input.
2827
// Anything that is no divisible by sparsityFactor will become 0.
2928
A = floor(T * 1000);
3029
A = A * ((A % sparsityFactor) == 0) / 1000;
3130
// Make it positive definite
32-
A = transpose(A) + A + A.dims(0)*identity(A.dims(0), A.dims(0), f32);
31+
A = transpose(A) + A + A.dims(0) * identity(A.dims(0), A.dims(0), f32);
3332

3433
// Make A sparse as spA
3534
spA = sparse(A);
3635

3736
// Generate x0: Random guess
3837
x0 = randu(A.dims(0), f32);
3938

40-
//Generate b
39+
// Generate b
4140
b = matmul(A, x0);
4241

4342
std::cout << "Sparsity of A = "
44-
<< 100.f * (float)sparseGetNNZ(spA) / (float)spA.elements()
45-
<< "%" << std::endl;
46-
std::cout << "Memory Usage of A = "
47-
<< A.bytes() / (1024.f * 1024.f)
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)
4846
<< " MB" << std::endl;
4947
std::cout << "Memory Usage of spA = "
50-
<<(sparseGetValues(spA).bytes()
51-
+ sparseGetRowIdx(spA).bytes()
52-
+ sparseGetColIdx(spA).bytes()) / (1024.f * 1024.f)
48+
<< (sparseGetValues(spA).bytes() + sparseGetRowIdx(spA).bytes() +
49+
sparseGetColIdx(spA).bytes()) /
50+
(1024.f * 1024.f)
5351
<< " MB" << std::endl;
5452
}
5553

56-
void sparseConjugateGradient(void)
57-
{
54+
void sparseConjugateGradient(void) {
5855
array x = constant(0, b.dims(), f32);
5956
array r = b - matmul(spA, x);
6057
array p = r;
6158

6259
for (int i = 0; i < maxIter; ++i) {
63-
array Ap = matmul(spA, p);
60+
array Ap = matmul(spA, p);
6461
array alpha_num = dot(r, r);
6562
array alpha_den = dot(p, Ap);
66-
array alpha = alpha_num/alpha_den;
67-
r -= tile(alpha, Ap.dims())*Ap;
68-
x += tile(alpha, Ap.dims())*p;
63+
array alpha = alpha_num / alpha_den;
64+
r -= tile(alpha, Ap.dims()) * Ap;
65+
x += tile(alpha, Ap.dims()) * p;
6966
array beta_num = dot(r, r);
70-
array beta = beta_num/alpha_num;
71-
p = r + tile(beta, p.dims()) * p;
67+
array beta = beta_num / alpha_num;
68+
p = r + tile(beta, p.dims()) * p;
7269
}
7370
}
7471

75-
void denseConjugateGradient(void)
76-
{
72+
void denseConjugateGradient(void) {
7773
array x = constant(0, b.dims(), f32);
7874
array r = b - matmul(A, x);
7975
array p = r;
8076

8177
for (int i = 0; i < maxIter; ++i) {
82-
array Ap = matmul(A, p);
78+
array Ap = matmul(A, p);
8379
array alpha_num = dot(r, r);
8480
array alpha_den = dot(p, Ap);
85-
array alpha = alpha_num/alpha_den;
86-
r -= tile(alpha, Ap.dims())*Ap;
87-
x += tile(alpha, Ap.dims())*p;
81+
array alpha = alpha_num / alpha_den;
82+
r -= tile(alpha, Ap.dims()) * Ap;
83+
x += tile(alpha, Ap.dims()) * p;
8884
array beta_num = dot(r, r);
89-
array beta = beta_num/alpha_num;
90-
p = r + tile(beta, p.dims()) * p;
85+
array beta = beta_num / alpha_num;
86+
p = r + tile(beta, p.dims()) * p;
9187
}
9288
}
9389

94-
void checkConjugateGradient(const af::array in)
95-
{
90+
void checkConjugateGradient(const af::array in) {
9691
array x = constant(0, b.dims(), f32);
9792
array r = b - matmul(in, x);
9893
array p = r;
9994

10095
for (int i = 0; i < maxIter; ++i) {
101-
array Ap = matmul(in, p);
96+
array Ap = matmul(in, p);
10297
array alpha_num = dot(r, r);
10398
array alpha_den = dot(p, Ap);
104-
array alpha = alpha_num/alpha_den;
105-
r -= tile(alpha, Ap.dims())*Ap;
106-
x += tile(alpha, Ap.dims())*p;
99+
array alpha = alpha_num / alpha_den;
100+
r -= tile(alpha, Ap.dims()) * Ap;
101+
x += tile(alpha, Ap.dims()) * p;
107102
array beta_num = dot(r, r);
108-
array beta = beta_num/alpha_num;
109-
p = r + tile(beta, p.dims()) * p;
103+
array beta = beta_num / alpha_num;
104+
p = r + tile(beta, p.dims()) * p;
110105
}
111106
array res = x0 - x;
112107

113-
std::cout<<"Final difference in solutions:\n";
108+
std::cout << "Final difference in solutions:\n";
114109
af_print(dot(res, res));
115110
}
116111

117-
int main(int , char **)
118-
{
112+
int main(int, char **) {
119113
af::info();
120114
setupInputs();
121115

@@ -128,12 +122,10 @@ int main(int , char **)
128122
af::sync();
129123

130124
std::cout << "Dense Conjugate Gradient Time: "
131-
<< timeit(denseConjugateGradient) * 1000
132-
<< "ms" << std::endl;
125+
<< timeit(denseConjugateGradient) * 1000 << "ms" << std::endl;
133126

134127
std::cout << "Sparse Conjugate Gradient Time: "
135-
<< timeit(sparseConjugateGradient) * 1000
136-
<< "ms" << std::endl;
128+
<< timeit(sparseConjugateGradient) * 1000 << "ms" << std::endl;
137129

138130
return 0;
139131
}

examples/benchmarks/fft.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@
88
********************************************************/
99

1010
#include <arrayfire.h>
11-
#include <stdio.h>
1211
#include <math.h>
12+
#include <stdio.h>
1313
#include <cstdlib>
1414

1515
using namespace af;
1616

1717
// create a small wrapper to benchmark
18-
static array A; // populated before each timing
19-
static void fn()
20-
{
18+
static array A; // populated before each timing
19+
static void fn() {
2120
array B = fft2(A); // matrix multiply
2221
B.eval(); // ensure evaluated
2322
}
2423

25-
int main(int argc, char ** argv)
26-
{
24+
int main(int argc, char** argv) {
2725
try {
2826
int device = argc > 1 ? atoi(argv[1]) : 0;
2927
setDevice(device);
@@ -34,16 +32,14 @@ int main(int argc, char ** argv)
3432
int N = (1 << M);
3533

3634
printf("%4d x %4d: ", N, N);
37-
A = randu(N,N);
38-
double time = timeit(fn); // time in seconds
35+
A = randu(N, N);
36+
double time = timeit(fn); // time in seconds
3937
double gflops = 10.0 * N * N * M / (time * 1e9);
4038

4139
printf(" %4.0f Gflops\n", gflops);
4240
fflush(stdout);
4341
}
44-
} catch (af::exception& e) {
45-
fprintf(stderr, "%s\n", e.what());
46-
}
42+
} catch (af::exception& e) { fprintf(stderr, "%s\n", e.what()); }
4743

4844
return 0;
4945
}

examples/benchmarks/pi.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
- count what percent fell inside (top quarter) of unit circle
1616
*/
1717

18-
#include <stdio.h>
18+
#include <arrayfire.h>
1919
#include <math.h>
20+
#include <stdio.h>
2021
#include <cstdlib>
21-
#include <arrayfire.h>
2222
using namespace af;
2323

2424
// generate millions of random samples
@@ -27,40 +27,35 @@ static int samples = 20e6;
2727
/* Self-contained code to run host and device estimates of PI. Note that
2828
each is generating its own random values, so the estimates of PI
2929
will differ. */
30-
static double pi_device()
31-
{
32-
array x = randu(samples,f32), y = randu(samples,f32);
33-
return 4.0 * sum<float>(sqrt(x*x + y*y) < 1) / samples;
30+
static double pi_device() {
31+
array x = randu(samples, f32), y = randu(samples, f32);
32+
return 4.0 * sum<float>(sqrt(x * x + y * y) < 1) / samples;
3433
}
3534

36-
static double pi_host()
37-
{
35+
static double pi_host() {
3836
int count = 0;
3937
for (int i = 0; i < samples; ++i) {
4038
float x = float(rand()) / RAND_MAX;
4139
float y = float(rand()) / RAND_MAX;
42-
if (sqrt(x*x + y*y) < 1)
43-
count++;
40+
if (sqrt(x * x + y * y) < 1) count++;
4441
}
4542
return 4.0 * count / samples;
4643
}
4744

48-
49-
5045
// void wrappers for timeit()
5146
static void device_wrapper() { pi_device(); }
5247
static void host_wrapper() { pi_host(); }
5348

54-
55-
int main(int argc, char ** argv)
56-
{
49+
int main(int argc, char** argv) {
5750
try {
5851
int device = argc > 1 ? atoi(argv[1]) : 0;
5952
setDevice(device);
6053
info();
6154

62-
printf("device: %.5f seconds to estimate pi = %.5f\n", timeit(device_wrapper), pi_device());
63-
printf(" host: %.5f seconds to estimate pi = %.5f\n", timeit(host_wrapper), pi_host());
55+
printf("device: %.5f seconds to estimate pi = %.5f\n",
56+
timeit(device_wrapper), pi_device());
57+
printf(" host: %.5f seconds to estimate pi = %.5f\n",
58+
timeit(host_wrapper), pi_host());
6459
} catch (exception& e) {
6560
fprintf(stderr, "%s\n", e.what());
6661
throw;

examples/common/idxio.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,27 @@
99

1010
#pragma once
1111

12-
#include <iostream>
12+
#include <arrayfire.h>
13+
#include <algorithm>
1314
#include <fstream>
15+
#include <iostream>
1416
#include <stdexcept>
1517
#include <vector>
16-
#include <algorithm>
17-
#include <arrayfire.h>
1818

19-
union Data
20-
{
19+
union Data {
2120
unsigned dim;
2221
char bytes[4];
2322
};
2423

25-
unsigned char reverse_char(unsigned char b)
26-
{
24+
unsigned char reverse_char(unsigned char b) {
2725
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
2826
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
2927
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
3028
return b;
3129
}
3230

3331
// http://stackoverflow.com/a/9144870/2192361
34-
unsigned reverse(unsigned x)
35-
{
32+
unsigned reverse(unsigned x) {
3633
x = ((x >> 1) & 0x55555555u) | ((x & 0x55555555u) << 1);
3734
x = ((x >> 2) & 0x33333333u) | ((x & 0x33333333u) << 2);
3835
x = ((x >> 4) & 0x0f0f0f0fu) | ((x & 0x0f0f0f0fu) << 4);
@@ -42,24 +39,22 @@ unsigned reverse(unsigned x)
4239
}
4340

4441
template<class ty>
45-
void read_idx(std::vector<dim_t> &dims, std::vector<ty> &data, const char *name)
46-
{
42+
void read_idx(std::vector<dim_t> &dims, std::vector<ty> &data,
43+
const char *name) {
4744
std::ifstream f(name, std::ios::in | std::ios::binary);
4845
if (!f.is_open()) throw std::runtime_error("Unable to open file");
4946

5047
Data d;
5148
f.read(d.bytes, sizeof(d.bytes));
5249

53-
if (d.bytes[2] != 8) {
54-
throw std::runtime_error("Unsupported data type");
55-
}
50+
if (d.bytes[2] != 8) { throw std::runtime_error("Unsupported data type"); }
5651

57-
unsigned numdims = d.bytes[3];
52+
unsigned numdims = d.bytes[3];
5853
unsigned elemsize = 1;
5954

6055
// Read the dimensions
6156
size_t elem = 1;
62-
dims = std::vector<dim_t>(numdims);
57+
dims = std::vector<dim_t>(numdims);
6358
for (unsigned i = 0; i < numdims; i++) {
6459
f.read(d.bytes, sizeof(d.bytes));
6560

0 commit comments

Comments
 (0)