TMtx.Mul Method

Overload List

#SignatureDescription
1TMtx Mul(TMtx A, TMtx B)Matrix multiplication.
2TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtx Mtx3)Returns the matrix product of three matrices.
3TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtx Mtx3, TMtx Mtx4)Returns the matrix product of four matrices.
4TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtxOperation Operation1, TMtxOperation Operation2, TJITedMul JITedMul)Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix.
5TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtxType Mtx1Type, TMtxType Mtx2Type, TMtxOperation Operation1, TMtxOperation Operation2, TJITedMul JITedMul)Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix.
6TMtxVec Mul(TMtxVec Vec)Vector multiplication.
└ indexed: TMtxVec Mul(TMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len)
7TMtxVec Mul(TMtxVec Vec1, TMtxVec Vec2)Multiply all Vec1 elements with corresponding Vec2 elements.
└ indexed: TMtxVec Mul(TMtxVec Vec1, TMtxVec Vec2, Int32 Vec1Index, Int32 Vec2Index, Int32 Index, Int32 Len)
8TMtxVec Mul(TMtxVec X, TMtxVec Y, TCplx Z)self = X*Y*zScalar
└ indexed: TMtxVec Mul(TMtxVec X, Int32 XIndex, TMtxVec Y, Int32 YIndex, TCplx Z, Int32 Index, Int32 Len)
9TMtxVec Mul(TMtxVec X, TMtxVec Y, TMtxVec Z)self = X*Y*Z
└ indexed: TMtxVec Mul(TMtxVec X, Int32 XIndex, TMtxVec Y, Int32 YIndex, TMtxVec Z, Int32 zIndex, Int32 Index, Int32 Len)
10TMtxVec Mul(TMtxVec X, TMtxVec Y, Double Z)self = X*Y*zScalar
└ indexed: TMtxVec Mul(TMtxVec X, Int32 XIndex, TMtxVec Y, Int32 YIndex, Double Z, Int32 Index, Int32 Len)
11TMtxVec Mul(TCplx Value)Multiply all calling object elements with complex Value in-place.
└ indexed: TMtxVec Mul(TCplx Value, Int32 Index, Int32 Len)
12TMtxVec Mul(TMtxVec Vec, TCplx Value)Multiply each element of Vec with complex Value.
└ indexed: TMtxVec Mul(TMtxVec Vec, TCplx Value, Int32 VecIndex, Int32 Index, Int32 Len)
13TMtxVec Mul(TMtxVec Vec, Double Value)Multiply each element of Vec with Value.
└ indexed: TMtxVec Mul(TMtxVec Vec, Double Value, Int32 VecIndex, Int32 Index, Int32 Len)
14TMtxVec Mul(Double Value)Multiply object elements with Value.
└ indexed: TMtxVec Mul(Double Value, Int32 Index, Int32 Len)

Overload 1: TMtx Mul(TMtx A, TMtx B)

Matrix multiplication.

#NameTypeDescription
1ATMtxsource TMtx
2BTMtxsource TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

Performs matrix multiplication. In most general case the matrix multiplication is defined by the following equation (result = calling matrix):

result=αop(M1)op(M2)+βresult\text{result}=\alpha \cdot \text{op}(M_1) \cdot \text{op}(M_2) + \beta \cdot \text{result}

where a and b are Dew.Math.TMtxVec.Alfa and Dew.Math.TMtxVec.Beta variables. The default values for a and b are Cplx(1,0) and Cplx(0,0), so the above equation is reduced to:

result=op(M1)op(M2)\text{result}=\text{op}(M_1)\cdot \text{op}(M_2)

The Operation1 and Operation2 indicate additional Dew.Math.TMtxOperation, performed on Mtx1 and Mtx2 respectively. Default value for operation is opNone (no additional operation). The Mtx1Type and Mtx2Type parameters indicate the Dew.Math.TMtxType of Mtx1 and Mtx2 matrices. Depending what type of matrices you are multiplying, the Mul method will choose most optimized multiplication method. So, choosing the correct values for Mtx1Type and Mtx2Type can significantly speed up the multiplication.

This overloaded function performs a left side multiply operation B with A matrix and stores the results in the calling matrix. If Operation1 and/or Operation2 parameters are specified, perform additional operation on A or B. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The Dew.Math.TMtx.Rows, Dew.Math.TMtx.Cols and Dew.Math.TMtxVec.Complex properties of the calling matrix are adjusted automatically. An exception is raised is A Cols property does not match the B Rows property (matrix multiplication is not possible). An exception is raised, if Dew.Math.TMtxVec.Complex property of A and B does not match.

Note

  • If you are not sure, which Dew.Math.TMtxType of matrix are you multiplying, you can use the mtGeneral type (general case).
  • You can also use the Dew.Math.TMtx.DetectMtxType method to determine the type of matrix.
  • The routine is multithreaded, if specified by the environment variable.
Examples
TMtx A;
TMtx B;
TMtx C;
MtxVec.CreateIt(out A, out B, out C);
try
    {
        A.SetIt(2,2,false,[1,2,
        2,4]);
        B.SetIt(2,2,false,[1,2,
        2,4]);
        C.Mul(A,B);
    }
finally
    {
        MtxVec.FreeIt(ref A, ref B, ref C);
    }
See Also: TMtx.MulElem

Overload 2: TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtx Mtx3)

Returns the matrix product of three matrices.

#NameTypeDescription
1Mtx1TMtxsource TMtx
2Mtx2TMtxsource TMtx
3Mtx3TMtxsource TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

Internally calls Dew.Math.TMtx.Mul and does JIT-ed (faster) multiply only for small square sized matrices.

Overload 3: TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtx Mtx3, TMtx Mtx4)

Returns the matrix product of four matrices.

#NameTypeDescription
1Mtx1TMtxsource TMtx
2Mtx2TMtxsource TMtx
3Mtx3TMtxsource TMtx
4Mtx4TMtxsource TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

Internally calls Dew.Math.TMtx.Mul and does JIT-ed (faster) multiply only for small square sized matrices.

Overload 4: TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtxOperation Operation1, TMtxOperation Operation2, TJITedMul JITedMul)

Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix.

#NameTypeDescription
1Mtx1TMtxsource TMtx
2Mtx2TMtxsource TMtx
3Operation1TMtxOperation
4Operation2TMtxOperation
5JITedMulTJITedMul

Result: stored in self (calling object), returns self for chaining

Remarks:

If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The Dew.Math.TMtx.Rows, Dew.Math.TMtx.Cols and Dew.Math.TMtxVec.Complex properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of Mtx1 and Mtx2 does not match.

When JITedMul is set to jtmEnabled, the JIT-ed matrix kernel will be created. This creation takes some time and should only be used, if the function will be called many times with the same parameters. The parameters that may not change include the size of the matrices, but matrix objects and memory locations can vary. As a rule of thumb, the change of the parameters can be 2-3x slower than using tmDisabled, but when the parameters do not change for a small matrix of 2x2 the speed-up can be 50x.

Overload 5: TMtx Mul(TMtx Mtx1, TMtx Mtx2, TMtxType Mtx1Type, TMtxType Mtx2Type, TMtxOperation Operation1, TMtxOperation Operation2, TJITedMul JITedMul)

Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix.

#NameTypeDescription
1Mtx1TMtxsource TMtx
2Mtx2TMtxsource TMtx
3Mtx1TypeTMtxType
4Mtx2TypeTMtxType
5Operation1TMtxOperation
6Operation2TMtxOperation
7JITedMulTJITedMul

Result: stored in self (calling object), returns self for chaining

Remarks:

If parameters Mtx1Type and/or Mtx2Type are specified, the optimized multiplication method will be used. If parameters Mtx1Type and/or Mtx2Type are omitted, default values (general matrix) will be used. If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The Dew.Math.TMtx.Rows, Dew.Math.TMtx.Cols and Dew.Math.TMtxVec.Complex properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of Mtx1 and Mtx2 does not match.

When JITedMul is set to jtmEnabled, the JIT-ed matrix kernel will be created. This creation takes some time and should only be used, if the function will be called many times with the same parameters. The parameters that may not change include the size of the matrices, but matrix objects and memory locations can vary. As a rule of thumb, the change of the parameters can be 2-3x slower than using tmDisabled, but when the parameters do not change for a small matrix of 2x2 the speed-up can be 50x.

Overload 6: TMtxVec Mul(TMtxVec Vec)

Vector multiplication.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

Multiply each of Vec elements with corresponding elements in the calling object. Size and Dew.Math.TMtxVec.Complex property of the calling object are set automatically. The result is stored in the calling object.

Indexed: TMtxVec Mul(TMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len)

Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2VecIndexInt32
3IndexInt32start index
4LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

An exception is raised if Vec and calling object Dew.Math.TMtxVec.Complex property do not match or if array borders are overrun/underrun.

Overload 7: TMtxVec Mul(TMtxVec Vec1, TMtxVec Vec2)

Multiply all Vec1 elements with corresponding Vec2 elements.

#NameTypeDescription
1Vec1TMtxVecsource TVec or TMtx
2Vec2TMtxVecsource TVec or TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

Store the results in calling object. Size and Dew.Math.TMtxVec.Complex property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and Dew.Math.TMtxVec.Complex property do not match.

Indexed: TMtxVec Mul(TMtxVec Vec1, TMtxVec Vec2, Int32 Vec1Index, Int32 Vec2Index, Int32 Index, Int32 Len)

Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1].

#NameTypeDescription
1Vec1TMtxVecsource TVec or TMtx
2Vec2TMtxVecsource TVec or TMtx
3Vec1IndexInt32
4Vec2IndexInt32
5IndexInt32start index
6LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

Store the results in calling object elements [Index]..[Index+Len-1]. Size and Dew.Math.TMtxVec.Complex properties of the calling object must be set explicitly. An exception is raised if Dew.Math.TMtxVecBase.ConditionCheck is True and array borders are overrun or underrun.

Overload 8: TMtxVec Mul(TMtxVec X, TMtxVec Y, TCplx Z)

Compute X*Y*zScalar

#NameTypeDescription
1XTMtxVecsource TVec or TMtx
2YTMtxVecsource TVec or TMtx
3ZTCplxscalar

Result: stored in self (calling object), returns self for chaining

Remarks:

The following expression would also run at the same or higher speed, when passing X also for the Z parameter:

X^2*zScalar

Indexed: TMtxVec Mul(TMtxVec X, Int32 XIndex, TMtxVec Y, Int32 YIndex, TCplx Z, Int32 Index, Int32 Len)

Compute X*Y*zScalar on sub array

#NameTypeDescription
1XTMtxVecsource TVec or TMtx
2XIndexInt32X start index
3YTMtxVecsource TVec or TMtx
4YIndexInt32Y start index
5ZTCplxscalar
6IndexInt32start index
7LenInt32element count

Result: stored in self (calling object), returns self for chaining

Overload 9: TMtxVec Mul(TMtxVec X, TMtxVec Y, TMtxVec Z)

Compute X*Y*Z

#NameTypeDescription
1XTMtxVecsource TVec or TMtx
2YTMtxVecsource TVec or TMtx
3ZTMtxVecsource TVec or TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

The following expression would also run at the same or higher speed, when passing X also for the Z parameter:

X^2*Y

Indexed: TMtxVec Mul(TMtxVec X, Int32 XIndex, TMtxVec Y, Int32 YIndex, TMtxVec Z, Int32 zIndex, Int32 Index, Int32 Len)

Compute X*Y*Z on sub array

#NameTypeDescription
1XTMtxVecsource TVec or TMtx
2XIndexInt32X start index
3YTMtxVecsource TVec or TMtx
4YIndexInt32Y start index
5ZTMtxVecsource TVec or TMtx
6zIndexInt32
7IndexInt32start index
8LenInt32element count

Result: stored in self (calling object), returns self for chaining

Overload 10: TMtxVec Mul(TMtxVec X, TMtxVec Y, Double Z)

Compute X*Y*zScalar

#NameTypeDescription
1XTMtxVecsource TVec or TMtx
2YTMtxVecsource TVec or TMtx
3ZDoublescalar

Result: stored in self (calling object), returns self for chaining

Remarks:

The following expression would also run at the same or higher speed, when passing X also for the Z parameter:

X^2*zScalar

Indexed: TMtxVec Mul(TMtxVec X, Int32 XIndex, TMtxVec Y, Int32 YIndex, Double Z, Int32 Index, Int32 Len)

Compute X*Y*zScalar on sub array

#NameTypeDescription
1XTMtxVecsource TVec or TMtx
2XIndexInt32X start index
3YTMtxVecsource TVec or TMtx
4YIndexInt32Y start index
5ZDoublescalar
6IndexInt32start index
7LenInt32element count

Result: stored in self (calling object), returns self for chaining

Overload 11: TMtxVec Mul(TCplx Value)

Multiply all calling object elements with complex Value in-place.

#NameTypeDescription
1ValueTCplxscalar

Result: stored in self (calling object), returns self for chaining

Indexed: TMtxVec Mul(TCplx Value, Int32 Index, Int32 Len)

Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place.

#NameTypeDescription
1ValueTCplxscalar
2IndexInt32start index
3LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

An exception is raised if array borders are overrun or underrun.

Overload 12: TMtxVec Mul(TMtxVec Vec, TCplx Value)

Multiply each element of Vec with complex Value.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2ValueTCplxscalar

Result: stored in self (calling object), returns self for chaining

Remarks:

Store the result in the calling object. Size of the calling object is set automatically. Dew.Math.TMtxVec.Complex property of the calling object is set to True.

Indexed: TMtxVec Mul(TMtxVec Vec, TCplx Value, Int32 VecIndex, Int32 Index, Int32 Len)

Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2ValueTCplxscalar
3VecIndexInt32
4IndexInt32start index
5LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. Dew.Math.TMtxVec.Complex propertiy of the calling object is set to True.

Overload 13: TMtxVec Mul(TMtxVec Vec, Double Value)

Multiply each element of Vec with Value.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2ValueDoublescalar

Result: stored in self (calling object), returns self for chaining

Remarks:

Store the result in the calling object. Size and Dew.Math.TMtxVec.Complex properties of the calling object are adjusted automatically.

Indexed: TMtxVec Mul(TMtxVec Vec, Double Value, Int32 VecIndex, Int32 Index, Int32 Len)

Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2ValueDoublescalar
3VecIndexInt32
4IndexInt32start index
5LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. Dew.Math.TMtxVec.Complex propertiy of the calling object is set implicitly.

Overload 14: TMtxVec Mul(Double Value)

Multiply object elements with Value.

#NameTypeDescription
1ValueDoublescalar

Result: stored in self (calling object), returns self for chaining

Remarks:

Multiplies all calling object elements with Value in-place.

Examples
Vector v;
v.SetIt(1,3,false,new double[] {2,3,5});  // v = new double[] {2,3,5}
v = v*3; // v = new double[] {6,9,15}

Indexed: TMtxVec Mul(Double Value, Int32 Index, Int32 Len)

Multipy calling object elements [Index]..[Index+Len-1] with Value in-place.

#NameTypeDescription
1ValueDoublescalar
2IndexInt32start index
3LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

An exception is raised if array borders are overrun or underrun.