Repository: opencv/opencv
File: modules/dnn/src/layers/dft_layer.cpp (C++)

Code before:
        if (axis_attr != INT_MIN)
        {
            axis = axis_attr;
            if (axis < 0) axis += ndims;
        }
        else if (!axes.empty())
        {
            CV_Assert(axes.size() == 1);
            axis = axes[0];
            if (axis < 0) axis += ndims;
        }
        CV_Assert(axis >= 0 && axis < (srcHasComplex ? ndims - 1 : ndims));
        CV_Assert(!onesided);

        std::vector<int> outSizesVec;
        outSizesVec.resize(srcHasComplex ? ndims : ndims + (srcLastIsOne ? 0 : 1));
        for (int i = 0; i < ndims; ++i) outSizesVec[i] = src.size[i];
        int complexDim = (int)outSizesVec.size() - 1;
        outSizesVec[complexDim] = 2;
        if (dft_length > 0)
        {
            int dstDimsNoComplex = (int)outSizesVec.size() - 1;
            if (axis >= 0 && axis < dstDimsNoComplex)
                outSizesVec[axis] = dft_length;
        }
        dst.create((int)outSizesVec.size(), &outSizesVec[0], src.type());

        std::vector<int> dimSizesSrc(ndims);
        for (int i = 0; i < ndims; ++i) {
            dimSizesSrc[i] = src.size[i];
        }
        std::vector<size_t> stridesSrc(ndims, 1);
        for (int i = ndims - 2; i >= 0; --i) {
            stridesSrc[i] = stridesSrc[i + 1] * (size_t)dimSizesSrc[i + 1];
        }
        const int ndimsDst = dst.dims;
        std::vector<int> dimSizesDst(ndimsDst);
        for (int i = 0; i < ndimsDst; ++i) {
            dimSizesDst[i] = dst.size[i];
        }
        std::vector<size_t> stridesDst(ndimsDst, 1);
        for (int i = ndimsDst - 2; i >= 0; --i) {
            stridesDst[i] = stridesDst[i + 1] * (size_t)dimSizesDst[i + 1];
        }

        int N = dimSizesSrc[axis];
        if (dft_length > 0) N = dft_length;
        const size_t strideAxisSrc = stridesSrc[axis];
        const size_t strideAxisDst = stridesDst[axis];
        std::vector<int> iterDims;
        for (int i = 0; i < (srcHasComplex ? ndims - 1 : ndims); ++i){

Review comment (suggestion):
create is not good here. Please, use `OutputArrayOfArrays::kind`, as usual.

Code after:
        CV_Assert(inputs.size() >= 1);
        const MatShape &inshape = inputs[0];
        CV_Assert(!inshape.empty());
        MatShape out = inshape;

        int last = out.back();
        if (last == 1)
            out.back() = 2;
        else if (last != 2)
            out.push_back(2);

        int ndims_in = (int)inshape.size();
        int ax = axis_attr;
        if (ax == INT_MIN)
        {
            ax = (inshape.back() == 2 || inshape.back() == 1) ? ndims_in - 2 : ndims_in - 1;
        }
        if (ax < 0) ax += ndims_in;
        if (ax >= 0 && ax < (int)out.size() - 1)
        {
            int dft_length = getDftLengthFromConstant();
            int signalLen = dft_length > 0 ? dft_length : (ax < (int)inshape.size() ? inshape[ax] : out[ax]);
            out[ax] = onesided ? (signalLen / 2 + 1) : signalLen;
        }
        outputs.assign(1, out);
        return false;
    }

    void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays /*internals_arr*/) CV_OVERRIDE
    {
        std::vector<Mat> inputs, outputs;
        inputs_arr.getMatVector(inputs);

        CV_Assert(!inputs.empty());
        CV_Assert(inputs[0].dims >= 1);

        const Mat &src = inputs[0];

        const int ndims = src.dims;
        CV_Assert(ndims >= 1);
        const bool srcHasComplex = (src.size[ndims - 1] == 2);
        const bool srcLastIsOne = (src.size[ndims - 1] == 1);
        int axis = (srcHasComplex ? ndims - 2 : ndims - 1);
        if (axis_attr != INT_MIN)
        {
            axis = axis_attr;
            if (axis < 0) axis += ndims;
        }
        else if (!axes.empty())
        {
            CV_Assert(axes.size() == 1);