Way to translation of Mat class operators defined in C++

This is a list of implemented matrix operations that can be combined in arbitrary complex expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a real-valued scalar ( double )):

In c#, it is not possible to explicitly overload compound assignment operators such as “A *= B“. Instead, binary operator overloading is used implicitly. Therefore, whenever an operator is used, a new mat is created and assigned.

Addition, subtraction, negation: A+B, A-B, A+s, A-s, s+A, s-A, -A
A + BM1 + M2

Core.add (M1, M2, M_dst)

A – BM1 – M2

Core.subtract (M1, M2, M_dst)

A + sM1 + s

Core.add (M1, s, M_dst)

A – sM1 – s

Core.subtract (M1, s, M_dst)


Core.multiply (M1, Scalar.all (-1), M_dst)

Scaling: A*alpha A/alpha
A * αM1 * 3

Core.multiply (M1, Scalar.all (3), M_dst)

A / αM1 / 3

Core.divide (M1, Scalar.all (3), M_dst)

Per-element multiplication and division: A.mul(B), A/B, alpha/A

M1.mul (M2)

A / BM1 / M2

Core.divide (M1, M2, M_dst)

α / A3 / M1

Core.divide (new Mat (M1.size (), M1.type (), Scalar.all (3)), M1, M_dst)

Matrix multiplication: A*B
A * BM1 * M2

Core.gemm (M1, M2, 1, new Mat (), 0, M_dst)

Comparison: A cmpop B, A cmpop alpha, alpha cmpop A, where cmpop is one of :  >, >=, ==, !=, <=, <. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or 0.
A > BM1 > M2

Core.compare (M1, M2, M_dst, Core.CMP_GT)

A >= BM1 >= M2

Core.compare (M1, M2, M_dst, Core.CMP_GE)

A == BM1 == M2

Core.compare (M1, M2, M_dst, Core.CMP_EQ)

A != BM1 != M2

Core.compare (M1, M2, M_dst, Core.CMP_NE)

A <= BM1 <= M2

Core.compare (M1, M2, M_dst, Core.CMP_LE)

A < BM1 < M2

Core.compare (M1, M2, M_dst, Core.CMP_LT)

Bitwise logical operations: A logicop B, A logicop s, s logicop A, ~A, where logicop is one of :  &, |, ^.
A & BM1 & M2

Core.bitwise_and (M1, M2, M_dst)

A | BM1 | M2

Core.bitwise_or (M1, M2, M_dst)

A ^ BM1 ^ M2

Core.bitwise_xor (M1, M2, M_dst)


Core.bitwise_not (M1, M_dst)

Matrix assignment operators:
C = A + BM3 = M1 + M2

Core.add (M1, M2, M3)

A = sM1 = s

M1.setTo (s)