Skip to content

Commit

Permalink
Merge pull request #118 from isuruf/compat
Browse files Browse the repository at this point in the history
Julia v0.7 support
  • Loading branch information
isuruf authored Apr 15, 2018
2 parents 4b0615b + 3d299ea commit 9c393c3
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 201 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.6
Compat 0.25.0
Compat 0.63.0
RecipesBase 0.0.6
BinDeps 0.4.0
Conda 0.4.0
6 changes: 6 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using BinDeps
using Compat
import BinDeps: lower
using Conda

if VERSION > VersionNumber("0.7.0-DEV")
# TODO: Remove this hack when BinDeps is fixed
lower(s::Base.Process, c::BinDeps.SynchronousStepCollection) = nothing
end

@BinDeps.setup

# Use x.y.z for downloading binaries, but only check for x.y in shared libraries
Expand Down
8 changes: 7 additions & 1 deletion src/SymEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __precompile__()
module SymEngine

import Base: show, convert, real, imag
import Compat: String, unsafe_string, @compat, denominator, numerator, invokelatest
import Compat: String, unsafe_string, @compat, denominator, numerator, invokelatest, Cvoid, Nothing, MathConstants.γ, MathConstants.e, MathConstants.φ, MathConstants.catalan, LinearAlgebra, finalizer, Libdl

export Basic, symbols, @vars, @funs, SymFunction
export free_symbols, get_args
Expand All @@ -26,6 +26,12 @@ const have_mpfr = have_component("mpfr")
const have_mpc = have_component("mpc")
const libversion = get_libversion()

if VERSION > VersionNumber("0.7.0-DEV")
_finalizer(f, o) = finalizer(f, o)
else
_finalizer(f, o) = finalizer(o, f)
end

