Skip to content

Commit

Permalink
Merge pull request #60 from oscar-system/bl/decoration
Browse files Browse the repository at this point in the history
various improvements: add decoration type, improve tropicalnumber, some graph stuff
  • Loading branch information
benlorenz authored May 31, 2024
2 parents 56a5401 + c1b684c commit f7fb433
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 105 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test-polymake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
julia-version: ['~1.6.0-0', '~1.9.0-0', '~1.10.0-0', 'nightly']
libcxxwrap: [ '' ]
julia-version: ['1.6', '~1.10.0-0', '~1.11.0-0', 'nightly']

fail-fast: true

Expand All @@ -51,11 +50,7 @@ jobs:
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
- name: "pin libcxxwrap_julia"
run: julia --project=test/project -e 'using Pkg;
Pkg.instantiate();
Pkg.add("libcxxwrap_julia_jll${{ matrix.libcxxwrap }}");
Pkg.pin("libcxxwrap_julia_jll");'
arch: ${{ matrix.julia-version == '1.6' && 'x64' || runner.arch }}
- name: "Build and set override"
run: |
julia --project=test/project test-prepare.jl --override --build --ignore-compat
Expand Down
14 changes: 7 additions & 7 deletions OscarCI.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ os = [ "ubuntu-latest", "macos-latest" ]
# 1.6 is done with some extra combinations in include
# also to avoid some weird behaviour by github actions which seems to merge
# the includes with the normal matrix entries
julia-version = [ "~1.6.0-0", "~1.10.0-0", "nightly" ]
julia-version = [ "~1.10.0-0", "nightly" ]
branches = [ "release", "<matching>" ]

[pkgs]
Expand All @@ -22,28 +22,28 @@ branches = [ "release", "<matching>" ]
[include.master]
Polymake = "master"
Oscar = "master"
julia-version = "1.9"
julia-version = "1.10"
os = "ubuntu-latest"

[include.matching]
[include.lts]
Polymake = "<matching>"
julia-version = "1.9"
julia-version = "1.6"
os = "ubuntu-latest"

[include.oscar]
Oscar = "<matching>"
Polymake = "<matching>"
julia-version = "1.9"
julia-version = "1.10"
os = "ubuntu-latest"

[include.oscarmac]
Oscar = "<matching>"
Polymake = "<matching>"
julia-version = "1.9"
julia-version = "1.10"
os = "macos-latest"

[include.oscarstable]
Oscar = "release"
Polymake = "release"
julia-version = "1.9"
julia-version = "1.10"
os = "ubuntu-latest"
3 changes: 2 additions & 1 deletion include/jlpolymake/jlpolymake.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <polymake/Graph.h>
#include <polymake/topaz/HomologyComplex.h>
#include <polymake/group/switch_table.h>
#include <polymake/graph/Decoration.h>
#include <polymake/RandomGenerators.h>

#include <polymake/perl/calls.h>
Expand All @@ -43,7 +44,7 @@

#define JLPOLYMAKE_VERSION_MAJOR 0
#define JLPOLYMAKE_VERSION_MINOR 11
#define JLPOLYMAKE_VERSION_PATCH 1
#define JLPOLYMAKE_VERSION_PATCH 6

