3
3
import numpy as np
4
4
import pandas as pd
5
5
import scipy .sparse as sp
6
- import torch
7
6
8
7
modALinput = Union [sp .csr_matrix , pd .DataFrame , np .ndarray , list ]
9
8
@@ -26,8 +25,6 @@ def data_vstack(blocks: Sequence[modALinput]) -> modALinput:
26
25
return np .concatenate (blocks )
27
26
elif isinstance (blocks [0 ], list ):
28
27
return np .concatenate (blocks ).tolist ()
29
- elif torch .is_tensor (blocks [0 ]):
30
- return torch .cat (blocks )
31
28
32
29
raise TypeError ('%s datatype is not supported' % type (blocks [0 ]))
33
30
@@ -50,8 +47,6 @@ def data_hstack(blocks: Sequence[modALinput]) -> modALinput:
50
47
return np .hstack (blocks )
51
48
elif isinstance (blocks [0 ], list ):
52
49
return np .hstack (blocks ).tolist ()
53
- elif torch .is_tensor (blocks [0 ]):
54
- return torch .cat (blocks , dim = 1 )
55
50
56
51
TypeError ('%s datatype is not supported' % type (blocks [0 ]))
57
52
@@ -65,8 +60,6 @@ def add_row(X: modALinput, row: modALinput):
65
60
row] """
66
61
if isinstance (X , np .ndarray ):
67
62
return np .vstack ((X , row ))
68
- elif torch .is_tensor (X ):
69
- return torch .cat ((X , row ))
70
63
elif isinstance (X , list ):
71
64
return np .vstack ((X , row )).tolist ()
72
65
@@ -107,8 +100,6 @@ def retrieve_rows(X: modALinput,
107
100
return X_return
108
101
elif isinstance (X , np .ndarray ):
109
102
return X [I ]
110
- elif torch .is_tensor (X ):
111
- return X [I ]
112
103
113
104
raise TypeError ('%s datatype is not supported' % type (X ))
114
105
@@ -128,9 +119,6 @@ def drop_rows(X: modALinput,
128
119
return np .delete (X , I , axis = 0 )
129
120
elif isinstance (X , list ):
130
121
return np .delete (X , I , axis = 0 ).tolist ()
131
- elif torch .is_tensor (X ):
132
- return X [[True if row not in I else False
133
- for row in range (X .size (0 ))]]
134
122
135
123
raise TypeError ('%s datatype is not supported' % type (X ))
136
124
@@ -149,8 +137,8 @@ def enumerate_data(X: modALinput):
149
137
return enumerate (X .tocsr ())
150
138
elif isinstance (X , pd .DataFrame ):
151
139
return X .iterrows ()
152
- elif isinstance (X , np .ndarray ) or isinstance (X , list ) or torch . is_tensor ( X ) :
153
- # numpy arrays, torch tensors and lists can readily be enumerated
140
+ elif isinstance (X , np .ndarray ) or isinstance (X , list ):
141
+ # numpy arrays and lists can readily be enumerated
154
142
return enumerate (X )
155
143
156
144
raise TypeError ('%s datatype is not supported' % type (X ))
@@ -165,7 +153,5 @@ def data_shape(X: modALinput):
165
153
return X .shape
166
154
elif isinstance (X , list ):
167
155
return np .array (X ).shape
168
- elif torch .is_tensor (X ):
169
- return tuple (X .size ())
170
156
171
157
raise TypeError ('%s datatype is not supported' % type (X ))
0 commit comments