sxjscience commented on a change in pull request #16209: Complex data type support and numpy operator fft URL: https://github.com/apache/incubator-mxnet/pull/16209#discussion_r331722310
########## File path: src/operator/numpy/np_fft-inl.h ########## @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file np_fft-inl.h + * \brief Function definition of numpy-compatible fft operator + */ + +#ifndef MXNET_OPERATOR_NUMPY_NP_FFT_INL_H_ +#define MXNET_OPERATOR_NUMPY_NP_FFT_INL_H_ + +#include <string> +#include <vector> +#include "../mshadow_op.h" +#include "../operator_common.h" +#include "../tensor/broadcast_reduce_op.h" + +namespace mxnet { +namespace op { + +struct NPFFTParam : public dmlc::Parameter<NPFFTParam> { + // the maximum size of sub-batch to be forwarded through FFT in one time + int batch_size; + dmlc::optional<int> n; + dmlc::optional<int> axis; + dmlc::optional<std::string> norm; + DMLC_DECLARE_PARAMETER(NPFFTParam) { + DMLC_DECLARE_FIELD(n) + .set_default(dmlc::optional<int>()) + .describe("Length of the transformed axis of the output"); + DMLC_DECLARE_FIELD(batch_size) + .set_default(128) + .describe("Maximum size of sub-batch to be forwarded at one time"); + } +}; + +struct resize_and_cast { + template <typename IType, typename OType> + MSHADOW_XINLINE static void Map(int i, OType* out, IType* in, + int in_dim, int out_dim, float scale = 1) { + int tmp = i / out_dim; + int offset = i - tmp * out_dim; + out[i] = (offset >= in_dim) ? OType(0) + : OType(in[tmp * in_dim + offset] / scale); + } +}; + +#ifdef __CUDACC__ +#include "np_fft-inl.cuh" +template <typename xpu, typename IType, typename OType, typename FFTType> +inline void FFTExec(const OpContext& ctx, + const mshadow::Tensor<gpu, 2, IType>& in_data, + const mshadow::Tensor<gpu, 2, OType>& out_data, + const FFTType& indicator, int n_ffts, int len_fft, + int batch_size, int grad_dim = 0) { Review comment: Let's move the definition to the .cu and .cc file. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
