~magnusmorton/delayrepay

ref: f51bdaf0308c1ff814fefdf2f83e47bd745db144 delayrepay/delayrepay/cpu.py -rw-r--r-- 572 bytes
f51bdaf0 — Magnus Morton added run and fallback etc. 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy
from .visitor import Visitor

np = numpy
fallback = numpy

class CpuVisitor(Visitor):
    def visit_NPArray(self, node):
        return node.array

    def visit_Scalar(self, node):
        return node.val

    def visit_UnaryFuncEx(self, node):
        return node.func(*self.visit(node.children))

    def visit_BinaryFuncEx(self, node):
        return node.func(*self.visit(node.children))

    def visit_BinaryNumpyEx(self, node):
        return node.func(*self.visit(node.children))


def run(ex):
    visitor = CpuVisitor()
    return visitor.visit(ex)