def test_adk(): # Test properties. assert ADK(EQ()).stationary assert not ADK(Linear()).stationary # Test printing. assert str(ADK(EQ())) == "EQ()" assert str(ADK(EQ()) + ADK(Linear())) == "EQ() + Linear()" assert str(ADK(EQ() + Linear())) == "EQ() + Linear()" # Test equality. assert ADK(EQ()) == ADK(EQ()) assert ADK(EQ()) != ADK(Linear()) # Test computation. x = B.linspace(0, 5, 10) approx(pairwise(ADK(EQ()), x), pairwise(EQ(), x)) approx(elwise(ADK(EQ()), x), elwise(EQ(), x)) # Check that the dimensionality resolves to `None`. assert dimensionality(EQ()) == 1 assert dimensionality(ADK(EQ())) is None
def elwise(k: MultiOutputKernel, x: B.Numeric, y: B.Numeric): return elwise(k, tuple(p(x) for p in k.ps), tuple(p(y) for p in k.ps))
def elwise(k, x, y: tuple): return elwise(k, (x,), y)
def elwise(k, x: tuple, y): return elwise(k, x, (y,))
def elwise(k, x: tuple, y: tuple): if len(x) != len(y): raise ValueError('"elwise" must be called with similarly sized tuples.') return B.concat(*[elwise(k, xi, yi) for xi, yi in zip(x, y)], axis=-2)
def elwise(k: AmbiguousDimensionalityKernel, x, y): return elwise(k[0], x, y)