nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/layers/einsum_layer.cpp
**Change Type:** added
**Context:** PR #24037: Add Support for Einsum Layer
**Review Line:** 687

**Code Changes:**
```diff
+{
+    // Only compute this function if ellipsis "..." was found in the equation
+    if (numOfEllipsisDims > 0){
+        // add assert inplace of return bool
+        CV_Error(Error::StsError, "Ellipsis are not supperted currenly");
+    }
+}
+
+
+
+void LayerEinsumImpl::processEquation(const std::vector<MatShape>& inputs)
```

Review comment:
As this method called once I'd (same as createOutputSubsctipt), let's move such checks closer to corresponding variables initialization.
**File:** modules/dnn/src/layers/einsum_layer.cpp
**Change Type:** added
**Context:** PR #24037: Add Support for Einsum Layer
**Review Line:** 764

**Code Changes:**
```diff
+                            {
+                                CV_Error(Error::StsError, cv::format("Einsum operands can not be broadcasted."
+                                                                     "Check input shapes/equation passed."
+                                                                     "Input shape of operand [%d]", inputIdx) +
+                                                          cv::format(" is incompatible in the dimention [%zu].", static_cast<size_t>(dim_count)));
+                            }
+                        }
+                    }
+                }
+                ++letter2count[letterIdx];
+                currTokenIndices.push_back(letter2index[letterIdx]);
```

Review comment:
`CV_CheckEQ`
**File:** modules/dnn/src/layers/einsum_layer.cpp
**Change Type:** added
**Context:** PR #24037: Add Support for Einsum Layer

**Code Changes:**
```diff
@@ -0,0 +1,1114 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include <inttypes.h>
+#include <opencv2/dnn/shape_utils.hpp>
+#include "../precomp.hpp"
+#include "layers_common.hpp"
+
```

Review comment:
remove unrelated commented code
**File:** modules/dnn/src/layers/einsum_layer.cpp
**Change Type:** added
**Context:** PR #24037: Add Support for Einsum Layer
**Review Line:** 924

**Code Changes:**
```diff
+                Mat tensorToReduce = !currentRight.empty() ? currentRight : right;
+                MatShape shapeToReduce = !currentRight.empty() ? shape(currentRight) : rightDims;
+                currentLeft = reduceSum(tensorToReduce, shapeToReduce);
+            }
+
+        } else {
+            // This dimension is not reduced (i.e.) it appears in the output after processing these 2 operands
+            // Both the left and right operands have non-trivial dimension value along this axis
+            // They must be equal
+            if (hasLeftDim && hasRightDim){
+                CV_CheckEQ(leftDim, rightDim, "Input shapes do not align");
```

Review comment:
Mix of code styles
**File:** modules/dnn/src/layers/einsum_layer.cpp
**Change Type:** added
**Context:** PR #24037: Add Support for Einsum Layer
**Review Line:** 336

**Code Changes:**
```diff
+            int inputDims = param.size();
+            std::vector<int> shape;
+            for (int i = 0; i < inputDims; ++i)
+                shape.emplace_back(param.get<int>(i));
+            einsumInpShapes.emplace_back(shape);
+        }
+
+
+        // Maintains a mapping between input indices and their corresponding subscript labels for each input
+        inputSubscriptIndices.reserve(numInputs);
+
```

Review comment:
Please change naming. `inputSize` is actually a number of inputs (so something `numInputs` is correct). `num_inps` is a number of dimensions.
**File:** modules/dnn/src/layers/einsum_layer.cpp
**Change Type:** added
**Context:** PR #24037: Add Support for Einsum Layer
**Review Line:** 346

**Code Changes:**
```diff
+
+        // We allocate space for 10 values as a precaution,
+        // assuming that we won't encounter any input with a rank greater than 10.
+        // In such cases, the value of num_subscript_indices_ would be greater than 10.
+        subscriptIndicesToLastInput.reserve(10);
+        subscriptIndicesToDimValue.reserve(10);
+
+        // fill in vectors to avoid getting random numbers
+        letter2count.fill(0);
+        letter2index.fill(-1);
+
```

Review comment:
Do we really need this allocation?
**File:** modules/ts/src/ts_func.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV

**Code Changes:**
```diff
@@ -2264,7 +2264,7 @@ int cmpEps2( TS* ts, const Mat& a, const Mat& b, double success_err_level,
         {
             ts->printf( TS::LOG, "%s\n", msg );
         }
-        else if( a.dims == 2 && (a.rows == 1 || a.cols == 1) )
+        else if( a.dims <= 2 && (a.rows == 1 || a.cols == 1) )
         {
             ts->printf( TS::LOG, "%s at element %d\n", msg, idx[0] + idx[1] );
         }
@@ -2365,7 +2365,7 @@ void gemm( const Mat& _a, const Mat& _b, double alpha,
```

