Skip to content

Commit 9404e33

Browse files
authored
Apply clang-tidy suggestions to all backends (arrayfire#2839)
* Add clang-tidy configuration file * Cleanup some exception code * Add additional upstream directories to .gitignore * Remove unused parameters from wrap and transform implementations * Fix warnings and removed unused calls
1 parent 9d268cd commit 9404e33

388 files changed

Lines changed: 4009 additions & 3009 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ GPATH
1111
docs/details/examples.dox
1212
/TAGS
1313
external/
14+
extern/
1415
compile_commands.json
16+
venv
17+
test/gtest
18+
src/backend/cuda/cub

include/af/features.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace af
3838
~features();
3939

4040
/// Copy assignment operator
41-
features& operator= (const features& f);
41+
features& operator= (const features& other);
4242

4343
/// Returns the number of features represented by this object
4444
size_t getNumFeatures() const;

include/af/graphics.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ class AFAPI Window {
8383
Creates a window object with default width
8484
and height with title set to "ArrayFire"
8585
86-
\param[in] wnd is an \ref af_window handle which can be retrieved by
86+
\param[in] window is an \ref af_window handle which can be retrieved
87+
by
8788
doing a get call on any \ref Window object
8889
8990
\ingroup gfx_func_window
9091
*/
91-
Window(const af_window wnd);
92+
Window(const af_window window);
9293

9394
/**
9495
Destroys the window handle

include/af/random.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ namespace af
5353
/**
5454
Copy constructor for \ref af::randomEngine.
5555
56-
\param[in] in The input random engine object
56+
\param[in] other The input random engine object
5757
*/
58-
randomEngine(const randomEngine &in);
58+
randomEngine(const randomEngine &other);
5959

6060
/**
6161
Creates a copy of the random engine object from a \ref
@@ -73,11 +73,11 @@ namespace af
7373
/**
7474
\brief Assigns the internal state of randome engine
7575
76-
\param[in] in The object to be assigned to the random engine
76+
\param[in] other The object to be assigned to the random engine
7777
7878
\returns the reference to this
7979
*/
80-
randomEngine &operator=(const randomEngine &in);
80+
randomEngine &operator=(const randomEngine &other);
8181

8282
/**
8383
\brief Sets the random type of the random engine

include/af/seq.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ class AFAPI seq
111111
112112
Creates a copy seq from another sequence.
113113
114-
\param[in] afs seqence to be copies
114+
\param[in] other seqence to be copies
115115
\param[in] is_gfor is the gfor flag
116116
*/
117-
seq(seq afs, bool is_gfor);
117+
seq(seq other, bool is_gfor);
118118

119119
/**
120120
\brief Create a seq object from an \ref af_seq struct

src/.clang-tidy

Lines changed: 391 additions & 0 deletions
Large diffs are not rendered by default.

src/api/c/anisotropic_diffusion.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,24 @@
1717
#include <gradient.hpp>
1818
#include <handle.hpp>
1919
#include <reduce.hpp>
20+
2021
#include <af/dim4.hpp>
2122
#include <af/image.h>
2223

2324
#include <type_traits>
2425

2526
using af::dim4;
26-
using namespace detail;
2727

2828
template<typename T>
29-
af_array diffusion(const Array<float> in, const float dt, const float K,
29+
af_array diffusion(const Array<float>& in, const float dt, const float K,
3030
const unsigned iterations, const af_flux_function fftype,
3131
const af::diffusionEq eq) {
32-
auto out = copyArray(in);
33-
auto dims = out.dims();
34-
auto g0 = createEmptyArray<float>(dims);
35-
auto g1 = createEmptyArray<float>(dims);
36-
float cnst = -2.0f * K * K / dims.elements();
32+
auto out = copyArray(in);
33+
auto dims = out.dims();
34+
auto g0 = createEmptyArray<float>(dims);
35+
auto g1 = createEmptyArray<float>(dims);
36+
float cnst =
37+
-2.0f * K * K / dims.elements(); // NOLINT(readability-magic-numbers)
3738

3839
for (unsigned i = 0; i < iterations; ++i) {
3940
gradient<float>(g0, g1, out);
@@ -71,7 +72,7 @@ af_err af_anisotropic_diffusion(af_array* out, const af_array in,
7172

7273
auto input = castArray<float>(in);
7374

74-
af_array output = 0;
75+
af_array output = nullptr;
7576
switch (inputType) {
7677
case f64:
7778
output = diffusion<double>(input, dt, K, iterations, F, eq);

src/api/c/approx.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
#include <af/signal.h>
2020

2121
using af::dim4;
22-
using namespace detail;
22+
using detail::approx1;
23+
using detail::approx2;
24+
using detail::cdouble;
25+
using detail::cfloat;
2326

2427
namespace {
2528
template<typename Ty, typename Tp>
@@ -53,10 +56,10 @@ void af_approx1_common(af_array *yo, const af_array yi, const af_array xo,
5356
const ArrayInfo &yi_info = getInfo(yi);
5457
const ArrayInfo &xo_info = getInfo(xo);
5558

56-
const dim4 yi_dims = yi_info.dims();
57-
const dim4 xo_dims = xo_info.dims();
58-
dim4 yo_dims = yi_dims;
59-
yo_dims[xdim] = xo_dims[xdim];
59+
const dim4 &yi_dims = yi_info.dims();
60+
const dim4 &xo_dims = xo_info.dims();
61+
dim4 yo_dims = yi_dims;
62+
yo_dims[xdim] = xo_dims[xdim];
6063

6164
ARG_ASSERT(1, yi_info.isFloating()); // Only floating and complex types
6265
ARG_ASSERT(2, xo_info.isRealFloating()); // Only floating types
@@ -70,7 +73,7 @@ void af_approx1_common(af_array *yo, const af_array yi, const af_array xo,
7073
// yi_dims[3])
7174
if (xo_dims[xdim] != xo_dims.elements()) {
7275
for (int i = 0; i < 4; i++) {
73-
if (xdim != i) DIM_ASSERT(2, xo_dims[i] == yi_dims[i]);
76+
if (xdim != i) { DIM_ASSERT(2, xo_dims[i] == yi_dims[i]); }
7477
}
7578
}
7679

@@ -196,7 +199,9 @@ void af_approx2_common(af_array *zo, const af_array zi, const af_array xo,
196199
// POS should either be (x, y, 1, 1) or (x, y, zi_dims[2], zi_dims[3])
197200
if (xo_dims[xdim] * xo_dims[ydim] != xo_dims.elements()) {
198201
for (int i = 0; i < 4; i++) {
199-
if (xdim != i && ydim != i) DIM_ASSERT(2, xo_dims[i] == zi_dims[i]);
202+
if (xdim != i && ydim != i) {
203+
DIM_ASSERT(2, xo_dims[i] == zi_dims[i]);
204+
}
200205
}
201206
}
202207

src/api/c/array.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
#include <sparse_handle.hpp>
1717
#include <af/sparse.h>
1818

19-
using namespace detail;
20-
19+
using af::dim4;
2120
using common::half;
2221
using common::SparseArrayBase;
23-
24-
af_array createHandle(const af::dim4 &d, af_dtype dtype) {
25-
using namespace detail;
26-
22+
using detail::cdouble;
23+
using detail::cfloat;
24+
using detail::intl;
25+
using detail::uchar;
26+
using detail::uint;
27+
using detail::uintl;
28+
using detail::ushort;
29+
30+
af_array createHandle(const dim4 &d, af_dtype dtype) {
2731
// clang-format off
2832
switch (dtype) {
2933
case f32: return createHandle<float >(d);
@@ -44,9 +48,7 @@ af_array createHandle(const af::dim4 &d, af_dtype dtype) {
4448
// clang-format on
4549
}
4650

47-
af_array createHandleFromValue(const af::dim4 &d, double val, af_dtype dtype) {
48-
using namespace detail;
49-
51+
af_array createHandleFromValue(const dim4 &d, double val, af_dtype dtype) {
5052
// clang-format off
5153
switch (dtype) {
5254
case f32: return createHandleFromValue<float >(d, val);
@@ -161,7 +163,7 @@ af_err af_create_handle(af_array *result, const unsigned ndims,
161163
try {
162164
AF_CHECK(af_init());
163165

164-
if (ndims > 0) ARG_ASSERT(2, ndims > 0 && dims != NULL);
166+
if (ndims > 0) { ARG_ASSERT(2, ndims > 0 && dims != NULL); }
165167

166168
dim4 d(0);
167169
for (unsigned i = 0; i < ndims; i++) { d[i] = dims[i]; }
@@ -181,40 +183,39 @@ af_err af_copy_array(af_array *out, const af_array in) {
181183

182184
af_array res = 0;
183185
if (info.isSparse()) {
184-
SparseArrayBase sbase = getSparseArrayBase(in);
186+
const SparseArrayBase sbase = getSparseArrayBase(in);
185187
if (info.ndims() == 0) {
186188
return af_create_sparse_array_from_ptr(
187189
out, info.dims()[0], info.dims()[1], 0, nullptr, nullptr,
188190
nullptr, type, sbase.getStorage(), afDevice);
189-
} else {
190-
switch (type) {
191-
case f32: res = copySparseArray<float>(in); break;
192-
case f64: res = copySparseArray<double>(in); break;
193-
case c32: res = copySparseArray<cfloat>(in); break;
194-
case c64: res = copySparseArray<cdouble>(in); break;
195-
default: TYPE_ERROR(0, type);
196-
}
197191
}
192+
switch (type) {
193+
case f32: res = copySparseArray<float>(in); break;
194+
case f64: res = copySparseArray<double>(in); break;
195+
case c32: res = copySparseArray<cfloat>(in); break;
196+
case c64: res = copySparseArray<cdouble>(in); break;
197+
default: TYPE_ERROR(0, type);
198+
}
199+
198200
} else {
199201
if (info.ndims() == 0) {
200202
return af_create_handle(out, 0, nullptr, type);
201-
} else {
202-
switch (type) {
203-
case f32: res = copyArray<float>(in); break;
204-
case c32: res = copyArray<cfloat>(in); break;
205-
case f64: res = copyArray<double>(in); break;
206-
case c64: res = copyArray<cdouble>(in); break;
207-
case b8: res = copyArray<char>(in); break;
208-
case s32: res = copyArray<int>(in); break;
209-
case u32: res = copyArray<uint>(in); break;
210-
case u8: res = copyArray<uchar>(in); break;
211-
case s64: res = copyArray<intl>(in); break;
212-
case u64: res = copyArray<uintl>(in); break;
213-
case s16: res = copyArray<short>(in); break;
214-
case u16: res = copyArray<ushort>(in); break;
215-
case f16: res = copyArray<half>(in); break;
216-
default: TYPE_ERROR(1, type);
217-
}
203+
}
204+
switch (type) {
205+
case f32: res = copyArray<float>(in); break;
206+
case c32: res = copyArray<cfloat>(in); break;
207+
case f64: res = copyArray<double>(in); break;
208+
case c64: res = copyArray<cdouble>(in); break;
209+
case b8: res = copyArray<char>(in); break;
210+
case s32: res = copyArray<int>(in); break;
211+
case u32: res = copyArray<uint>(in); break;
212+
case u8: res = copyArray<uchar>(in); break;
213+
case s64: res = copyArray<intl>(in); break;
214+
case u64: res = copyArray<uintl>(in); break;
215+
case s16: res = copyArray<short>(in); break;
216+
case u16: res = copyArray<ushort>(in); break;
217+
case f16: res = copyArray<half>(in); break;
218+
default: TYPE_ERROR(1, type);
218219
}
219220
}
220221
std::swap(*out, res);
@@ -254,7 +255,7 @@ af_err af_get_data_ref_count(int *use_count, const af_array in) {
254255

255256
af_err af_release_array(af_array arr) {
256257
try {
257-
if (arr == 0) return AF_SUCCESS;
258+
if (arr == 0) { return AF_SUCCESS; }
258259
const ArrayInfo &info = getInfo(arr, false, false);
259260
af_dtype type = info.getType();
260261

@@ -338,7 +339,6 @@ void write_array(af_array arr, const T *const data, const size_t bytes,
338339
} else {
339340
writeDeviceDataArray(getArray<T>(arr), data, bytes);
340341
}
341-
return;
342342
}
343343

344344
af_err af_write_array(af_array arr, const void *data, const size_t bytes,

0 commit comments

Comments
 (0)