Commit 99805385 authored by Marvin Teichmann's avatar Marvin Teichmann
Browse files

Automating tests for eigen libary.

parent e668c4db
import numpy as np import numpy as np
import eigen as e import eigen as e
V = np.random.randn(3).astype(np.float32) import pytest
M = np.random.randn(3,3).astype(np.float32)
foo = e.vectorXf(V)
assert np.all(np.array(foo) == V)
foo = e.matrixXf(M) def test_vector_conversion():
assert np.all(np.array(foo) == M) np_vector = np.random.randn(3).astype(np.float32)
c_vector = e.vectorXf(np_vector)
assert np.all(np.array(c_vector) == np_vector)
def test_matrix_conversion():
np_matrix = np.random.randn(3, 3).astype(np.float32)
assert(np_matrix.ndim == 2)
c_matrix = e.matrixXf(np_matrix)
assert np.all(np.array(c_matrix) == np_matrix)
def test_wrong_dims():
np_matrix = np.random.randn(3, 3, 3).astype(np.float32)
assert(np_matrix.ndim == 3)
# c_matrix only supports ndim == 2
with pytest.raises(ValueError):
# Check whether a Value Error is raised
e.matrixXf(np_matrix)
def test_wrong_type():
np_matrix = np.random.randn(3, 3, 3).astype(np.float64)
# c_matrix requies type np.float32
with pytest.raises(ValueError):
# Check whether a Value Error is raised
e.matrixXf(np_matrix)
def test_none_type():
np_matrix = None
with pytest.raises(TypeError):
# Check whether a Value Error is raised
e.matrixXf(np_matrix)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment