Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 3700f61a authored by EXT José Ignacio Requeno Jarabo's avatar EXT José Ignacio Requeno Jarabo
Browse files

Cythonization

parent c3f37883
Pipeline #47812 failed with stages
in 2 minutes and 20 seconds
......@@ -23,7 +23,9 @@ build_test:
## Testing
- pytest --ignore=Tests/test_Search.py --ignore=Tests/test_Oracle_OracleMatlab.py
- cd Tests
- pytest test_Search.py::SearchOracleFunctionTestCase
## Next test raises error on ParSearch class [y_list = p.map(pbin_search, args_pbin_search)] for python 2.7 but not
## for python 3.*
## - pytest test_Search.py::SearchOracleFunctionTestCase
build:
stage: build
......@@ -63,6 +65,9 @@ test:
- cd dist/
- pip install *.whl --user
- cd ../Tests
## Moved from 'build_test' stage
- pytest test_Search.py::SearchOracleFunctionTestCase
##
- ./coverage_all.sh
artifacts:
when: on_success
......
......@@ -97,12 +97,12 @@ class Rectangle:
assert dim(min_corner) == dim(max_corner)
# min_corner, max_corner
# self.min_corner = tuple(min(mini, maxi) for mini, maxi in zip(min_corner, max_corner))
# self.max_corner = tuple(max(mini, maxi) for mini, maxi in zip(min_corner, max_corner))
# self._min_corner = tuple(min(mini, maxi) for mini, maxi in zip(min_corner, max_corner))
# self._max_corner = tuple(max(mini, maxi) for mini, maxi in zip(min_corner, max_corner))
self._min_corner = minimum(min_corner, max_corner)
self._max_corner = maximum(min_corner, max_corner)
# self.min_corner = min_corner
# self.max_corner = max_corner
# self._min_corner = min_corner
# self._max_corner = max_corner
# Volume (self.vol) is calculated on demand the first time is accessed, and cached afterwards.
# Using self.vol = -1.0 for indicating that attribute vol is outdated
......@@ -111,7 +111,7 @@ class Rectangle:
# Vertices are also cached.
self.vertx = []
assert greater_equal(self.max_corner, self.min_corner) or incomparables(self.min_corner, self.max_corner)
assert greater_equal(self._max_corner, self._min_corner) or incomparables(self._min_corner, self._max_corner)
@cython.ccall
@cython.returns(cython.void)
......@@ -143,7 +143,7 @@ class Rectangle:
value (tuple): The value
Returns:
None: self.min_corner = value.
None: self._min_corner = value.
Example:
>>> x = (0,0,0)
......@@ -180,7 +180,7 @@ class Rectangle:
value (tuple): The value
Returns:
None: self.max_corner = value.
None: self._max_corner = value.
Example:
>>> x = (0,0,0)
......@@ -215,8 +215,8 @@ class Rectangle:
>>> x in r
>>> False
"""
return (greater(xpoint, self.min_corner) and
less(xpoint, self.max_corner))
return (greater(xpoint, self._min_corner) and
less(xpoint, self._max_corner))
@cython.ccall
@cython.locals(xpoint=tuple)
......@@ -243,8 +243,8 @@ class Rectangle:
>>> True
"""
# xpoint is inside the rectangle or along the border
return (greater_equal(xpoint, self.min_corner) and
less_equal(xpoint, self.max_corner))
return (greater_equal(xpoint, self._min_corner) and
less_equal(xpoint, self._max_corner))
@cython.ccall
@cython.returns(str)
......@@ -253,7 +253,7 @@ class Rectangle:
"""
Printer.
"""
_string = '[{0}, {1}]'.format(self.min_corner, self.max_corner)
_string = '[{0}, {1}]'.format(self._min_corner, self._max_corner)
return _string
@cython.returns(str)
......@@ -278,8 +278,8 @@ class Rectangle:
"""
self == other
"""
# return (other.min_corner == self.min_corner) and (other.max_corner == self.max_corner)
return equal(other.min_corner, self.min_corner) and equal(other.max_corner, self.max_corner)
return (other.min_corner == self._min_corner) and (other.max_corner == self._max_corner)
# return equal(other.min_corner, self._min_corner) and equal(other.max_corner, self._max_corner)
@cython.returns(cython.bint)
def __ne__(self, other):
......@@ -295,7 +295,7 @@ class Rectangle:
"""
self < other
"""
return less(self.max_corner, other.max_corner)
return less(self._max_corner, other.max_corner)
@cython.returns(cython.bint)
def __le__(self, other):
......@@ -303,7 +303,7 @@ class Rectangle:
"""
self <= other
"""
return less_equal(self.max_corner, other.max_corner)
return less_equal(self._max_corner, other.max_corner)
def __gt__(self, other):
# type: (Rectangle, Rectangle) -> bool
......@@ -326,8 +326,8 @@ class Rectangle:
"""
Identity function (via hashing).
"""
return hash((self.min_corner, self.max_corner))
# return hash((tuple(self.min_corner), tuple(self.max_corner)))
return hash((self._min_corner, self._max_corner))
# return hash((tuple(self._min_corner), tuple(self._max_corner)))
# Rectangle properties
@cython.ccall
......@@ -350,7 +350,7 @@ class Rectangle:
>>> r.dim()
>>> 3
"""
return dim(self.min_corner)
return dim(self._min_corner)
@cython.locals(diagonal_length=tuple, _prod=cython.double)
@cython.returns(cython.double)
......@@ -413,7 +413,7 @@ class Rectangle:
def _vertices(self):
# type: (Rectangle) -> list
deltas = self.diag_vector()
vertex = self.min_corner
vertex = self._min_corner
vertices = []
# For dim = 3, indexes =
# (0, 0, 0)
......@@ -434,7 +434,7 @@ class Rectangle:
def _vertices_func(self):
# type: (Rectangle) -> list
deltas = self.diag_vector()
vertex = self.min_corner
vertex = self._min_corner
num_vertex = self.num_vertices()
d = self.dim()
vertices = [None] * num_vertex
......@@ -490,7 +490,7 @@ class Rectangle:
>>> r.diag()
>>> (1.0,1.0)
"""
return Segment(self.min_corner, self.max_corner)
return Segment(self._min_corner, self._max_corner)
@cython.ccall
@cython.returns(tuple)
......@@ -512,7 +512,7 @@ class Rectangle:
>>> r.diag_vector()
>>> (2.0,2.0,2.0)
"""
return subtract(self.max_corner, self.min_corner)
return subtract(self._max_corner, self._min_corner)
@cython.ccall
@cython.locals(diagonal=object)
......@@ -560,7 +560,7 @@ class Rectangle:
>>> (0.5,0.5)
"""
offset = div(self.diag_vector(), 2.0)
return add(self.min_corner, offset)
return add(self._min_corner, offset)
@cython.ccall
@cython.locals(xpoint=tuple, middle_point=tuple, eucledian_dist=cython.double)
......@@ -613,7 +613,7 @@ class Rectangle:
# n internal points = n + 1 internal segments
m = float(n + 1) # Type conversion required for point operations
diag_step = div(self.diag_vector(), m)
min_point = add(self.min_corner, diag_step)
min_point = add(self._min_corner, diag_step)
point_list = [add(min_point, mult(diag_step, i)) for i in range(n)]
return point_list
......@@ -648,15 +648,15 @@ class Rectangle:
concatenable = False
# Two rectangles are concatenable if d-1 coordinates are aligned and they only differ in 1 coordinate
min_corner_eq = (self_i == other_i for self_i, other_i in zip(self.min_corner, other.min_corner))
max_corner_eq = (self_i == other_i for self_i, other_i in zip(self.max_corner, other.max_corner))
min_corner_eq = (self_i == other_i for self_i, other_i in zip(self._min_corner, other.min_corner))
max_corner_eq = (self_i == other_i for self_i, other_i in zip(self._max_corner, other.max_corner))
corner_eq = [min_c and max_c for min_c, max_c in zip(min_corner_eq, max_corner_eq)]
if sum(corner_eq) == (self.dim() - 1):
# Besides, the mismatching coordinate must have continuous interval
mismatching_index = corner_eq.index(False)
concatenable = (self.max_corner[mismatching_index] == other.min_corner[mismatching_index]) or \
(other.max_corner[mismatching_index] == self.min_corner[mismatching_index])
concatenable = (self._max_corner[mismatching_index] == other.min_corner[mismatching_index]) or \
(other.max_corner[mismatching_index] == self._min_corner[mismatching_index])
return concatenable
......@@ -727,13 +727,13 @@ class Rectangle:
assert self.dim() == other.dim(), 'Rectangles should have the same dimension'
assert (not self.overlaps(other)), 'Rectangles should not overlap: {0}, {1}'.format(self, other)
rect = Rectangle(self.min_corner, self.max_corner)
rect = Rectangle(self._min_corner, self._max_corner)
if self.is_concatenable(other):
# rect.min_corner = tuple(min(self_i, other_i) for self_i, other_i in zip(self.min_corner, other.min_corner))
# rect.max_corner = tuple(max(self_i, other_i) for self_i, other_i in zip(self.max_corner, other.max_corner))
rect.min_corner = minimum(self.min_corner, other.min_corner)
rect.max_corner = maximum(self.max_corner, other.max_corner)
# rect.min_corner = tuple(min(self_i, other_i) for self_i, other_i in zip(self._min_corner, other.min_corner))
# rect.max_corner = tuple(max(self_i, other_i) for self_i, other_i in zip(self._max_corner, other.max_corner))
rect.min_corner = minimum(self._min_corner, other.min_corner)
rect.max_corner = maximum(self._max_corner, other.max_corner)
return rect
......@@ -767,7 +767,7 @@ class Rectangle:
vert_self = set(self.vertices())
vert_other = set(other.vertices())
inter = vert_self.intersection(vert_other)
rect = Rectangle(self.min_corner, self.max_corner)
rect = Rectangle(self._min_corner, self._max_corner)
# if len(vert_1) == len(vert_2) and \
# len(vert_1) == pow(2, d) and \
......@@ -815,13 +815,13 @@ class Rectangle:
# if 'self' and 'other' are concatenable
if self.is_concatenable(other):
# min_corner = tuple(min(self_i, other_i) for self_i, other_i in zip(self.min_corner, other.min_corner))
# max_corner = tuple(max(self_i, other_i) for self_i, other_i in zip(self.max_corner, other.max_corner))
min_corner = minimum(self.min_corner, other.min_corner)
max_corner = maximum(self.max_corner, other.max_corner)
# min_corner = tuple(min(self_i, other_i) for self_i, other_i in zip(self._min_corner, other.min_corner))
# max_corner = tuple(max(self_i, other_i) for self_i, other_i in zip(self._max_corner, other.max_corner))
min_corner = minimum(self._min_corner, other.min_corner)
max_corner = maximum(self._max_corner, other.max_corner)
self.min_corner = min_corner
self.max_corner = max_corner
self._min_corner = min_corner
self._max_corner = max_corner
self.reset()
return self
......@@ -869,8 +869,8 @@ class Rectangle:
assert len(new_union_vertices) > 0, \
'Error in computing vertices for the concatenation of "{0}" and "{1}"'.format(self, other)
self.min_corner = min(new_union_vertices)
self.max_corner = max(new_union_vertices)
self._min_corner = min(new_union_vertices)
self._max_corner = max(new_union_vertices)
self.reset()
return self
......@@ -900,10 +900,10 @@ class Rectangle:
"""
assert self.dim() == other.dim(), 'Rectangles should have the same dimension'
# minc = tuple(max(self_i, other_i) for self_i, other_i in zip(self.min_corner, other.min_corner))
# maxc = tuple(min(self_i, other_i) for self_i, other_i in zip(self.max_corner, other.max_corner))
minc = maximum(self.min_corner, other.min_corner)
maxc = minimum(self.max_corner, other.max_corner)
# minc = tuple(max(self_i, other_i) for self_i, other_i in zip(self._min_corner, other.min_corner))
# maxc = tuple(min(self_i, other_i) for self_i, other_i in zip(self._max_corner, other.max_corner))
minc = maximum(self._min_corner, other.min_corner)
maxc = minimum(self._max_corner, other.max_corner)
return less(minc, maxc)
@cython.ccall
......@@ -933,14 +933,14 @@ class Rectangle:
"""
assert self.dim() == other.dim(), 'Rectangles should have the same dimension'
# minc = tuple(max(self_i, other_i) for self_i, other_i in zip(self.min_corner, other.min_corner))
# maxc = tuple(min(self_i, other_i) for self_i, other_i in zip(self.max_corner, other.max_corner))
minc = maximum(self.min_corner, other.min_corner)
maxc = minimum(self.max_corner, other.max_corner)
# minc = tuple(max(self_i, other_i) for self_i, other_i in zip(self._min_corner, other.min_corner))
# maxc = tuple(min(self_i, other_i) for self_i, other_i in zip(self._max_corner, other.max_corner))
minc = maximum(self._min_corner, other.min_corner)
maxc = minimum(self._max_corner, other.max_corner)
if less(minc, maxc):
return Rectangle(minc, maxc)
# else:
# return Rectangle(self.min_corner, self.max_corner)
# return Rectangle(self._min_corner, self._max_corner)
@cython.ccall
@cython.locals(minc=tuple, maxc=tuple)
......@@ -973,13 +973,13 @@ class Rectangle:
"""
assert self.dim() == other.dim(), 'Rectangles should have the same dimension'
# minc = tuple(max(self_i, other_i) for self_i, other_i in zip(self.min_corner, other.min_corner))
# maxc = tuple(min(self_i, other_i) for self_i, other_i in zip(self.max_corner, other.max_corner))
minc = maximum(self.min_corner, other.min_corner)
maxc = minimum(self.max_corner, other.max_corner)
# minc = tuple(max(self_i, other_i) for self_i, other_i in zip(self._min_corner, other.min_corner))
# maxc = tuple(min(self_i, other_i) for self_i, other_i in zip(self._max_corner, other.max_corner))
minc = maximum(self._min_corner, other.min_corner)
maxc = minimum(self._max_corner, other.max_corner)
if less(minc, maxc):
self.min_corner = minc
self.max_corner = maxc
self._min_corner = minc
self._max_corner = maxc
self.reset()
return self
......@@ -1025,10 +1025,10 @@ class Rectangle:
if inter is None:
diff_set.add(self)
else:
# ground = self.min_corner
# ceil = self.max_corner
ground = tuple(self.min_corner)
ceil = tuple(self.max_corner)
# ground = self._min_corner
# ceil = self._max_corner
ground = tuple(self._min_corner)
ceil = tuple(self._max_corner)
# The maximum number of sub-cubes is 2*d (2 boxes per coordinate)
for i in range(self.dim()):
......@@ -1104,16 +1104,16 @@ class Rectangle:
# d is a list with dimension equal to the rectangle dimension.
dimension = self.dim()
# For each dimension i, d[i] = {self.min_corner[i], self.max_corner[i]} plus
# For each dimension i, d[i] = {self._min_corner[i], self._max_corner[i]} plus
# all the points of rectangle 'other' that fall inside of rectangle 'self'
d = [{self.min_corner[i], self.max_corner[i]} for i in range(dimension)]
d = [{self._min_corner[i], self._max_corner[i]} for i in range(dimension)]
# At maximum:
# d[i] = {self.min_corner[i], other.min_corner[i], other.max_corner[i], self.max_corner[i]}
# d[i] = {self._min_corner[i], other.min_corner[i], other.max_corner[i], self._max_corner[i]}
for i in range(dimension):
if self.min_corner[i] < other.min_corner[i] < self.max_corner[i]:
if self._min_corner[i] < other.min_corner[i] < self._max_corner[i]:
d[i].add(other.min_corner[i])
if self.min_corner[i] < other.max_corner[i] < self.max_corner[i]:
if self._min_corner[i] < other.max_corner[i] < self._max_corner[i]:
d[i].add(other.max_corner[i])
# elem[i] = pairwise(d[i])
......@@ -1167,9 +1167,9 @@ class Rectangle:
def dominates_point(self, xpoint):
# type: (Rectangle, tuple) -> bool
"""
Synonym of Point.dominates(self.max_corner, xpoint).
Synonym of Point.dominates(self._max_corner, xpoint).
"""
return less_equal(self.max_corner, xpoint)
return less_equal(self._max_corner, xpoint)
@cython.ccall
@cython.locals(xpoint=tuple)
......@@ -1177,9 +1177,9 @@ class Rectangle:
def is_dominated_by_point(self, xpoint):
# type: (Rectangle, tuple) -> bool
"""
Synonym of Point.dominates(xpoint, self.min_corner).
Synonym of Point.dominates(xpoint, self._min_corner).
"""
return less_equal(xpoint, self.min_corner)
return less_equal(xpoint, self._min_corner)
@cython.ccall
@cython.locals(other=object)
......@@ -1187,10 +1187,10 @@ class Rectangle:
def dominates_rect(self, other):
# type: (Rectangle, Rectangle) -> bool
"""
Synonym of Point.dominates(self.max_corner, other.min_corner).
Synonym of Point.dominates(self._max_corner, other.min_corner).
"""
return less_equal(self.max_corner, other.min_corner) # testing. Strict dominance and not overlap
# return less_equal(self.min_corner, other.min_corner) and less_equal(self.max_corner, other.max_corner) # working
return less_equal(self._max_corner, other.min_corner) # testing. Strict dominance and not overlap
# return less_equal(self._min_corner, other.min_corner) and less_equal(self._max_corner, other.max_corner) # working
@cython.ccall
@cython.locals(other=object)
......@@ -1226,14 +1226,14 @@ class Rectangle:
>>> r.scale(f)
>>> [(70.0,-1.0), (70.0,0.0)]
"""
self.min_corner = f(self.min_corner)
self.max_corner = f(self.max_corner)
self._min_corner = f(self._min_corner)
self._max_corner = f(self._max_corner)
min_c = minimum(self.min_corner, self.max_corner)
max_c = maximum(self.min_corner, self.max_corner)
min_c = minimum(self._min_corner, self._max_corner)
max_c = maximum(self._min_corner, self._max_corner)
self.min_corner = min_c
self.max_corner = max_c
self._min_corner = min_c
self._max_corner = max_c
# Matplot functions
@cython.ccall
......@@ -1258,7 +1258,7 @@ class Rectangle:
"""
assert (self.dim() >= 2), 'Dimension required >= 2'
mc = (self.min_corner[xaxe], self.min_corner[yaxe],)
mc = (self._min_corner[xaxe], self._min_corner[yaxe],)
width = self.diag_vector()[xaxe]
height = self.diag_vector()[yaxe]
return patches.Rectangle(
......@@ -1296,8 +1296,8 @@ class Rectangle:
"""
assert (self.dim() >= 3), 'Dimension required >= 3'
minc = (self.min_corner[xaxe], self.min_corner[yaxe], self.min_corner[zaxe],)
maxc = (self.max_corner[xaxe], self.max_corner[yaxe], self.max_corner[zaxe],)
minc = (self._min_corner[xaxe], self._min_corner[yaxe], self._min_corner[zaxe],)
maxc = (self._max_corner[xaxe], self._max_corner[yaxe], self._max_corner[zaxe],)
rect = Rectangle(minc, maxc)
# sorted(vertices) =
......
......@@ -215,7 +215,7 @@ class _OracleSTLeCommon(Oracle):
return OracleSTLe(stl_prop_file=self.stl_prop_file, csv_signal_file=self.csv_signal_file,
stl_param_file=self.stl_param_file)
@cython.locals(memo=dict)
# @cython.locals(memo=dict)
@cython.returns(object)
def __deepcopy__(self, memo):
# type: (OracleSTLe, dict) -> OracleSTLe
......
......@@ -53,9 +53,8 @@ def pbin_search_ser(args):
RootSearch.logger.debug('y, steps_binsearch: {0}, {1}'.format(y, steps_binsearch))
return y
# @cython.locals(args=(object, dict, cython.double, cython.ushort), xrectangle=object, dict_man=dict,
@cython.locals(xrectangle=object, dict_man=dict, epsilon=cython.double, n=cython.ushort, ora=object, error=tuple,
# dict_man=dict
@cython.locals(xrectangle=object, epsilon=cython.double, n=cython.ushort, ora=object, error=tuple,
y=object, steps_binsearch=cython.ushort)
@cython.returns(object)
def pbin_search(args):
......
......@@ -33,8 +33,8 @@ def makeExtension(extName, extPath):
def cython_exclude(module_list):
return [filename for (module, filename) in module_list if ('_py3k' in module)]
# return [filename for (module, filename) in module_list if ('__init__.py' in filename) or ('_py3k' in module)]
# return [filename for (module, filename) in module_list if ('_py3k' in module)]
return [filename for (module, filename) in module_list if ('__init__.py' in filename) or ('_py3k' in module)]
# class build_py(build_py_orig):
......@@ -44,21 +44,23 @@ class build_py(build_py_orig, object):
# ('ParetoLib.JAMT', '__init__', 'ParetoLib/JAMT/__init__.py')
# ('ParetoLib._py3k', 'TemporaryDirectory', 'ParetoLib/_py3k/TemporaryDirectory.py')
(package, module, filepath) = tup
return '_py3k' in package
return '_py3k' in package or '__init__' in module
# return '_py3k' in package
def find_modules(self):
modules = super(build_py, self).find_modules()
# modules = build_py_orig.find_modules()
print("m " + modules)
# print("find_modules: {0} ".format(modules))
fm = list(filter(self.not_cythonized, modules))
print("find_modules: {0} ".format(fm))
return fm
def find_package_modules(self, package, package_dir):
modules = super(build_py, self).find_package_modules(package=package, package_dir=package_dir)
# print("find_package_modules: {0} ".format(modules))
# modules = build_py_orig.find_package_modules(package=package, package_dir=package_dir)
fm = list(filter(self.not_cythonized, modules))
print("fpm modules", modules)
print("fpm modules2 ", fm)
print("find_package_modules: {0} ".format(fm))
return fm
# def build_packages(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment