Skip to content

Commit

Permalink
Merge pull request #65 from IntelPython/bugfix/gh-64
Browse files Browse the repository at this point in the history
Fixes #64
  • Loading branch information
oleksandr-pavlyk authored Aug 18, 2021
2 parents f7b2c68 + 0e8bd13 commit dd9c783
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 7 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions mkl_fft/_pydfti.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 14 additions & 5 deletions mkl_fft/tests/test_fftnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def test_matrix5(self):
mkl_fft.fftn(y[i0, :, : , i3]),
rtol=r_tol, atol=a_tol
)




class Test_Regressions(TestCase):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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)

0 comments on commit dd9c783

Please sign in to comment.