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

Code before:

    virtual bool dynamicOutputShapes() const CV_OVERRIDE
    {
        return false;
    }

    bool getMemoryShapes(const std::vector<MatShape>& inputs,
                         const int requiredOutputs,
                         std::vector<MatShape>& outputs,
                         std::vector<MatShape>& internals) const CV_OVERRIDE
    {
        CV_Assert(inputs.size() == (size_t)1);
        CV_Assert(requiredOutputs == 1);
        outputs.assign(1, inputs[0]);
        internals.clear();
        return true;
    }

    void getTypes(const std::vector<MatType>& inputs,
                  const int requiredOutputs,
                  const int requiredInternals,
                  std::vector<MatType>& outputs,
                  std::vector<MatType>& internals) const CV_OVERRIDE
    {
        CV_Assert(inputs.size() == (size_t)1);
        int outType = output_dtype >= 0 ? output_dtype : inputs[0];
        outputs.assign(1, outType);
        CV_Assert(requiredInternals == 0);
        internals.clear();
    }

    void forward(InputArrayOfArrays inputs_arr,
                 OutputArrayOfArrays outputs_arr,
                 OutputArrayOfArrays) CV_OVERRIDE
    {
        CV_TRACE_FUNCTION();
        CV_TRACE_ARG_VALUE(name, "name", name.c_str());

        Size size = inputs_arr.size();
        int ninputs = size.area();
        CV_Assert(ninputs == 1);

        Mat inp = inputs_arr.getMat(0);
        MatShape outShape = inp.shape();

        int outType = output_dtype >= 0 ? output_dtype : inp.type();

        auto kind = outputs_arr.kind();
        if (kind == _InputArray::STD_VECTOR_MAT) {
            std::vector<Mat>& outs = outputs_arr.getMatVecRef();
            outs.resize(1);

Review comment (suggestion):
output_dtype is ONNX constant, it's not OpenCV constant. Please, transform it to OpenCV type enumeration.

Code after:
    {
        CV_Assert(inputs.size() == (size_t)1);
        CV_Assert(requiredOutputs == 1);
        outputs.assign(1, inputs[0]);
        internals.clear();
        return true;
    }

    void getTypes(const std::vector<MatType>& inputs,
                  const int requiredOutputs,
                  const int requiredInternals,
                  std::vector<MatType>& outputs,
                  std::vector<MatType>& internals) const CV_OVERRIDE
    {
        CV_Assert(inputs.size() == (size_t)1);
        int outType = outputType >= 0 ? outputType : inputs[0];
        outputs.assign(1, outType);
        CV_Assert(requiredInternals == 0);
        internals.clear();
    }

    void forward(InputArrayOfArrays inputs_arr,
                 OutputArrayOfArrays outputs_arr,
                 OutputArrayOfArrays) CV_OVERRIDE
    {
        CV_TRACE_FUNCTION();
        CV_TRACE_ARG_VALUE(name, "name", name.c_str());

        Size size = inputs_arr.size();
        int ninputs = size.area();
        CV_Assert(ninputs == 1);

        Mat inp = inputs_arr.getMat(0);
        MatShape outShape = inp.shape();

        int outType = outputType >= 0 ? outputType : inp.type();

        auto kind = outputs_arr.kind();
        if (kind == _InputArray::STD_VECTOR_MAT) {
            std::vector<Mat>& outs = outputs_arr.getMatVecRef();
            outs.resize(1);
            outs[0].fit(outShape, outType);
            fillRandomNormal(outs[0], mean, scale, has_seed, seed);
        } else if (kind == _InputArray::STD_VECTOR_UMAT) {
            std::vector<UMat>& outs = outputs_arr.getUMatVecRef();
            outs.resize(1);
            outs[0].fit(outShape, outType);
            fillRandomNormal(outs[0], mean, scale, has_seed, seed);
        } else {
            CV_Error(Error::StsNotImplemented, "");
        }