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
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
def c(v): if isinstance(v, _adolc.adub): return _adolc.adouble(v) return v