From d9c25a577007794b3f3f7555e820fc458ca2880e Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 18 Aug 2021 14:30:57 -0500 Subject: [PATCH 1/3] Fixes #64 Use iter_complementary method which dispatches to fftn_direct only for dtypes that fftn_direct supports, that is floating point types. --- mkl_fft/_pydfti.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkl_fft/_pydfti.pyx b/mkl_fft/_pydfti.pyx index 7521727d..308f1d4c 100644 --- a/mkl_fft/_pydfti.pyx +++ b/mkl_fft/_pydfti.pyx @@ -944,7 +944,7 @@ def iter_complementary(x, axes, func, kwargs, result): size *= x_shape[ri] sub_shape.append(x_shape[ri]) dual_ind.append(ri) - + for ind in range(size): m_ind = flat_to_multi(ind, sub_shape) for k1, k2 in zip(dual_ind, m_ind): @@ -1077,7 +1077,7 @@ def _fftnd_impl(x, shape=None, axes=None, overwrite_x=False, direction=+1, doubl if _direct: return _direct_fftnd(x, overwrite_arg=overwrite_x, direction=direction, fsc=fsc) else: - if (shape is None): + if (shape is None and x.dtype in [np.complex64, np.complex128, np.float32, np.float64]): x = np.asarray(x) res = np.empty(x.shape, dtype=_output_dtype(x.dtype)) return iter_complementary( From 0c6f3f373f2e8c1ee4a324eab5f745b47b10d8eb Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 18 Aug 2021 14:37:24 -0500 Subject: [PATCH 2/3] Added test for issue 64 --- mkl_fft/tests/test_fftnd.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mkl_fft/tests/test_fftnd.py b/mkl_fft/tests/test_fftnd.py index 39d0246a..63c780e8 100644 --- a/mkl_fft/tests/test_fftnd.py +++ b/mkl_fft/tests/test_fftnd.py @@ -113,8 +113,8 @@ def test_matrix5(self): mkl_fft.fftn(y[i0, :, : , i3]), rtol=r_tol, atol=a_tol ) - - + + class Test_Regressions(TestCase): @@ -147,6 +147,16 @@ def test_rfftn_numpy(self): tr_rfft = np.transpose(mkl_fft.rfftn_numpy(x, axes=a), a) assert_allclose(rfft_tr, tr_rfft, rtol=r_tol, atol=a_tol) + def test_gh64(self): + """Test example from #64""" + a = np.arange(12).reshape((3,4)) + x = a.astype(np.cdouble) + # should executed successfully + r1 = mkl_fft.fftn(a, shape=None, axes=(-2,-1)) + r2 = mkl_fft.fftn(x) + r_tol, a_tol = _get_rtol_atol(x) + assert_allclose(r1, r2, rtol=r_tol, atol=a_tol) + class Test_Scales(TestCase): def setUp(self): @@ -185,7 +195,7 @@ def test_scale_nd(self): X.flat[:] = np.cbrt(np.arange(0, X.size, dtype=X.dtype)) f = mkl_fft.fftn(X) f_scale = mkl_fft.fftn(X, forward_scale=0.2) - + r_tol, a_tol = _get_rtol_atol(X) assert_allclose(f, 5*f_scale, rtol=r_tol, atol=a_tol) @@ -194,7 +204,6 @@ def test_scale_nd_axes(self): X.flat[:] = np.cbrt(np.arange(X.size, dtype=X.dtype)) f = mkl_fft.fftn(X, axes=(0, 1, 2, 3)) f_scale = mkl_fft.fftn(X, axes=(0, 1, 2, 3), forward_scale=0.2) - + r_tol, a_tol = _get_rtol_atol(X) assert_allclose(f, 5*f_scale, rtol=r_tol, atol=a_tol) - From 0e8bd13a43b33fedb022072e03908a6959a5bbf2 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 18 Aug 2021 14:43:50 -0500 Subject: [PATCH 3/3] Try using workflows to test packages --- .github/workflows/conda-package.yml | 113 ++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 .github/workflows/conda-package.yml diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml new file mode 100644 index 00000000..6a30b394 --- /dev/null +++ b/.github/workflows/conda-package.yml @@ -0,0 +1,113 @@ +name: Conda package + +on: push + +env: + PACKAGE_NAME: mkl_fft + MODULE_NAME: mkl_fft + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python: [3.8] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set pkgs_dirs + run: | + echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc + - name: Cache conda packages + uses: actions/cache@v2 + env: + CACHE_NUMBER: 0 # Increase to reset cache + with: + path: ~/.conda/pkgs + key: + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }} + restore-keys: | + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- + + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + - name: Install conda-build + run: conda install conda-build + - name: Build conda package + run: | + CHANNELS="-c intel -c defaults --override-channels" + VERSIONS="--python ${{ matrix.python }}" + TEST="--no-test" + + conda build \ + $TEST \ + $VERSIONS \ + $CHANNELS \ + conda-recipe + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} + path: /usr/share/miniconda/conda-bld/linux-64/${{ env.PACKAGE_NAME }}-*.tar.bz2 + + test: + needs: build + runs-on: ${{ matrix.runner }} + + strategy: + matrix: + python: [3.8] + experimental: [false] + runner: [ubuntu-latest] + continue-on-error: ${{ matrix.experimental }} + env: + CHANNELS: -c intel -c defaults --override-channels + + steps: + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + - name: Install conda-build + run: conda install conda-build + - name: Create conda channel + run: | + mkdir -p $GITHUB_WORKSPACE/channel/linux-64 + mv ${PACKAGE_NAME}-*.tar.bz2 $GITHUB_WORKSPACE/channel/linux-64 + conda index $GITHUB_WORKSPACE/channel + # Test channel + conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels + + - name: Collect dependencies + run: | + CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" + conda install $PACKAGE_NAME python=${{ matrix.python }} $CHANNELS --only-deps --dry-run > lockfile + - name: Set pkgs_dirs + run: | + echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc + - name: Cache conda packages + uses: actions/cache@v2 + env: + CACHE_NUMBER: 0 # Increase to reset cache + with: + path: ~/.conda/pkgs + key: + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }} + restore-keys: | + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- + ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- + + - name: Install mkl_fft + run: | + CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" + conda install $PACKAGE_NAME pytest python=${{ matrix.python }} $CHANNELS + # Test installed packages + conda list + - name: Run tests + run: | + python -m pytest --pyargs $MODULE_NAME