Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jcarpent/eigenpy
  • gsaurel/eigenpy
  • stack-of-tasks/eigenpy
3 results
Show changes
Showing
with 504 additions and 76 deletions
from __future__ import print_function
import numpy as np import numpy as np
from complex import switchToNumpyArray, real, imag, ascomplex from complex import ascomplex, imag, real
switchToNumpyArray()
rows = 10 rows = 10
cols = 20 cols = 20
rng = np.random.default_rng()
def test(dtype): def test(dtype):
Z = np.zeros((rows, cols), dtype=dtype) Z = np.zeros((rows, cols), dtype=dtype)
Z.real = np.random.rand(rows, cols) Z.real = rng.random((rows, cols))
Z.imag = np.random.rand(rows, cols) Z.imag = rng.random((rows, cols))
Z_real = real(Z) Z_real = real(Z)
assert (Z_real == Z.real).all() assert (Z_real == Z.real).all()
......
from deprecation_policy import (
X,
some_deprecated_function,
some_future_deprecated_function,
)
some_deprecated_function()
some_future_deprecated_function()
X().deprecated_member_function()
from __future__ import print_function
import eigenpy import eigenpy
quat = eigenpy.Quaternion() quat = eigenpy.Quaternion()
# By default, we convert as numpy.matrix
eigenpy.switchToNumpyMatrix()
coeffs_vector = quat.coeffs()
assert len(coeffs_vector.shape) == 2
# Switch to numpy.array # Switch to numpy.array
eigenpy.switchToNumpyArray()
coeffs_vector = quat.coeffs() coeffs_vector = quat.coeffs()
assert len(coeffs_vector.shape) == 1 assert len(coeffs_vector.shape) == 1
import numpy as np import numpy as np
from eigen_ref import ( from eigen_ref import (
printMatrix,
getRefToStatic,
asRef,
asConstRef, asConstRef,
asRef,
copyRowVectorFromConstRef,
copyVectorFromConstRef,
editBlock,
fill, fill,
getBlock, getBlock,
editBlock, getRefToStatic,
modify_block,
has_ref_member, has_ref_member,
copyVectorFromConstRef, modify_block,
copyRowVectorFromConstRef, printMatrix,
) )
...@@ -60,7 +60,7 @@ def test_read_block(): ...@@ -60,7 +60,7 @@ def test_read_block():
def test_create_ref(mat): def test_create_ref(mat):
print("[asRef(mat)]") print("[asRef(mat)]")
ref = asRef(mat) ref = asRef(mat)
assert np.array_equal(ref, mat), "ref=\n{}\nmat=\n{}".format(ref, mat) assert np.array_equal(ref, mat), f"ref=\n{ref}\nmat=\n{mat}"
assert not (ref.flags.owndata) assert not (ref.flags.owndata)
assert ref.flags.writeable assert ref.flags.writeable
...@@ -68,7 +68,7 @@ def test_create_ref(mat): ...@@ -68,7 +68,7 @@ def test_create_ref(mat):
def test_create_const_ref(mat): def test_create_const_ref(mat):
print("[asConstRef]") print("[asConstRef]")
const_ref = asConstRef(mat) const_ref = asConstRef(mat)
assert np.array_equal(const_ref, mat), "ref=\n{}\nmat=\n{}".format(const_ref, mat) assert np.array_equal(const_ref, mat), f"ref=\n{const_ref}\nmat=\n{mat}"
assert not (const_ref.flags.writeable) assert not (const_ref.flags.writeable)
assert not (const_ref.flags.owndata) assert not (const_ref.flags.owndata)
...@@ -79,11 +79,11 @@ def test_edit_block(rows, cols): ...@@ -79,11 +79,11 @@ def test_edit_block(rows, cols):
mat[:, :] = np.arange(rows * cols).reshape(rows, cols) mat[:, :] = np.arange(rows * cols).reshape(rows, cols)
mat0 = mat.copy() mat0 = mat.copy()
for i, rowsize, colsize in ([0, 3, 2], [1, 1, 2], [0, 3, 1]): for i, rowsize, colsize in ([0, 3, 2], [1, 1, 2], [0, 3, 1]):
print("taking block [{}:{}, {}:{}]".format(i, rowsize + i, 0, colsize)) print(f"taking block [{i}:{rowsize + i}, {0}:{colsize}]")
B = getBlock(mat, i, 0, rowsize, colsize) B = getBlock(mat, i, 0, rowsize, colsize)
B = B.reshape(rowsize, colsize) B = B.reshape(rowsize, colsize)
lhs = mat[i : rowsize + i, :colsize] lhs = mat[i : rowsize + i, :colsize]
assert np.array_equal(lhs, B), "got lhs\n{}\nrhs B=\n{}".format(lhs, B) assert np.array_equal(lhs, B), f"got lhs\n{lhs}\nrhs B=\n{B}"
B[:] = 1.0 B[:] = 1.0
rhs = np.ones((rowsize, colsize)) rhs = np.ones((rowsize, colsize))
...@@ -100,9 +100,6 @@ def test_edit_block(rows, cols): ...@@ -100,9 +100,6 @@ def test_edit_block(rows, cols):
assert np.array_equal(mat, mat_copy) assert np.array_equal(mat, mat_copy)
class ModifyBlockImpl(modify_block): class ModifyBlockImpl(modify_block):
def __init__(self):
super(ModifyBlockImpl, self).__init__()
def call(self, mat): def call(self, mat):
n, m = mat.shape n, m = mat.shape
mat[:, :] = np.arange(n * m).reshape(n, m) mat[:, :] = np.arange(n * m).reshape(n, m)
......
import numpy as np import numpy as np
import eigenpy
eigenpy.switchToNumpyArray() import eigenpy
dim = 100 dim = 100
A = np.random.rand(dim, dim) rng = np.random.default_rng()
A = rng.random((dim, dim))
es = eigenpy.EigenSolver(A) es = eigenpy.EigenSolver(A)
......
from __future__ import print_function import numpy as np
from geometry import ( from geometry import (
AngleAxis, AngleAxis,
Quaternion, Quaternion,
testOutAngleAxis,
testInAngleAxis, testInAngleAxis,
testOutQuaternion,
testInQuaternion, testInQuaternion,
testOutAngleAxis,
testOutQuaternion,
) )
import numpy as np
from numpy import cos from numpy import cos
verbose = True verbose = True
......
import eigenpy
ldlt1 = eigenpy.LDLT()
ldlt2 = eigenpy.LDLT()
id1 = ldlt1.id()
id2 = ldlt2.id()
assert id1 != id2
assert id1 == ldlt1.id()
assert id2 == ldlt2.id()
from __future__ import print_function import platform
import numpy as np
import matrix as eigenpy import matrix as eigenpy
import numpy as np
verbose = True verbose = True
...@@ -182,3 +182,167 @@ assert (eigenpy.asRowMajorFromColMajorMatrix(vec) == vec).all() ...@@ -182,3 +182,167 @@ assert (eigenpy.asRowMajorFromColMajorMatrix(vec) == vec).all()
assert (eigenpy.asRowMajorFromColMajorVector(vec) == vec).all() assert (eigenpy.asRowMajorFromColMajorVector(vec) == vec).all()
assert (eigenpy.asRowMajorFromRowMajorMatrix(vec) == vec).all() assert (eigenpy.asRowMajorFromRowMajorMatrix(vec) == vec).all()
assert (eigenpy.asRowMajorFromRowMajorVector(vec) == vec).all() assert (eigenpy.asRowMajorFromRowMajorVector(vec) == vec).all()
# Test numpy -> Eigen -> numpy for all same type
def test_conversion(function, dtype):
input_array = np.array([1, 0], dtype=dtype)
assert input_array.dtype == dtype
output_array = function(input_array)
assert output_array.dtype == dtype
assert (output_array == input_array).all()
bool_t = np.dtype(np.bool_)
int8_t = np.dtype(np.int8)
uint8_t = np.dtype(np.uint8)
int16_t = np.dtype(np.int16)
uint16_t = np.dtype(np.uint16)
int32_t = np.dtype(np.int32)
uint32_t = np.dtype(np.uint32)
int64_t = np.dtype(np.int64)
uint64_t = np.dtype(np.uint64)
# On Windows long is a 32 bits integer but is a different type than int32.
long_t = np.dtype(np.int32 if platform.system() == "Windows" else np.int64)
ulong_t = np.dtype(np.uint32 if platform.system() == "Windows" else np.uint64)
longlong_t = np.dtype(np.longlong)
ulonglong_t = np.dtype(np.ulonglong)
float32_t = np.dtype(np.float32)
float64_t = np.dtype(np.float64)
complex64_t = np.dtype(np.complex64)
complex128_t = np.dtype(np.complex128)
complex256_t = np.dtype(np.clongdouble)
test_conversion(eigenpy.copyBoolToBool, bool_t)
test_conversion(eigenpy.copyInt8ToInt8, int8_t)
test_conversion(eigenpy.copyCharToChar, int8_t)
test_conversion(eigenpy.copyUCharToUChar, uint8_t)
test_conversion(eigenpy.copyInt16ToInt16, int16_t)
test_conversion(eigenpy.copyUInt16ToUInt16, uint16_t)
test_conversion(eigenpy.copyInt32ToInt32, int32_t)
test_conversion(eigenpy.copyUInt32ToUInt32, uint32_t)
test_conversion(eigenpy.copyInt64ToInt64, int64_t)
test_conversion(eigenpy.copyUInt64ToUInt64, uint64_t)
test_conversion(eigenpy.copyLongToLong, long_t)
test_conversion(eigenpy.copyULongToULong, ulong_t)
# On Windows long long is an int64_t alias.
# The numpy dtype match between longlong and int64.
# On Linux long long is a 64 bits integer but is a different type than int64_t.
# The numpy dtype doesn't match and it's not an issue since C++ type are different.
# On Mac long long is an int64_t and long alias.
# This is an issue because longlong numpy dtype is different than long numpy dtype
# but long and long long are the same type in C++.
# The test should pass thanks to the promotion code.
test_conversion(eigenpy.copyLongLongToLongLong, longlong_t)
test_conversion(eigenpy.copyULongLongToULongLong, ulonglong_t)
test_conversion(eigenpy.copyFloatToFloat, float32_t)
test_conversion(eigenpy.copyDoubleToDouble, float64_t)
# On Windows and Mac longdouble is 64 bits
test_conversion(eigenpy.copyLongDoubleToLongDouble, np.dtype(np.longdouble))
test_conversion(eigenpy.copyCFloatToCFloat, complex64_t)
test_conversion(eigenpy.copyCDoubleToCDouble, complex128_t)
# On Windows and Mac clongdouble is 128 bits
test_conversion(eigenpy.copyCLongDoubleToCLongDouble, complex256_t)
# Test numpy -> Eigen -> numpy promotion
def test_conversion_promotion(function, input_dtype, output_dtype):
input_array = np.array([1, 0], dtype=input_dtype)
assert input_array.dtype == input_dtype
output_array = function(input_array)
assert output_array.dtype == output_dtype
assert (output_array == input_array).all()
# Test bool to other type
test_conversion_promotion(eigenpy.copyInt8ToInt8, bool_t, int8_t)
test_conversion_promotion(eigenpy.copyUCharToUChar, bool_t, uint8_t)
test_conversion_promotion(eigenpy.copyInt16ToInt16, bool_t, int16_t)
test_conversion_promotion(eigenpy.copyUInt16ToUInt16, bool_t, uint16_t)
test_conversion_promotion(eigenpy.copyInt32ToInt32, bool_t, int32_t)
test_conversion_promotion(eigenpy.copyUInt32ToUInt32, bool_t, uint32_t)
test_conversion_promotion(eigenpy.copyInt64ToInt64, bool_t, int64_t)
test_conversion_promotion(eigenpy.copyUInt64ToUInt64, bool_t, uint64_t)
test_conversion_promotion(eigenpy.copyLongToLong, bool_t, long_t)
test_conversion_promotion(eigenpy.copyULongToULong, bool_t, ulong_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, bool_t, int64_t)
test_conversion_promotion(eigenpy.copyULongLongToULongLong, bool_t, uint64_t)
# Test int8 to other type
test_conversion_promotion(eigenpy.copyInt16ToInt16, int8_t, int16_t)
test_conversion_promotion(eigenpy.copyInt16ToInt16, uint8_t, int16_t)
test_conversion_promotion(eigenpy.copyUInt16ToUInt16, uint8_t, uint16_t)
test_conversion_promotion(eigenpy.copyInt32ToInt32, int8_t, int32_t)
test_conversion_promotion(eigenpy.copyInt32ToInt32, uint8_t, int32_t)
test_conversion_promotion(eigenpy.copyUInt32ToUInt32, uint8_t, uint32_t)
test_conversion_promotion(eigenpy.copyInt64ToInt64, int8_t, int64_t)
test_conversion_promotion(eigenpy.copyInt64ToInt64, uint8_t, int64_t)
test_conversion_promotion(eigenpy.copyUInt64ToUInt64, uint8_t, uint64_t)
test_conversion_promotion(eigenpy.copyLongToLong, int8_t, long_t)
test_conversion_promotion(eigenpy.copyLongToLong, uint8_t, long_t)
test_conversion_promotion(eigenpy.copyULongToULong, uint8_t, ulong_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, int8_t, int64_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, uint8_t, int64_t)
test_conversion_promotion(eigenpy.copyULongLongToULongLong, uint8_t, uint64_t)
# Test int16 to other type
test_conversion_promotion(eigenpy.copyInt32ToInt32, int16_t, int32_t)
test_conversion_promotion(eigenpy.copyInt32ToInt32, uint16_t, int32_t)
test_conversion_promotion(eigenpy.copyUInt32ToUInt32, uint16_t, uint32_t)
test_conversion_promotion(eigenpy.copyInt64ToInt64, int16_t, int64_t)
test_conversion_promotion(eigenpy.copyInt64ToInt64, uint16_t, int64_t)
test_conversion_promotion(eigenpy.copyUInt64ToUInt64, uint16_t, uint64_t)
test_conversion_promotion(eigenpy.copyLongToLong, int16_t, long_t)
test_conversion_promotion(eigenpy.copyLongToLong, uint16_t, long_t)
test_conversion_promotion(eigenpy.copyULongToULong, uint16_t, ulong_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, int16_t, int64_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, uint16_t, int64_t)
test_conversion_promotion(eigenpy.copyULongLongToULongLong, uint16_t, uint64_t)
# Test int32 to other type
test_conversion_promotion(eigenpy.copyInt64ToInt64, int32_t, int64_t)
test_conversion_promotion(eigenpy.copyInt64ToInt64, uint32_t, int64_t)
test_conversion_promotion(eigenpy.copyUInt64ToUInt64, uint32_t, uint64_t)
test_conversion_promotion(eigenpy.copyLongToLong, int32_t, long_t)
test_conversion_promotion(eigenpy.copyLongToLong, uint32_t, long_t)
test_conversion_promotion(eigenpy.copyULongToULong, uint32_t, ulong_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, int32_t, int64_t)
test_conversion_promotion(eigenpy.copyLongLongToLongLong, uint32_t, int64_t)
test_conversion_promotion(eigenpy.copyULongLongToULongLong, uint32_t, uint64_t)
# Test float to double
test_conversion_promotion(eigenpy.copyDoubleToDouble, float32_t, float64_t)
# Test complex to other type
test_conversion_promotion(eigenpy.copyCDoubleToCDouble, complex64_t, complex128_t)
test_conversion_promotion(
eigenpy.copyCLongDoubleToCLongDouble,
complex64_t,
complex256_t,
)
# Only Linux store complex double into 258 bits.
# Then, 128 bits complex can be promoted.
if platform.system() == "Linux":
test_conversion_promotion(
eigenpy.copyCLongDoubleToCLongDouble,
complex128_t,
complex256_t,
)
import multiple_registration # noqa
import numpy as np
import return_by_ref import return_by_ref
from return_by_ref import Matrix, RowMatrix, Vector from return_by_ref import Matrix, RowMatrix, Vector
import numpy as np
def test_shared(mat): def test_shared(mat):
......
import eigenpy
import numpy as np import numpy as np
eigenpy.switchToNumpyArray() import eigenpy
dim = 100 dim = 100
A = np.random.rand(dim, dim) rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 A = (A + A.T) * 0.5
es = eigenpy.SelfAdjointEigenSolver(A) es = eigenpy.SelfAdjointEigenSolver(A)
......
import numpy as np
import sparse_matrix
from scipy.sparse import csr_matrix
m = sparse_matrix.emptyMatrix()
assert m.shape == (0, 0)
v = sparse_matrix.emptyVector()
assert v.shape == (0, 0)
m = sparse_matrix.matrix1x1(2)
assert m.toarray() == np.array([2])
v = sparse_matrix.vector1x1(2)
assert v.toarray() == np.array([2])
rng = np.random.default_rng()
diag_values = rng.random(10)
diag_mat = sparse_matrix.diagonal(diag_values)
assert (diag_mat.toarray() == np.diag(diag_values)).all()
diag_mat_copy = sparse_matrix.copy(diag_mat)
assert (diag_mat_copy != diag_mat).nnz == 0
diag_mat_csr = csr_matrix(diag_mat)
assert (sparse_matrix.copy(diag_mat_csr) != diag_mat_csr).nnz == 0
# test zero matrix
zero_mat = csr_matrix(np.zeros((10, 1)))
zero_mat_copy = sparse_matrix.copy(zero_mat)
assert (zero_mat_copy != zero_mat).nnz == 0
import std_array
ints = std_array.get_arr_3_ints()
print(ints[0])
print(ints[1])
print(ints[2])
print(ints.tolist())
assert ints.tolist() == [1, 2, 3]
_ints_slice = ints[1:3]
print("Printing slice...")
for el in _ints_slice:
print(el)
ref = [1, 2, 3]
assert len(ref[1:2]) == 1 # sanity check
assert len(_ints_slice) == 2, f"Slice size should be 1, got {len(_ints_slice)}"
assert _ints_slice[0] == 2
assert _ints_slice[1] == 3
# Test that insert/delete is impossible with the slice operator
# prepend
try:
ints[0:0] = [0, 1]
except NotImplementedError:
pass
else:
assert False, "Insert value with slice operator should be impossible"
# append
try:
ints[10:12] = [0]
except NotImplementedError:
pass
else:
assert False, "Insert value with slice operator should be impossible"
# append
try:
ints[3:3] = [0]
except NotImplementedError:
pass
else:
assert False, "Insert value with slice operator should be impossible"
# Erase two elements and replace by one
try:
ints[1:3] = [0]
except NotImplementedError:
pass
else:
assert False, "Insert value with slice operator should be impossible"
# Erase two elements and replace by three
try:
ints[1:3] = [0, 1, 2]
except NotImplementedError:
pass
else:
assert False, "Insert value with slice operator should be impossible"
# Test that delete operator is not implemented
# Index delete
try:
del ints[0]
except NotImplementedError:
pass
else:
assert False, "del is not implemented"
# Slice delete
try:
del ints[1:3]
except NotImplementedError:
pass
else:
assert False, "del is not implemented"
# Slice delete
try:
del ints[1:3]
except NotImplementedError:
pass
else:
assert False, "del is not implemented"
# Test that append/extend are not implemented
# append
try:
ints.append(4)
except AttributeError:
pass
else:
assert False, "append is not implemented"
# extend
try:
ints.extend([4, 5])
except AttributeError:
pass
else:
assert False, "extend is not implemented"
# Test set_slice nominal case
ints[1:3] = [10, 20]
assert ints[1] == 10
assert ints[2] == 20
# print(ints.tolist())
vecs = std_array.get_arr_3_vecs()
assert len(vecs) == 3
print(vecs[0])
print(vecs[1])
print(vecs[2])
# slices do not work for Eigen objects...
# v2 = vecs[:]
# assert isinstance(v2, std_array.StdVec_VectorXd)
# assert len(v2) == 3
# print(v2.tolist())
# print(v2[0])
ts = std_array.test_struct()
assert len(ts.integs) == 3
assert len(ts.vecs) == 2
print(ts.integs[:].tolist())
print(ts.vecs[0])
print(ts.vecs[1])
ts.integs[:] = 111
print("Test of set_slice for std::array<int>:", ts.integs[:].tolist())
for el in ts.integs:
assert el == 111
ts.vecs[0][0] = 0.0
ts.vecs[1][0] = -243
print(ts.vecs[0])
print(ts.vecs[1])
from std_map import X, copy, copy_boost, copy_X, std_map_to_dict
t = {"one": 1.0, "two": 2.0}
t2 = {"one": 1, "two": 2, "three": 3}
assert std_map_to_dict(t) == t
assert std_map_to_dict(copy(t)) == t
m = copy_boost(t2)
assert m.todict() == t2
xmap_cpp = copy_X({"one": X(1), "two": X(2)})
print(xmap_cpp.todict())
x1 = xmap_cpp["one"]
x1.val = 11
print(xmap_cpp.todict())
assert xmap_cpp["one"].val == 11
assert xmap_cpp["two"].val == 2
from std_pair import copy, passthrough, std_pair_to_tuple
t = (1, 2.0)
assert std_pair_to_tuple(t) == t
assert copy(t) == t
assert passthrough(t) == t
from std_unique_ptr import (
V1,
UniquePtrHolder,
make_unique_complex,
make_unique_int,
make_unique_null,
make_unique_str,
make_unique_v1,
)
v = make_unique_int()
assert isinstance(v, int)
assert v == 10
v = make_unique_v1()
assert isinstance(v, V1)
assert v.v == 10
v = make_unique_null()
assert v is None
v = make_unique_str()
assert isinstance(v, str)
assert v == "str"
v = make_unique_complex()
assert isinstance(v, complex)
assert v == 1 + 0j
unique_ptr_holder = UniquePtrHolder()
v = unique_ptr_holder.int_ptr
assert isinstance(v, int)
assert v == 20
# v is a copy, int_ptr will not be updated
v = 10
assert unique_ptr_holder.int_ptr == 20
v = unique_ptr_holder.v1_ptr
assert isinstance(v, V1)
assert v.v == 200
# v is a ref, v1_ptr will be updated
v.v = 10
assert unique_ptr_holder.v1_ptr.v == 10
v = unique_ptr_holder.null_ptr
assert v is None
v = unique_ptr_holder.str_ptr
assert isinstance(v, str)
assert v == "str"
# v is a copy, str_ptr will not be updated
v = "str_updated"
assert unique_ptr_holder.str_ptr == "str"
v = unique_ptr_holder.complex_ptr
assert isinstance(v, complex)
assert v == 1 + 0j
# v is a copy, complex_ptr will not be updated
v = 1 + 2j
assert unique_ptr_holder.complex_ptr == 1 + 0j
import numpy as np
import eigenpy
import inspect
import pprint import pprint
import numpy as np
import std_vector import std_vector
from std_vector import printVectorOfMatrix, printVectorOf3x3, copyStdVector from std_vector import copyStdVector, printVectorOf3x3, printVectorOfMatrix
np.random.seed(0) import eigenpy
l1 = [np.random.randn(3), np.random.randn(2)] rng = np.random.default_rng(0)
l1 = [rng.standard_normal(3), rng.standard_normal(2)]
l2 = eigenpy.StdVec_VectorXd(l1) l2 = eigenpy.StdVec_VectorXd(l1)
l3 = [np.random.randn(2, 2), np.random.randn(3, 1)] l3 = [rng.standard_normal((2, 2)), rng.standard_normal((3, 1))]
l3.append(np.asfortranarray(np.eye(2))) l3.append(np.asfortranarray(np.eye(2)))
l3.append(np.eye(2)) l3.append(np.eye(2))
l4 = [np.random.randn(3, 3).T for _ in range(3)] l4 = [rng.standard_normal((3, 3)).T for _ in range(3)]
l4[-1] = l4[-1].T l4[-1] = l4[-1].T
l5 = [rng.standard_normal((2, 2)).T for _ in range(3)]
def checkAllValues(li1, li2): def checkAllValues(li1, li2):
...@@ -47,9 +49,9 @@ l4_copy2 = std_vector.copyStdVec_3x3(l4) ...@@ -47,9 +49,9 @@ l4_copy2 = std_vector.copyStdVec_3x3(l4)
assert isinstance(l4_copy2, std_vector.StdVec_Mat3d) assert isinstance(l4_copy2, std_vector.StdVec_Mat3d)
def checkZero(l): def checkZero(v):
for x in l: for x in v:
assert np.allclose(x, 0.0), "x = {}".format(x) assert np.allclose(x, 0.0), f"x = {x}"
print("Check setZero() works:") print("Check setZero() works:")
...@@ -83,3 +85,16 @@ print("-----------------") ...@@ -83,3 +85,16 @@ print("-----------------")
# vector.setZero(l4) # vector.setZero(l4)
# pprint.pprint(list(l4)) # pprint.pprint(list(l4))
# checkZero(l4) # checkZero(l4)
# Test StdVec_Mat2d that had been registered
# before calling exposeStdVectorEigenSpecificType
# Test conversion and tolistl5 == l5_copy == l5_py
l5_copy = std_vector.StdVec_Mat2d(l5)
l5_py = l5_copy.tolist()
checkAllValues(l5, l5_copy)
checkAllValues(l5, l5_py)
# Test mutable __getitem__
l5[0][:] = 0.0
assert np.allclose(l5[0], 0.0)
from __future__ import print_function
import eigenpy
import numpy as np
eigenpy.switchToNumpyMatrix()
quat = eigenpy.Quaternion()
# By default, we convert as numpy.matrix
coeffs_vector = quat.coeffs()
print(type(coeffs_vector))
assert isinstance(coeffs_vector, np.matrixlib.defmatrix.matrix)
assert eigenpy.getNumpyType() == np.matrix
# Switch to numpy.array
eigenpy.switchToNumpyArray()
coeffs_array = quat.coeffs()
print(type(coeffs_array))
assert isinstance(coeffs_vector, np.ndarray)
assert eigenpy.getNumpyType() == np.ndarray
import numpy as np import numpy as np
import tensor import tensor
dim = np.array([10, 20, 30], dtype=np.int32) dim = np.array([10, 20, 30], dtype=np.int64)
t = tensor.TensorContainer3(dim) t = tensor.TensorContainer3(dim)
r = t.get_ref() r = t.get_ref()
r[:] = 0.0 r[:] = 0.0
......
import type_info
d = type_info.Dummy()
assert "Dummy" in d.type_info().pretty_name()
assert type_info.type_info(1).pretty_name() == "int"
assert "basic_string" in type_info.type_info("toto").pretty_name()