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

Code before:
namespace
{
    void fillRandomNormal(OutputArray out, float mean, float scale,
                          bool has_seed, float seed)
    {
        CV_Assert(out.isMat() || out.isUMat());
        const Scalar mean_s = Scalar::all(mean);
        const Scalar scale_s = Scalar::all(scale);

        if (has_seed)
        {
            uint64 seed_u64 = (uint64)std::llround((double)seed);
            if (!seed_u64)
                seed_u64 = 0x12345678ULL;

            RNG rng(seed_u64);
            if (out.isMat())
            {
                Mat& m = out.getMatRef();
                rng.fill(m, RNG::NORMAL, mean_s, scale_s);
            }
            else
            {
                UMat& u = out.getUMatRef();
                rng.fill(u, RNG::NORMAL, mean_s, scale_s);
            }
        }
        else
        {
            RNG& rng = theRNG();
            if (out.isMat())
            {
                Mat& m = out.getMatRef();
                rng.fill(m, RNG::NORMAL, mean_s, scale_s);
            }
            else
            {
                UMat& u = out.getUMatRef();
                rng.fill(u, RNG::NORMAL, mean_s, scale_s);
            }
        }
    }
}

class RandomNormalLikeLayerImpl CV_FINAL : public RandomNormalLikeLayer
{
public:
    RandomNormalLikeLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);


Review comment (suggestion):
You may just propagate OuputArray to the next function, getMatRef call is not needed.
So the code may be reduced to
```
          if (!seed_u64)
                seed_u64 = 0x12345678ULL;

            RNG rng(seed_u64);
            rng.fill(out, RNG::NORMAL, mean_s, scale_s);
````

Code after:
namespace
{
    void fillRandomNormal(OutputArray out, float mean, float scale,
                          bool has_seed, float seed)
    {
        CV_Assert(out.isMat() || out.isUMat());
        const Scalar mean_s = Scalar::all(mean);
        const Scalar scale_s = Scalar::all(scale);

        RNG local_rng;
        if (has_seed)
        {
            uint64 seed_u64 = (uint64)std::llround((double)seed);
            if (!seed_u64)
                seed_u64 = 0x12345678ULL;
            local_rng = RNG(seed_u64);
        }

        RNG& rng = has_seed ? local_rng : theRNG();

        if (out.isMat())
        {
            Mat& m = out.getMatRef();
            rng.fill(m, RNG::NORMAL, mean_s, scale_s);
        }
        else
        {
            UMat& u = out.getUMatRef();
            rng.fill(u, RNG::NORMAL, mean_s, scale_s);
        }
    }
}

class RandomNormalLikeLayerImpl CV_FINAL : public RandomNormalLikeLayer
{
public:
    RandomNormalLikeLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);

        mean = params.get<float>("mean", 0.f);
        scale = params.get<float>("scale", 1.f);
        int dt = params.get<int>("output_dtype", -1);
        outputType = dt >= 0 ? onnxDataTypeToCV(static_cast<OnnxDataType>(dt)) : -1;
        has_seed = params.has("seed");
        seed = has_seed ? params.get<float>("seed") : 0.f;

        CV_Assert(scale >= 0.f);
    }

    virtual bool supportBackend(int backendId) CV_OVERRIDE