def __init__(self, config): self.debug = config.getboolean("global", "DEBUG", fallback=True) self.config = config["detector_service"] self.thresholds = [ float(v) for v in self.config.get("THRESHOLDS").split(",") ] logger.info( f"thresholds {self.thresholds}") self.conn = self._get_conn() self.rpc = lazy(lambda: self.conn.root) self.hub: PubSub = AMemoryPubSub(asyncio.Queue)
def test_force_eval_on_objects() -> None: evaluated = False def do_something(x: int, y: int) -> int: nonlocal evaluated evaluated = True return x + y res = lazy(do_something, 1, 2) assert not evaluated force_eval(res) assert evaluated
def lazy_contract(address, owner=None, force=False): def _owner(owner): if owner: return owner try: click_ctx = click.get_current_context() except Exception: return None return click_ctx.obj.get("lazy_contract_default_account", None) return lazy(lambda: load_contract(address, _owner(owner), force=force))
def test_lazy_function_with_eagle_argument_evaluation() -> None: evaluated = False def add(x: int, y: int) -> int: nonlocal evaluated evaluated = True return x + y res = lazy(add, 1, 2) assert not evaluated assert isinstance(res, Proxy) assert res == 3 assert evaluated assert isinstance(res, int)
def test_multiple_lazy_on_expression() -> None: evaluated = False def add(x: int, y: int) -> int: nonlocal evaluated evaluated = True return x + y res = lazy(lambda: add(1, 2)) assert res is not add res2 = lazy(res) assert res is res2 assert not evaluated assert res == 3 assert evaluated assert res2 == 3 evaluated = False res = lazy(lazy(lazy(lambda: add(1, 2)))) assert res is not add assert not evaluated assert res == 3 assert evaluated
def test_lazy_simple_expression_evaluation() -> None: evaluated = False def add(x: int, y: int) -> int: nonlocal evaluated evaluated = True return x + y res = lazy(lambda: add(1, 2)) assert not evaluated assert isinstance(res, Proxy) assert res == 3 assert evaluated assert isinstance(res, int)
def __init__( self, task_service: TaskService, setting_service: SettingService, detector_service: DetectorService, config: ConfigParser, ): # Hub for PubSub self.hub = AMemoryPubSub(asyncio.Queue) self.task_service = task_service self.setting_service = setting_service self.detector_service = detector_service self.rpc_conn = self._get_rpc_conn(config['camera_rpc']) self.rpc = lazy(lambda: self.rpc_conn.root) self.queue_mgr = self._get_queue_mgr(config["camera_queue"]) self.status_queue = lazy(lambda: self.queue_mgr.status_queue()) self.cmd_queue = lazy(lambda: self.queue_mgr.cmd_queue()) logger.info( f'qmgr should be lazily evaludated, not connected at this moment') self.config = config['camera_rpc']
intermediate_location = f"{os.path.basename(__file__)}-intermediate_data" if not os.path.exists(intermediate_location): os.mkdir(intermediate_location) if __name__ == '__main__': regenerate = False def load_w2v(): print("Loading model...") w2v_model = gensim.downloader.load('word2vec-google-news-300') print("Loaded.") return w2v_model model = lazy(load_w2v) input_files = [ '9.csv', '21.csv', '25.csv', '26.csv', '31.csv', '32.csv', 'jigsaw-toxic.csv' ] # Load the data into these variables all_posts = list() all_labels = list() all_embeddings = list() for file_name in input_files: data_path = 'data' file_path = os.path.join(data_path, file_name) if not os.path.exists(file_path): print(f"Skipping {file_path}, because source is not available")
# they limit everyone to 5 requests/second # if the contract hasn't been fetched, getting it will take longer than a second # if the contract has been already fetched, we won't hit their API max_workers = min(multiprocessing.cpu_count(), 5) with ThreadPoolExecutor(max_workers=max_workers) as executor: def poke_contract(contract): _ = contract.address futures = [ executor.submit(poke_contract, contract) for contract in contracts ] for _f in as_completed(futures): # we could check errors here and log, but the user will see those errors if they actually use a broken contract # and if they aren't using hte contract, there's no reason to bother them with warnings pass # eip-2470 SingletonFactory = lazy_contract("0xce0042B868300000d44A59004Da54A005ffdcf9f") # dydx wrapper https://github.com/albertocuestacanada/ERC3156-Wrappers DyDxFlashLender = lazy_contract("0x6bdC1FCB2F13d1bA9D26ccEc3983d5D4bf318693") OneSplit = lazy_contract("1proto.eth") ArgobytesBrownieProject = lazy(lambda: project.ArgobytesBrownieProject) ArgobytesInterfaces = lazy(lambda: ArgobytesBrownieProject.interface)
def __init__(self): self.plugins = lazy(self._load)
import stanza from spacy_stanza import StanzaLanguage from transformers import MarianMTModel, MarianTokenizer from sklearn.decomposition import PCA REUTERS_DIRECTORY = 'data/reuters' LANGUAGE_DIRECTORIES = { 'en': os.path.join(REUTERS_DIRECTORY, "rcv1"), 'es': os.path.join(REUTERS_DIRECTORY, "RCV2_Multilingual_Corpus/spanish-latam"), 'ru': os.path.join(REUTERS_DIRECTORY, "RCV2_Multilingual_Corpus/russian") } LANGUAGE_MODELS = { 'en': lazy(lambda: spacy.load("en_core_web_lg")), 'es': lazy(lambda: spacy.load("es_core_news_lg")), 'ru': lazy(lambda: StanzaLanguage(stanza.Pipeline(lang="ru"))) } def get_mt_tokenizer_and_model(model_name, device): return MarianTokenizer.from_pretrained( model_name), MarianMTModel.from_pretrained(model_name).to(device) def load_stop_words(lang): stop_words = set() with open('data/stopwords/%s.txt' % lang, 'r') as f: for word in f.readlines(): stop_words.add(word.strip())
def lazy_contract(address: str): return lazy(lambda: load_contract(address))
# we could check errors here and log, but the user will see those errors if they actually use a broken contract # and if they aren't using hte contract, there's no reason to bother them with warnings pass # eip-2470 SingletonFactory = lazy_contract("0xce0042B868300000d44A59004Da54A005ffdcf9f") # dydx wrapper https://github.com/albertocuestacanada/ERC3156-Wrappers DyDxFlashLender = lazy_contract("0x6bdC1FCB2F13d1bA9D26ccEc3983d5D4bf318693") OneSplit = lazy_contract("1proto.eth") # USDC may not be decentralized, but Coinbase can trade to USD in my bank account at 1:1 and no fee USDC = lazy_contract("usdc") ArgobytesProject = lazy(lambda: brownie.project.ArgobytesContractsProject) ArgobytesInterfaces = lazy(lambda: ArgobytesProject.interface) # lazy load these because they aren't available at import time here # TODO: use long project path in case multiple projects are loaded? ArgobytesAuthority = lazy(lambda: ArgobytesProject.ArgobytesAuthority) ArgobytesFactory = lazy(lambda: ArgobytesProject.ArgobytesFactory) ArgobytesMulticall = lazy(lambda: ArgobytesProject.ArgobytesMulticall) # clonable ArgobytesFlashBorrower = lazy(lambda: ArgobytesProject.ArgobytesFlashBorrower) ArgobytesProxy = lazy(lambda: ArgobytesProject.ArgobytesProxy) # actions ArgobytesTrader = lazy(lambda: ArgobytesProject.ArgobytesTrader)