Skip to content

Commit

Permalink
Merge 6064629 into 7aaeadc
Browse files Browse the repository at this point in the history
  • Loading branch information
fieker committed Feb 20, 2020
2 parents 7aaeadc + 6064629 commit e272ecb
Show file tree
Hide file tree
Showing 30 changed files with 127 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Force Ubuntu 16.04 "Xenial" to get newer GCC, binutils etc.
dist: xenial
# Force Ubuntu 18.04 "Bionic" to get even newer GCC, binutils etc.
dist: bionic

addons:
apt:
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Singular"
uuid = "bcd08a7b-43d2-5ff7-b6d4-c458787f915c"
version = "0.1.0"
version = "0.2.0"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand All @@ -15,8 +15,8 @@ BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
[compat]
AbstractAlgebra = "^0.8.0"
Nemo = "^0.16.0"
julia = "1.0, 1.1, 1.2, 1.3"
CxxWrap = "^0.8.1"
julia = "1.0, 1.1, 1.2, 1.3, 1.4"
CxxWrap = "^0.9"
BinaryProvider = "^0.5.8"

[extras]
Expand Down
2 changes: 2 additions & 0 deletions deps/src/ideals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ void singular_define_ideals(jlcxx::Module & Singular)
Singular.method("setindex_internal",
[](ideal r, poly n, int o) { return r->m[o] = n; });

Singular.set_override_module(jl_base_module);
Singular.method("getindex",
[](ideal r, int o) { return (poly)(r->m[o]); });
Singular.unset_override_module();

Singular.method("idIs0", &idIs0);

Expand Down
20 changes: 18 additions & 2 deletions deps/src/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,25 @@
#include <Singular/fehelp.h>

