def arraycast(x, val): if type(x) is SparseArray: return x elif not isinstance(x, anp.ndarray): return anp.array(cast(x, val.ravel()[0])) else: if anp.iscomplexobj(val) and not anp.iscomplexobj(x): return anp.array(x, dtype=anp.complex) elif not anp.iscomplexobj(val) and anp.iscomplexobj(x): return anp.real(anp.array(x)) else: return x
def cast(value, example): return cast(value, cast_to_list)
def cast(value, example): return cast(value, cast_to_dict)