Ejemplo n.º 1
0
 def _gen_weldobj(self, arr):
     '''
     Generating a new weldarray from a given arr for self.
     @arr: weldarray or ndarray.
         - weldarray: Just update the weldobject with the context from the
           weldarray.
         - ndarray: Add the given array to the context of the weldobject.
     Sets self.name and self.weldobj.
     '''
     self.weldobj = WeldObject(NumpyArrayEncoder(), NumpyArrayDecoder())
     if isinstance(arr, weldarray):
         self.weldobj.update(arr.weldobj)
         self.weldobj.weld_code = arr.weldobj.weld_code
         self.name = arr.name
     else:
         # general case for arr being numpy scalar or ndarray
         # weldobj returns the name bound to the given array. That is also
         # the array that future ops will act on, so set weld_code to it.
         self.name = self.weldobj.weld_code = self.weldobj.update(
             arr, SUPPORTED_DTYPES[str(arr.dtype)])
Ejemplo n.º 2
0
from weld.weldobject import *
from weld.types import *
from weld.encoders import NumpyArrayEncoder, NumpyArrayDecoder, ScalarDecoder

_encoder = NumpyArrayEncoder()
_decoder = NumpyArrayDecoder()


class HelloWeldVector(object):
    def __init__(self, vector):
        self.vector = vector
        self.weldobj = WeldObject(_encoder, _decoder)
        name = self.weldobj.update(vector, WeldVec(WeldInt()))
        self.weldobj.weld_code = name
        self.cached = None

    def add(self, number):
        self.cached = None
        template = "map({0}, |e| e + {1})"
        self.weldobj.weld_code = template.format(self.weldobj.weld_code,
                                                 str(number))
        return self

    def sum(self):
        self.cached = None
        template = "result(for({0}, merger[i64,+], |b,i,e| merge(b, i64(e))))"
        prev_code = self.weldobj.weld_code
        self.weldobj.weld_code = template.format(self.weldobj.weld_code)
        self.weldobj.decoder = ScalarDecoder()
        result = self.weldobj.evaluate(WeldLong(), verbose=False)
        self.weldobj.decoder = _decoder
Ejemplo n.º 3
0
 def __init__(self, value, weldty):
     self.value = value
     self.weldty = weldty
     self.weldobj = WeldObject(NumpyArrayEncoder(), NumpyArrayDecoder())
     name = self.weldobj.update(value, WeldInt)