How to use the geoopt.manifolds.poincare.math.mobius_scalar_mul function in geoopt

To help you get started, we’ve selected a few geoopt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_associative(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 * r2, a, c=c)
    res1 = poincare.math.mobius_scalar_mul(
        r1, poincare.math.mobius_scalar_mul(r2, a, c=c), c=c
    )
    res2 = poincare.math.mobius_scalar_mul(
        r2, poincare.math.mobius_scalar_mul(r1, a, c=c), c=c
    )
    tolerance = {
        torch.float32: dict(atol=1e-7, rtol=1e-6),  # worked with rtol=1e-7 locally
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scaling_property(a, c, r1):
    x1 = a / a.norm(dim=-1, keepdim=True)
    ra = poincare.math.mobius_scalar_mul(r1, a, c=c)
    x2 = poincare.math.mobius_scalar_mul(abs(r1), a, c=c) / ra.norm(
        dim=-1, keepdim=True
    )
    tolerance = {
        torch.float32: dict(rtol=1e-5, atol=1e-6),
        torch.float64: dict(atol=1e-10),
    }
    np.testing.assert_allclose(x1, x2, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scaling_property(a, c, r1):
    x1 = a / a.norm(dim=-1, keepdim=True)
    ra = poincare.math.mobius_scalar_mul(r1, a, c=c)
    x2 = poincare.math.mobius_scalar_mul(abs(r1), a, c=c) / ra.norm(
        dim=-1, keepdim=True
    )
    tolerance = {
        torch.float32: dict(rtol=1e-5, atol=1e-6),
        torch.float64: dict(atol=1e-10),
    }
    np.testing.assert_allclose(x1, x2, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_distributive(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 + r2, a, c=c)
    res1 = poincare.math.mobius_add(
        poincare.math.mobius_scalar_mul(r1, a, c=c),
        poincare.math.mobius_scalar_mul(r2, a, c=c),
        c=c,
    )
    res2 = poincare.math.mobius_add(
        poincare.math.mobius_scalar_mul(r1, a, c=c),
        poincare.math.mobius_scalar_mul(r2, a, c=c),
        c=c,
    )
    tolerance = {
        torch.float32: dict(atol=1e-6, rtol=1e-7),
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_distributive(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 + r2, a, c=c)
    res1 = poincare.math.mobius_add(
        poincare.math.mobius_scalar_mul(r1, a, c=c),
        poincare.math.mobius_scalar_mul(r2, a, c=c),
        c=c,
    )
    res2 = poincare.math.mobius_add(
        poincare.math.mobius_scalar_mul(r1, a, c=c),
        poincare.math.mobius_scalar_mul(r2, a, c=c),
        c=c,
    )
    tolerance = {
        torch.float32: dict(atol=1e-6, rtol=1e-7),
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_associative(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 * r2, a, c=c)
    res1 = poincare.math.mobius_scalar_mul(
        r1, poincare.math.mobius_scalar_mul(r2, a, c=c), c=c
    )
    res2 = poincare.math.mobius_scalar_mul(
        r2, poincare.math.mobius_scalar_mul(r1, a, c=c), c=c
    )
    tolerance = {
        torch.float32: dict(atol=1e-7, rtol=1e-6),  # worked with rtol=1e-7 locally
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_associative(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 * r2, a, c=c)
    res1 = poincare.math.mobius_scalar_mul(
        r1, poincare.math.mobius_scalar_mul(r2, a, c=c), c=c
    )
    res2 = poincare.math.mobius_scalar_mul(
        r2, poincare.math.mobius_scalar_mul(r1, a, c=c), c=c
    )
    tolerance = {
        torch.float32: dict(atol=1e-7, rtol=1e-6),  # worked with rtol=1e-7 locally
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_associative(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 * r2, a, c=c)
    res1 = poincare.math.mobius_scalar_mul(
        r1, poincare.math.mobius_scalar_mul(r2, a, c=c), c=c
    )
    res2 = poincare.math.mobius_scalar_mul(
        r2, poincare.math.mobius_scalar_mul(r1, a, c=c), c=c
    )
    tolerance = {
        torch.float32: dict(atol=1e-7, rtol=1e-6),  # worked with rtol=1e-7 locally
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])
github geoopt / geoopt / tests / test_poincare_math.py View on Github external
def test_scalar_multiplication_associative(a, c, r1, r2):
    res = poincare.math.mobius_scalar_mul(r1 * r2, a, c=c)
    res1 = poincare.math.mobius_scalar_mul(
        r1, poincare.math.mobius_scalar_mul(r2, a, c=c), c=c
    )
    res2 = poincare.math.mobius_scalar_mul(
        r2, poincare.math.mobius_scalar_mul(r1, a, c=c), c=c
    )
    tolerance = {
        torch.float32: dict(atol=1e-7, rtol=1e-6),  # worked with rtol=1e-7 locally
        torch.float64: dict(atol=1e-7, rtol=1e-10),
    }
    np.testing.assert_allclose(res1, res, **tolerance[c.dtype])
    np.testing.assert_allclose(res2, res, **tolerance[c.dtype])