Review comment:
`transpose()` for 1D/0D should be prohibited to avoid coding mistakes. User should reshape mat to 2D first in explicit way.
**File:** modules/core/test/test_arithm.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV

**Code Changes:**
```diff
@@ -857,8 +857,8 @@ namespace reference {
 
 static void flip(const Mat& src, Mat& dst, int flipcode)
 {
-    CV_Assert(src.dims == 2);
-    dst.create(src.size(), src.type());
+    CV_Assert(src.dims <= 2);
+    dst.createSameSize(src, src.type());
     int i, j, k, esz = (int)src.elemSize(), width = src.cols*esz;
 
```

Review comment:
`createSameSize()`
**File:** modules/core/test/test_mat.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 1786

**Code Changes:**
```diff
 TEST(Mat, from_initializer_list)
 {
     Mat A({1.f, 2.f, 3.f});
-    Mat_<float> B(3, 1); B << 1, 2, 3;
+    int n = 3;
+    Mat_<float> B(1, &n); B << 1, 2, 3;
     Mat_<float> C({3}, {1,2,3});
 
     ASSERT_EQ(A.type(), CV_32F);
@@ -1796,7 +1799,8 @@ TEST(Mat, from_initializer_list)
 TEST(Mat_, from_initializer_list)
```

Review comment:
> n use self-described names. `int shapeB[1] = { 3 };`
**File:** modules/core/include/opencv2/core/mat.inl.hpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 727

**Code Changes:**
```diff
@@ -188,6 +188,7 @@ inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; }
 inline bool _InputArray::isUMat() const  { return kind() == _InputArray::UMAT; }
 inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; }
 inline bool _InputArray::isUMatVector() const  { return kind() == _InputArray::STD_VECTOR_UMAT; }
+inline bool _InputArray::isVecVector() const  { return kind() == _InputArray::STD_VECTOR_VECTOR; }
 inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; }
 inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR ||
                                                    kind() == _InputArray::STD_BOOL_VECTOR ||
@@ -321,6 +322,28 @@ _OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr)
     return v;
 }
 
+inline
+std::vector<Mat>& _OutputArray::getMatVecRef() const
+{
```

Review comment:
There is no sense to use both arguments for 1D/0D cases.
**File:** modules/3d/misc/java/test/Cv3dTest.java
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 553

**Code Changes:**
```diff
 
         Cv3d.undistortPoints(src, dst, cameraMatrix, distCoeffs);
 
-        assertEquals(src.size(), dst.size());
+        assertEquals(src.cols(), dst.rows());
+        assertEquals(src.rows(), dst.cols());
         for(int i=0; i<src.toList().size(); i++) {
             //Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
             assertTrue(src.toList().get(i).equals(dst.toList().get(i)));
```

Review comment:
Why do we want to swap rows/cols? This doesn't look like a convenient behavior.
**File:** modules/3d/perf/perf_pnp.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 44

**Code Changes:**
```diff
     projectPoints(points3d, rvec, tvec, intrinsics, distortion, points2d);
 
     //add noise
-    Mat noise(1, (int)points2d.size(), CV_32FC2);
+    int sz = (int)points2d.size();
+    Mat noise(1, &sz, CV_32FC2);
     randu(noise, 0, 0.01);
     cv::add(points2d, noise, points2d);
 
@@ -93,7 +94,8 @@ PERF_TEST_P(PointsNum_Algo, solvePnPSmallPoints,
     cv::projectPoints(points3d, rvec, tvec, intrinsics, distortion, points2d);
```

Review comment:
Requirement of test modification means that we would broke user code. We could add new tests easily, but not to modify it. We need compatibility code to support both inputs (old and new).
**File:** modules/core/include/opencv2/core/mat.hpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 2150

**Code Changes:**
```diff
     The method increments the reference counter associated with the matrix data. If the matrix header
@@ -2134,6 +2147,7 @@ class CV_EXPORTS Mat
     int dims;
     //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
     int rows, cols;
+    int dummy = 153;
     //! pointer to the data
     uchar* data;
 
@@ -2307,6 +2321,8 @@ template<typename _Tp> class Mat_ : public Mat
     void create(Size _size);
```

Review comment:
I will remove it in one of the subsequent commits in a different pull request; Let it stay here for a few weeks/months to catch the situation when Mat.size.p (when it points to rows or cols) is accessed outside of those 2 fields
**File:** modules/core/test/test_mat.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 2442

