X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.pythonlink%2Fscl%2FPython.scl;h=5fc78318e62b88ce0f7fee4ed2b539613abec558;hb=refs%2Fchanges%2F16%2F316%2F1;hp=b1ca052ef2b026c3a3f00ebdcf05b2784e3962d8;hpb=35382d886800c915bbdcfd595cf7b8401413377f;p=simantics%2Fpython.git diff --git a/org.simantics.pythonlink/scl/Python.scl b/org.simantics.pythonlink/scl/Python.scl index b1ca052..5fc7831 100644 --- a/org.simantics.pythonlink/scl/Python.scl +++ b/org.simantics.pythonlink/scl/Python.scl @@ -1,5 +1,3 @@ -import "Vector" - effect Python "Simantics/Python/Python" "org.simantics.pythonlink.PythonContext" @@ -36,6 +34,27 @@ importJava "org.simantics.pythonlink.NDArray" where @JavaName equals ndarrayEquals :: NDArray -> NDArray -> Boolean +class NDArrayInput a where + ndarrayInput :: a -> ([Integer], [Double]) + +instance NDArrayInput [Double] where + ndarrayInput v = ([length v], v) + +instance (NDArrayInput [a]) => NDArrayInput [[a]] where + ndarrayInput v = let + inp = map ndarrayInput v + dims = map fst inp + vals = join $ map snd inp + in + if not (all (== (dims!0)) dims) then + fail "List of lists not of uniform dimension" + else + ([length v] + (dims!0), vals) + +ndarrayFromList :: NDArrayInput a => a -> NDArray +ndarrayFromList v = ndarrayN (vector dims) (vector vals) where + (dims, vals) = ndarrayInput v + instance Show NDArray where show = ndarrayToString @@ -50,22 +69,35 @@ importJava "org.simantics.pythonlink.PythonContext" where executePythonStatement :: String -> () + setPythonBooleanVariable :: String -> Boolean -> () setPythonIntegerVariable :: String -> Integer -> () - setPythonIntegerArrayVariable :: String -> Vector Integer -> () + setPythonLongVariable :: String -> Long -> () setPythonDoubleVariable :: String -> Double -> () - setPythonDoubleArrayVariable :: String -> Vector Double -> () setPythonStringVariable :: String -> String -> () + + setPythonBooleanArrayVariable :: String -> Vector Boolean -> () + setPythonIntegerArrayVariable :: String -> Vector Integer -> () + setPythonLongArrayVariable :: String -> Vector Long -> () + setPythonDoubleArrayVariable :: String -> Vector Double -> () setPythonStringArrayVariable :: String -> Vector String -> () setPythonNDArrayVariable :: String -> NDArray -> () + getPythonBooleanVariable :: String -> Boolean getPythonIntegerVariable :: String -> Integer - getPythonIntegerArrayVariable :: String -> Vector Integer + getPythonLongVariable :: String -> Long getPythonDoubleVariable :: String -> Double - getPythonDoubleArrayVariable :: String -> Vector Double getPythonStringVariable :: String -> String + + getPythonBooleanArrayVariable :: String -> Vector Boolean + getPythonIntegerArrayVariable :: String -> Vector Integer + getPythonLongArrayVariable :: String -> Vector Long + getPythonDoubleArrayVariable :: String -> Vector Double getPythonStringArrayVariable :: String -> Vector String getPythonNDArrayVariable :: String -> NDArray + setPythonVariantVariable :: String -> Variant -> () + getPythonVariantVariable :: String -> Variant + importJava "org.simantics.pythonlink.Python" where openPythonContext :: PythonContext