1
1
import pickle
2
2
import os
3
3
import resource
4
- import torch
5
4
from typing import Union , Any , Dict
6
- from model .instance import Instance
7
- from torch import Tensor
8
5
9
6
# =====================================================================
10
7
# =*= COMMON TOOLS (objects and functions) USED ACCROSS THE PROJECT =*=
@@ -27,13 +24,6 @@ def __init__(self, data: str, instances: str, models: str, out: str, scripts: st
27
24
all_types_feature = Union [int , float , bool , list ]
28
25
generic_object = Union [object , Dict [Any , Any ]]
29
26
30
- def add_into_tensor (tensor_list : Tensor | None , tensor_val : Tensor ):
31
- if tensor_list is None :
32
- tensor_list = tensor_val
33
- else :
34
- tensor_list = torch .cat ((tensor_list , tensor_val ), dim = 0 )
35
- return tensor_list
36
-
37
27
def load_instance (path : str ):
38
28
with open (path , 'rb' ) as file :
39
29
return pickle .load (file )
@@ -49,9 +39,6 @@ def load_instances(path: str):
49
39
print ("end of loading!" )
50
40
return instances
51
41
52
- def to_binary (booleanVal : bool ):
53
- return 1 if booleanVal else 0
54
-
55
42
def set_memory_limit (max_ram_bytes : num_feature ):
56
43
_ , hard = resource .getrlimit (resource .RLIMIT_AS )
57
44
resource .setrlimit (resource .RLIMIT_AS , (max_ram_bytes * 1024 * 1024 * 1024 , hard ))
@@ -77,15 +64,6 @@ def init_several_3D(a: int, b: int, c: int, default_value: all_types_feature, nb
77
64
def to_bool (s : str ):
78
65
return s .lower () in ['true' , '1' , 't' , 'y' , 'yes' ]
79
66
80
- def features2tensor (features : list , device : str ):
81
- for f in features :
82
- if isinstance (f , bool ):
83
- f = to_binary (f )
84
- return torch .tensor ([[f for f in features ]], dtype = torch .float , device = device )
85
-
86
- def id2tensor (id1 : int , id2 : int , device : str ):
87
- return torch .tensor ([[id1 ], [id2 ]], dtype = torch .long , device = device )
88
-
89
67
def search_object_by_id (objects : list [generic_object ], id : int ):
90
68
for obj in objects :
91
69
if obj ['id' ] == id :
0 commit comments