def make_blaze(value): if not isinstance(value, blaze.Array): dshape = T.typeof(value) if not dshape.shape: value = blaze.array([value], dshape) else: value = blaze.array(value, dshape) return value
def construct(bfunc, ctx, overload, args): """ Blaze expression graph construction for deferred evaluation. Parameters ---------- bfunc : Blaze Function (Overloaded) blaze function representing the operation ctx: ExprContext Context of the expression overload: blaze.overload.Overload Instance representing the overloaded function args: list bfunc parameters """ assert isinstance(bfunc, BlazeFunc), bfunc params = [] # [(graph_term, ExprContext)] # ------------------------------------------------- # Build type unification parameters for i, arg in enumerate(args): if isinstance(arg, blaze.Array) and arg.expr: # Compose new expression using previously constructed expression term, context = arg.expr if not arg.deferred: ctx.add_input(term, arg) elif isinstance(arg, blaze.Array): term = ArrayOp(arg.dshape) ctx.add_input(term, arg) empty = ExprContext() arg.expr = (term, empty) elif not isinstance(arg, blaze.Array): term = ArrayOp(T.typeof(arg)) ctx.terms[term] = arg params.append(term) # ------------------------------------------------- assert isinstance(overload.resolved_sig, T.Function) restype = blaze.dshape(overload.resolved_sig.parameters[-1]) # ------------------------------------------------- return KernelOp(restype, *params, kernel=bfunc, overload=overload, **bfunc.metadata)
def from_value(value): return ArrayOp(T.typeof(value), value)