def test_properties(a, constant, scalar, creator): array = np.asarray(a) if creator: ref = Operation() tensor = Tensor(a, constant=constant, _creator=ref, _scalar_only=scalar) else: tensor = Tensor(a, constant=constant, _scalar_only=scalar) assert tensor.ndim == array.ndim assert tensor.shape == array.shape assert tensor.size == array.size assert len(tensor) == len(array) assert tensor.dtype == array.dtype assert_equal(actual=tensor.data, desired=a) assert (not creator) or tensor.creator is ref
assert_equal(actual=Tensor(x).data, desired=x) @given(x=hnp.arrays(dtype=float, shape=hnp.array_shapes())) def test_items(x): """ verify that tensor.item() mirrors array.item()""" tensor = Tensor(x) try: value = x.item() assert_allclose(value, tensor.item()) except ValueError: with raises(ValueError): tensor.item() op = Operation() dtype_strat = st.sampled_from(( None, int, float, np.int8, np.int16, np.int32, np.int64, np.float16, np.float32, np.float64, )) dtype_strat_numpy = st.sampled_from((np.int8, np.int16, np.int32, np.int64, np.float16, np.float32, np.float64))