Lightweight SQLAlchemy-side version of SparseVector. This mimics oracledb.SparseVector. .. versionadded:: 2.0.43
| 200 | |
| 201 | |
| 202 | class SparseVector: |
| 203 | """ |
| 204 | Lightweight SQLAlchemy-side version of SparseVector. |
| 205 | This mimics oracledb.SparseVector. |
| 206 | |
| 207 | .. versionadded:: 2.0.43 |
| 208 | |
| 209 | """ |
| 210 | |
| 211 | def __init__( |
| 212 | self, |
| 213 | num_dimensions: int, |
| 214 | indices: Union[list, array.array], |
| 215 | values: Union[list, array.array], |
| 216 | ): |
| 217 | if not isinstance(indices, array.array) or indices.typecode != "I": |
| 218 | indices = array.array("I", indices) |
| 219 | if not isinstance(values, array.array): |
| 220 | values = array.array("d", values) |
| 221 | if len(indices) != len(values): |
| 222 | raise TypeError("indices and values must be of the same length!") |
| 223 | |
| 224 | self.num_dimensions = num_dimensions |
| 225 | self.indices = indices |
| 226 | self.values = values |
| 227 | |
| 228 | def __str__(self): |
| 229 | return ( |
| 230 | f"SparseVector(num_dimensions={self.num_dimensions}, " |
| 231 | f"size={len(self.indices)}, typecode={self.values.typecode})" |
| 232 | ) |
| 233 | |
| 234 | |
| 235 | class VECTOR(types.TypeEngine): |
no outgoing calls