Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions arraycontext/impl/pytato/fake_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,10 @@ def amin(self, a, axis=None):
def absolute(self, a):
return self.abs(a)

def vdot(self, a: Array, b: Array, order_a: str = "C", order_b: str = "C"):

flat_a = self.ravel(a, order_a)
flat_b = self.ravel(b, order_b)

return rec_multimap_array_container(pt.vdot, flat_a, flat_b)
Comment thread
nkoskelo marked this conversation as resolved.
Outdated
# }}}
43 changes: 43 additions & 0 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,52 @@ def evaluate(np_, *args_):

assert_close_to_numpy_in_containers(actx, evaluate, args)


@pytest.mark.parametrize(("sym_name", "n_args", "dtype"), [
# float only
("arctan2", 2, np.float64),
("minimum", 2, np.float64),
("maximum", 2, np.float64),
("where", 3, np.float64),
("min", 1, np.float64),
("max", 1, np.float64),
("any", 1, np.float64),
("all", 1, np.float64),
("arctan", 1, np.float64),

# float + complex
("sin", 1, np.float64),
("sin", 1, np.complex128),
("exp", 1, np.float64),
("exp", 1, np.complex128),
("conj", 1, np.float64),
("conj", 1, np.complex128),
("vdot", 2, np.float64),
("vdot", 2, np.complex128),
("abs", 1, np.float64),
("abs", 1, np.complex128),
("sum", 1, np.float64),
("sum", 1, np.complex64),
("isnan", 1, np.float64),
])
def test_array_context_np_workalike_with_scalars(actx_factory, sym_name, n_args, dtype):
Comment thread
nkoskelo marked this conversation as resolved.
Outdated
actx = actx_factory()
if not hasattr(actx.np, sym_name):
pytest.skip(f"'{sym_name}' not implemented on '{type(actx).__name__}'")
if sym_name in ["where", "min", "max", "any", "all", "conj", "vdot", "sum"]:
pytest.skip(f"'{sym_name}' not supported on scalars")

c_to_numpy_arc_functions = {
"atan": "arctan",
"atan2": "arctan2",
}

def evaluate(np_, *args_):
func = getattr(np_, sym_name,
getattr(np_, c_to_numpy_arc_functions.get(sym_name, sym_name)))

return func(*args_)

args = [randn(0, dtype)[()] for i in range(n_args)]
assert_close_to_numpy(actx, evaluate, args)

Expand Down