https://github.com/lmfit/lmfit-py
Raw File
Tip revision: c2b7ea15507baf2032f497441de917e505c6b784 authored by Matthew Newville on 31 May 2017, 19:11:22 UTC
correctly create non-constraint parameter values and bounds for least_squares()
Tip revision: c2b7ea1
_test_make_paras_and_func.py
# -*- coding: utf-8 -*-

import lmfit


def test_wrap_function():
    get_names = lambda p: [p_key for p_key in p ]

    def func(A, b, c, d=5, e=10):
        return A + b + c + d

    x0 = [1, 2, 3]
    para, f = lmfit.make_paras_and_func(func, x0)
    assert(get_names(para) == ['A', 'b', 'c'])
    y1 = f(para)
    y2 = func(*x0)
    assert(y1==y2)

    x0 = [1, 2, 3, 4]
    para, f = lmfit.make_paras_and_func(func, x0)
    assert(get_names(para) == ['A', 'b', 'c', 'd'])
    y1 = f(para)
    y2 = func(*x0)
    assert(y1==y2)

    x0 = [1, 2, 3]
    para, f = lmfit.make_paras_and_func(func, x0, {'e': 3})
    assert(get_names(para) == ['A', 'b', 'c', 'e'])
    y1 = f(para)
    y2 = func(*x0)
    assert(y1==y2)
back to top