Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document use of / in LinearAlgebra #43632

Merged
merged 14 commits into from
Jan 20, 2022
Merged
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Other sparse solvers are available as Julia packages.
```@docs
Base.:*(::AbstractMatrix, ::AbstractMatrix)
Base.:\(::AbstractMatrix, ::AbstractVecOrMat)
Base.:/(::AbstractVecOrMat, ::AbstractVecOrMat)
LinearAlgebra.SingularException
LinearAlgebra.PosDefException
LinearAlgebra.ZeroPivotException
Expand Down
25 changes: 25 additions & 0 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,31 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
end

(\)(a::AbstractVector, b::AbstractArray) = pinv(a) * b

"""
A / B

Matrix right-division: `A / B` is equivalent to `(A' \ B')'` where [`\`](@ref) is the left-division operator.
For square matrices, the result `X` is such that `A == X*B`.

See also: [`rdiv!`](@ref).

# Examples
```jldoctest
julia> X = Float64[1 4 2; 3 4 2; 8 7 1]; B = Float64[1 4 5; 3 9 2];
simonbyrne marked this conversation as resolved.
Show resolved Hide resolved

julia> A = B/X
2×3 Matrix{Float64}:
-0.65 3.75 -1.2
3.25 -2.75 1.0

julia> A ≈ B*pinv(X)
true

julia> A*X ≈ B
true
```
"""
function (/)(A::AbstractVecOrMat, B::AbstractVecOrMat)
size(A,2) != size(B,2) && throw(DimensionMismatch("Both inputs should have the same number of columns"))
return copy(adjoint(adjoint(B) \ adjoint(A)))
Expand Down