From 17ad48928c6594151d21f5faf8c1abb330ee03cf Mon Sep 17 00:00:00 2001 From: Jinyu Date: Thu, 9 Jun 2022 20:33:52 +0800 Subject: [PATCH] update frame precision warning condition to epsilon=0.00001 --- maro/backends/raw_backend.pyx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maro/backends/raw_backend.pyx b/maro/backends/raw_backend.pyx index 0d7195f64..76e616192 100644 --- a/maro/backends/raw_backend.pyx +++ b/maro/backends/raw_backend.pyx @@ -501,7 +501,7 @@ cdef class AttributeFloatAccessor(AttributeAccessor): cdef void set_value(self, NODE_INDEX node_index, SLOT_INDEX slot_index, object value) except +: n_val = float(f"{value:e}") assert abs(n_val - value) < 1, f"Value {value} out of range (AttributeType.Float)" - if n_val != value: + if abs(n_val - value) > 0.00001: warnings.warn(f"[Precision lost] Value {value} would be converted to {n_val}") self._backend._frame.set_value[ATTR_FLOAT](node_index, self._attr_type, slot_index, value) @@ -511,14 +511,14 @@ cdef class AttributeFloatAccessor(AttributeAccessor): cdef void append_value(self, NODE_INDEX node_index, object value) except +: n_val = float(f"{value:e}") assert abs(n_val - value) < 1, f"Value {value} out of range (AttributeType.Float)" - if n_val != value: + if abs(n_val - value) > 0.00001: warnings.warn(f"[Precision lost] Value {value} would be converted to {n_val}") self._backend._frame.append_to_list[ATTR_FLOAT](node_index, self._attr_type, value) cdef void insert_value(self, NODE_INDEX node_index, SLOT_INDEX slot_index, object value) except +: n_val = float(f"{value:e}") assert abs(n_val - value) < 1, f"Value {value} out of range (AttributeType.Float)" - if n_val != value: + if abs(n_val - value) > 0.00001: warnings.warn(f"[Precision lost] Value {value} would be converted to {n_val}") self._backend._frame.insert_to_list[ATTR_FLOAT](node_index, self._attr_type, slot_index, value) @@ -527,7 +527,7 @@ cdef class AttributeDoubleAccessor(AttributeAccessor): cdef void set_value(self, NODE_INDEX node_index, SLOT_INDEX slot_index, object value) except +: n_val = float(f"{value:.15e}") assert abs(n_val - value) < 1, f"Value {value} out of range (AttributeType.Double)" - if n_val != value: + if abs(n_val - value) > 0.00001: warnings.warn(f"[Precision lost] Value {value} would be converted to {n_val}") self._backend._frame.set_value[ATTR_DOUBLE](node_index, self._attr_type, slot_index, value) @@ -537,13 +537,13 @@ cdef class AttributeDoubleAccessor(AttributeAccessor): cdef void append_value(self, NODE_INDEX node_index, object value) except +: n_val = float(f"{value:.15e}") assert abs(n_val - value) < 1, f"Value {value} out of range (AttributeType.Double)" - if n_val != value: + if abs(n_val - value) > 0.00001: warnings.warn(f"[Precision lost] Value {value} would be converted to {n_val}") self._backend._frame.append_to_list[ATTR_DOUBLE](node_index, self._attr_type, value) cdef void insert_value(self, NODE_INDEX node_index, SLOT_INDEX slot_index, object value) except +: n_val = float(f"{value:.15e}") assert abs(n_val - value) < 1, f"Value {value} out of range (AttributeType.Double)" - if n_val != value: + if abs(n_val - value) > 0.00001: warnings.warn(f"[Precision lost] Value {value} would be converted to {n_val}") self._backend._frame.insert_to_list[ATTR_DOUBLE](node_index, self._attr_type, slot_index, value)