Exemple #1
0
def gradient(tape_tag,x):
	"""
	evaluate the gradient g = f'(x), f:R^N -> R
	"""
	assert type(tape_tag) == int
	ts = tapestats(tape_tag)
	N = ts['NUM_INDEPENDENTS']
	M = ts['NUM_DEPENDENTS']
	x = numpy.asarray(x, dtype=float)
	assert numpy.size(x) == N
	assert numpy.ndim(x) == 1
	g = numpy.zeros(N, dtype=float)
	_adolc.gradient(tape_tag, N, x, g)
	return g
def gradient(tape_tag, x):
    """
    evaluate the gradient g = f'(x), f:R^N -> R
    """
    assert type(tape_tag) == int
    ts = tapestats(tape_tag)
    N = ts['NUM_INDEPENDENTS']
    M = ts['NUM_DEPENDENTS']
    x = numpy.ascontiguousarray(x, dtype=float)
    assert numpy.size(x) == N
    assert numpy.ndim(x) == 1
    g = numpy.zeros(N, dtype=float)
    rc = _adolc.gradient(tape_tag, N, x, g)
    if (rc < 0):
        raise ErrorReturnCode("gradient", rc)
    return g
Exemple #3
0
def gradient(tape_tag,x):
    """
    evaluate the gradient g = f'(x), f:R^N -> R
    """
    assert type(tape_tag) == int
    ts = tapestats(tape_tag)
    N = ts['NUM_INDEPENDENTS']
    M = ts['NUM_DEPENDENTS']
    x = numpy.ascontiguousarray(x, dtype=float)
    assert numpy.size(x) == N
    assert numpy.ndim(x) == 1
    g = numpy.zeros(N, dtype=float)
    rc = _adolc.gradient(tape_tag, N, x, g)
    if (rc < 0):
        raise ErrorReturnCode("gradient", rc)
    return g