예제 #1
0
def adouble(x):
	"""
	Return adouble from scalar or array of arbitrary shape
	INPUT:  either a float or an array of floats
	OUTPUT: adouble or array of adoubles
	"""
	if numpy.isscalar(x):
		return _adolc.adouble(float(x))
	elif isinstance(x,_adolc.adouble) or isinstance(x,_adolc.adub):
		return _adolc.adouble(x)
	
	else:
		x = numpy.asarray(x, dtype=float)
		shp = numpy.shape(x)
		xr = numpy.ravel(x)
		axr = numpy.array([_adolc.adouble(xr[n]) for n in range(len(xr))])
		ax = axr.reshape(shp)
		return ax
예제 #2
0
def adouble(x):
    """
    Return adouble from scalar or array of arbitrary shape
    INPUT:  either a float or an array of floats
    OUTPUT: adouble or array of adoubles
    """
    if numpy.isscalar(x):
        return _adolc.adouble(float(x))
    elif isinstance(x, _adolc.adouble) or isinstance(x, _adolc.adub):
        return _adolc.adouble(x)

    else:
        x = numpy.ascontiguousarray(x, dtype=float)
        shp = numpy.shape(x)
        xr = numpy.ravel(x)
        axr = numpy.array([_adolc.adouble(xr[n]) for n in range(len(xr))])
        ax = axr.reshape(shp)
        return ax
예제 #3
0
 def c(v):
     if isinstance(v, _adolc.adub):
         return _adolc.adouble(v)
     return v
예제 #4
0
 def c(v):
     if isinstance(v, _adolc.adub):
         return _adolc.adouble(v)
     return v