**Code Changes:**
```diff
     {
@@ -2432,6 +2439,7 @@ TEST(Mat1D, DISABLED_basic)
         Mat m(5, 100, CV_8UC1, Scalar::all(0));
         const Mat row2D = m.row(2);
         EXPECT_NO_THROW(m1.copyTo(row2D));
+        EXPECT_NO_THROW(row2D.copyTo(m1_copy));
     }
 
     {
@@ -2452,16 +2460,19 @@ TEST(Mat1D, DISABLED_basic)
         SCOPED_TRACE("CvMatND");
```

Review comment:
Idea is to write set of simple independent tests with common predefined variables. This line violates that rule as it modifies common variable (result affects checks below).
**File:** modules/core/test/test_mat.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 2601

**Code Changes:**
```diff
 
+TEST(InputArray, dumpEmpty)
+{
+    std::string s;
+    s = cv::utils::dumpInputArray(noArray());
+    EXPECT_EQ(s, "InputArray: noArray()");
+    s = cv::utils::dumpInputArray(Mat());
+    EXPECT_EQ(s, "InputArray: empty()=true kind=0x00010000 flags=0x01010000 total(-1)=0 dims(-1)=0 size(-1)=0x0 type(-1)=CV_8UC1");
+}
+
 }} // namespace
```

Review comment:
Signature for `_EQ` is `ASSERT_EQ(expected_reference, actual_result);`. Correct order of parameters are required to emit valid error messages. Reference: https://github.com/opencv/opencv/blob/4.0.0/modules/ts/include/opencv2/ts/ts_gtest.h#L8196-L8200 ``` GTEST_API_ AssertionResult EqFailure(const char* expected_expression, const char* actual_expression, const std::string& expected_value, const std::string& actual_value, bool ignoring_case); ```
**File:** modules/dnn/include/opencv2/dnn/shape_utils.hpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 164

**Code Changes:**
```diff
 static inline int total(const MatShape& shape, int start = -1, int end = -1)
 {
-    if (shape.empty())
-        return 0;
+    //if (shape.empty())
+    //    return 0;
 
     int dims = (int)shape.size();
 
@@ -240,9 +240,9 @@ static inline std::ostream& operator<<(std::ostream &out, const std::vector<_Tp>
 static inline
```

Review comment:
Why not just `return 1` for 0D tensor?
**File:** modules/dnn/include/opencv2/dnn/shape_utils.hpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 244

**Code Changes:**
```diff
 {
-    CV_Check(axis, axis >= -dims && axis < dims, "");
-    axis = (axis < 0) ? (dims + axis) : axis;
-    CV_DbgCheck(axis, axis >= 0 && axis < dims, "");
+    CV_Assert(dims >= 0);
+    CV_Check(axis, axis >= -dims && axis <= dims, "");
+    axis = (unsigned)axis < (unsigned)dims ? axis : axis < 0 ? axis + dims : axis - dims;
     return axis;
 }
 
@@ -255,7 +255,7 @@ int normalize_axis(int axis, const MatShape& shape)
```

Review comment:
> `axis <= dims` We should not allow `axis == dims`. It is not allowed in classic index/stride rules (e.g. in Python) ``` >>> a = [1, 2, 3] >>> a[-3] 1 >>> a[-2] 2 >>> a[-1] 3 >>> a[0] 1 >>> a[1] 2 >>> a[2] 3 >>> a[3] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of range >>> ```
**File:** modules/dnn/test/test_onnx_importer.cpp
**Change Type:** modified
**Context:** PR #23473: attempt to add 0d/1d mat support to OpenCV
**Review Line:** 1908

**Code Changes:**
```diff
@@ -1899,7 +1905,7 @@ TEST_P(Test_ONNX_layers, Quantized_Convolution)
 
 TEST_P(Test_ONNX_layers, Quantized_MatMul)
 {
-    testONNXModels("quantized_matmul_uint8_weights", npy, 0.005, 0.007);
+    testONNXModels("quantized_matmul_uint8_weights", npy, 0.008, 0.015);
     testONNXModels("quantized_matmul_int8_weights", npy, 0.06, 0.2);
     testONNXModels("quantized_matmul_per_channel_weights", npy, 0.06, 0.22);
 }
@@ -1998,7 +2004,7 @@ TEST_P(Test_ONNX_layers, Quantized_Concat)
 
```

