From 2783834cb1e2df6e41ed2689cbd1a2db63ee18d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Fri, 17 Jan 2025 12:45:51 +0800 Subject: [PATCH] nac3artiq/demo: merge EmbeddingMap into min_artiq --- nac3artiq/demo/embedding_map.py | 39 ------------------------------- nac3artiq/demo/min_artiq.py | 41 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 nac3artiq/demo/embedding_map.py diff --git a/nac3artiq/demo/embedding_map.py b/nac3artiq/demo/embedding_map.py deleted file mode 100644 index a43af698..00000000 --- a/nac3artiq/demo/embedding_map.py +++ /dev/null @@ -1,39 +0,0 @@ -class EmbeddingMap: - def __init__(self): - self.object_inverse_map = {} - self.object_map = {} - self.string_map = {} - self.string_reverse_map = {} - self.function_map = {} - self.attributes_writeback = [] - - def store_function(self, key, fun): - self.function_map[key] = fun - return key - - def store_object(self, obj): - obj_id = id(obj) - if obj_id in self.object_inverse_map: - return self.object_inverse_map[obj_id] - key = len(self.object_map) + 1 - self.object_map[key] = obj - self.object_inverse_map[obj_id] = key - return key - - def store_str(self, s): - if s in self.string_reverse_map: - return self.string_reverse_map[s] - key = len(self.string_map) - self.string_map[key] = s - self.string_reverse_map[s] = key - return key - - def retrieve_function(self, key): - return self.function_map[key] - - def retrieve_object(self, key): - return self.object_map[key] - - def retrieve_str(self, key): - return self.string_map[key] - diff --git a/nac3artiq/demo/min_artiq.py b/nac3artiq/demo/min_artiq.py index 62d32cc3..fef018b2 100644 --- a/nac3artiq/demo/min_artiq.py +++ b/nac3artiq/demo/min_artiq.py @@ -6,7 +6,6 @@ from typing import Generic, TypeVar from math import floor, ceil import nac3artiq -from embedding_map import EmbeddingMap __all__ = [ @@ -193,6 +192,46 @@ def print_int64(x: int64): raise NotImplementedError("syscall not simulated") +class EmbeddingMap: + def __init__(self): + self.object_inverse_map = {} + self.object_map = {} + self.string_map = {} + self.string_reverse_map = {} + self.function_map = {} + self.attributes_writeback = [] + + def store_function(self, key, fun): + self.function_map[key] = fun + return key + + def store_object(self, obj): + obj_id = id(obj) + if obj_id in self.object_inverse_map: + return self.object_inverse_map[obj_id] + key = len(self.object_map) + 1 + self.object_map[key] = obj + self.object_inverse_map[obj_id] = key + return key + + def store_str(self, s): + if s in self.string_reverse_map: + return self.string_reverse_map[s] + key = len(self.string_map) + self.string_map[key] = s + self.string_reverse_map[s] = key + return key + + def retrieve_function(self, key): + return self.function_map[key] + + def retrieve_object(self, key): + return self.object_map[key] + + def retrieve_str(self, key): + return self.string_map[key] + + @nac3 class Core: ref_period: KernelInvariant[float]