Here are the examples of the python api numpy.asfortranarray taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : test_surface.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def _eval_bary_multi_helper(self, **kwargs):
nodes = np.asfortranarray([[0.0, 2.0, -3.0], [0.0, 1.0, 2.0]])
surface = self._make_one(nodes, 1, _copy=False)
param_vals = np.asfortranarray([[1.0, 0.0, 0.0]])
patch = unittest.mock.patch(
"bezier._surface_helpers.evaluate_barycentric_multi",
return_value=unittest.mock.sentinel.evaluated,
)
with patch as mocked:
result = surface.evaluate_barycentric_multi(param_vals, **kwargs)
self.astertEqual(result, unittest.mock.sentinel.evaluated)
mocked.astert_called_once_with(nodes, 1, param_vals, 2)
3
View Complete Implementation : test__intersection_helpers.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_double_root(self):
# B1([5461/8192, 5462/8192]) and B2([2730/8192, 2731/8192]) are
# linearized and the segments are parallel. The curves intersect
# at the point B1(2/3) = [1/2, 1/2] = B2(1/3) and they have parallel
# tangent vectors B1'(2/3) = [3/4, 0] = B2'(1/3).
nodes1 = np.asfortranarray([[0.0, 0.375, 0.75], [0.0, 0.75, 0.375]])
s = 10923.0 / 16384.0
nodes2 = np.asfortranarray([[0.25, 0.625, 1.0], [0.625, 0.25, 1.0]])
t = 5461.0 / 16384.0
computed_s, computed_t = self._call_function_under_test(
s, nodes1, t, nodes2
)
utils.almost(self, 2.0 / 3.0, computed_s, 1)
utils.almost(self, 1.0 / 3.0, computed_t, 1)
3
View Complete Implementation : test_curve.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
@unittest.mock.patch("bezier._plot_helpers.new_axis")
def test_plot_explicit(self, new_axis_mock):
nodes = np.asfortranarray([[0.0, 1.0], [0.0, 1.0]])
curve = self._make_one(nodes, 1, _copy=False)
num_pts = 2 # This value is crucial for the plot call.
ax = unittest.mock.Mock(spec=["plot"])
color = (0.75, 1.0, 1.0)
alpha = 0.625
result = curve.plot(num_pts, color=color, alpha=alpha, ax=ax)
self.astertIs(result, ax)
# Verify mocks.
new_axis_mock.astert_not_called()
# Check the call to ax.plot(). We can't astert_any_call()
# since == breaks on NumPy arrays.
self.astertEqual(ax.plot.call_count, 1)
call = ax.plot.mock_calls[0]
utils.check_plot_call(self, call, nodes, color=color, alpha=alpha)
3
View Complete Implementation : test_surface.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_area_property_wrong_dimension(self):
nodes = np.asfortranarray([[0.0, 0.0], [1.0, 2.0], [2.0, 3.0]])
surface = self._make_one(nodes, 1)
with self.astertRaises(NotImplementedError) as exc_info:
getattr(surface, "area")
exc_args = exc_info.exception.args
expected_args = (
"2D is the only supported dimension",
"Current dimension",
3,
)
self.astertEqual(exc_args, expected_args)
3
View Complete Implementation : test__intersection_helpers.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_below_error_ratio(self):
# B1([12287/16384, 3/4]) and B2([2457/8192, 2458/8192]) are linearized
# and when the segments intersect they produce
# s = 33555797/33551701 > 1.
nodes1 = np.asfortranarray([[1.0, -1.0, 1.0], [0.0, 0.25, 0.5]])
s = 25163776.0 / 33551701.0
nodes2 = np.asfortranarray(
[[-0.125, 0.5, 1.125], [-0.28125, 1.28125, -0.28125]]
)
t = 41228331827.0 / 137427767296.0
evaluate_fn = self._simple_evaluate(nodes1, nodes2)
converged, current_s, current_t = self._call_function_under_test(
evaluate_fn, s, t
)
self.astertTrue(converged)
self.astertEqual(0.75, current_s)
utils.almost(self, 3.0 / 10.0, current_t, 1)
3
View Complete Implementation : test__curve_helpers.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_cubic(self):
nodes = np.asfortranarray(
[[0.0, 1.0, 1.0, 3.0], [0.0, -1.0, -2.0, 2.0]]
)
result = self._call_function_under_test(nodes, 0.125, 0.625)
expected = (
np.asfortranarray(
[[171, 375, 499, 735], [-187, -423, -579, -335]], dtype=FLOAT64
)
/ 512.0
)
self.astertEqual(result, expected)
3
View Complete Implementation : test_curve.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_elevate(self):
nodes = np.asfortranarray([[0.0, 1.0, 3.0, 3.5], [0.5, 1.0, 2.0, 4.0]])
curve = self._make_one(nodes, 3)
self.astertEqual(curve.degree, 3)
elevated = curve.elevate()
self.astertEqual(elevated.degree, 4)
s_vals = np.linspace(0.0, 1.0, 64 + 1)
orig_vals = curve.evaluate_multi(s_vals)
new_vals = elevated.evaluate_multi(s_vals)
self.astertEqual(orig_vals, new_vals)
3
View Complete Implementation : test__clipping.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_parallel(self):
from bezier import _clipping
nodes1 = np.asfortranarray([[0.0, 1.0, 2.0], [1.0, 3.0, 1.0]])
nodes2 = np.asfortranarray(
[[0.0, 0.5, 1.0, 1.5, 2.0], [0.0, 4.0, 4.0, 4.0, 0.0]]
)
with self.astertRaises(NotImplementedError) as exc_info:
self._call_function_under_test(nodes1, nodes2)
expected_args = (_clipping.NO_PARALLEL,)
self.astertEqual(exc_info.exception.args, expected_args)
3
View Complete Implementation : test__intersection_helpers.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_simple_root(self):
# B1([4095/8192, 1/2]) and B2([1365/8192, 1366/8192]) are linearized
# and when the segments intersect they produce s = 24580/24579 > 1.
nodes1 = np.asfortranarray([[0.0, 0.375, 0.75], [0.0, 0.75, 0.375]])
s = 100675585.0 / 201351168.0
nodes2 = np.asfortranarray(
[[0.25, 0.625, 1.0], [0.5625, 0.1875, 0.9375]]
)
t = 33558529.0 / 201351168.0
computed_s, computed_t = self._call_function_under_test(
s, nodes1, t, nodes2
)
utils.almost(self, 0.5, computed_s, 1)
utils.almost(self, 1.0 / 6.0, computed_t, 4)
3
View Complete Implementation : test__helpers.py
Copyright Apache License 2.0
Author : dhermes
Copyright Apache License 2.0
Author : dhermes
def test_it(self):
vec0 = np.asfortranarray([1.0, 7.0]) / 8.0
vec1 = np.asfortranarray([-11.0, 24.0]) / 32.0
result = self._call_function_under_test(vec0, vec1)
vec0_as_3d = np.zeros((3,), order="F")
vec0_as_3d[:2] = vec0
vec1_as_3d = np.zeros((3,), order="F")
vec1_as_3d[:2] = vec1
actual_cross = np.cross(vec0_as_3d, vec1_as_3d)
expected = np.asfortranarray([0.0, 0.0, result])
self.astertEqual(actual_cross, expected)