pybind11/example/example7.py
Jason Rhinelander 7de9f6c72d Tests can skip by exiting with 99; fix eigen test failure
This allows (and changes the current examples) to exit with status 99 to
skip a test instead of outputting a special string ("NumPy missing").

This also fixes the eigen test, which currently fails when eigen
headers are available but NumPy is not, to skip instead of failing when
NumPy isn't available.
2016-07-09 14:33:10 -04:00

33 lines
542 B
Python
Executable File

#!/usr/bin/env python
from __future__ import print_function
import sys
sys.path.append('.')
from example import Matrix
try:
import numpy as np
except ImportError:
# NumPy missing: skip test
exit(99)
m = Matrix(5, 5)
print(m[2, 3])
m[2, 3] = 4
print(m[2, 3])
m2 = np.array(m, copy=False)
print(m2)
print(m2[2, 3])
m2[2, 3] = 5
print(m[2, 3])
m3 = np.array([[1,2,3],[4,5,6]]).astype(np.float32)
print(m3)
m4 = Matrix(m3)
for i in range(m4.rows()):
for j in range(m4.cols()):
print(m4[i, j], end = ' ')
print()