Skip to content

Commit

Permalink
clean up root for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Nov 10, 2024
1 parent 7964472 commit 81b54f9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion hvcc/core/hv2ir/HLangAdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
assert obj_type == "adc"
super().__init__(obj_type, args, graph,
num_inlets=0,
num_outlets=len(args[self._HEAVY_LANG_DICT.root[obj_type].args[0].name]),
num_outlets=len(args[self._HEAVY_LANG_DICT[obj_type].args[0].name]),
annotations=annotations)

def _resolved_outlet_type(self, outlet_index: int = 0) -> str:
Expand Down
2 changes: 1 addition & 1 deletion hvcc/core/hv2ir/HLangDac.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
) -> None:
assert obj_type == "dac"
super().__init__(obj_type, args, graph,
num_inlets=len(args[self._HEAVY_LANG_DICT.root[obj_type].args[0].name]),
num_inlets=len(args[self._HEAVY_LANG_DICT[obj_type].args[0].name]),
num_outlets=0,
annotations=annotations)

Expand Down
2 changes: 1 addition & 1 deletion hvcc/core/hv2ir/HLangSequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
annotations: Optional[Dict] = None
) -> None:
# get the number of outlets that this object has
num_outlets = len(args[self._HEAVY_LANG_DICT.root[obj_type].args[0].name])
num_outlets = len(args[self._HEAVY_LANG_DICT[obj_type].args[0].name])
super().__init__(obj_type, args, graph,
num_inlets=1,
num_outlets=num_outlets,
Expand Down
12 changes: 6 additions & 6 deletions hvcc/core/hv2ir/HeavyIrObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HeavyIrObject(HeavyLangObject):

# load the HeavyIR object definitions
with open(os.path.join(os.path.dirname(__file__), "../json/heavy.ir.json"), "r") as f:
__HEAVY_OBJS_IR_DICT = HeavyIRType(json.load(f))
__HEAVY_OBJS_IR_DICT = HeavyIRType(json.load(f)).root

def __init__(
self,
Expand All @@ -49,11 +49,11 @@ def __init__(
annotations: Optional[Dict] = None
) -> None:
# allow the number of inlets and outlets to be overridden
num_inlets = (len(self.__HEAVY_OBJS_IR_DICT.root[obj_type].inlets)
num_inlets = (len(self.__HEAVY_OBJS_IR_DICT[obj_type].inlets)
if num_inlets < 0
else num_inlets)

num_outlets = (len(self.__HEAVY_OBJS_IR_DICT.root[obj_type].outlets)
num_outlets = (len(self.__HEAVY_OBJS_IR_DICT[obj_type].outlets)
if num_outlets < 0
else num_outlets)

Expand All @@ -74,7 +74,7 @@ def __resolve_default_ir_args(self) -> None:
""" Resolves missing default arguments. Also checks to make sure that all
required arguments are present.
"""
if self.type in self.__HEAVY_OBJS_IR_DICT.root.keys():
if self.type in self.__HEAVY_OBJS_IR_DICT.keys():
for arg in self.__obj_desc.args:
if arg.name not in self.args:
# if a defined argument is not in the argument dictionary
Expand All @@ -96,7 +96,7 @@ def __resolve_default_ir_args(self) -> None:
def is_ir(cls, obj_type: str) -> bool:
"""Returns true if the type is an IR object. False otherwise.
"""
return obj_type in cls.__HEAVY_OBJS_IR_DICT.root.keys()
return obj_type in cls.__HEAVY_OBJS_IR_DICT.keys()

@property
def does_process_signal(self) -> bool:
Expand All @@ -108,7 +108,7 @@ def does_process_signal(self) -> bool:
def __obj_desc(self) -> IRNode:
""" Returns the original HeavyIR object description.
"""
return self.__HEAVY_OBJS_IR_DICT.root[self.type]
return self.__HEAVY_OBJS_IR_DICT[self.type]

def inlet_requires_signal(self, inlet_index: int = 0) -> bool:
""" Returns True if the indexed inlet requires a signal connection. False otherwise.
Expand Down
6 changes: 3 additions & 3 deletions hvcc/core/hv2ir/HeavyLangObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HeavyLangObject:

# load the Heavy object definitions
with open(os.path.join(os.path.dirname(__file__), "../json/heavy.lang.json"), "r") as f:
_HEAVY_LANG_DICT = HeavyLangType(json.load(f))
_HEAVY_LANG_DICT = HeavyLangType(json.load(f)).root

def __init__(
self,
Expand Down Expand Up @@ -111,7 +111,7 @@ def name(self) -> Optional[str]:
def _obj_desc(self) -> LangNode:
""" Returns the HeavyLang object description.
"""
return self._HEAVY_LANG_DICT.root[self.type]
return self._HEAVY_LANG_DICT[self.type]

def inlet_connection_type(self, index: int) -> Inlet:
return self._obj_desc.inlets[index]
Expand Down Expand Up @@ -196,7 +196,7 @@ def __resolve_default_lang_args(self) -> None:
""" Resolves missing default arguments. Also checks to make sure that all
required arguments are present. Does nothing if the object is IR.
"""
if self.type in HeavyLangObject._HEAVY_LANG_DICT.root.keys():
if self.type in HeavyLangObject._HEAVY_LANG_DICT.keys():
for arg in self._obj_desc.args:
if arg.name not in self.args:
# if a defined argument is not in the argument dictionary
Expand Down
6 changes: 3 additions & 3 deletions hvcc/generators/ir2c/ir2c_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class ir2c_perf:
def perf(cls, ir: Dict, blocksize: int = 512, mhz: int = 1000, verbose: bool = False) -> Dict:
# read the hv.ir.json file
with open(os.path.join(os.path.dirname(__file__), "../../core/json/heavy.ir.json"), "r") as f:
HEAVY_IR_JSON = HeavyIRType(json.load(f))
HEAVY_IR_JSON = HeavyIRType(json.load(f)).root

objects: Counter = Counter()
perf: Counter = Counter()
per_object_perf: Dict = defaultdict(Counter)
for o in ir["signal"]["processOrder"]:
obj_id = o["id"]
obj_type = ir["objects"][obj_id]["type"]
if obj_type in HEAVY_IR_JSON.root.keys():
if obj_type in HEAVY_IR_JSON.keys():
objects[obj_type] += 1
c = Counter(HEAVY_IR_JSON.root[obj_type].perf)
c = Counter(HEAVY_IR_JSON[obj_type].perf)
perf = perf + c
per_object_perf[obj_type] = per_object_perf[obj_type] + c
else:
Expand Down
12 changes: 6 additions & 6 deletions hvcc/interpreters/pd2hv/HeavyObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class HeavyObject(PdObject):

heavy_lang_json = importlib_resources.files('hvcc') / 'core/json/heavy.lang.json'
with open(heavy_lang_json, "r") as f:
__HEAVY_LANG_OBJS = HeavyLangType(json.load(f))
__HEAVY_LANG_OBJS = HeavyLangType(json.load(f)).root

heavy_ir_json = importlib_resources.files('hvcc') / 'core/json/heavy.ir.json'
with open(heavy_ir_json, "r") as f:
__HEAVY_IR_OBJS = HeavyIRType(json.load(f))
__HEAVY_IR_OBJS = HeavyIRType(json.load(f)).root

def __init__(
self,
Expand All @@ -48,9 +48,9 @@ def __init__(

# get the object dictionary (note that it is NOT a copy)
if self.is_hvlang:
self.__obj_dict = self.__HEAVY_LANG_OBJS.root[obj_type]
self.__obj_dict = self.__HEAVY_LANG_OBJS[obj_type]
elif self.is_hvir:
self.__obj_dict = self.__HEAVY_IR_OBJS.root[obj_type]
self.__obj_dict = self.__HEAVY_IR_OBJS[obj_type]
else:
assert False, f"{obj_type} is not a Heavy Lang or IR object."

Expand Down Expand Up @@ -144,11 +144,11 @@ def force_arg_type(

@property
def is_hvlang(self) -> bool:
return self.obj_type in self.__HEAVY_LANG_OBJS.root.keys()
return self.obj_type in self.__HEAVY_LANG_OBJS.keys()

@property
def is_hvir(self) -> bool:
return self.obj_type in self.__HEAVY_IR_OBJS.root.keys()
return self.obj_type in self.__HEAVY_IR_OBJS.keys()

def get_inlet_connection_type(self, inlet_index: int) -> Optional[str]:
""" Returns the inlet connection type, None if the inlet does not exist.
Expand Down

0 comments on commit 81b54f9

Please sign in to comment.