Skip to content

Commit

Permalink
Document use of / in LinearAlgebra (#43632)
Browse files Browse the repository at this point in the history
Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
Co-authored-by: Simon Byrne <simonbyrne@gmail.com>
  • Loading branch information
3 people authored Jan 20, 2022
1 parent 487f0b4 commit 05d3e84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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
24 changes: 24 additions & 0 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,30 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
end

(\)(a::AbstractVector, b::AbstractArray) = pinv(a) * b
"""
A / B
Matrix right-division: `A / B` is equivalent to `(B' \\ A')'` 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> A = Float64[1 4 5; 3 9 2]; B = Float64[1 4 2; 3 4 2; 8 7 1];
julia> X = A / B
2×3 Matrix{Float64}:
-0.65 3.75 -1.2
3.25 -2.75 1.0
julia> isapprox(A, X*B)
true
julia> isapprox(X, A*pinv(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

0 comments on commit 05d3e84

Please sign in to comment.