From a914b5c694f7a2db5d839f2423a1d613514bd27c Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 26 Dec 2018 18:37:55 +0100 Subject: [PATCH] Adding multi-functions input capabilities (1) --- src/daComposant/daCore/Aidsm.py | 10 ++++++++-- src/daComposant/daCore/BasicObjects.py | 23 ++++++++++++++++++----- src/daComposant/daCore/PlatformInfo.py | 18 +++++++++++++++++- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index a13a093..1c398ae 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -350,6 +350,7 @@ class Aidsm(object): Script = None, Stored = False, AvoidRC = True, + InputAsMF = False, Checked = False): "Definition d'un concept de calcul" Concept = "ObservationOperator" @@ -363,6 +364,7 @@ class Aidsm(object): asDict = Parameters, appliedInX = AppliedInXb, avoidRC = AvoidRC, + inputAsMF = InputAsMF, scheduledBy = None, toBeChecked = Checked, ) @@ -376,9 +378,10 @@ class Aidsm(object): ThreeFunctions = None, Parameters = None, Script = None, - Stored = False, Scheduler = None, + Stored = False, AvoidRC = True, + InputAsMF = False, Checked = False): "Definition d'un concept de calcul" Concept = "EvolutionModel" @@ -392,6 +395,7 @@ class Aidsm(object): asDict = Parameters, appliedInX = None, avoidRC = AvoidRC, + inputAsMF = InputAsMF, scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -405,9 +409,10 @@ class Aidsm(object): ThreeFunctions = None, Parameters = None, Script = None, - Stored = False, Scheduler = None, + Stored = False, AvoidRC = True, + InputAsMF = False, Checked = False): "Definition d'un concept de calcul" Concept = "ControlModel" @@ -421,6 +426,7 @@ class Aidsm(object): asDict = Parameters, appliedInX = None, avoidRC = AvoidRC, + inputAsMF = InputAsMF, scheduledBy = Scheduler, toBeChecked = Checked, ) diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 0ea2aab..c99697f 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -418,8 +418,6 @@ class FullOperator(object): # if __appliedInX is not None: self.__FO["AppliedInX"] = {} - if not isinstance(__appliedInX, dict): - raise ValueError("Error: observation operator defined by \"AppliedInX\" need a dictionary as argument.") for key in list(__appliedInX.keys()): if type( __appliedInX[key] ) is type( numpy.matrix([]) ): # Pour le cas où l'on a une vraie matrice @@ -1598,7 +1596,7 @@ class Covariance(object): def __mul__(self, other): "x.__mul__(y) <==> x*y" - if self.ismatrix() and isinstance(other,numpy.matrix): + if self.ismatrix() and isinstance(other, (int, numpy.matrix, float)): return self.__C * other elif self.ismatrix() and isinstance(other, (list, numpy.ndarray, tuple)): if numpy.ravel(other).size == self.shape[1]: # Vecteur @@ -1628,7 +1626,7 @@ class Covariance(object): def __rmul__(self, other): "x.__rmul__(y) <==> y*x" - if self.ismatrix() and isinstance(other,numpy.matrix): + if self.ismatrix() and isinstance(other, (int, numpy.matrix, float)): return other * self.__C elif self.isvector() and isinstance(other,numpy.matrix): if numpy.ravel(other).size == self.shape[0]: # Vecteur @@ -1636,7 +1634,7 @@ class Covariance(object): elif numpy.asmatrix(other).shape[1] == self.shape[0]: # Matrice return numpy.asmatrix(numpy.array(other) * self.__C) else: - raise ValueError("operands could not be broadcast together with shapes %s %s in %s matrix"%(self.shape,numpy.ravel(other).shape,self.__name)) + raise ValueError("operands could not be broadcast together with shapes %s %s in %s matrix"%(numpy.ravel(other).shape,self.shape,self.__name)) elif self.isscalar() and isinstance(other,numpy.matrix): return other * self.__C elif self.isobject(): @@ -1712,6 +1710,21 @@ class CaseLogger(object): raise ValueError("Loading as \"%s\" is not available"%__format) return __formater.load(__filename, __content, __object) +# ============================================================================== +def MultiFonction( __xserie, _sFunction = lambda x: x ): + """ + Pour une liste ordonnée de vecteurs en entrée, renvoie en sortie la liste + correspondante de valeurs de la fonction en argument + """ + if not PlatformInfo.isIterable( __xserie ): + raise ValueError("MultiFonction not iterable unkown input type: %s"%(type(__xserie),)) + # + __multiHX = [] + for __xvalue in __xserie: + __multiHX.append( _sFunction( __xvalue ) ) + # + return __multiHX + # ============================================================================== def CostFunction3D(_x, _Hm = None, # Pour simuler Hm(x) : HO["Direct"].appliedTo diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index 2d474c7..e6468e6 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -250,7 +250,23 @@ def uniq( __sequence ): __seen = set() return [x for x in __sequence if x not in __seen and not __seen.add(x)] -def date2int(__date, __lang="FR"): +def isIterable( __sequence, __check = False, __header = "" ): + """ + Vérification que l'argument est un itérable + """ + if isinstance( __sequence, (list, tuple, map) ): + __isOk = True + elif type(__sequence).__name__ in ('generator','range'): + __isOk = True + elif "_iterator" in type(__sequence).__name__: + __isOk = True + else: + __isOk = False + if __check and not __isOk: + raise TypeError("Not iterable or unkown input type%s: %s"%(__header, type(__sequence),)) + return __isOk + +def date2int( __date, __lang="FR" ): """ Fonction de secours, conversion pure : dd/mm/yy hh:mm ---> int(yyyymmddhhmm) """ -- 2.39.2