Best Python code snippet using autotest_python
get_data.py
Source:get_data.py
...34 # Validation/testing data35 for container, indices in [ (val_data, val_indices), (test_data, test_indices) ]:36 for m, sampling_percent in indices:37 for sampling in all_samplers:38 container[0].append(get_embedding_id(task, 'complete_data', 0))39 container[1].append(get_embedding_id(task, sampling, sampling_percent))40 container[2].append(task_map[task])41 container[3].append(metric_map[m])42 container[4].append(43 count_performance_retained(results[task][m][sampling_percent][sampling], m, scaled = False)44 )45 # Training data46 for m, sampling_percent in train_indices:47 y = [ count_performance_retained(48 results[task][m][sampling_percent][sampling], m, scaled = False49 ) for sampling in all_samplers ]50 # Pointwise51 for at, sampling in enumerate(all_samplers):52 if y[at] in [ INF, -INF ]: continue53 train_data_pointwise[0].append(get_embedding_id(task, 'complete_data', 0))54 train_data_pointwise[1].append(get_embedding_id(task, sampling, sampling_percent))55 train_data_pointwise[2].append(task_map[task])56 train_data_pointwise[3].append(metric_map[m])57 train_data_pointwise[4].append(y[at])58 # Pairwise59 for i in range(len(all_samplers)):60 for j in range(i+1, len(all_samplers)):61 if y[i] in [ INF, -INF ]: continue62 if y[j] in [ INF, -INF ]: continue63 if y[i] == y[j]: continue64 if y[i] > y[j]: better, lower = i, j65 else: better, lower = j, i66 train_data_pairwise[0].append(get_embedding_id(task, 'complete_data', 0))67 train_data_pairwise[1].append(get_embedding_id(task, all_samplers[better], sampling_percent))68 train_data_pairwise[2].append(get_embedding_id(task, all_samplers[lower], sampling_percent))69 train_data_pairwise[3].append(task_map[task])70 train_data_pairwise[4].append(metric_map[m])71 save_obj([ train_data_pointwise, val_data, test_data ], TRAINING_DATA_PATH(dataset, "pointwise"))72 save_obj([ train_data_pairwise, val_data, test_data ], TRAINING_DATA_PATH(dataset, "pairwise"))73def get_results(dataset):74 PATH = CACHED_KENDALL_TAU_PATH(dataset)75 if os.path.exists(PATH + ".pkl"): return load_obj(PATH)76 loop = tqdm(77 total = len(scenarios) * ((len(svp_methods) * len(sampling_svp)) + len(sampling_kinds)) * \78 len(methods_to_compare) * len(percent_rns_options)79 )80 y = {}81 for task, metrics_to_return in scenarios:82 ...
postgresql.py
Source:postgresql.py
...22 return row['id']23 except psycopg2.errors.UniqueViolation:24 self.get_connection().rollback()25 # We anyway will return the ID of already saved embedding26 return self.get_embedding_id(recognizer, digest)27 finally:28 cur.close()29 def get_embeddings(self, recognizer) -> List[PersonEmbedding]:30 cur = self.get_connection().cursor()31 sql = "SELECT id, person, embedding, tags FROM embeddings WHERE recognizer = %s"32 cur.execute(sql, (recognizer,))33 return [PersonEmbedding(r['id'], r['person'], np.array(r['embedding']), r['tags']) for r in cur.fetchall()]34 def get_embedding(self, embedding_id: str) -> dict:35 cur = self.get_connection().cursor()36 sql = "SELECT * FROM embeddings WHERE id = %s"37 cur.execute(sql, (embedding_id,))38 return cur.fetchone()39 def get_embedding_id(self, recognizer, digest) -> Optional[str]:40 cur = self.get_connection().cursor()41 cur.execute(42 "SELECT id FROM embeddings WHERE recognizer = %s AND digest = %s", (recognizer, digest),43 )44 row = cur.fetchone()45 return str(row['id']) if row else None46 def get_connection(self) -> psycopg2.extensions.connection:47 if self.conn is None:48 self.conn = self.connect()49 return self.conn50 def connect(self) -> psycopg2.extensions.connection:...
test_embeddings.py
Source:test_embeddings.py
...5 db = EmbeddingsDatabase(data_dir=_data_dir)6 embedding_name: str = 'r-16'7 embedding_id: int = db.add_embedding(embedding_name)8 assert embedding_id in list(db.list_ready_embedding_ids())9 assert embedding_id == db.get_embedding_id(embedding_name)10 new_embedding_id: int = db.push_new_embedding_version(embedding_name)11 assert new_embedding_id != embedding_id12 assert new_embedding_id in list(db.list_ready_embedding_ids())13 assert embedding_id not in list(db.list_ready_embedding_ids())14 assert new_embedding_id == db.get_embedding_id(embedding_name)15 assert isinstance(db.get_embedding(new_embedding_id), Embedding)16 other_embedding_id: int = db.get_embedding_id('r-32')17 url = 'data:,This is a test sentence'18 emb_vectors = list(db.get_url_vectors(url=url))19 assert len(emb_vectors) == 220 assert all(embedding_id in [new_embedding_id, other_embedding_id] for embedding_id, v in emb_vectors)21 db.print_embeddings()22 del db23 # Let's reconnect.24 db = EmbeddingsDatabase(data_dir=_data_dir)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!