Skip to content

Require julia 1.3 and use new jll package #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: julia
sudo: false
julia:
- 1.0
- 1.2
- 1.3
- nightly
os:
- linux
Expand Down
12 changes: 6 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ uuid = "123dc426-2d89-5057-bbad-38513e3affd8"
version = "0.7.1"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
SymEngine_jll = "3428059b-622b-5399-b16f-d347a77089a4"

[compat]
BinaryProvider = "≥ 0.3.0"
Compat = "≥ 0.63.0"
RecipesBase = "≥ 0.0.6"
julia = "≥ 1.0.0"
Compat = "3"
RecipesBase = "0.8"
julia = "1.3"
SymEngine_jll = "0.6"
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
environment:
matrix:
- julia_version: 1.0
- julia_version: 1.2
- julia_version: 1.3
- julia_version: nightly

platform:
Expand Down
60 changes: 0 additions & 60 deletions deps/build.jl

This file was deleted.

9 changes: 0 additions & 9 deletions deps/deps.jl.in

This file was deleted.

36 changes: 5 additions & 31 deletions src/SymEngine.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__precompile__()

module SymEngine

using SymEngine_jll

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

Expand All @@ -11,36 +11,13 @@ export coeff
export ascii_art
export subs, lambdify, N, cse
export series
if VERSION >= v"1.0.0-rc1"
export expand
end

const deps_file = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
const deps_in_file = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl.in")

noinit = false

if !isfile(deps_file)
cp(deps_in_file, deps_file)
end

include(deps_file)

if !noinit
check_deps()
end
export expand

include("utils.jl")
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("exceptions.jl")
include("types.jl")
include("ctypes.jl")
Expand All @@ -54,11 +31,8 @@ include("calculus.jl")
include("recipes.jl")
include("dense-matrix.jl")

if !noinit
function __init__()
check_deps()
init_constants()
end
function __init__()
init_constants()
end

end
22 changes: 8 additions & 14 deletions src/ctypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end

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

Expand Down Expand Up @@ -41,7 +41,7 @@ end

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

Expand Down Expand Up @@ -70,15 +70,9 @@ end
start(s::CVecBasic) = 0
done(s::CVecBasic, i) = (i == Base.length(s))
next(s::CVecBasic, i) = s[i], i+1
if VERSION < v"0.7.0-rc1"
Base.start(s::CVecBasic) = start(s)
Base.done(s::CVecBasic, i) = done(s, i)
Base.next(s::CVecBasic, i) = next(s, i)
else
function Base.iterate(s::CVecBasic, i=start(s))
done(s, i) && return nothing
next(s, i)
end
function Base.iterate(s::CVecBasic, i=start(s))
done(s, i) && return nothing
next(s, i)
end

## CMapBasicBasic
Expand All @@ -88,7 +82,7 @@ end

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

Expand Down Expand Up @@ -143,13 +137,13 @@ end

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

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

Expand Down
60 changes: 60 additions & 0 deletions src/customfuncs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Pkg
Pkg.activate(".")
using SymEngine

struct CustomFunc
name::String
cfunc::Base.CFunction
func1
func2
end

struct CFunctionWrapperClass
name::Ptr{Cchar}
create_ptr::Ptr{Cvoid}
diff_ptr::Ptr{Cvoid}
end

function create_func(name, f)
function _create_func(a::Basic, args_ptr::Ptr{Cvoid})::Cint
args = SymEngine.CVecBasic(args_ptr)
try
res = f(convert(Vector, args))
catch e
res = nothing
end
if res == nothing
return 1
else
res = Basic(res)
ccall((:basic_assign, SymEngine.libsymengine), Nothing, (Ref{Basic}, Ref{Basic}), a, res)
return 0
end
end
create_ptr = @cfunction($_create_func, Cint, (Ref{Basic}, Ptr{Cvoid}))
return CustomFunc(name, create_ptr, f, _create_func)
end

function my_real(x::Vector{Basic})
return real(N(x[1]))
end

function my_norm(x::Vector{Basic})
a, b = N(x[1]), N(x[2])
return sqrt(a^2+b^2)
end

@vars x

