Export from Google

This commit is contained in:
Corentin Le Molgat
2021-02-22 15:06:21 +01:00
parent 0d77851fb5
commit 909004aa84
5 changed files with 60 additions and 38 deletions

View File

@@ -41,7 +41,6 @@
// std::function utilities.
%include "ortools/util/python/functions.i"
%include "ortools/util/python/vector.i"
// We *do* need to use SWIGTYPE_... type names directly, because the

View File

@@ -16,8 +16,7 @@
%include "ortools/base/base.i"
%include "std_pair.i"
%template(IntBoolPair) std::pair<int, bool>;
%include "ortools/util/python/pair.i"
%include "ortools/constraint_solver/python/constraint_solver.i"
%include "ortools/constraint_solver/python/routing_types.i"
@@ -53,6 +52,7 @@ DEFINE_INDEX_TYPE_TYPEDEF(
operations_research::RoutingVehicleClassIndex,
operations_research::RoutingModel::VehicleClassIndex);
%ignore operations_research::RoutingModel::RegisterStateDependentTransitCallback;
%ignore operations_research::RoutingModel::StateDependentTransitCallback;
%ignore operations_research::RoutingModel::MakeStateDependentTransit;

View File

@@ -53,6 +53,7 @@ bool PyObjAs(PyObject *py, IndexT* i) {
}
%}
PY_LIST_OUTPUT_TYPEMAP(IndexT, PyInt_Check, PyInt_FromIndexT<IndexT>);
PY_LIST_INPUT_VALUE_PRIMITIVE_TYPEMAP(IndexT);
PY_LIST_LIST_INPUT_TYPEMAP(IndexT, PyInt_Check);
%enddef // DEFINE_INDEX_TYPE

View File

@@ -0,0 +1,29 @@
// Copyright 2010-2018 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SWIG Macros to use std::pair<T, U> OUTPUT in Python,
//
// Normally we'd simply use:
// ```swig
// %include "std_pair.i"
// %template(IntBoolPair) std::pair<int, bool>;
// ```
// see http://swig.org/Doc4.0/Library.html#Library_std_vector), but
// here we can't, because exceptions are forbidden and std_pair.i will rely on
// on python/pystdcommon.swg which use few throw in type traits...
%include "ortools/base/base.i"
%typemap(out) std::pair<int, bool> {
$result = Py_BuildValue("(ib)", $1.first, $1.second);
}

View File

@@ -48,16 +48,6 @@
$1 = i == size;
}
}
%typemap(in) std::vector<type> (std::vector<type> temp) {
if (!vector_input_helper($input, &temp, PyObjAs<type>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(type) expected");
return NULL;
}
$1 = temp;
}
%typemap(in) const std::vector<type>& (std::vector<type> temp),
const std::vector<type>* (std::vector<type> temp) {
if (!vector_input_helper($input, &temp, PyObjAs<type>)) {
@@ -85,34 +75,35 @@
}
%enddef // PY_LIST_OUTPUT_TYPEMAP
%define PY_LIST_INPUT_VALUE_TYPEMAP(type)
%typemap(in) std::vector<type> (std::vector<type> temp) {
if (!vector_input_helper($input, &temp, PyObjAs<type>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(type) expected");
return NULL;
}
$1 = temp;
}
%enddef // PY_LIST_INPUT_VALUE_TYPEMAP
%define PY_LIST_INPUT_VALUE_PRIMITIVE_TYPEMAP(type)
%typemap(in) std::vector<type> {
if (!vector_input_helper($input, &$1, PyObjAs<type>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(type) expected");
return NULL;
}
}
%enddef // PY_LIST_INPUT_VALUE_PRIMITIVE_TYPEMAP
PY_LIST_OUTPUT_TYPEMAP(int, PyInt_Check, PyInt_FromLong);
PY_LIST_INPUT_VALUE_PRIMITIVE_TYPEMAP(int);
PY_LIST_OUTPUT_TYPEMAP(int64, SwigPyIntOrLong_Check, PyLong_FromLongLong);
PY_LIST_INPUT_VALUE_PRIMITIVE_TYPEMAP(int64);
PY_LIST_OUTPUT_TYPEMAP(double, PyFloat_Check, PyFloat_FromDouble);
// Optimization
%typemap(in) std::vector<int> {
if (!vector_input_helper($input, &$1, PyObjAs<int>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(int) expected");
return NULL;
}
}
%typemap(in) std::vector<int64> {
if (!vector_input_helper($input, &$1, PyObjAs<int64>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(int64) expected");
return NULL;
}
}
%typemap(in) std::vector<double> {
if (!vector_input_helper($input, &$1, PyObjAs<double>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(double) expected");
return NULL;
}
}
PY_LIST_INPUT_VALUE_PRIMITIVE_TYPEMAP(double);
// Add conversion list(tuple(int)) -> std::vector<std::vector>.
// TODO(user): see if we can also get rid of this and utilize already
@@ -211,6 +202,7 @@ if (!vector_input_helper($input, &$1, PyObjAs<double>)) {
}
}
}
%enddef // PY_LIST_LIST_INPUT_TYPEMAP
PY_LIST_LIST_INPUT_TYPEMAP(int, PyInt_Check);
@@ -262,4 +254,5 @@ bool CanConvertTo ## Class(PyObject *py_obj) {
}
PY_LIST_OUTPUT_TYPEMAP(operations_research::Class*, CanConvertTo ## Class,
FromObject ## Class);
PY_LIST_INPUT_VALUE_TYPEMAP(operations_research::Class*);
%enddef