#define __JLPOLYMAKE_STR_HELPER(x) #x
#define __JLPOLYMAKE_STR(x) __JLPOLYMAKE_STR_HELPER(x)
Expand Down
30 changes: 10 additions & 20 deletions include/jlpolymake/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,51 +57,41 @@ struct Polymake_Data {
extern Polymake_Data data;

template <typename T> struct WrappedSetIterator {
const pm::Set<T>& set;
typename pm::Set<T>::const_iterator iterator;
using value_type = T;
WrappedSetIterator<T>(const pm::Set<T>& S)
{
iterator = pm::entire(S);
}
WrappedSetIterator<T>(const pm::Set<T>& S) : set(S), iterator(pm::entire(set)) { }
};

template<typename TDir>
struct WrappedGraphNodeIterator {
const pm::graph::Graph<TDir>& graph;
typename pm::Nodes<pm::graph::Graph<TDir>>::const_iterator iterator;
using dir = TDir;
WrappedGraphNodeIterator<TDir>(const pm::graph::Graph<TDir>& G)
{
iterator = pm::entire(pm::nodes(G));
}
WrappedGraphNodeIterator<TDir>(const pm::graph::Graph<TDir>& G) : graph(G), iterator(pm::entire(pm::nodes(graph))) { }
};

template<typename TDir>
struct WrappedGraphEdgeIterator {
const pm::graph::Graph<TDir>& graph;
typename pm::Edges<pm::graph::Graph<TDir>>::const_iterator iterator;
using dir = TDir;
WrappedGraphEdgeIterator<TDir>(const pm::graph::Graph<TDir>& G)
{
iterator = pm::entire(pm::edges(G));
}
WrappedGraphEdgeIterator<TDir>(const pm::graph::Graph<TDir>& G) : graph(G), iterator(pm::entire(pm::edges(graph))) { }
};

template <typename T> struct WrappedStdListIterator {
const std::list<T>& list;
typename std::list<T>::const_iterator iterator;
using value_type = T;
WrappedStdListIterator<T>(const std::list<T>& L)
{
iterator = L.begin();
}
WrappedStdListIterator<T>(const std::list<T>& L) : list(L), iterator(list.begin()) { }
};

template <typename S, typename T> struct WrappedMapIterator {
const pm::Map<S,T>& map;
typename pm::Map<S,T>::const_iterator iterator;
using key_type = S;
using mapped_type = T;
WrappedMapIterator<S,T>(const pm::Map<S,T>& M)
{
iterator = M.begin();
}
WrappedMapIterator<S,T>(const pm::Map<S,T>& M) : map(M), iterator(map.begin()) { }
};

}
Expand Down
1 change: 1 addition & 0 deletions include/jlpolymake/type_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void add_quadraticextension(jlcxx::Module& jlpolymake);
void add_homologygroup(jlcxx::Module& jlpolymake);
void add_incidencematrix(jlcxx::Module& jlpolymake);
void add_switchtable(jlcxx::Module& jlpolymake);
void add_decoration(jlcxx::Module& jlpolymake);

void add_graph(jlcxx::Module& jlpolymake);

Expand Down
5 changes: 3 additions & 2 deletions src/jlpolymake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ JLCXX_MODULE define_module_polymake(jlcxx::Module& jlpolymake)

add_switchtable(jlpolymake);

// currently empty
// might be needed to resolve some order issues
add_decoration(jlpolymake);

// contains nodemap for decoration (depends on set and decoration)
wrap_types_extra(jlpolymake);

add_direct_calls(jlpolymake);
Expand Down
25 changes: 23 additions & 2 deletions src/polymake/type_setup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
my %needed_types;
my $type_tuples = [];
my $wrap_calls = [];
my $core_calls = [];
my $extra_calls = [];

