示例#1
0
def test_ArrayStore_get_view():
    """Tests for ArrayStore class.get_view()."""
    sample = np.asarray(np.random.uniform(-1, 1, size=100), order='F')
    arraystore = carma.dArrayStore(sample, True)
    arr = arraystore.get_view(False)
    assert arr.flags['OWNDATA'] is False
    np.testing.assert_allclose(arr.flatten(), sample)
示例#2
0
def test_ArrayStore_writeable():
    """Test ArrayStore class when marked as writeable."""
    sample = np.asarray(np.random.uniform(-1, 1, size=100), order='F')
    arraystore = carma.dArrayStore(sample, True)
    arr = arraystore.get_view(True)
    assert arr.flags['OWNDATA'] is False
    assert arr.flags['WRITEABLE'] is True
    arr[0, 0] = 1.0
示例#3
0
def test_ArrayStore_non_writeable():
    """Test ArrayStore class when marked as non-readable."""
    sample = np.asarray(np.random.uniform(-1, 1, size=100), order='F')
    arraystore = carma.dArrayStore(sample, True)
    arr = arraystore.get_view(False)
    assert arr.flags['OWNDATA'] is False
    assert arr.flags['WRITEABLE'] is False
    with pytest.raises(ValueError):
        arr[0, 0] = 1.0
示例#4
0
def test_ArrayStore_set_data_flags():
    """Test ArrayStore class function set_data."""
    sample1 = np.asarray(np.random.uniform(-1, 1, size=100), order='F')
    sample2 = np.asarray(np.random.uniform(-1, 1, size=100), order='F')

    arraystore = carma.dArrayStore(sample1, True)
    arr = arraystore.get_view(True)
    assert arr.flags['OWNDATA'] is False
    assert arr.flags['WRITEABLE'] is True

    arraystore.set_array(sample2, True)
    arr = arraystore.get_view(False)
    assert arr.flags['OWNDATA'] is False
    assert arr.flags['WRITEABLE'] is False
示例#5
0
def test_ArrayStore_steal():
    """Test ArrayStore class when we steal the memory."""
    og_sample = np.asarray(np.random.uniform(-1, 1, size=100), order='F')
    sample = og_sample.copy()

    arraystore = carma.dArrayStore(sample, False)
    arr = arraystore.get_view(True)
    np.testing.assert_allclose(arr.flatten(), og_sample)

    # trigger destructor
    arraystore = None
    del arraystore
    arr = None
    del arr
示例#6
0
def test_ArrayStore_set_data():
    """Test ArrayStore class function set_data."""
    sample1 = np.random.uniform(-1, 1, size=100)
    sample2 = np.random.uniform(-1, 1, size=100)

    arraystore = carma.dArrayStore(sample1, True)
    arr = arraystore.get_view(True)
    np.testing.assert_allclose(arr.flatten(), sample1)

    arraystore.set_data(sample2, True)
    arr = arraystore.get_view(True)
    np.testing.assert_allclose(arr.flatten(), sample2)
    assert arr.flags['OWNDATA'] is False
    assert arr.flags['WRITEABLE'] is True
示例#7
0
def test_ArrayStore_copy():
    """Test ArrayStore class when not stealing."""
    og_sample = np.asarray(np.random.uniform(-1, 1, size=100), order='F')
    sample = og_sample.copy()

    arraystore = carma.dArrayStore(sample, True)
    arr = arraystore.get_view(False)
    np.testing.assert_allclose(arr.flatten(), og_sample)

    # trigger descructor
    arraystore = None
    del arraystore
    arr = None
    del arr
    # Validate the memory of sample is untouched
    assert np.allclose(sample, og_sample)