namespace jlcxx {
template <> struct IsBits<n_coeffType> : std::true_type {
template <> struct IsMirroredType<n_coeffType> : std::true_type {
};
template <> struct IsBits<rRingOrder_t> : std::true_type {
template <> struct IsMirroredType<rRingOrder_t> : std::true_type {
};
template <> struct IsMirroredType<n_Procs_s> : std::false_type {
};
template <> struct IsMirroredType<snumber> : std::false_type {
};
template <> struct IsMirroredType<sip_smap> : std::false_type {
};
template <> struct IsMirroredType<ssyStrategy> : std::false_type {
};
template <> struct IsMirroredType<ip_smatrix> : std::false_type {
};
template <> struct IsMirroredType<sip_sideal> : std::false_type {
};
template <> struct IsMirroredType<spolyrec> : std::false_type {
};
template <> struct IsMirroredType<__mpz_struct> : std::false_type {
};
} // namespace jlcxx

Expand Down
2 changes: 2 additions & 0 deletions deps/src/matrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ void singular_define_matrices(jlcxx::Module & Singular)

Singular.method("id_Matrix2Module", &id_Matrix2Module);

Singular.set_override_module(jl_base_module);
Singular.method("getindex", [](matrix M, int i, int j) {
return (poly)MATELEM(M, i, j);
});
Singular.unset_override_module();

Singular.method("setindex", [](matrix M, poly p, int i, int j, ring R) {
MATELEM(M, i, j) = p_Copy(p, R);
Expand Down
2 changes: 1 addition & 1 deletion deps/src/rings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void singular_define_rings(jlcxx::Module & Singular)
poly p_cp = p_Copy(p, r);
return p_Subst(p_cp, i, q, r);
});
Singular.method("maEvalAt", [](poly p, jlcxx::ArrayRef<void*> vals, ring r) {
Singular.method("maEvalAt", [](poly p, jlcxx::ArrayRef<snumber *> vals, ring r) {
number * varr = (number *) omAlloc0(vals.size() * sizeof(number));
for (int i = 0; i < vals.size(); i++)
varr[i] = (number) vals[i];
Expand Down
6 changes: 3 additions & 3 deletions src/Meta.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=
This file generates (at precompilation time) wrapper for all Singular library functions
This file generates (at precompilation time) wrappers for all Singular library functions
All wrappers are given by LIBRARYNAME.functionname. We currently use all caps library names
to avoid confusion between the LIBRARYNAME modules and other types, for example "Ideal" or "Poly".
=#
Expand Down Expand Up @@ -32,7 +32,7 @@ output_manipulator_funcs = Dict(
For each library `lib` a module `LIB` is created, which contains wrappers for all globally exposed
functions of the library. Each library function `foo` can be called either as `foo(ring, args...)`,
where `ring` is the ring the arguments belong to, or as `foo(args...)` if no ring is needed or the
ring con be determined from the input arguments. Furthermore, if applicaple, input and output manipulator
ring can be determined from the input arguments. Furthermore, if applicable, input and output manipulator
functions are added to the call.
=#
for (name, funcs) in libraryfunctiondictionary
Expand All @@ -46,7 +46,7 @@ for (name, funcs) in libraryfunctiondictionary
input_manipulator = get(get(input_manipulator_funcs, name, Dict()), symb, identity)
output_manipulator = get(get(output_manipulator_funcs, name, Dict()), symb, identity)
push!(func_calls, :($symb(args...) = $(output_manipulator)(low_level_caller($(name_string), $func_name, $(input_manipulator)(args)...)) ))
push!(func_calls, :($symb(ring::PolyRing,args...) = $(output_manipulator)(low_level_caller_rng($(name_string), $func_name, ring, $(input_manipulator)(args)...)) ))
push!(func_calls, :($symb(ring::PolyRing, args...) = $(output_manipulator)(low_level_caller_rng($(name_string), $func_name, ring, $(input_manipulator)(args)...)) ))
end
end
eval(:(baremodule $name_caps
Expand Down
10 changes: 5 additions & 5 deletions src/caller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ function get_ring(arg_list)
return ring
end

function prepare_argument(x::Array{Int64,1})
function prepare_argument(x::Array{Int64, 1})
return Any[mapping_types_reversed[:INTVEC_CMD], libSingular.jl_array_to_intvec(x)], nothing
end

function prepare_argument(x::Array{Int64,2})
function prepare_argument(x::Array{Int64, 2})
return Any[mapping_types_reversed[:INTMAT_CMD], libSingular.jl_array_to_intmat(x)], nothing
end

Expand Down Expand Up @@ -146,17 +146,17 @@ function prepare_argument(x::sresolution)
end

function prepare_argument(x::Any)
if x.ptr isa libSingular.number
if x.ptr isa libSingular.number_ptr
ptr = x.ptr
rng = parent(x)
new_ptr = libSingular.n_Copy(ptr, rng.ptr)
return Any[mapping_types_reversed[:NUMBER_CMD], new_ptr.cpp_object], nothing
elseif x.ptr isa libSingular.ip_smatrix
elseif x.ptr isa libSingular.matrix_ptr
rng = parent(x)
return Any[mapping_types_reversed[:MATRIX_CMD], libSingular.mpCopy(x.ptr, rng.ptr).cpp_object ], rng
elseif x.ptr isa libSingular.__mpz_struct
return Any[mapping_types_reversed[:BIGINT_CMD], x.ptr.cpp_object], nothing
elseif x.ptr isa libSingular.sip_smap
elseif x.ptr isa libSingular.map_ptr
return Any[mapping_types_reversed[:MAP_CMD], x.ptr.cpp_object], nothing
elseif x.ptr isa libSingular.bigintmat
return Any[mapping_types_reversed[:BIGINTMAT_CMD], x.ptr.cpp_object], nothing
Expand Down
4 changes: 2 additions & 2 deletions src/ideal/IdealTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mutable struct IdealSet{T <: Nemo.RingElem} <: Set
end

mutable struct sideal{T <: Nemo.RingElem} <: Module{T}
ptr::libSingular.ideal
ptr::libSingular.ideal_ptr
base_ring::PolyRing
isGB::Bool

Expand All @@ -36,7 +36,7 @@ mutable struct sideal{T <: Nemo.RingElem} <: Module{T}
return z
end

function sideal{T}(R::PolyRing, id::libSingular.ideal) where T
function sideal{T}(R::PolyRing, id::libSingular.ideal_ptr) where T
z = new(id, R, false)
R.refcount += 1
finalizer(_sideal_clear_fn, z)
Expand Down
8 changes: 4 additions & 4 deletions src/ideal/ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function fres(id::Union{sideal{T}, smodule{T}}, max_length::Int, method::String
error("wrong optional argument for fres")
end
r, minimal = libSingular.id_fres(id.ptr, Cint(max_length + 1), method, R.ptr)
return sresolution{T}(R, r, minimal)
return sresolution{T}(R, r, Bool(minimal))
end

@doc Markdown.doc"""
Expand All @@ -528,7 +528,7 @@ function sres(I::sideal{T}, max_length::Int) where T <: Nemo.RingElem
# TODO: consider qrings
end
r, minimal = libSingular.id_sres(I.ptr, Cint(max_length + 1), R.ptr)
return sresolution{T}(R, r, minimal)
return sresolution{T}(R, r, Bool(minimal))
end

###############################################################################
Expand All @@ -548,12 +548,12 @@ function Ideal(R::PolyRing{T}, ids::Array{spoly{T}, 1}) where T <: Nemo.RingElem
return sideal{S}(R, ids...)
end

function Ideal(R::PolyRing{T}, id::libSingular.ideal) where T <: Nemo.RingElem
function Ideal(R::PolyRing{T}, id::libSingular.ideal_ptr) where T <: Nemo.RingElem
S = elem_type(R)
return sideal{S}(R, id)
end

function (R::PolyRing{T})(id::libSingular.ideal) where T <: Nemo.RingElem
function (R::PolyRing{T})(id::libSingular.ideal_ptr) where T <: Nemo.RingElem
return Ideal(R,id)
end

Expand Down
21 changes: 16 additions & 5 deletions src/libsingular/LibSingularTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#
###############################################################################

const number_ref = numberRef
const coeffs_ptr = CxxPtr{coeffs}
const coeffs_ref = CxxRef{coeffs}

const number_ptr = CxxPtr{number}
const number_ref = CxxRef{number}

const mpz_t = Ptr{__mpz_struct}

Expand All @@ -14,7 +18,11 @@ const mpz_t = Ptr{__mpz_struct}
#
###############################################################################

const poly_ref = polyRef
const ring_ptr = CxxPtr{ring}
const ring_ref = CxxRef{ring}

const poly_ptr = CxxPtr{poly}
const poly_ref = CxxRef{poly}

const vector = poly

Expand All @@ -24,23 +32,26 @@ const vector = poly
#
###############################################################################

const ideal_ref = idealRef
const ideal_ptr = CxxPtr{ideal}
const ideal_ref = CxxRef{ideal}

###############################################################################
#
# Matrices
#
###############################################################################

const matrix_ref = ip_smatrixRef
const matrix_ptr = CxxPtr{ip_smatrix}
const matrix_ref = CxxRef{ip_smatrix}

###############################################################################
#
# Resolvente (module list)
#
###############################################################################

const resolvente = Ptr{ideal}
const syStrategy_ptr = CxxPtr{syStrategy}
const syStrategy_ref = CxxRef{syStrategy}

###############################################################################
#
Expand Down
16 changes: 8 additions & 8 deletions src/libsingular/coeffs.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# initialise a number from an mpz
function n_InitMPZ(b::BigInt, cf::coeffs)
function n_InitMPZ(b::BigInt, cf::coeffs_ptr)
bb = pointer_from_objref(b)
return n_InitMPZ_internal(bb, cf)
end

# get an mpz from a number
function n_GetMPZ(s::numberRef, r::coeffs)
function n_GetMPZ(s::number_ptr, r::coeffs_ptr)
res = BigInt(1)
resp = pointer_from_objref(res)
n_GetMPZ_internal(resp, s, r)
return res
end

# write a number to a Singular string
function n_Write(n::numberRef, cf::coeffs, bShortOut::Bool = false)
function n_Write(n::number_ptr, cf::coeffs_ptr, bShortOut::Bool = false)
d = Int(bShortOut)
n_Write_internal(n, cf, d);
end

function n_ExtGcd(a::number, b::number, s::Ptr{numberRef}, t::Ptr{numberRef}, cf:: coeffs)
function n_ExtGcd(a::number_ptr, b::number_ptr, s::Ptr{number_ptr}, t::Ptr{number_ptr}, cf:: coeffs_ptr)
sp = reinterpret(Ptr{Nothing}, s)
tp = reinterpret(Ptr{Nothing}, t)
return n_ExtGcd_internal(a, b, sp, tp, cf);
end

function n_QuotRem(a::number, b::number, p::Ptr{number}, cf::coeffs)
function n_QuotRem(a::number_ptr, b::number_ptr, p::Ptr{number_ptr}, cf::coeffs_ptr)
pp = reinterpret(Ptr{Nothing}, p)
n_QuotRem_internal(a, b, pp, cf)
end

function n_ChineseRemainderSym(a::Array{number, 1}, b::Array{number, 1}, n::Cint, signed::Cint, cf::coeffs)
function n_ChineseRemainderSym(a::Array{number_ptr, 1}, b::Array{number_ptr, 1}, n::Cint, signed::Cint, cf::coeffs_ptr)
p1 = reinterpret(Ptr{Nothing}, pointer(a))
p2 = reinterpret(Ptr{Nothing}, pointer(b))
return n_ChineseRemainderSym_internal(p1, p2, n, signed, cf)
Expand All @@ -52,7 +52,7 @@ end
#
###############################################################################

function setindex!(ptr::Ptr{number}, n::number)
function setindex!(ptr::Ptr{number_ptr}, n::number_ptr)
pp = reinterpret(Ptr{Nothing}, ptr)
setindex_internal(pp, n)
end
Expand All @@ -72,7 +72,7 @@ end

const nemoNumberID = Base.Dict{UInt, live_cache}()

function julia(cf::coeffs)
function julia(cf::coeffs_ptr)
ptr = get_coeff_data(cf)
return unsafe_pointer_to_objref(ptr)
end
Expand Down
8 changes: 4 additions & 4 deletions src/libsingular/rings.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
function rDefault(cf::coeffs, vars::Array{T,1}, ord::Array{rRingOrder_t, 1},
function rDefault(cf::coeffs_ptr, vars::Array{T,1}, ord::Array{rRingOrder_t, 1},
blk0::Array{Cint, 1}, blk1::Array{Cint, 1}, bitmask::Culong) where {T}
blk0ptr = pointer(blk0)
blk1ptr = pointer(blk1)
r = rDefault_long_helper(cf, vars, ord, blk0ptr, blk1ptr, bitmask);
return r
end

function p_GetExpVL(p::poly, ev::Array{Clong, 1}, r::ring)
function p_GetExpVL(p::poly_ptr, ev::Array{Clong, 1}, r::ring_ptr)
ptr = pointer(ev)
p_GetExpVL_internal(p, ptr, r)
end

function p_SetExpV(p::poly, ev::Array{Cint, 1}, r::ring)
function p_SetExpV(p::poly_ptr, ev::Array{Cint, 1}, r::ring_ptr)
@assert ev[1] == 0
ptr = pointer(ev)
p_SetExpV_internal(p, ptr, r)
end

function p_ExtGcd(a::polyRef, b::polyRef, res::Ptr{polyRef}, s::Ptr{polyRef}, t::Ptr{polyRef}, r::ring)
function p_ExtGcd(a::poly_ptr, b::poly_ptr, res::Ptr{poly_ptr}, s::Ptr{poly_ptr}, t::Ptr{poly_ptr}, r::ring_ptr)
sp = reinterpret(Ptr{Nothing},s)
tp = reinterpret(Ptr{Nothing},t)
rp = reinterpret(Ptr{Nothing},res)
Expand Down
4 changes: 2 additions & 2 deletions src/map/MapTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mutable struct SIdAlgHom{T} <: AbstractAlgebra.Map{PolyRing, PolyRing,

domain::PolyRing
image::Vector
ptr::libSingular.ideal
ptr::libSingular.ideal_ptr

function SIdAlgHom{T}(R::PolyRing) where T <: Union{Ring, Field}
V = gens(R)
Expand Down Expand Up @@ -54,7 +54,7 @@ mutable struct SAlgHom{T} <: AbstractAlgebra.Map{PolyRing, PolyRing,
domain::PolyRing
codomain::PolyRing
image::Vector
ptr::libSingular.ideal
ptr::libSingular.ideal_ptr

function SAlgHom{T}(domain::PolyRing, codomain::PolyRing,
V::Vector) where T <: Union{Ring, Field}
Expand Down
6 changes: 3 additions & 3 deletions src/matrix/MatrixTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ mutable struct MatrixSpace{T <: Nemo.RingElem} <: Set
end

mutable struct smatrix{T <: Nemo.RingElem} <: Nemo.SetElem
ptr::libSingular.matrix_ref
ptr::libSingular.matrix_ptr
base_ring::PolyRing

# really takes a Singular module, which has type ideal
function smatrix{T}(R::PolyRing, m::libSingular.ideal) where T
function smatrix{T}(R::PolyRing, m::libSingular.ideal_ptr) where T
ptr = libSingular.id_Copy(m, R.ptr)
ptr = libSingular.id_Module2Matrix(ptr, R.ptr)
z = new(ptr, R)
finalizer(_smatrix_clear_fn, z)
return z
end

function smatrix{T}(R::PolyRing, ptr::libSingular.matrix_ref) where {T}
function smatrix{T}(R::PolyRing, ptr::libSingular.matrix_ptr) where {T}
z = new(ptr, R)
finalizer(_smatrix_clear_fn, z)
return z
Expand Down
2 changes: 1 addition & 1 deletion src/matrix/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ end
#
###############################################################################

function (S::MatrixSpace{T})(ptr::libSingular.matrix_ref) where T <: AbstractAlgebra.RingElem
function (S::MatrixSpace{T})(ptr::libSingular.matrix_ptr) where T <: AbstractAlgebra.RingElem
M = smatrix{T}(base_ring(S), ptr)
(S.ncols != ncols(M) || S.nrows != nrows(M)) && error("Incompatible dimensions")
return M
Expand Down
Loading

0 comments on commit e272ecb

Please sign in to comment.