From: Jean-Philippe ARGAUD Date: Fri, 21 Jun 2024 13:26:58 +0000 (+0200) Subject: Minor source review update for type compatibilities X-Git-Tag: V9_13_0rc1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cd77b9ba473459cf40a721cdf90f924a8523fe34;p=modules%2Fadao.git Minor source review update for type compatibilities --- diff --git a/src/daComposant/daAlgorithms/Atoms/ecwdeim.py b/src/daComposant/daAlgorithms/Atoms/ecwdeim.py index 78be5a0..42697e9 100644 --- a/src/daComposant/daAlgorithms/Atoms/ecwdeim.py +++ b/src/daComposant/daAlgorithms/Atoms/ecwdeim.py @@ -164,6 +164,10 @@ def DEIM_offline(selfA, EOS = None, Verbose = False): __M = __M + 1 # # -------------------------- + __mu = numpy.array(__mu) + __I = numpy.array(__I) + __errors = numpy.array(__errors) + # -------------------------- if len(__errors) > 0 and __errors[-1] < selfA._parameters["EpsilonEIM"]: logging.debug("%s %s (%.1e)"%(selfA._name, "The convergence is obtained when reaching the required EIM tolerance", selfA._parameters["EpsilonEIM"])) # noqa: E501 if __M >= __maxM: diff --git a/src/daComposant/daAlgorithms/Atoms/ecweim.py b/src/daComposant/daAlgorithms/Atoms/ecweim.py index 89b0550..78a24b7 100644 --- a/src/daComposant/daAlgorithms/Atoms/ecweim.py +++ b/src/daComposant/daAlgorithms/Atoms/ecweim.py @@ -144,6 +144,10 @@ def EIM_offline(selfA, EOS = None, Verbose = False): __errors.append(__eM) # # -------------------------- + __mu = numpy.array(__mu) + __I = numpy.array(__I) + __errors = numpy.array(__errors) + # -------------------------- if __errors[-1] < selfA._parameters["EpsilonEIM"]: logging.debug("%s %s (%.1e)"%(selfA._name, "The convergence is obtained when reaching the required EIM tolerance", selfA._parameters["EpsilonEIM"])) # noqa: E501 if __M >= __maxM: diff --git a/src/daComposant/daAlgorithms/Atoms/ecwubfeim.py b/src/daComposant/daAlgorithms/Atoms/ecwubfeim.py index 1700d9e..c4f7e9d 100644 --- a/src/daComposant/daAlgorithms/Atoms/ecwubfeim.py +++ b/src/daComposant/daAlgorithms/Atoms/ecwubfeim.py @@ -169,6 +169,10 @@ def UBFEIM_offline(selfA, EOS = None, Verbose = False): __M = __M + 1 # # -------------------------- + __mu = numpy.array(__mu) + __I = numpy.array(__I) + __errors = numpy.array(__errors) + # -------------------------- if len(__errors) > 0 and __errors[-1] < selfA._parameters["EpsilonEIM"]: logging.debug("%s %s (%.1e)"%(selfA._name, "The convergence is obtained when reaching the required EIM tolerance", selfA._parameters["EpsilonEIM"])) # noqa: E501 if __M >= __maxM: diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index eb7ed9c..abc4f51 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -138,6 +138,7 @@ class _TUIViewer(GenericCaseViewer): GenericCaseViewer.__init__(self, __name, __objname, __content, __object) self._addLine("# -*- coding: utf-8 -*-") self._addLine("#\n# Python script using ADAO TUI\n#") + self._addLine("import numpy as np") self._addLine("from numpy import array, matrix") self._addLine("from adao import adaoBuilder") self._addLine("%s = adaoBuilder.New('%s')"%(self._objname, self._name)) @@ -216,6 +217,7 @@ class _COMViewer(GenericCaseViewer): self._observerIndex = 0 self._addLine("# -*- coding: utf-8 -*-") self._addLine("#\n# Python script using ADAO COMM\n#") + self._addLine("import numpy as np") self._addLine("from numpy import array, matrix") self._addLine("#") self._addLine("%s = {}"%__objname) @@ -1210,14 +1212,14 @@ class ImportScalarLinesFromFile(ImportFromFile): __usecols = (0, 1, 2, 3) def __replaceNoneN( s ): - if s.strip() == b'None': - return numpy.NINF + if s.strip() in (b'None', 'None'): + return -numpy.inf else: return s def __replaceNoneP( s ): - if s.strip() == b'None': - return numpy.PINF + if s.strip() in (b'None', 'None'): + return numpy.inf else: return s __converters = {2: __replaceNoneN, 3: __replaceNoneP} @@ -1234,8 +1236,8 @@ class ImportScalarLinesFromFile(ImportFromFile): __usecols = tuple(range(len(HeaderNames))) def __replaceNone( s ): - if s.strip() == b'None': - return numpy.NAN + if s.strip() in (b'None', 'None'): + return numpy.nan else: return s __converters = dict() diff --git a/src/daComposant/daCore/Persistence.py b/src/daComposant/daCore/Persistence.py index f814f38..588465e 100644 --- a/src/daComposant/daCore/Persistence.py +++ b/src/daComposant/daCore/Persistence.py @@ -297,9 +297,10 @@ class Persistence(object): élémentaires numpy. """ try: - return [numpy.mean(item, dtype=mfp).astype('float') for item in self.__values] + __sr = [numpy.mean(item, dtype=mfp).astype('float') for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def stds(self, ddof=0): """ @@ -312,11 +313,12 @@ class Persistence(object): """ try: if numpy.version.version >= '1.1.0': - return [numpy.array(item).std(ddof=ddof, dtype=mfp).astype('float') for item in self.__values] + __sr = [numpy.array(item).std(ddof=ddof, dtype=mfp).astype('float') for item in self.__values] else: return [numpy.array(item).std(dtype=mfp).astype('float') for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def sums(self): """ @@ -325,9 +327,10 @@ class Persistence(object): numpy. """ try: - return [numpy.array(item).sum() for item in self.__values] + __sr = [numpy.array(item).sum() for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def mins(self): """ @@ -336,9 +339,10 @@ class Persistence(object): numpy. """ try: - return [numpy.array(item).min() for item in self.__values] + __sr = [numpy.array(item).min() for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def maxs(self): """ @@ -347,9 +351,10 @@ class Persistence(object): numpy. """ try: - return [numpy.array(item).max() for item in self.__values] + __sr = [numpy.array(item).max() for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def powers(self, x2): """ @@ -358,9 +363,10 @@ class Persistence(object): numpy. """ try: - return [numpy.power(item, x2) for item in self.__values] + __sr = [numpy.power(item, x2) for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def norms(self, _ord=None): """ @@ -371,9 +377,10 @@ class Persistence(object): numpy. """ try: - return [numpy.linalg.norm(item, _ord) for item in self.__values] + __sr = [numpy.linalg.norm(item, _ord) for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def traces(self, offset=0): """ @@ -384,9 +391,10 @@ class Persistence(object): types élémentaires numpy. """ try: - return [numpy.trace(item, offset, dtype=mfp) for item in self.__values] + __sr = [numpy.trace(item, offset, dtype=mfp).astype('float') for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def maes(self, _predictor=None): """ @@ -401,7 +409,7 @@ class Persistence(object): """ if _predictor is None: try: - return [numpy.mean(numpy.abs(item)) for item in self.__values] + __sr = [numpy.mean(numpy.abs(item)) for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") else: @@ -411,9 +419,10 @@ class Persistence(object): if numpy.asarray(_predictor[i]).size != numpy.asarray(item).size: raise ValueError("Predictor size at step %i is incompatible with the values"%i) try: - return [numpy.mean(numpy.abs(numpy.ravel(item) - numpy.ravel(_predictor[i]))) for i, item in enumerate(self.__values)] + __sr = [numpy.mean(numpy.abs(numpy.ravel(item) - numpy.ravel(_predictor[i]))) for i, item in enumerate(self.__values)] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) def mses(self, _predictor=None): """ @@ -429,7 +438,7 @@ class Persistence(object): if _predictor is None: try: __n = self.shape()[0] - return [(numpy.linalg.norm(item)**2 / __n) for item in self.__values] + __sr = [(numpy.linalg.norm(item)**2 / __n) for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") else: @@ -440,9 +449,10 @@ class Persistence(object): raise ValueError("Predictor size at step %i is incompatible with the values"%i) try: __n = self.shape()[0] - return [(numpy.linalg.norm(numpy.ravel(item) - numpy.ravel(_predictor[i]))**2 / __n) for i, item in enumerate(self.__values)] + __sr = [(numpy.linalg.norm(numpy.ravel(item) - numpy.ravel(_predictor[i]))**2 / __n) for i, item in enumerate(self.__values)] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) msds = mses # Mean-Square Deviation (MSD=MSE) @@ -460,7 +470,7 @@ class Persistence(object): if _predictor is None: try: __n = self.shape()[0] - return [(numpy.linalg.norm(item) / math.sqrt(__n)) for item in self.__values] + __sr = [(numpy.linalg.norm(item) / math.sqrt(__n)) for item in self.__values] except Exception: raise TypeError("Base type is incompatible with numpy") else: @@ -471,9 +481,10 @@ class Persistence(object): raise ValueError("Predictor size at step %i is incompatible with the values"%i) try: __n = self.shape()[0] - return [(numpy.linalg.norm(numpy.ravel(item) - numpy.ravel(_predictor[i])) / math.sqrt(__n)) for i, item in enumerate(self.__values)] + __sr = [(numpy.linalg.norm(numpy.ravel(item) - numpy.ravel(_predictor[i])) / math.sqrt(__n)) for i, item in enumerate(self.__values)] except Exception: raise TypeError("Base type is incompatible with numpy") + return( numpy.array(__sr).tolist() ) rmsds = rmses # Root-Mean-Square Deviation (RMSD=RMSE) diff --git a/src/daComposant/daCore/Templates.py b/src/daComposant/daCore/Templates.py index 552dcf0..b14072b 100644 --- a/src/daComposant/daCore/Templates.py +++ b/src/daComposant/daCore/Templates.py @@ -86,7 +86,7 @@ class TemplateStorage(object): for ik in self.keys(): __orders.append( self.__values[ik]['order'] ) __reorder = numpy.array(__orders).argsort() - return list(numpy.array(self.keys())[__reorder]) + return (numpy.array(self.keys())[__reorder]).tolist() # ============================================================================== ObserverTemplates = TemplateStorage()