A_mul_B!

A_mul_B!(Y, A, B) -> Y

Calculates the matrix-matrix or matrix-vector product $Aâ‹…B$ and stores the result in Y, overwriting the existing value of Y. Note that Y must not be aliased with either A or B.

julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); A_mul_B!(Y, A, B);

julia> Y
2x2 Array{Float64,2}:
 3.0  3.0
 7.0  7.0

Examples

  1. Matrix-matrix multiplication:

    julia> A = [1.0 2.0; 3.0 4.0];
    julia> B = [1.0 1.0; 1.0 1.0];
    julia> Y = similar(B);
    julia> A_mul_B!(Y, A, B);
    julia> Y
    2×2 Array{Float64,2}:
    3.0  3.0
    7.0  7.0

    This example calculates the matrix-matrix product A⋅B and stores the result in Y.

  2. Matrix-vector multiplication:

    julia> A = [1.0 2.0; 3.0 4.0];
    julia> B = [1.0, 1.0];
    julia> Y = similar(B);
    julia> A_mul_B!(Y, A, B);
    julia> Y
    2-element Array{Float64,1}:
    3.0
    7.0

    It performs the matrix-vector multiplication A⋅B and stores the result in Y.

  3. Avoid aliasing:
    julia> A = [1.0 2.0; 3.0 4.0];
    julia> B = [1.0 1.0; 1.0 1.0];
    julia> A_mul_B!(A, A, B);  # Aliasing A with itself
    ERROR: Mutating arrays is not allowed inside a loop

    It's important to avoid aliasing Y with either A or B. Mutating the arrays being multiplied inside the function call can lead to errors.

See Also

Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: