Convert sparse matrix to tuple representation.
(sparse_mx)
| 91 | |
| 92 | |
| 93 | def sparse_to_tuple(sparse_mx): |
| 94 | """Convert sparse matrix to tuple representation.""" |
| 95 | def to_tuple(mx): |
| 96 | if not sp.isspmatrix_coo(mx): |
| 97 | mx = mx.tocoo() |
| 98 | coords = np.vstack((mx.row, mx.col)).transpose() |
| 99 | values = mx.data |
| 100 | shape = mx.shape |
| 101 | return coords, values, shape |
| 102 | |
| 103 | if isinstance(sparse_mx, list): |
| 104 | for i in range(len(sparse_mx)): |
| 105 | sparse_mx[i] = to_tuple(sparse_mx[i]) |
| 106 | else: |
| 107 | sparse_mx = to_tuple(sparse_mx) |
| 108 | |
| 109 | return sparse_mx |
| 110 | |
| 111 | |
| 112 | def preprocess_features(features): |
no test coverage detected