diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..4304e0ed --- /dev/null +++ b/.clang-format @@ -0,0 +1,42 @@ +BasedOnStyle: LLVM + +AccessModifierOffset: -4 + +AlignConsecutiveMacros: true +AlignConsecutiveBitFields: true +AlignEscapedNewlines: Right + +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Empty + +AlwaysBreakTemplateDeclarations: Yes + +BinPackParameters: false + +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Never + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBraces: Custom + +ColumnLimit: 80 + +IndentWidth: 4 +IndentWrappedFunctionNames: true + +Standard: c++17 diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 277cc51b..2aa0315c 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -5,3 +5,6 @@ # Add cython-lint to pre-commit config 5df98187dda56f6d340f0824570fe5080d0b4f05 + +# Move from clang-format-15 to clang-format-22 +ffe413c18571422f4b974e780ea19f83f1f776bf diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c01f6e01..739eecb8 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -30,12 +30,5 @@ jobs: codespell pylint - - name: Set up clang-format - run: | - sudo apt-get install -y clang-format-15 - sudo unlink /usr/bin/clang-format - sudo ln -s /usr/bin/clang-format-15 /usr/bin/clang-format - clang-format --version - - name: Run pre-commit checks uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76635152..6133b417 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,8 +51,8 @@ repos: - id: black exclude: "_vendored/conv_template.py" -- repo: https://github.com/pocc/pre-commit-hooks - rev: v1.3.5 +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v22.1.0 hooks: - id: clang-format args: ["-i"] diff --git a/mkl_fft/src/mklfft.h b/mkl_fft/src/mklfft.h index c5c6834f..da0ce686 100644 --- a/mkl_fft/src/mklfft.h +++ b/mkl_fft/src/mklfft.h @@ -27,74 +27,131 @@ #include "mkl.h" #include "numpy/arrayobject.h" -typedef struct DftiCache { - DFTI_DESCRIPTOR_HANDLE hand; - int initialized; +typedef struct DftiCache +{ + DFTI_DESCRIPTOR_HANDLE hand; + int initialized; } DftiCache; extern int _free_dfti_cache(DftiCache *); /* Complex input, in-place */ -extern int cdouble_mkl_fft1d_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); -extern int cfloat_mkl_fft1d_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); -extern int cdouble_mkl_ifft1d_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); -extern int cfloat_mkl_ifft1d_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); +extern int + cdouble_mkl_fft1d_in(PyArrayObject *, npy_intp, int, double, DftiCache *); +extern int + cfloat_mkl_fft1d_in(PyArrayObject *, npy_intp, int, double, DftiCache *); +extern int + cdouble_mkl_ifft1d_in(PyArrayObject *, npy_intp, int, double, DftiCache *); +extern int + cfloat_mkl_ifft1d_in(PyArrayObject *, npy_intp, int, double, DftiCache *); /* Complex input/output, out-of-place */ -extern int cfloat_cfloat_mkl_fft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); -extern int cdouble_cdouble_mkl_fft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); -extern int cfloat_cfloat_mkl_ifft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); -extern int cdouble_cdouble_mkl_ifft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); +extern int cfloat_cfloat_mkl_fft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); +extern int cdouble_cdouble_mkl_fft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); +extern int cfloat_cfloat_mkl_ifft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); +extern int cdouble_cdouble_mkl_ifft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); /* Real input, complex output, out-of-place */ -extern int float_cfloat_mkl_fft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, int, double, +extern int float_cfloat_mkl_fft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + int, + double, DftiCache *); -extern int double_cdouble_mkl_fft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, int, double, +extern int double_cdouble_mkl_fft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + int, + double, DftiCache *); -extern int float_cfloat_mkl_ifft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, int, double, +extern int float_cfloat_mkl_ifft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + int, + double, DftiCache *); -extern int double_cdouble_mkl_ifft1d_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, int, double, +extern int double_cdouble_mkl_ifft1d_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + int, + double, DftiCache *); /* Real input, real output, in-place */ -extern int float_mkl_rfft_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); -extern int float_mkl_irfft_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); +extern int + float_mkl_rfft_in(PyArrayObject *, npy_intp, int, double, DftiCache *); +extern int + float_mkl_irfft_in(PyArrayObject *, npy_intp, int, double, DftiCache *); -extern int double_mkl_rfft_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); -extern int double_mkl_irfft_in(PyArrayObject *, npy_intp, int, double, - DftiCache *); +extern int + double_mkl_rfft_in(PyArrayObject *, npy_intp, int, double, DftiCache *); +extern int + double_mkl_irfft_in(PyArrayObject *, npy_intp, int, double, DftiCache *); /* Real input, real output, out-of-place */ -extern int float_float_mkl_rfft_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); -extern int float_float_mkl_irfft_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); - -extern int double_double_mkl_rfft_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); -extern int double_double_mkl_irfft_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); +extern int float_float_mkl_rfft_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); +extern int float_float_mkl_irfft_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); + +extern int double_double_mkl_rfft_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); +extern int double_double_mkl_irfft_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); /* Complex input. real output, out-of-place */ -extern int cdouble_double_mkl_irfft_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); -extern int cfloat_float_mkl_irfft_out(PyArrayObject *, npy_intp, int, - PyArrayObject *, double, DftiCache *); +extern int cdouble_double_mkl_irfft_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); +extern int cfloat_float_mkl_irfft_out(PyArrayObject *, + npy_intp, + int, + PyArrayObject *, + double, + DftiCache *); /* Complex, ND, in-place */ extern int cdouble_cdouble_mkl_fftnd_in(PyArrayObject *, double); @@ -102,21 +159,21 @@ extern int cdouble_cdouble_mkl_ifftnd_in(PyArrayObject *, double); extern int cfloat_cfloat_mkl_fftnd_in(PyArrayObject *, double); extern int cfloat_cfloat_mkl_ifftnd_in(PyArrayObject *, double); -extern int cdouble_cdouble_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, - double); -extern int cdouble_cdouble_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, - double); -extern int cfloat_cfloat_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, - double); -extern int cfloat_cfloat_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, - double); +extern int + cdouble_cdouble_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, double); +extern int + cdouble_cdouble_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, double); +extern int + cfloat_cfloat_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, double); +extern int + cfloat_cfloat_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, double); extern int float_cfloat_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, double); -extern int float_cfloat_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, - double); -extern int double_cdouble_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, - double); -extern int double_cdouble_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, - double); +extern int + float_cfloat_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, double); +extern int + double_cdouble_mkl_fftnd_out(PyArrayObject *, PyArrayObject *, double); +extern int + double_cdouble_mkl_ifftnd_out(PyArrayObject *, PyArrayObject *, double); extern char *mkl_dfti_error(MKL_LONG); diff --git a/mkl_fft/src/multi_iter.h b/mkl_fft/src/multi_iter.h index 6a95b437..f3f73129 100644 --- a/mkl_fft/src/multi_iter.h +++ b/mkl_fft/src/multi_iter.h @@ -33,32 +33,34 @@ #include #include -typedef struct multi_iter_t { - npy_intp *shape; // shape of the tensor - npy_intp *ind; // multi-index - int rank; // tensor rank, length of shape and of ind - char done; // boolean variable: True when end of iterator has been reached +typedef struct multi_iter_t +{ + npy_intp *shape; // shape of the tensor + npy_intp *ind; // multi-index + int rank; // tensor rank, length of shape and of ind + char done; // boolean variable: True when end of iterator has been reached } multi_iter_t; -typedef struct multi_iter_masked_t { - npy_intp *shape; // shape of the tensor - npy_intp *ind; // multi-index - int *mask; // list of indexes to iterate over - int rank; // tensor rank, length of shape and of ind - int mask_len; - char done; // boolean variable: True when end of iterator has been reached +typedef struct multi_iter_masked_t +{ + npy_intp *shape; // shape of the tensor + npy_intp *ind; // multi-index + int *mask; // list of indexes to iterate over + int rank; // tensor rank, length of shape and of ind + int mask_len; + char done; // boolean variable: True when end of iterator has been reached } multi_iter_masked_t; -#define MultiIter_Index(mit) ((mit).ind) -#define MultiIter_Shape(mit) ((mit).shape) -#define MultiIter_Done(mit) ((mit).done) -#define MultiIter_Rank(mit) ((mit).rank) -#define MultiIter_Mask(mit) ((mit).mask) +#define MultiIter_Index(mit) ((mit).ind) +#define MultiIter_Shape(mit) ((mit).shape) +#define MultiIter_Done(mit) ((mit).done) +#define MultiIter_Rank(mit) ((mit).rank) +#define MultiIter_Mask(mit) ((mit).mask) #define MultiIter_MaskLength(mit) ((mit).mask_len) #define MultiIter_IndexElem(mit, i) ((mit).ind)[(i)] #define MultiIter_ShapeElem(mit, i) ((mit).shape)[(i)] -#define MultiIter_MaskElem(mit, i) ((mit).mask)[(i)] +#define MultiIter_MaskElem(mit, i) ((mit).mask)[(i)] /* void multi_iter_new(multi_iter_t*, npy_intp*, int); @@ -71,127 +73,135 @@ void multi_iter_masked_free(multi_iter_masked_t*); int multi_iter_masked_next(multi_iter_masked_t*); */ -static NPY_INLINE void multi_iter_new(multi_iter_t *mi, npy_intp shape[], - int rank) { - int i; - char d = 0; +static NPY_INLINE void + multi_iter_new(multi_iter_t *mi, npy_intp shape[], int rank) +{ + int i; + char d = 0; - assert(rank > 0); + assert(rank > 0); - MultiIter_Index(*mi) = (npy_intp *)mkl_calloc(rank, sizeof(npy_intp), 64); - MultiIter_Shape(*mi) = (npy_intp *)mkl_malloc(rank * sizeof(npy_intp), 64); - memcpy(MultiIter_Shape(*mi), shape, rank * sizeof(npy_intp)); - MultiIter_Rank(*mi) = rank; + MultiIter_Index(*mi) = (npy_intp *)mkl_calloc(rank, sizeof(npy_intp), 64); + MultiIter_Shape(*mi) = (npy_intp *)mkl_malloc(rank * sizeof(npy_intp), 64); + memcpy(MultiIter_Shape(*mi), shape, rank * sizeof(npy_intp)); + MultiIter_Rank(*mi) = rank; - for (i = 0; i < rank; i++) { - d |= MultiIter_IndexElem(*mi, i) >= MultiIter_ShapeElem(*mi, i); - if (d) - break; - } + for (i = 0; i < rank; i++) { + d |= MultiIter_IndexElem(*mi, i) >= MultiIter_ShapeElem(*mi, i); + if (d) + break; + } - MultiIter_Done(*mi) = d; + MultiIter_Done(*mi) = d; - return; + return; } static NPY_INLINE void multi_iter_masked_new(multi_iter_masked_t *mi, - npy_intp shape[], int rank, - int mask[], int mask_len) { - int i; - char d = 0; - - assert(rank > 0); - - MultiIter_Index(*mi) = (npy_intp *)mkl_calloc(rank, sizeof(npy_intp), 64); - MultiIter_Shape(*mi) = (npy_intp *)mkl_malloc(rank * sizeof(npy_intp), 64); - memcpy(MultiIter_Shape(*mi), shape, rank * sizeof(npy_intp)); - MultiIter_Rank(*mi) = rank; - - for (i = 0; i < rank; i++) { - d |= MultiIter_IndexElem(*mi, i) >= MultiIter_ShapeElem(*mi, i); - if (d) - break; - } + npy_intp shape[], + int rank, + int mask[], + int mask_len) +{ + int i; + char d = 0; + + assert(rank > 0); + + MultiIter_Index(*mi) = (npy_intp *)mkl_calloc(rank, sizeof(npy_intp), 64); + MultiIter_Shape(*mi) = (npy_intp *)mkl_malloc(rank * sizeof(npy_intp), 64); + memcpy(MultiIter_Shape(*mi), shape, rank * sizeof(npy_intp)); + MultiIter_Rank(*mi) = rank; + + for (i = 0; i < rank; i++) { + d |= MultiIter_IndexElem(*mi, i) >= MultiIter_ShapeElem(*mi, i); + if (d) + break; + } - MultiIter_Done(*mi) = d; + MultiIter_Done(*mi) = d; - assert(mask_len > 0); - MultiIter_MaskLength(*mi) = mask_len; - MultiIter_Mask(*mi) = (int *)mkl_malloc(mask_len * sizeof(int), 64); - memcpy(MultiIter_Mask(*mi), mask, mask_len * sizeof(int)); + assert(mask_len > 0); + MultiIter_MaskLength(*mi) = mask_len; + MultiIter_Mask(*mi) = (int *)mkl_malloc(mask_len * sizeof(int), 64); + memcpy(MultiIter_Mask(*mi), mask, mask_len * sizeof(int)); - return; + return; } -static NPY_INLINE void multi_iter_masked_free(multi_iter_masked_t *mi) { - if (mi) { - if (MultiIter_Index(*mi)) - mkl_free(MultiIter_Index(*mi)); +static NPY_INLINE void multi_iter_masked_free(multi_iter_masked_t *mi) +{ + if (mi) { + if (MultiIter_Index(*mi)) + mkl_free(MultiIter_Index(*mi)); - if (MultiIter_Shape(*mi)) - mkl_free(MultiIter_Shape(*mi)); + if (MultiIter_Shape(*mi)) + mkl_free(MultiIter_Shape(*mi)); - if (MultiIter_Mask(*mi)) - mkl_free(MultiIter_Mask(*mi)); - } + if (MultiIter_Mask(*mi)) + mkl_free(MultiIter_Mask(*mi)); + } - return; + return; } -static NPY_INLINE void multi_iter_free(multi_iter_t *mi) { - if (mi) { - if (MultiIter_Index(*mi)) - mkl_free(MultiIter_Index(*mi)); +static NPY_INLINE void multi_iter_free(multi_iter_t *mi) +{ + if (mi) { + if (MultiIter_Index(*mi)) + mkl_free(MultiIter_Index(*mi)); - if (MultiIter_Shape(*mi)) - mkl_free(MultiIter_Shape(*mi)); - } + if (MultiIter_Shape(*mi)) + mkl_free(MultiIter_Shape(*mi)); + } - return; + return; } /* Modifies iterator in-place, returns 1 when iterator is empty, 0 otherwise */ -static NPY_INLINE int multi_iter_next(multi_iter_t *mi) { - int j, k; - - if (MultiIter_Done(*mi)) - return 1; - - for (k = MultiIter_Rank(*mi); k > 0; k--) { - j = k - 1; - if (++(MultiIter_IndexElem(*mi, j)) < MultiIter_ShapeElem(*mi, j)) - return 0; - else { - MultiIter_IndexElem(*mi, j) = 0; - if (!j) { - MultiIter_Done(*mi) = 1; - } +static NPY_INLINE int multi_iter_next(multi_iter_t *mi) +{ + int j, k; + + if (MultiIter_Done(*mi)) + return 1; + + for (k = MultiIter_Rank(*mi); k > 0; k--) { + j = k - 1; + if (++(MultiIter_IndexElem(*mi, j)) < MultiIter_ShapeElem(*mi, j)) + return 0; + else { + MultiIter_IndexElem(*mi, j) = 0; + if (!j) { + MultiIter_Done(*mi) = 1; + } + } } - } - return 1; + return 1; } /* Modifies iterator in-place, returns 1 when iterator is empty, 0 otherwise */ -static NPY_INLINE int multi_iter_masked_next(multi_iter_masked_t *mi) { - int j, k; - - if (MultiIter_Done(*mi)) - return 1; - - for (k = MultiIter_MaskLength(*mi); k > 0; k--) { - j = MultiIter_MaskElem(*mi, k - 1); - if (++(MultiIter_IndexElem(*mi, j)) < MultiIter_ShapeElem(*mi, j)) - return 0; - else { - MultiIter_IndexElem(*mi, j) = 0; - if (!k) { - MultiIter_Done(*mi) = 1; - } +static NPY_INLINE int multi_iter_masked_next(multi_iter_masked_t *mi) +{ + int j, k; + + if (MultiIter_Done(*mi)) + return 1; + + for (k = MultiIter_MaskLength(*mi); k > 0; k--) { + j = MultiIter_MaskElem(*mi, k - 1); + if (++(MultiIter_IndexElem(*mi, j)) < MultiIter_ShapeElem(*mi, j)) + return 0; + else { + MultiIter_IndexElem(*mi, j) = 0; + if (!k) { + MultiIter_Done(*mi) = 1; + } + } } - } - return 1; + return 1; } #endif