Salome HOME
Adding multi-functions input capabilities (1)
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 26 Dec 2018 17:37:55 +0000 (18:37 +0100)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 26 Dec 2018 17:37:55 +0000 (18:37 +0100)
src/daComposant/daCore/Aidsm.py
src/daComposant/daCore/BasicObjects.py
src/daComposant/daCore/PlatformInfo.py

index a13a09392aea60cf3bcf864c9e92af1a9cb48294..1c398ae1944077031f51263db0e9692bd4f970e4 100644 (file)
@@ -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,
             )
index 0ea2aab9e7c18b6a8b76e52a7a1dcd8e6ff8c96d..c99697f56aeb1d742a4e48a2ec1f762af1cb92db 100644 (file)
@@ -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
index 2d474c7a52051cfc93f357955a9fb0897eb5faf3..e6468e693d5ace174036900204a507e8d570043f 100644 (file)
@@ -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)
     """