function (c::CustomFunc)(args...)
v = convert(SymEngine.CVecBasic, args...)
a = Basic()
ccall((:basic_create_function_wrapper, SymEngine.libsymengine), Nothing, (Ref{Basic}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}, Ptr{Cvoid}), a, v.ptr, pointer(c.name), c.cfunc.ptr, C_NULL)
return a
end

c = create_func("Re", my_real)
c(x)

d = create_func("Norm", my_norm)
d(2, 3)
4 changes: 0 additions & 4 deletions src/dense-matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ function LinearAlgebra.lu(a::CDenseMatrix)
convert(Matrix, l), convert(Matrix, u), Matrix{Basic}(LinearAlgebra.I, size(l)[1], size(l)[1])
end

if VERSION < VersionNumber("0.7.0-DEV")
LinearAlgebra.lu(a::Array{T,2}) where {T <: Basic} = LinearAlgebra.lu(convert(CDenseMatrix, a))
end


# solve using LU_solve
import Base: \
Expand Down
9 changes: 2 additions & 7 deletions src/mathfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ end
Base.abs2(x::SymEngine.Basic) = abs(x)^2

if get_symbol(:basic_atan2) != C_NULL
if VERSION < VersionNumber(0,7)
import Base.atan2
IMPLEMENT_TWO_ARG_FUNC(:(Base.atan2), :atan2)
else
import Base.atan
IMPLEMENT_TWO_ARG_FUNC(:(Base.atan), :atan2)
end
import Base.atan
IMPLEMENT_TWO_ARG_FUNC(:(Base.atan), :atan2)
end

# export not import
Expand Down
2 changes: 1 addition & 1 deletion src/mathops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ macro init_constant(op, libnm)
begin
ccall($alloc_tup, Nothing, (Ref{Basic}, ), $op)
ccall($tup, Nothing, (Ref{Basic}, ), $op)
_finalizer(basic_free, $op)
finalizer(basic_free, $op)
end
)
end
Expand Down
3 changes: 0 additions & 3 deletions src/simplify.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
if VERSION < v"1.0.0-rc1"
import Base.expand
end
IMPLEMENT_ONE_ARG_FUNC(:expand, :expand)

if get_symbol(:basic_cse) != C_NULL
Expand Down
14 changes: 3 additions & 11 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mutable struct Basic <: Number
function Basic()
z = new(C_NULL)
ccall((:basic_new_stack, libsymengine), Nothing, (Ref{Basic}, ), z)
_finalizer(basic_free, z)
finalizer(basic_free, z)
return z
end
function Basic(v::Ptr{Cvoid})
Expand Down Expand Up @@ -95,11 +95,7 @@ Basic(x::Basic) = x

Base.promote_rule(::Type{Basic}, ::Type{S}) where {S<:Number} = Basic
Base.promote_rule(::Type{S}, ::Type{Basic}) where {S<:Number} = Basic
if VERSION > VersionNumber("0.7.0-DEV")
Base.promote_rule(::Type{S}, ::Type{Basic}) where {S<:AbstractIrrational} = Basic
else
Base.promote_rule(::Type{S}, ::Type{Basic}) where {S<:Irrational} = Basic
end
Base.promote_rule(::Type{S}, ::Type{Basic}) where {S<:AbstractIrrational} = Basic

## Class ID
get_type(s::Basic) = ccall((:basic_get_type, libsymengine), UInt, (Ref{Basic},), s)
Expand Down Expand Up @@ -210,11 +206,7 @@ Base.promote_rule(::Type{S}, ::Type{T} ) where {T<:BasicType, S<:Number} = T
# to intersperse BasicType and Basic in math ops
Base.promote_rule(::Type{T}, ::Type{Basic} ) where {T<:BasicType} = T
Base.promote_rule( ::Type{Basic}, ::Type{T} ) where {T<:BasicType} = T
if VERSION > VersionNumber("0.7.0-DEV")
Base.promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational, T<:BasicType} = T
else
Base.promote_rule(::Type{S}, ::Type{T}) where {S<:Irrational, T<:BasicType} = T
end
Base.promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational, T<:BasicType} = T

## needed for mathops
convert(::Type{T}, val::Number) where {T<:BasicType} = T(Basic(val))
Expand Down