Usage

Constructors

FunctionDescription
Subspace(basis::Array{<:Number, N+1})Subspace from basis, where last index of array indexes the basis elements.
Subspace(basis::Array{Array{<:Number, N}, 1})Subspace from list of basis elements.
random_subspace(T, dim, size)Random subspace of the given size and dimension, on base field T.
random_hermitian_subspaceRandom subspace satisfying S == S'
empty_subspaceEmpty subspace
full_subspaceFull subspace

Operations

FunctionDescription
size(S)Size of the elements of S.
dim(S)Dimension of subspace S.
S.basisArray representing an orthonormal basis of S, with the last index of the array indexing the basis elements.
each_basis_element(S)Generator for iterating over orthonormal basis elements.
random_element(S)Returns a random element of subspace S.
perp(S), ~SPerpendicular (orthogonal) subspace.
tobasis(S, x)Transform a vector into basis coordinates. Projects x onto S if x is not an element of S.
frombasis(S, x)Returns a vector given the basis coordinates.
projection(S, x)Projects vector x onto subspace S.
hermitian_basis(S)For a subspace satisfying S == S', returns a basis consisting of Hermitian operators.
hcat(S1, S2, ...)Direct sum of subspaces.
vcat(S1, S2, ...)Direct sum of subspaces.
hvcat(rows, S1, S2, ...)Direct sum of subspaces.
cat(S1, S2, ...; dims)Direct sum of subspaces.
kron(S, T)Direct product of subspaces.
adjoint(S), S'Subspace consisting of adjoints of vectors, $\{ x' : x \in S \}$.
S ⟂ TCheck whether subspace S is orthogonal to T.
S == TCheck for equality of subspaces.
x in S, x ∈ SCheck membership of x in subspace S.
S ⊆ TCheck whether subspace S is contained in T.
S ⊇ TCheck whether subspace S contains T.
S + T, S &#124; TLinear span of union of subspaces, $\textrm{span}\{ x y : x \in S, y \in T \}$.
S & T, S ∩ TIntersection of subspaces.
S * TLinear span of products of elements of S and of T.
S / TVector space quotient. Requires T ⊆ S.

Convex.jl integration

FunctionDescription
variable_in_space(S)Creates a variable constrained to space S.
tobasis(S, x)Transform variale from vector to basis coordinates.
frombasis(S, x)Transform variale from basis coordinates to vector.
x in SCreates a constraint requiring variable x to be in subspace S.

As an example, here is how one could do a positive semidefinite matrix completion.

using Convex, SCS, Subspaces

n = 3
A = [ 1 2 0
      0 0 6
      0 0 9 ]

basis_element(x, y) = [ i==x && j == y for i in 1:n, j in 1:n ]

S = Subspace([ basis_element(I[1], I[2]) for I in findall(A .== 0) ])

X = variable_in_space(S)

problem = minimize(tr(X), [ X+A ⪰ 0 ])
solve!(problem, () -> SCS.Optimizer(verbose=0, eps=1e-9))
evaluate(X+A)

# output

3×3 Array{Float64,2}:
 1.0  2.0  3.0
 2.0  4.0  6.0
 3.0  6.0  9.0

Alternately, instead of X = variable_in_space(S) we could use X ∈ S.

X = Variable(n, n)
problem = minimize(tr(X), [ X ∈ S, X+A ⪰ 0 ])

solve!(problem, () -> SCS.Optimizer(verbose=0, eps=1e-9))
evaluate(X+A)

# output

3×3 Array{Float64,2}:
 1.0  2.0  3.0
 2.0  4.0  6.0
 3.0  6.0  9.0