MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / SparseVector

Class SparseVector

lib/sqlalchemy/dialects/oracle/vector.py:202–232  ·  view source on GitHub ↗

Lightweight SQLAlchemy-side version of SparseVector. This mimics oracledb.SparseVector. .. versionadded:: 2.0.43

Source from the content-addressed store, hash-verified

200
201
202class 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
235class VECTOR(types.TypeEngine):

Callers 2

processMethod · 0.85

Calls

no outgoing calls

Tested by 1