sub check_type {
Expand Down Expand Up @@ -73,6 +74,8 @@ sub template {
sub Undirected { return ["Undirected","pm::graph::Undirected","Undirected","undirected"]; }
sub String { return ["String","std::string","CxxWrap.StdString","string"]; }
sub BigObject { return ["BigObject", "pm::perl::BigObject", "BigObject", "bigobject"]; }
sub BigObjectType { return ["BigObjectType", "pm::perl::BigObjectType", "BigObjectType", "bigobjecttype"]; }
sub BasicDecoration { return [ "BasicDecoration", "polymake::graph::lattice::BasicDecoration", "BasicDecoration", "basicdecoration"]; }

sub QuadraticExtension {
return template("QuadraticExtension", @_);
Expand Down Expand Up @@ -178,6 +181,7 @@ sub EdgeMap {
["OptionSet", "pm::perl::OptionSet", "OptionSet", undef],

BigObject,
BigObjectType,

Pair(Array(Int),Array(Int)),
Array(Pair(Array(Int),Array(Int))),
Expand All @@ -201,13 +205,19 @@ sub EdgeMap {
Array(Set(Int)),
Array(Set(Set(Int))),

Pair(Set(Int),Int),
Array(Pair(Set(Int),Int)),

Array(String),
Array(Array(Int)),
Array(Array(Integer)),
Array(Array(Rational)),
Array(Array(Set(Int))),
Array(Matrix(Integer)),
Array(BigObject),

Pair(Matrix(TropicalNumber(Max,Rational)),Matrix(TropicalNumber(Max,Rational))),
Pair(Matrix(TropicalNumber(Min,Rational)),Matrix(TropicalNumber(Min,Rational))),
);

# must be after Set{Int}
Expand Down Expand Up @@ -255,7 +265,6 @@ sub EdgeMap {
EdgeMap(Integer),
EdgeMap(Rational),


[
"HomologyGroup_Integer",
"polymake::topaz::HomologyGroup<pm::Integer>",
Expand All @@ -276,6 +285,18 @@ sub EdgeMap {
],
);

# core calls done
$core_calls = $wrap_calls;
$wrap_calls = [];

add_types(
BasicDecoration,
NodeMap(BasicDecoration),
Array(BasicDecoration),
);

$extra_calls = $wrap_calls;

my @keys = qw(type_string ctype jltype convert_f);

my $type_hashes = [];
Expand Down Expand Up @@ -543,7 +564,7 @@ sub wrap_types_extra_src {


foreach (keys %generated) {
my $files = $generated{$_}->($type_hashes, $wrap_calls, $_);
my $files = $generated{$_}->($type_hashes, $core_calls, $_);
$files = {$_ => $files} if ref($files) ne "HASH";
while(my($k, $v) = each %$files) {
open my $f, ">", "$k";
Expand Down
25 changes: 25 additions & 0 deletions src/type_decoration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "jlpolymake/jlpolymake.h"

#include "jlpolymake/tools.h"

#include "jlpolymake/functions.h"

#include "jlpolymake/type_modules.h"

namespace jlpolymake {

void add_decoration(jlcxx::Module& jlpolymake)
{
using DecT = polymake::graph::lattice::BasicDecoration;
auto type = jlpolymake.add_type<DecT>("BasicDecoration")
.constructor<const pm::Set<Int>&, Int>()
.method("decoration_face", [](const DecT& a) { return a.face; })
.method("decoration_rank", [](const DecT& a) { return a.rank; })

.method("show_small_obj", [](const DecT& S) {
return show_small_object<DecT>(S);
});

}

}
4 changes: 4 additions & 0 deletions src/type_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ void add_graph(jlcxx::Module& jlpolymake)
wrapped.method("_squeeze", [](WrappedT& G) { return G.squeeze(); });
wrapped.method("_rem_vertex", [](WrappedT& G, int64_t i) { return wary(G).delete_node(i); });
wrapped.method("_rem_edge", [](WrappedT& G, int64_t tail, int64_t head) { return wary(G).delete_edge(tail, head); });
wrapped.method("_degree", [](const WrappedT& G, int64_t node) { return G.degree(static_cast<Int>(node)); });
wrapped.method("_indegree", [](const WrappedT& G, int64_t node) { return G.in_degree(static_cast<Int>(node)); });
wrapped.method("_outdegree", [](const WrappedT& G, int64_t node) { return G.out_degree(static_cast<Int>(node)); });
wrapped.method("_contract_edge", [](WrappedT& G, int64_t tail, int64_t head) { G.contract_edge(static_cast<Int>(tail), static_cast<Int>(head)); });

wrapped.method("show_small_obj", [](const WrappedT& S) {
return show_small_object<WrappedT>(S);
Expand Down
54 changes: 27 additions & 27 deletions src/type_integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,69 +65,69 @@ void add_integer(jlcxx::Module& jlpolymake)
.add_type<pm::Integer>("Integer",
jlcxx::julia_type("Integer", "Base"))
.constructor<int64_t>()
.method("<", [](pm::Integer& a, pm::Integer& b) { return a < b; })
.method("<", [](pm::Integer& a,
.method("<", [](const pm::Integer& a, const pm::Integer& b) { return a < b; })
.method("<", [](const pm::Integer& a,
int64_t b) { return a < static_cast<pm::Int>(b); })
.method("<", [](int64_t a,
pm::Integer& b) { return static_cast<pm::Int>(a) < b; })
.method("<=", [](pm::Integer& a, pm::Integer& b) { return a <= b; })
.method("<=", [](pm::Integer& a,
const pm::Integer& b) { return static_cast<pm::Int>(a) < b; })
.method("<=", [](const pm::Integer& a, const pm::Integer& b) { return a <= b; })
.method("<=", [](const pm::Integer& a,
int64_t b) { return a <= static_cast<pm::Int>(b); })
.method("<=",
[](int64_t a, pm::Integer& b) {
[](int64_t a, const pm::Integer& b) {
return static_cast<pm::Int>(a) <= b;
})

.method("show_small_obj",
[](pm::Integer& i) {
[](const pm::Integer& i) {
return show_small_object<pm::Integer>(i, false);
})
.method("isfinite", [](const pm::Integer& i) { return isfinite(i); })
.method("Float64", [](pm::Integer& a) { return double(a); })
.method("-", [](pm::Integer& a, pm::Integer& b) { return a - b; })
.method("-", [](pm::Integer& a,
.method("Float64", [](const pm::Integer& a) { return double(a); })
.method("-", [](const pm::Integer& a, const pm::Integer& b) { return a - b; })
.method("-", [](const pm::Integer& a,
int64_t b) { return a - static_cast<pm::Int>(b); })
.method("-", [](int64_t a,
pm::Integer& b) { return static_cast<pm::Int>(a) - b; })
const pm::Integer& b) { return static_cast<pm::Int>(a) - b; })
// unary minus
.method("-", [](pm::Integer& a) { return -a; })
.method("-", [](const pm::Integer& a) { return -a; })

.method("div", [](pm::Integer& a, pm::Integer& b) { return a / b; })
.method("div", [](pm::Integer& a,
.method("div", [](const pm::Integer& a, const pm::Integer& b) { return a / b; })
.method("div", [](const pm::Integer& a,
int64_t b) { return a / static_cast<pm::Int>(b); })
.method("div",
[](int64_t a, pm::Integer& b) {
[](int64_t a, const pm::Integer& b) {
return static_cast<pm::Int>(a) / b;
})

.method("rem", [](pm::Integer& a, pm::Integer& b) { return a % b; })
.method("rem", [](pm::Integer& a,
.method("rem", [](const pm::Integer& a, const pm::Integer& b) { return a % b; })
.method("rem", [](const pm::Integer& a,
int64_t b) { return a % static_cast<pm::Int>(b); })
.method("rem",
[](int64_t a, pm::Integer& b) {
[](int64_t a, const pm::Integer& b) {
return static_cast<pm::Int>(a) % b;
});

jlpolymake.set_override_module(jlpolymake.julia_module());
jlpolymake.method("==", [](pm::Integer& a, pm::Integer& b) {
jlpolymake.method("==", [](const pm::Integer& a, const pm::Integer& b) {
return a == b; });
jlpolymake.method("==", [](pm::Integer& a, int64_t b) {
jlpolymake.method("==", [](const pm::Integer& a, int64_t b) {
return a == static_cast<pm::Int>(b); });
jlpolymake.method("==", [](int64_t a, pm::Integer& b) {
jlpolymake.method("==", [](int64_t a, const pm::Integer& b) {
return static_cast<pm::Int>(a) == b; });

// the symmetric definitions are on the julia side
jlpolymake.method("+", [](pm::Integer& a, pm::Integer& b) {
jlpolymake.method("+", [](const pm::Integer& a, const pm::Integer& b) {
return a + b; });
jlpolymake.method("+", [](pm::Integer& a, int64_t b) {
jlpolymake.method("+", [](const pm::Integer& a, int64_t b) {
return a + static_cast<pm::Int>(b); });
jlpolymake.method("+", [](int64_t a, pm::Integer& b) {
jlpolymake.method("+", [](int64_t a, const pm::Integer& b) {
return static_cast<pm::Int>(a) + b; });
jlpolymake.method("*", [](pm::Integer& a, pm::Integer& b) {
jlpolymake.method("*", [](const pm::Integer& a, const pm::Integer& b) {
return a * b; });
jlpolymake.method("*", [](pm::Integer& a, int64_t b) {
jlpolymake.method("*", [](const pm::Integer& a, int64_t b) {
return a * static_cast<pm::Int>(b); });
jlpolymake.method("*", [](int64_t a, pm::Integer& b) {
jlpolymake.method("*", [](int64_t a, const pm::Integer& b) {
return static_cast<pm::Int>(a) * b; });
jlpolymake.unset_override_module();

Expand Down
Loading

0 comments on commit f7fb433

Please sign in to comment.