def key_exists(bucket, key, storage=None): '''Return true if a key exists in storage''' if storage is None: storage = lithops.Storage() try: storage.head_object(bucket=bucket, key=key) return True except StorageNoSuchKeyError: return False except Exception as e: raise e
a = 1500 # We do some checks in order to verify the sizes if not A.shape[1] == B.shape[0]: raise ValueError(f'''The number of columns in matrix A must be equal to the number of rows in matrix B.''') if m % a != 0: raise ValueError(f'The number of rows in A is not divisible by {a}') if l % a != 0: raise ValueError(f'The number of columns in B is not divisible by {a}') # ============================================================================= # Pickle storage # ============================================================================= namespace = 'mat_mult' storage = lithops.Storage() storage.put_object(namespace, 'Amat', pickle.dumps(A)) storage.put_object(namespace, 'Bmat', pickle.dumps(B)) # We create a list of two dimensional indices and give it also namespace indi = [] for i in range(m // a): for j in range(l // a): indi.append((namespace, (i, j))) # We will create len(indi) workers n_workers = len(indi) # ============================================================================= # Plain text multiplication # ============================================================================= # Start the timer to analyze function speed
def _create_storage_client(self): """ Creates a storage client """ if self.storage is None: self.storage = lithops.Storage()
def list_all_keys(bucket, prefix, storage=None): if storage is None: storage = lithops.Storage() keys = storage.list_keys(bucket=bucket, prefix=prefix + "/") return keys