| 1 |
# This file is licensed differently to the rest of pyFFTW. The license |
| 2 |
# is as set out below. |
| 3 |
# |
| 4 |
# Copyright (c) 2005-2011, NumPy Developers. |
| 5 |
# All rights reserved. |
| 6 |
# |
| 7 |
# Redistribution and use in source and binary forms, with or without |
| 8 |
# modification, are permitted provided that the following conditions are |
| 9 |
# met: |
| 10 |
# |
| 11 |
# * Redistributions of source code must retain the above copyright |
| 12 |
# notice, this list of conditions and the following disclaimer. |
| 13 |
# |
| 14 |
# * Redistributions in binary form must reproduce the above |
| 15 |
# copyright notice, this list of conditions and the following |
| 16 |
# disclaimer in the documentation and/or other materials provided |
| 17 |
# with the distribution. |
| 18 |
# |
| 19 |
# * Neither the name of the NumPy Developers nor the names of any |
| 20 |
# contributors may be used to endorse or promote products derived |
| 21 |
# from this software without specific prior written permission. |
| 22 |
# |
| 23 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 26 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 27 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 28 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 29 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 30 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 31 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 33 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 |
# |
| 35 |
# A module containing the latest version of _cook_nd_args from |
| 36 |
# numpy.fft.fftpack. It can be used to overwrite an earlier |
| 37 |
# broken version in the tests. |
| 38 |
|
| 39 |
from numpy.core import take |
| 40 |
|
| 41 |
def _cook_nd_args(a, s=None, axes=None, invreal=0): |
| 42 |
if s is None: |
| 43 |
shapeless = 1 |
| 44 |
if axes is None: |
| 45 |
s = list(a.shape) |
| 46 |
else: |
| 47 |
s = take(a.shape, axes) |
| 48 |
else: |
| 49 |
shapeless = 0 |
| 50 |
s = list(s) |
| 51 |
if axes is None: |
| 52 |
axes = range(-len(s), 0) |
| 53 |
if len(s) != len(axes): |
| 54 |
raise ValueError("Shape and axes have different lengths.") |
| 55 |
if invreal and shapeless: |
| 56 |
# Here is the fix. The following line is replaced |
| 57 |
# (see numpy commit 88a02920daf0b408086106439c53bd488e73af29): |
| 58 |
#s[axes[-1]] = (s[axes[-1]] - 1) * 2 |
| 59 |
s[-1] = (a.shape[axes[-1]] - 1) * 2 |
| 60 |
return s, axes |