Review comment:
What is happened?
**File:** modules/python/src2/cv2.hpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -39,12 +39,20 @@
 
 class ArgInfo
 {
+private:
+    static const uint32_t arg_outputarg_flag     = 0x1;
+    static const uint32_t arg_arithm_op_src_flag = 0x2;
+
 public:
     const char* name;
```

Review comment:
Prefer to use unsigned integers for bitwise operations [High Integrity C++ Standard, Section 5.6.1](http://www.codingstandard.com/section/5-6-shift-operators/) > Use of signed operands with bitwise operators is in some cases subject to undefined or implementation defined behavior. Therefore, bitwise operators should only be used with operands of unsigned integral types.
**File:** modules/python/test/test_misc.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -42,6 +42,93 @@ def get_conversion_error_msg(value, expected, actual):
 def get_no_exception_msg(value):
     return 'Exception is not risen for {} of type {}'.format(value, type(value).__name__)
 
+
+def rpad(src, dst_size, pad_value=0):
+    """Extend `src` up to `dst_size` with given value.
+
+    Args:
+        src (np.ndarray | tuple | list): 1d array like object to pad.
```

Review comment:
This is essentially the same as `cv.subtract(src1_mat, 32)` add a trailing comma for tuple with length 1: `cv.subtract(src1_mat, (32, ))`
**File:** modules/python/test/test_misc.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -42,6 +42,93 @@ def get_conversion_error_msg(value, expected, actual):
 def get_no_exception_msg(value):
     return 'Exception is not risen for {} of type {}'.format(value, type(value).__name__)
 
+
+def rpad(src, dst_size, pad_value=0):
+    """Extend `src` up to `dst_size` with given value.
+
+    Args:
+        src (np.ndarray | tuple | list): 1d array like object to pad.
```

Review comment:
I don't think that we should add tests for NumPy behavior, because it has types promotion and different casting rules: ``` >>> import numpy as np >>> a = np.array([250, 250, 250], dtype=np.uint8) >>> a += [10, 10, 20] Traceback (most recent call last): File "<stdin>", line 1, in <module> numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('int64') to dtype('uint8') with casting rule 'same_kind' >>> b = a + [10, 10, 20] >>> b.dtype dtype('int64') ```
**File:** modules/python/test/test_misc.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -42,6 +42,93 @@ def get_conversion_error_msg(value, expected, actual):
 def get_no_exception_msg(value):
     return 'Exception is not risen for {} of type {}'.format(value, type(value).__name__)
 
+
+def rpad(src, dst_size, pad_value=0):
+    """Extend `src` up to `dst_size` with given value.
+
+    Args:
+        src (np.ndarray | tuple | list): 1d array like object to pad.
```

Review comment:
Yes, I think it is not need to test. I'l remove it.
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
use `Mat::zeros(sz2, 1, CV_64F)`, than loop ```cxx for( i = sz; i < sz2; i++ ) // Padding 0 { m.at<double>(i) = 0.0; } ``` (lines 113-116) can be omitted.
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
can be defined in the following loop: ```cxx for (int i = 0; i < sz; i++) ```
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
`const int sz2 = info.arithm_op_src ? std::max(4, sz) : sz;`
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
redundant change
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
`m = cv::Mat::zeros(sz2, 1, CV_64F)`
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
`for (int i = 0; i < zs; ++i)`
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
Redundant if `m = cv::Mat::zeros(sz2, 1, CV_64F)`
**File:** modules/python/src2/hdr_parser.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -535,6 +535,13 @@ def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
 
         funcname = self.get_dotted_name(funcname)
 
+        # see https://github.com/opencv/opencv/issues/24057
+        is_arithm_op_func = funcname in {"cv.add",
+                                         "cv.subtract",
+                                         "cv.absdiff",
+                                         "cv.multiply",
+                                         "cv.divide"}
```

Review comment:
This check ` arg_name in { "src1", "src2" }` is really necessary? Name of the argument shouldn't impact its properties.
**File:** modules/python/test/test_misc.py
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -42,6 +42,93 @@ def get_conversion_error_msg(value, expected, actual):
 def get_no_exception_msg(value):
     return 'Exception is not risen for {} of type {}'.format(value, type(value).__name__)
 
+
+def rpad(src, dst_size, pad_value=0):
+    """Extend `src` up to `dst_size` with given value.
+
+    Args:
+        src (np.ndarray | tuple | list): 1d array like object to pad.
```

Review comment:
I've prepared a bit more comprehensive test. You can manually apply changes from attached patch file: [arithm_op_python_tests.txt](https://github.com/opencv/opencv/files/12430618/arithm_op_python_tests.txt) `git apply arithm_op_python_tests.txt`
**File:** modules/python/src2/cv2_convert.cpp
**Change Type:** modified
**Context:** PR #24074: python: support tuple src for cv::add()/subtract()/...

**Code Changes:**
```diff
@@ -63,20 +63,39 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
     if( PyInt_Check(o) )
     {
         double v[] = {static_cast<double>(PyInt_AsLong((PyObject*)o)), 0., 0., 0.};
+        if ( info.arithm_op_src )
+        {
+            // Normally cv.XXX(x) means cv.XXX( (x, 0., 0., 0.) );
+            // However  cv.add(mat,x) means cv::add(mat, (x,x,x,x) ).
+            v[1] = v[0];
+            v[2] = v[0];
```

Review comment:
I agree with you, to use `std::max()` makes more simply.