Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
MarisaKirisame committed Jul 12, 2019
1 parent c6f152c commit 616ab79
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions python/tvm/relay/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from collections import deque

import tvm
import numpy as np

from . import module
from .base import Span, SourceName
Expand All @@ -42,8 +41,7 @@
raise Exeption("Couldn't find ANTLR parser. Try building with USE_ANTLR=ON.")

try:
from antlr4 import ParserRuleContext, InputStream, CommonTokenStream
from antlr4.tree.Tree import TerminalNode
from antlr4 import InputStream, CommonTokenStream
from antlr4.error.ErrorListener import ErrorListener
except ImportError:
raise Exception("Couldn't find ANTLR runtime." +
Expand All @@ -66,23 +64,27 @@ def __repr__(self):
def __str__(self):
return repr(self)

# Overload the __call__ for op.
class OpWrapper:
"""Overload the __call__ for op."""
pass

class ExprOp(OpWrapper):
def __init__(self, op):
self.op = op
"""Call an expr. The default, but does not handle attrs well."""
def __init__(self, operator):
self.operator = operator

def __call__(self, args, attrs, type_args):
try:
return expr.Call(self.op, args, attrs, type_args)
return expr.Call(self.operator, args, attrs, type_args)
except Exception:
raise Exception(str(self.op) + " " + str(attrs))
raise Exception(str(self.operator) + " " + str(attrs))

class FuncOp(OpWrapper):
def __init__(self, op):
self.op = op
"""Convert the attrs, call the python function with the attrs passed in as keyword arguments.
Tvm should provide this in the future, as this is pretty similar to what op.get is providing.
"""
def __init__(self, operator):
self.operator = operator

def convert(self, v):
if isinstance(v, tuple):
Expand All @@ -96,7 +98,7 @@ def convert(self, v):
def __call__(self, args, attrs, type_args):
if attrs is None:
attrs = {}
x = self.op(*args, **{k: self.convert(v) for k, v in attrs.items()})
x = self.operator(*args, **{k: self.convert(v) for k, v in attrs.items()})
if isinstance(x, expr.TupleWrapper):
x = x.astuple()
return x
Expand Down Expand Up @@ -633,6 +635,7 @@ def make_parser(data):
__source_name_counter__ = 0

class StrictErrorListener(ErrorListener):
"""This ErrorListener fail eagerly on all error, and report the program."""
def __init__(self, text):
self.text = text

Expand Down

0 comments on commit 616ab79

Please sign in to comment.