include("types.jl")
include("ctypes.jl")
include("display.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/calculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Base: diff

function diff(b1::SymbolicType, b2::BasicType{Val{:Symbol}})
a = Basic()
ret = ccall((:basic_diff, libsymengine), Int, (Ptr{Basic}, Ptr{Basic}, Ptr{Basic}), &a, &b1, &b2)
ret = ccall((:basic_diff, libsymengine), Int, (Ref{Basic}, Ref{Basic}, Ref{Basic}), a, b1, b2)
return a
end

Expand Down
70 changes: 35 additions & 35 deletions src/ctypes.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# types from SymEngine to Julia
## CSetBasic
type CSetBasic
ptr::Ptr{Void}
mutable struct CSetBasic
ptr::Ptr{Cvoid}
end

function CSetBasic()
z = CSetBasic(ccall((:setbasic_new, libsymengine), Ptr{Void}, ()))
finalizer(z, CSetBasic_free)
z = CSetBasic(ccall((:setbasic_new, libsymengine), Ptr{Cvoid}, ()))
_finalizer(CSetBasic_free, z)
z
end

function CSetBasic_free(x::CSetBasic)
if x.ptr != C_NULL
ccall((:setbasic_free, libsymengine), Void, (Ptr{Void},), x.ptr)
ccall((:setbasic_free, libsymengine), Nothing, (Ptr{Cvoid},), x.ptr)
x.ptr = C_NULL
end
end

function Base.length(s::CSetBasic)
ccall((:setbasic_size, libsymengine), UInt, (Ptr{Void},), s.ptr)
ccall((:setbasic_size, libsymengine), UInt, (Ptr{Cvoid},), s.ptr)
end

function Base.getindex(s::CSetBasic, n::UInt)
result = Basic()
ccall((:setbasic_get, libsymengine), Void, (Ptr{Void}, UInt, Ptr{Basic}), s.ptr, n, &result)
ccall((:setbasic_get, libsymengine), Nothing, (Ptr{Cvoid}, UInt, Ref{Basic}), s.ptr, n, result)
result
end

Expand All @@ -35,30 +35,30 @@ Base.convert(::Type{Set}, x::CSetBasic) = Set(convert(Vector, x))

## VecBasic Need this for get_args...

type CVecBasic
ptr::Ptr{Void}
mutable struct CVecBasic
ptr::Ptr{Cvoid}
end

function CVecBasic()
z = CVecBasic(ccall((:vecbasic_new, libsymengine), Ptr{Void}, ()))
finalizer(z, CVecBasic_free)
z = CVecBasic(ccall((:vecbasic_new, libsymengine), Ptr{Cvoid}, ()))
_finalizer(CVecBasic_free, z)
z
end

function CVecBasic_free(x::CVecBasic)
if x.ptr != C_NULL
ccall((:vecbasic_free, libsymengine), Void, (Ptr{Void},), x.ptr)
ccall((:vecbasic_free, libsymengine), Nothing, (Ptr{Cvoid},), x.ptr)
x.ptr = C_NULL
end
end

function Base.length(s::CVecBasic)
ccall((:vecbasic_size, libsymengine), UInt, (Ptr{Void},), s.ptr)
ccall((:vecbasic_size, libsymengine), UInt, (Ptr{Cvoid},), s.ptr)
end

function Base.getindex(s::CVecBasic, n::UInt)
result = Basic()
ccall((:vecbasic_get, libsymengine), Void, (Ptr{Void}, UInt, Ptr{Basic}), s.ptr, n, &result)
ccall((:vecbasic_get, libsymengine), Nothing, (Ptr{Cvoid}, UInt, Ref{Basic}), s.ptr, n, result)
result
end

Expand All @@ -68,13 +68,13 @@ function Base.convert(::Type{Vector}, x::CVecBasic)
end

## CMapBasicBasic
type CMapBasicBasic
ptr::Ptr{Void}
mutable struct CMapBasicBasic
ptr::Ptr{Cvoid}
end

function CMapBasicBasic()
z = CMapBasicBasic(ccall((:mapbasicbasic_new, libsymengine), Ptr{Void}, ()))
finalizer(z, CMapBasicBasic_free)
z = CMapBasicBasic(ccall((:mapbasicbasic_new, libsymengine), Ptr{Cvoid}, ()))
_finalizer(CMapBasicBasic_free, z)
z
end

Expand All @@ -88,59 +88,59 @@ end

function CMapBasicBasic_free(x::CMapBasicBasic)
if x.ptr != C_NULL
ccall((:mapbasicbasic_free, libsymengine), Void, (Ptr{Void},), x.ptr)
ccall((:mapbasicbasic_free, libsymengine), Nothing, (Ptr{Cvoid},), x.ptr)
x.ptr = C_NULL
end
end

function Base.length(s::CMapBasicBasic)
ccall((:mapbasicbasic_size, libsymengine), UInt, (Ptr{Void},), s.ptr)
ccall((:mapbasicbasic_size, libsymengine), UInt, (Ptr{Cvoid},), s.ptr)
end

function Base.getindex(s::CMapBasicBasic, k::Basic)
result = Basic()
ret = ccall((:mapbasicbasic_get, libsymengine), Cint, (Ptr{Void}, Ptr{Basic}, Ptr{Basic}), s.ptr, &k, &result)
ret = ccall((:mapbasicbasic_get, libsymengine), Cint, (Ptr{Cvoid}, Ref{Basic}, Ref{Basic}), s.ptr, k, result)
if ret == 0
throw(KeyError("Key not found"))
end
result
end

function Base.setindex!(s::CMapBasicBasic, k::Basic, v::Basic)
ccall((:mapbasicbasic_insert, libsymengine), Void, (Ptr{Void}, Ptr{Basic}, Ptr{Basic}), s.ptr, &k, &v)
ccall((:mapbasicbasic_insert, libsymengine), Nothing, (Ptr{Cvoid}, Ref{Basic}, Ref{Basic}), s.ptr, k, v)
end

Base.convert(::Type{CMapBasicBasic}, x::Dict{Any, Any}) = CMapBasicBasic(x)

## Dense matrix

type CDenseMatrix <: DenseArray{Basic, 2}
ptr::Ptr{Void}
mutable struct CDenseMatrix <: DenseArray{Basic, 2}
ptr::Ptr{Cvoid}
end

Base.promote_rule{T <: Basic}(::Type{CDenseMatrix}, ::Type{Matrix{T}} ) = CDenseMatrix
Base.promote_rule(::Type{CDenseMatrix}, ::Type{Matrix{T}} ) where {T <: Basic} = CDenseMatrix

function CDenseMatrix_free(x::CDenseMatrix)
if x.ptr != C_NULL
ccall((:dense_matrix_free, libsymengine), Void, (Ptr{Void},), x.ptr)
ccall((:dense_matrix_free, libsymengine), Nothing, (Ptr{Cvoid},), x.ptr)
x.ptr = C_NULL
end
end

function CDenseMatrix()
z = CDenseMatrix(ccall((:dense_matrix_new, libsymengine), Ptr{Void}, ()))
finalizer(z, CDenseMatrix_free)
z = CDenseMatrix(ccall((:dense_matrix_new, libsymengine), Ptr{Cvoid}, ()))
_finalizer(CDenseMatrix_free, z)
z
end

function CDenseMatrix(m::Int, n::Int)
z = CDenseMatrix(ccall((:dense_matrix_new_rows_cols, libsymengine), Ptr{Void}, (Int, Int), m, n))
finalizer(z, CDenseMatrix_free)
z = CDenseMatrix(ccall((:dense_matrix_new_rows_cols, libsymengine), Ptr{Cvoid}, (Int, Int), m, n))
_finalizer(CDenseMatrix_free, z)
z
end


function CDenseMatrix{T}(x::Array{T, 2})
function CDenseMatrix(x::Array{T, 2}) where T
r,c = size(x)
M = CDenseMatrix(r, c)
for j in 1:c
Expand All @@ -157,14 +157,14 @@ function Base.convert(::Type{Matrix}, x::CDenseMatrix)
[x[i,j] for i in 1:m, j in 1:n]
end

Base.convert{T}(::Type{CDenseMatrix}, x::Array{T, 2}) = CDenseMatrix(x)
Base.convert{T}(::Type{CDenseMatrix}, x::Array{T, 1}) = convert(CDenseMatrix, reshape(x, length(x), 1))
Base.convert(::Type{CDenseMatrix}, x::Array{T, 2}) where {T} = CDenseMatrix(x)
Base.convert(::Type{CDenseMatrix}, x::Array{T, 1}) where {T} = convert(CDenseMatrix, reshape(x, length(x), 1))


function toString(b::CDenseMatrix)
a = ccall((:dense_matrix_str, libsymengine), Cstring, (Ptr{Void}, ), b.ptr)
a = ccall((:dense_matrix_str, libsymengine), Cstring, (Ptr{Cvoid}, ), b.ptr)
string = unsafe_string(a)
ccall((:basic_str_free, libsymengine), Void, (Cstring, ), a)
ccall((:basic_str_free, libsymengine), Nothing, (Cstring, ), a)
string = replace(string, "**", "^") # de pythonify
return string
end
Expand Down
Loading

0 comments on commit 9c393c3

Please sign in to comment.