Skip to content

Commit

Permalink
Fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Apr 15, 2019
1 parent 9d883fe commit e65407f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
2 changes: 2 additions & 0 deletions docs/src/atoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
```@docs
MomentMatrix
moment_matrix
SymMatrix
symmetric_setindex!
```

## Atomic measure
Expand Down
1 change: 1 addition & 0 deletions src/MultivariateMoments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract type AbstractMeasure{T} <: AbstractMeasureLike{T} end
include("moment.jl")
include("measure.jl")
include("expectation.jl")
include("symmatrix.jl")
include("moment_matrix.jl")
include("atomic.jl")
include("extract.jl")
Expand Down
42 changes: 0 additions & 42 deletions src/moment_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,6 @@ export SymMatrix, MomentMatrix, getmat, moment_matrix, symmetric_setindex!

using SemialgebraicSets

struct SymMatrix{T} <: AbstractMatrix{T}
Q::Vector{T}
n::Int
end

# i <= j
#function trimap(i, j, n) # It was used when Q was the lower triangular part
# div(n*(n+1), 2) - div((n-i+1)*(n-i+2), 2) + j-i+1
#end

# j <= i
function trimap(i, j)
div((i-1)*i, 2) + j
end

function trimat(::Type{T}, f, n, σ) where {T}
Q = Vector{T}(undef, trimap(n, n))
for i in 1:n
for j in 1:i
Q[trimap(i, j)] = f(σ[i], σ[j])
end
end
SymMatrix{T}(Q, n)
end

Base.size(Q::SymMatrix) = (Q.n, Q.n)

"""
symmetric_setindex!(Q::SymMatrix, value, i::Integer, j::Integer)
Set `Q[i, j]` and `Q[j, i]` to the value `value`.
"""
function symmetric_setindex!(Q::SymMatrix, value, i::Integer, j::Integer)
Q.Q[trimap(max(i, j), min(i, j))] = value
end

function Base.getindex(Q::SymMatrix, i::Integer, j::Integer)
return Q.Q[trimap(max(i, j), min(i, j))]
end
Base.getindex(Q::SymMatrix, I::Tuple) = Q[I...]
Base.getindex(Q::SymMatrix, I::CartesianIndex) = Q[I.I]

"""
mutable struct MomentMatrix{T, MT <: AbstractMonomial, MVT <: AbstractVector{MT}} <: AbstractMeasureLike{T}
Q::SymMatrix{T}
Expand Down
54 changes: 54 additions & 0 deletions src/symmatrix.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
struct SymMatrix{T} <: AbstractMatrix{T}
Q::Vector{T}
n::Int
end
Symmetric ``n \\times n`` matrix storing the vectorized upper triangular
part of the matrix in the `Q` vector (this corresponds to the vectorized
form of `MathOptInterface.PositiveSemidefiniteConeTriangle`).
It implement the `AbstractMatrix` interface except for `setindex!` as it might
break its symmetry. The [`symmetric_setindex!`](@ref) function should be used
instead.
"""
struct SymMatrix{T} <: AbstractMatrix{T}
Q::Vector{T}
n::Int
end

# i <= j
#function trimap(i, j, n) # It was used when Q was the lower triangular part
# div(n*(n+1), 2) - div((n-i+1)*(n-i+2), 2) + j-i+1
#end

# j <= i
function trimap(i, j)
div((i-1)*i, 2) + j
end

function trimat(::Type{T}, f, n, σ) where {T}
Q = Vector{T}(undef, trimap(n, n))
for i in 1:n
for j in 1:i
Q[trimap(i, j)] = f(σ[i], σ[j])
end
end
SymMatrix{T}(Q, n)
end

Base.size(Q::SymMatrix) = (Q.n, Q.n)

"""
symmetric_setindex!(Q::SymMatrix, value, i::Integer, j::Integer)
Set `Q[i, j]` and `Q[j, i]` to the value `value`.
"""
function symmetric_setindex!(Q::SymMatrix, value, i::Integer, j::Integer)
Q.Q[trimap(max(i, j), min(i, j))] = value
end

function Base.getindex(Q::SymMatrix, i::Integer, j::Integer)
return Q.Q[trimap(max(i, j), min(i, j))]
end
Base.getindex(Q::SymMatrix, I::Tuple) = Q[I...]
Base.getindex(Q::SymMatrix, I::CartesianIndex) = Q[I.I]

0 comments on commit e65407f

Please sign in to comment.