Ejemplo n.º 1
0
def test_generic():
    from jina.proto.ndarray.generic import GenericNdArray
    from scipy.sparse import coo_matrix

    row = np.array([0, 3, 1, 0])
    col = np.array([0, 3, 1, 2])
    data = np.array([4, 5, 7, 9])
    a = coo_matrix((data, (row, col)), shape=(4, 4))
    dense_a = a.toarray()

    b = GenericNdArray(is_sparse=True)

    b.value = a

    dense_b = b.value.toarray()
    np.testing.assert_equal(dense_b, dense_a)

    c = np.random.random([10, 3, 4])

    # without change of `is_sparse`, this should raise error
    with pytest.raises(AttributeError):
        b.value = c
    b.is_sparse = False
    b.value = c

    np.testing.assert_equal(b.value, c)
Ejemplo n.º 2
0
def test_array2pb():
    # i don't understand why is this set?
    # os env should be available to that process-context only
    if 'JINA_ARRAY_QUANT' in os.environ:
        print(f'quant is on: {os.environ["JINA_ARRAY_QUANT"]}')
        del os.environ['JINA_ARRAY_QUANT']

    d = GenericNdArray()
    d.value = e4
    np.testing.assert_almost_equal(d.value, e4)
Ejemplo n.º 3
0
def test_array_protobuf_conversions_with_quantize(quantize, type):
    random_array = np.random.rand(random.randrange(0, 50), random.randrange(0, 20)).astype(type)
    d = GenericNdArray(quantize=quantize)
    d.value = random_array
    np.testing.assert_almost_equal(d.value, random_array, decimal=2)
Ejemplo n.º 4
0
def test_array_protobuf_conversions(type):
    random_array = np.random.rand(random.randrange(0, 50), random.randrange(0, 20)).astype(type)
    d = GenericNdArray()
    d.value = random_array
    np.testing.assert_almost_equal(d.value, random_array)