Skip to content

Accessing Singular from Julia

malex984 edited this page Nov 12, 2014 · 26 revisions
using Cxx

const singdir = "/home/wbhart/singular-4/T/home/wbhart/singular-4/"

addHeaderDir(joinpath(singdir, "include"), kind = C_System)

addHeaderDir(joinpath(singdir, "include/singular"), kind = C_System)

cxxinclude("Singular/libsingular.h", isAngled=false)

dlopen(joinpath(singdir, "lib/libSingular.so"), RTLD_GLOBAL)

@cxx siInit(pointer(joinpath(singdir, "bin/Singular")))

Idea to wrap Singular "pointed" types (all of low level types):

abstract SingularPointer
abstract SingularNumbers <: SingularPointer
bitstype 64 GenericSingularNumber{C}  <: SingularNumbers

function InitWithInt{P <: SingularNumbers}( ::Type{P}, i::Int )
         return reinterpret(GenericSingularNumber{P}, i)
end

a = InitWithInt( Int, 2 ) # GenericSingularNumber{Int64}(0x0000000000000002)

Pros: we avoid one extra level of indirection (types in Julia are pointers to heap allocated things) Cons: we need to do "proper" initialization/cleanup "by hand"

Clone this wiki locally