Skip to content

New to tensor databases #123408

May 11, 2024 · 4 comments · 3 replies
Discussion options

You must be logged in to vote

import numpy as np
import sqlite3

class TensorDB:
def init(self, db_file):
self.conn = sqlite3.connect(db_file)
self.cursor = self.conn.cursor()
self._create_tables()

def _create_tables(self):
    self.cursor.execute("""
        CREATE TABLE Tensors (
            id INTEGER PRIMARY KEY,
            name TEXT,
            shape TEXT,
            data BLOB
        )
    """)
    self.conn.commit()

def store_tensor(self, name, tensor):
    shape = tensor.shape
    data = tensor.tobytes()
    self.cursor.execute("""
        INSERT INTO Tensors (name, shape, data) VALUES (?, ?, ?)
    """, (name, str(shape), data))
    self.conn.commit()

def retrieve_tensor(self, name):
    self.cursor.execu…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@AElnamaki
Comment options

Answer selected by tachochain
Comment options

You must be logged in to vote
1 reply
@AElnamaki
Comment options

This comment was marked as off-topic.

@Helloworldexampledotcom

This comment was marked as off-topic.

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants