Пример #1
0
    def test_new_function_init(self):
        class BFunction(IFunction1D):
            def __init__(self):
                super(BFunction, self).__init__()

            def init(self):
                self.declareParameter("C", 0.0)

            def function1D(self, xvals):
                c = self.getParameterValue("C")
                return c * xvals

        FunctionFactory.subscribe(BFunction)
        fun = BFunction()
        self.assertEqual(str(fun), 'name=BFunction,C=0')
        fun.C = 2
        self.assertEqual(fun(2), 4)
        fun = BFunction(C=3)
        self.assertEqual(fun.C, 3)
        self.assertEqual(fun(2), 6)
Пример #2
0
    def test_new_function_init(self):
        class BFunction(IFunction1D):
            def __init__(self):
                super(BFunction, self).__init__()

            def init(self):
                self.declareParameter("C", 0.0)

            def function1D(self, xvals):
                c = self.getParameterValue("C")
                return c * xvals

        FunctionFactory.subscribe(BFunction)
        fun = BFunction()
        self.assertEqual(str(fun), 'name=BFunction,C=0')
        fun.C = 2
        self.assertEqual(fun(2), 4)
        fun = BFunction(C=3)
        self.assertEqual(fun.C, 3)
        self.assertEqual(fun(2), 6)
Пример #3
0
    def test_new_function(self):
        class AFunction(IFunction1D):

            def init(self):
                self.declareParameter("C", 0.0)

            def function1D(self, xvals):
                c = self.getParameterValue("C")
                return c * xvals

        FunctionFactory.subscribe(AFunction)
        fun = AFunction()
        self.assertEqual(str(fun), 'name=AFunction,C=0')
        fun.C = 2
        self.assertEqual(fun(2), 4)
        fun = AFunction(C=3)
        self.assertEqual(fun.C, 3)
        self.assertEqual(fun(2), 6)
        self.assertTrue((fun([2, 3, 4]) == np.array([6, 9, 12])).all())
        self.assertTrue((fun(np.array([2, 3, 4])) == np.array([6, 9, 12])).all())
Пример #4
0
    def test_new_function(self):
        class AFunction(IFunction1D):

            def init(self):
                self.declareParameter("C", 0.0)

            def function1D(self, xvals):
                c = self.getParameterValue("C")
                return c * xvals

        FunctionFactory.subscribe(AFunction)
        fun = AFunction()
        self.assertEqual(str(fun), 'name=AFunction,C=0')
        fun.C = 2
        self.assertEqual(fun(2), 4)
        fun = AFunction(C=3)
        self.assertEqual(fun.C, 3)
        self.assertEqual(fun(2), 6)
        self.assertTrue((fun([2, 3, 4]) == np.array([6, 9, 12])).all())
        self.assertTrue((fun(np.array([2, 3, 4])) == np.array([6, 9, 12])).all())