Skip to content

Commit

Permalink
Merge 4511bcb into 7868a44
Browse files Browse the repository at this point in the history
  • Loading branch information
cuihantao committed Jul 3, 2020
2 parents 7868a44 + 4511bcb commit ec297dd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Project.toml
@@ -0,0 +1,23 @@
name = "CVXOPT"
uuid = "2972302f-8f71-4210-9e1d-00f20fa701cf"
authors = ["Martin Anderson <martin.skovgaard.andersen@gmail.com>"]
version = "0.3.2"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Pkg = "1.3.0"
Conda = "1.4.1"
PyCall = "1.19.4"
julia = "1.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

2 changes: 0 additions & 2 deletions REQUIRE

This file was deleted.

30 changes: 30 additions & 0 deletions src/CVXOPT.jl
Expand Up @@ -3,12 +3,16 @@ module CVXOPT
using PyCall
using SparseArrays

import SparseArrays: AbstractSparseMatrixCSC, SparseMatrixCSC
import Base: convert

const cvxopt = PyNULL()
const solvers = PyNULL()

function __init__()
copy!(cvxopt, pyimport_conda("cvxopt", "cvxopt", "conda-forge"))
copy!(solvers, pyimport_conda("cvxopt.solvers", "cvxopt"))
pytype_mapping(pyimport("cvxopt").spmatrix, SparseArrays.SparseMatrixCSC)
end

#
Expand Down Expand Up @@ -220,4 +224,30 @@ function julia_to_cvxopt(A)
return Ap;
end

"""
Convert CVXOPT spmatrix to SparseMatrixCSC
"""

function convert(::Type{T}, A::PyObject) where T<:AbstractSparseMatrixCSC

if A.typecode == "d"
r = SparseMatrixCSC(A.size[1], A.size[2],
vec(A.CCS[1])::Vector{Int64} .+ 1,
vec(A.CCS[2])::Vector{Int64} .+ 1,
vec(A.CCS[3])::Vector{Float64})::SparseMatrixCSC{Float64, Int64}
elseif A.typecode == "i"
r = SparseMatrixCSC(A.size[1], A.size[2],
vec(A.CCS[1])::Vector{Int64} .+ 1,
vec(A.CCS[2])::Vector{Int64} .+ 1,
vec(A.CCS[3])::Vector{Int64})::SparseMatrixCSC{Int64, Int64}

elseif A.typecode == "z"
r = SparseMatrixCSC(A.size[1], A.size[2],
vec(A.CCS[1])::Vector{Int64} .+ 1,
vec(A.CCS[2])::Vector{Int64} .+ 1,
vec(A.CCS[3])::Vector{ComplexF64})::SparseMatrixCSC{ComplexF64, Int64}
end
return r
end

end # end of module

0 comments on commit ec297dd

Please sign in to comment.