Commit 6cb5f23d authored by Martin Reinecke's avatar Martin Reinecke

return early for zero-sized arrays

parent 8ac40bf5
/*
* This file is part of pocketfft.
* Licensed under a 3-clause BSD style license - see LICENSE.md
*/
/*
* Main implementation file.
*
* Copyright (C) 2004-2019 Max-Planck-Society
* \author Martin Reinecke
*/
This file is part of pocketfft.
Copyright (C) 2010-2019 Max-Planck-Society
Author: Martin Reinecke
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef POCKETFFT_HDRONLY_H
#define POCKETFFT_HDRONLY_H
#ifndef __cplusplus
#error This file is C++ and requires a C++ compiler
#endif
#if __cplusplus < 201103L
#error This file requires at least C++11 support
#endif
#include <cmath>
#include <cstring>
#include <cstdlib>
......@@ -2409,6 +2437,7 @@ template<typename T> void c2c(const shape_t &shape, const stride_t &stride_in,
const std::complex<T> *data_in, std::complex<T> *data_out, T fct)
{
using namespace detail;
if (util::prod(shape)==0) return;
util::sanity_check(shape, stride_in, stride_out, data_in==data_out, axes);
ndarr<cmplx<T>> ain(data_in, shape, stride_in),
aout(data_out, shape, stride_out);
......@@ -2420,9 +2449,12 @@ template<typename T> void r2c(const shape_t &shape_in,
const T *data_in, std::complex<T> *data_out, T fct)
{
using namespace detail;
if (util::prod(shape_in)==0) return;
util::sanity_check(shape_in, stride_in, stride_out, false, axis);
ndarr<T> ain(data_in, shape_in, stride_in);
ndarr<cmplx<T>> aout(data_out, shape_in, stride_out); // FIXME
shape_t shape_out(shape_in);
shape_out[axis] = shape_in[axis]/2 + 1;
ndarr<cmplx<T>> aout(data_out, shape_out, stride_out);
general_r2c(ain, aout, axis, fct);
}
......@@ -2431,6 +2463,7 @@ template<typename T> void r2c(const shape_t &shape_in,
const T *data_in, std::complex<T> *data_out, T fct)
{
using namespace detail;
if (util::prod(shape_in)==0) return;
util::sanity_check(shape_in, stride_in, stride_out, false, axes);
r2c(shape_in, stride_in, stride_out, axes.back(), data_in, data_out, fct);
if (axes.size()==1) return;
......@@ -2447,6 +2480,7 @@ template<typename T> void c2r(const shape_t &shape_out,
const std::complex<T> *data_in, T *data_out, T fct)
{
using namespace detail;
if (util::prod(shape_out)==0) return;
util::sanity_check(shape_out, stride_in, stride_out, false, axis);
shape_t shape_in(shape_out);
shape_in[axis] = shape_out[axis]/2 + 1;
......@@ -2460,6 +2494,7 @@ template<typename T> void c2r(const shape_t &shape_out,
const std::complex<T> *data_in, T *data_out, T fct)
{
using namespace detail;
if (util::prod(shape_out)==0) return;
if (axes.size()==1)
{
c2r(shape_out, stride_in, stride_out, axes[0], data_in, data_out, fct);
......@@ -2486,6 +2521,7 @@ template<typename T> void r2r_fftpack(const shape_t &shape,
bool forward, const T *data_in, T *data_out, T fct)
{
using namespace detail;
if (util::prod(shape)==0) return;
util::sanity_check(shape, stride_in, stride_out, data_in==data_out, axis);
ndarr<T> ain(data_in, shape, stride_in), aout(data_out, shape, stride_out);
general_r(ain, aout, axis, forward, fct);
......@@ -2496,6 +2532,7 @@ template<typename T> void r2r_hartley(const shape_t &shape,
const T *data_in, T *data_out, T fct)
{
using namespace detail;
if (util::prod(shape)==0) return;
util::sanity_check(shape, stride_in, stride_out, data_in==data_out, axes);
ndarr<T> ain(data_in, shape, stride_in), aout(data_out, shape, stride_out);
general_hartley(ain, aout, axes, fct);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment