Skip to content

multiplication

MMMul(l, r) dataclass

Bases: _BinaryMixin, MatrixExpr

Matrix-Matrix multiplication.

Source code in geomech/core/operations/multiplication.py
def __init__(self, l, r):
    if l.type == ExprType.MATRIX and r.type == ExprType.MATRIX:
        _check_mul_sizes("MMMul", l, r)
        self.nodes = [l, r]
    else:
        raise ExpressionMismatchError("MMMul", l.type, r.type)

MVMul(l, r) dataclass

Bases: _BinaryMixin, VectorExpr

Matrix-Vector multiplication.

Source code in geomech/core/operations/multiplication.py
def __init__(self, l, r):
    if l.type == ExprType.MATRIX and r.type == ExprType.VECTOR:
        _check_mul_sizes("MVMul", l, r)
        self.nodes = [l, r]
    elif l.type == ExprType.VECTOR and r.type == ExprType.MATRIX:
        # Transpose(v) * M case
        from geomech.core.operations.geometry import Transpose

        if isinstance(l, Transpose):
            self.nodes = [l, r]
        else:
            raise ExpressionMismatchError("MVMul", l.type, r.type)
    else:
        raise ExpressionMismatchError("MVMul", l.type, r.type)

Mul(l, r) dataclass

Bases: _BinaryMixin, ScalarExpr

Scalar multiplication.

Source code in geomech/core/operations/multiplication.py
def __init__(self, l, r):
    l, r = _wrap_numeric(l), _wrap_numeric(r)
    if l.type == ExprType.SCALAR and r.type == ExprType.SCALAR:
        self.nodes = [l, r]
    else:
        raise ExpressionMismatchError("Mul", l.type, r.type)

SMMul(l, r) dataclass

Bases: _BinaryMixin, MatrixExpr

Scalar-Matrix multiplication. Normalized: left=matrix, right=scalar.

Source code in geomech/core/operations/multiplication.py
def __init__(self, l, r):
    l, r = _wrap_numeric(l), _wrap_numeric(r)
    if l.type == ExprType.MATRIX and r.type == ExprType.SCALAR:
        self.nodes = [l, r]
    elif l.type == ExprType.SCALAR and r.type == ExprType.MATRIX:
        self.nodes = [r, l]
    else:
        raise ExpressionMismatchError("SMMul", l.type, r.type)

SVMul(l, r) dataclass

Bases: _BinaryMixin, VectorExpr

Scalar-Vector multiplication. Normalized: left=vector, right=scalar.

Source code in geomech/core/operations/multiplication.py
def __init__(self, l, r):
    l, r = _wrap_numeric(l), _wrap_numeric(r)
    if l.type == ExprType.VECTOR and r.type == ExprType.SCALAR:
        self.nodes = [l, r]
    elif l.type == ExprType.SCALAR and r.type == ExprType.VECTOR:
        self.nodes = [r, l]
    else:
        raise ExpressionMismatchError("SVMul", l.type, r.type)

VVMul(l, r) dataclass

Bases: _BinaryMixin, Expr

Vector-Vector multiplication. Result type depends on Transpose: Transpose(v) * w → scalar v * Transpose(w) → matrix

Source code in geomech/core/operations/multiplication.py
def __init__(self, l, r):
    from geomech.core.operations.geometry import Transpose

    if l.type == ExprType.VECTOR and r.type == ExprType.VECTOR:
        if isinstance(l, Transpose) and not isinstance(r, Transpose):
            # v^T * w → scalar: sizes must match
            _check_mul_sizes("VVMul", l, r)
            self.nodes = [l, r]
            self._result_type = ExprType.SCALAR
        elif not isinstance(l, Transpose) and isinstance(r, Transpose):
            # v * w^T → matrix (outer product): any sizes valid
            self.nodes = [l, r]
            self._result_type = ExprType.MATRIX
        else:
            raise ExpressionMismatchError("VVMul", l.type, r.type)
    else:
        raise ExpressionMismatchError("VVMul", l.type, r.type)