Ejemplo n.º 1
0
    def test_convert(self):

        v = WorkspaceVariable.convert("Index", 1.2)
        assert (v == 1)

        v = WorkspaceVariable.convert("String", "string")
        assert (v == "string")

        v = WorkspaceVariable.convert("Numeric", 1)
        assert (type(v) == np.float64)

        v = WorkspaceVariable.convert("Vector", 1.0)
        assert (v.shape == (1, ))

        v = WorkspaceVariable.convert("Matrix", 1.0)
        assert (v.shape == (1, 1))

        v = WorkspaceVariable.convert("Tensor3", 1.0)
        assert (v.shape == (1, 1, 1))

        v = WorkspaceVariable.convert("Tensor6", 1.0)
        assert (v.shape == (1, 1, 1, 1, 1, 1))

        v = WorkspaceVariable.convert("ArrayOfArrayOfIndex", 1.0)
        assert (type(v) == list)
        assert (type(v[0]) == list)
        assert (type(v[0][0]) == int)

        v = WorkspaceVariable.convert("ArrayOfArrayOfIndex", 1)
        return v
Ejemplo n.º 2
0
    def get_default_input_dict(m_id, g_in):
        """Get dict mapping names of generic input arguments to default values.

        Is None if no default value for a given generic input is given.

        Args:
            m_id(int):   Index of the method.
            g_in([str]): Names of the generic input arguments.
        Return:
            dict: The mapping.
        """
        res = dict()
        for i, t in enumerate(g_in):
            k = arts_api.get_method_g_in(m_id, i).decode("utf8")
            d = arts_api.get_method_g_in_default(m_id, i).decode("utf8")
            if d == "":
                pass
            elif d[0] == "@":
                d = None
            elif d == "Inf":
                res[k] = np.float64("inf")
            else:
                try:
                    d = WorkspaceVariable.convert(group_names[t],
                                                  ast.literal_eval(d))
                    res[k] = d
                except:
                    res[k] = d
        return res