MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / SparseVector

Class SparseVector

lib/sqlalchemy/dialects/oracle/vector.py:201–231  ·  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

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

Callers 2

processMethod · 0.85

Calls

no outgoing calls

Tested by 1