def test_put_get_dataset(mock_data, use_cluster):
    """test sending and recieving a dataset with 2D tensors
    of every datatype
    """

    data = mock_data.create_data((10, 10))

    # Create a dataset to put
    dataset = Dataset("test-dataset")
    for index, tensor in enumerate(data):
        key = f"tensor_{str(index)}"
        dataset.add_tensor(key, tensor)

    client = Client(None, use_cluster)

    client.put_dataset(dataset)

    rdataset = client.get_dataset("test-dataset")
    for index, tensor in enumerate(data):
        key = f"tensor_{str(index)}"
        rtensor = rdataset.get_tensor(key)
        np.testing.assert_array_equal(
            rtensor,
            tensor,
            "Dataset returned from get_dataset not the same as sent dataset",
        )
def test_add_get_tensor(mock_data):
    """Test adding and retrieving 1D tensors to
    a dataset and with all datatypes
    """
    dataset = Dataset("test-dataset")

    # 1D tensors of all data types
    data = mock_data.create_data(10)
    add_get_arrays(dataset, data)
def test_add_get_strings(mock_data):
    """Test adding and retrieving strings to
    a dataset
    """
    dataset = Dataset("test-dataset")

    # list of strings
    data = mock_data.create_metadata_strings(10)
    add_get_strings(dataset, data)
def test_add_get_tensor_3D(mock_data):
    """Test adding and retrieving 3D tensors to
    a dataset and with all datatypes
    """
    dataset = Dataset("test-dataset")

    # 3D tensors of all datatypes
    data_3D = mock_data.create_data((10, 10, 10))
    add_get_arrays(dataset, data_3D)
示例#5
0
def test_bad_type_add_tensor(use_cluster):
    d = Dataset("test-dataset")
    with pytest.raises(TypeError):
        d.add_tensor("test-tensor", [1, 2, 3])
import numpy as np

from smartredis import Client, Dataset

# Create two arrays to store in the DataSet
data_1 = np.random.randint(-10, 10, size=(10, 10))
data_2 = np.random.randint(-10, 10, size=(20, 8, 2))

# Create a DataSet object and add the two sample tensors
dataset = Dataset("test-dataset")
dataset.add_tensor("tensor_1", data_1)
dataset.add_tensor("tensor_2", data_2)

# Connect SmartRedis client to Redis database
db_address = "127.0.0.1:6379"
client = Client(address=db_address, cluster=False)

# Place the DataSet into the database
client.put_dataset(dataset)

# Retrieve the DataSet from the database
rdataset = client.get_dataset("test-dataset")

# Retrieve a tensor from inside of the fetched
# DataSet
rdata_1 = rdataset.get_tensor("tensor_1")