math/mul
Element-wise multiplication
Usage
Y:=math/mul(X1, X2)Description
Computes the element-wise product of two numeric inputs. X1 and X2 may be scalars, vectors, or matrices. When one input is a scalar and the other is an array, the scalar is multiplied with every element of the array (scalar broadcasting). When multiplying vectors with matrices, broadcasting follows the rules in Details.
Note:
math/mulperforms Hadamard (element-wise) multiplication, not matrix-matrix linear algebra multiplication.
Input
Argument | Kind | Description |
|---|---|---|
|
| First factor. Supports scalars, vectors, and matrices. |
|
| Second factor. Must be shape-compatible with |
Supported scalar types: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64, rational (R64), and complex (C64).
Output
Argument | Kind | Description |
|---|---|---|
| matches input | Element-wise product of |
Examples
Multiply two scalars
42
Multiply two vectors
Multiply two matrices
Multiply a matrix by a scalar (scalar broadcasting)
Multiply a matrix by a column vector (broadcast by columns)
2x2
v:=[column vector length 2
Multiply a row vector by a matrix (broadcast by rows)
row vector length 2
m:=[2x2
Mixed types (float × int)
10.0
Complex multiplication
(11 + 2i)
Details
Element-wise semantics. Multiplication is applied per element. Shapes must either match exactly or be compatible via broadcasting.
Broadcasting rules.
Scalar × Array or Array × Scalar: The scalar is multiplied with every element of the array.
Matrix × Column Vector (or Vector × Matrix): A length-
mcolumn vector can multiply anm×nmatrix by multiplying the vector with each column of the matrix.Matrix × Row Vector (or Row Vector × Matrix): A length-
nrow vector can multiply anm×nmatrix by multiplying the vector with each row of the matrix.
Properties. math/mul is commutative and associative on compatible numeric types (ignoring floating-point rounding).
Type support. Implementations exist for signed/unsigned integers, floating-point, rationals, and complex numbers. When types differ, standard numeric promotions apply where defined by the runtime; otherwise a type error is raised.
Errors.
Shape mismatch that cannot be resolved by broadcasting.
Unsupported type combination.