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 541de06a authored by EXT José Ignacio Requeno Jarabo's avatar EXT José Ignacio Requeno Jarabo
Browse files

New mini/maxi and minimum/maximum operators in Point

New logger for Geometry
parent cd835b7b
......@@ -331,7 +331,7 @@ def incomparables(x, xprime):
return (not greater_equal(x, xprime)) and (not greater_equal(xprime, x))
def maximum(x, xprime):
def maxi(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise comparison of two Cartesian points.
......@@ -346,7 +346,7 @@ def maximum(x, xprime):
Example:
>>> x = (5, 6, 7)
>>> xprime = (3, 2, 1)
>>> maximum(x, xprime)
>>> maxi(x, xprime)
>>> (5, 6, 7)
"""
if greater_equal(x, xprime):
......@@ -355,7 +355,7 @@ def maximum(x, xprime):
return xprime
def minimum(x, xprime):
def mini(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise comparison of two Cartesian points.
......@@ -370,7 +370,7 @@ def minimum(x, xprime):
Example:
>>> x = (5, 6, 7)
>>> xprime = (3, 2, 1)
>>> minimum(x, xprime)
>>> mini(x, xprime)
>>> (3, 2, 1)
"""
if less_equal(x, xprime):
......@@ -379,6 +379,52 @@ def minimum(x, xprime):
return xprime
def maximum(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise maximum of two Cartesian points.
Args:
x (tuple): The first point.
xprime (tuple): The second point.
Returns:
tuple: max(x[i], xprime[i]) for i = 0..dim(x)-1
Example:
>>> x = (1, 2, 3)
>>> xprime = (3, 2, 1)
>>> maximum(x, xprime)
>>> (3, 2, 3)
"""
x = np.array(x)
xprime = np.array(xprime)
return tuple(np.maximum(x, xprime))
def minimum(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise minimum of two Cartesian points.
Args:
x (tuple): The first point.
xprime (tuple): The second point.
Returns:
tuple: min(x[i], xprime[i]) for i = 0..dim(x)-1
Example:
>>> x = (1, 2, 3)
>>> xprime = (3, 2, 1)
>>> mininum(x, xprime)
>>> (1, 2, 1)
"""
x = np.array(x)
xprime = np.array(xprime)
return tuple(np.minimum(x, xprime))
def subt(i, x, xprime):
# type: (int, tuple, tuple) -> tuple
"""
......
......@@ -330,7 +330,7 @@ def incomparables(x, xprime):
return (not greater_equal(x, xprime)) and (not greater_equal(xprime, x))
def maximum(x, xprime):
def maxi(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise comparison of two Cartesian points.
......@@ -345,7 +345,7 @@ def maximum(x, xprime):
Example:
>>> x = (5, 6, 7)
>>> xprime = (3, 2, 1)
>>> maximum(x, xprime)
>>> maxi(x, xprime)
>>> (5, 6, 7)
"""
if greater_equal(x, xprime):
......@@ -354,7 +354,7 @@ def maximum(x, xprime):
return xprime
def minimum(x, xprime):
def mini(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise comparison of two Cartesian points.
......@@ -369,7 +369,7 @@ def minimum(x, xprime):
Example:
>>> x = (5, 6, 7)
>>> xprime = (3, 2, 1)
>>> minimum(x, xprime)
>>> mini(x, xprime)
>>> (3, 2, 1)
"""
if less_equal(x, xprime):
......@@ -378,6 +378,48 @@ def minimum(x, xprime):
return xprime
def maximum(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise maximum of two Cartesian points.
Args:
x (tuple): The first point.
xprime (tuple): The second point.
Returns:
tuple: max(x[i], xprime[i]) for i = 0..dim(x)-1
Example:
>>> x = (1, 2, 3)
>>> xprime = (3, 2, 1)
>>> maximum(x, xprime)
>>> (3, 2, 3)
"""
return tuple(max(xi[0], xi[1]) for xi in zip(x, xprime))
def minimum(x, xprime):
# type: (tuple, tuple) -> tuple
"""
Component wise minimum of two Cartesian points.
Args:
x (tuple): The first point.
xprime (tuple): The second point.
Returns:
tuple: min(x[i], xprime[i]) for i = 0..dim(x)-1
Example:
>>> x = (1, 2, 3)
>>> xprime = (3, 2, 1)
>>> mininum(x, xprime)
>>> (1, 2, 1)
"""
return tuple(min(xi[0], xi[1]) for xi in zip(x, xprime))
def subt(i, x, xprime):
# type: (int, tuple, tuple) -> tuple
"""
......
......@@ -13,7 +13,9 @@ Regarding arithmetic precision, the maximum number of significant
decimal digits is indicated by __numdigits__
"""
import logging
import sys
from decimal import Decimal, getcontext
__name__ = 'Geometry'
__all__ = ['Lattice', 'Segment', 'Rectangle', 'ParRectangle', 'Point', 'PPoint']
......@@ -21,3 +23,20 @@ __all__ = ['Lattice', 'Segment', 'Rectangle', 'ParRectangle', 'Point', 'PPoint']
# Maximum number of decimal digits that should be used in computations.
# This value depends on the accurary (i.e., number of bits) used for float representations.
__numdigits__ = sys.float_info.dig
getcontext().prec = __numdigits__
# Logging configuration
# logging.basicConfig(format='%(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# Create handlers
handler = logging.StreamHandler()
#handler.setLevel(logging.INFO)
# Create formatter and add it to handler
form = logging.Formatter('%(message)s')
handler.setFormatter(form)
# Add handler to the logger
logger.addHandler(handler)
......@@ -55,6 +55,10 @@ class PointTestCase(unittest.TestCase):
self.time_for_n_iterations(lambda z: p.greater_equal(xprime, x), rep)
self.time_for_n_iterations(lambda z: p.less(x, xprime), rep)
self.time_for_n_iterations(lambda z: p.less_equal(x, xprime), rep)
self.time_for_n_iterations(lambda z: p.maxi(x, xprime), rep)
self.time_for_n_iterations(lambda z: p.maxi(xprime, x), rep)
self.time_for_n_iterations(lambda z: p.mini(x, xprime), rep)
self.time_for_n_iterations(lambda z: p.mini(xprime, x), rep)
self.time_for_n_iterations(lambda z: p.maximum(x, xprime), rep)
self.time_for_n_iterations(lambda z: p.maximum(xprime, x), rep)
self.time_for_n_iterations(lambda z: p.minimum(x, xprime), rep)
......@@ -72,8 +76,10 @@ class PointTestCase(unittest.TestCase):
# type: (PointTestCase, int, int) -> None
xxprime = np.random.rand(2, dim)
x = tuple(xxprime[0])
xprime = tuple(xxprime[1])
# x = tuple(xxprime[0])
# xprime = tuple(xxprime[1])
x = xxprime[0]
xprime = xxprime[1]
r1 = random.randint(0, len(x) - 1)
r2 = random.randint(0, 10)
......@@ -127,6 +133,8 @@ class PointTestCase(unittest.TestCase):
self.assertEqual(p.greater_equal(x, xprime), pp.greater_equal(x, xprime))
self.assertEqual(p.less(x, xprime), pp.less(x, xprime))
self.assertEqual(p.less_equal(x, xprime), pp.less_equal(x, xprime))
self.assertEqual(p.maxi(x, xprime), pp.maxi(x, xprime))
self.assertEqual(p.mini(x, xprime), pp.mini(x, xprime))
self.assertEqual(p.maximum(x, xprime), pp.maximum(x, xprime))
self.assertEqual(p.minimum(x, xprime), pp.minimum(x, xprime))
self.assertEqual(p.incomparables(x, xprime), pp.incomparables(x, xprime))
......
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