jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def blocked_inner_prod(x: ArraySequence, s: Float64Array) -> Float64Array:
    r"""
    Parameters
    ----------
    x : list of ndarray
        k-element list of arrays to construct the inner product
    s : ndarray
        Weighting matrix (k by k)

    Returns
    -------
    ndarray
        Weighted inner product constructed from x and s

    Notes
    -----
    Memory efficient implementation of high-dimensional inner product

    .. math::

      X'(S \otimes I_n)X

    where n is the number of observations in the sample
    """
    k = len(x)
    widths = [m.shape[1] for m in x]
    s_is_diag = np.all(np.asarray((s - np.diag(np.diag(s))) == 0.0))

    w0 = widths[0]
    homogeneous = all([w == w0 for w in widths])
    if homogeneous and not s_is_diag:
        # Fast path when all x have same number of columns
        # Slower than diag case when k is large since many 0s
        xa = np.hstack(x)
        return xa.T @ xa * np.kron(s, np.ones((w0, w0)))

    cum_width = np.cumsum([0] + widths)
    total = sum(widths)
    out: np.ndarray = np.zeros((total, total))

    for i in range(k):
        xi = x[i]
        sel_i = slice(cum_width[i], cum_width[i + 1])
        s_ii = s[i, i]
        prod = s_ii * (xi.T @ xi)
        out[sel_i, sel_i] = prod

    # Short circuit if identity
    if s_is_diag:
        return out

    for i in range(k):
        xi = x[i]
        sel_i = slice(cum_width[i], cum_width[i + 1])
        for j in range(i + 1, k):
            sel_j = slice(cum_width[j], cum_width[j + 1])
            xj = x[j]
            s_ij = s[i, j]
            prod = s_ij * (xi.T @ xj)
            out[sel_i, sel_j] = prod
            out[sel_j, sel_i] = prod.T

    return cast(np.ndarray, out)
//  [python]
def test_galcenrect_to_XYZ_negXsun():
    gcX, gcY, gcZ = -1.0, 4.0, 2.0
    XYZ = numpy.array(coords.galcenrect_to_XYZ(gcX, gcY, gcZ, Xsun=1.0, Zsun=0.2))
    XYZn = numpy.array(coords.galcenrect_to_XYZ(-gcX, gcY, gcZ, Xsun=-1.0, Zsun=0.2))
    assert n.all(
        n.fabs(XYZ - XYZn) < 10.0**-10.0
    ), "galcenrect_to_XYZ conversion did not work as expected for negative Xsun"
    return None
//  [python]
def test_galcenrect_to_XYZ_negXsun():
    gcX, gcY, gcZ = -1.0, 4.0, 2.0
    XYZ = numpy.array(coords.galcenrect_to_XYZ(gcX, gcY, gcZ, Xsun=1.0, Zsun=0.2))
    XYZn = numpy.array(coords.galcenrect_to_XYZ(-gcX, gcY, gcZ, Xsun=-1.0, Zsun=0.2))
    assert numpy.all(
        numpy.fabs(XYZ - XYZn) < 10.0**-10.0
    ), "galcenrect_to_XYZ conversion did not work as expected for negative Xsun"
    return None
//  [python]
def test_radec_to_lb_ncp():
    _turn_off_apy()
    ra, dec = 180.0, 90.0
    lb = coords.radec_to_lb(ra, dec, degree=True, epoch=1950.0)
    assert (
        numpy.fabs(lb[0] - 123.0) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 123"
    # Also test this for degree=False
    lb = coords.radec_to_lb(
        ra / 180.0 * numpy.pi, dec / 180.0 * numpy.pi, degree=False, epoch=1950.0
    )
    assert (
        numpy.fabs(lb[0] - 123.0 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 123"
    # Also test the latter for vector inputs
    os = numpy.ones(2)
    lb = coords.radec_to_lb(
        os * ra / 180.0 * numpy.pi,
        os * dec / 180.0 * numpy.pi,
        degree=False,
        epoch=1950.0,
    )
    assert n.all(
        numpy.fabs(lb[:, 0] - 123.0 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 123"
    _turn_on_apy()
    return None
//  [python]
def test_radec_to_lb_ncp():
    _turn_off_apy()
    ra, dec = 180.0, 90.0
    lb = coords.radec_to_lb(ra, dec, degree=True, epoch=1950.0)
    assert (
        numpy.fabs(lb[0] - 123.0) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 123"
    # Also test this for degree=False
    lb = coords.radec_to_lb(
        ra / 180.0 * numpy.pi, dec / 180.0 * numpy.pi, degree=False, epoch=1950.0
    )
    assert (
        numpy.fabs(lb[0] - 123.0 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 123"
    # Also test the latter for vector inputs
    os = numpy.ones(2)
    lb = coords.radec_to_lb(
        os * ra / 180.0 * numpy.pi,
        os * dec / 180.0 * numpy.pi,
        degree=False,
        epoch=1950.0,
    )
    assert numpy.all(
        numpy.fabs(lb[:, 0] - 123.0 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 123"
    _turn_on_apy()
    return None
//  [python]
def test_XYZ_to_galcenrect_vecSun():
    X, Y, Z = (
        numpy.array([1.0, 2.0]),
        numpy.array([3.0, 3.0]),
        numpy.array([-2.0, -2.0]),
    )
    gcXYZ = coords.XYZ_to_galcenrect(
        X, Y, Z, Xsun=numpy.array([1.0, -2.0]), Zsun=numpy.array([0.0, 0.0])
    )
    assert n.all(
        n.fabs(gcXYZ[:, 0]) < 10.0**-5.0
    ), "XYZ_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(gcXYZ[:, 1] - 3.0) < 10.0**-5.0
    ), "XYZ_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(gcXYZ[:, 2] + 2.0) < 10.0**-5.0
    ), "XYZ_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_XYZ_to_galcenrect_vecSun():
    X, Y, Z = (
        numpy.array([1.0, 2.0]),
        numpy.array([3.0, 3.0]),
        numpy.array([-2.0, -2.0]),
    )
    gcXYZ = coords.XYZ_to_galcenrect(
        X, Y, Z, Xsun=numpy.array([1.0, -2.0]), Zsun=numpy.array([0.0, 0.0])
    )
    assert numpy.all(
        numpy.fabs(gcXYZ[:, 0]) < 10.0**-5.0
    ), "XYZ_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(gcXYZ[:, 1] - 3.0) < 10.0**-5.0
    ), "XYZ_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(gcXYZ[:, 2] + 2.0) < 10.0**-5.0
    ), "XYZ_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_XYZ_to_galcencyl_vecSun():
    X, Y, Z = (
        numpy.array([5.0, 4.0]),
        numpy.array([4.0, 4.0]),
        numpy.array([-2.0, -2.0]),
    )
    gcRpZ = coords.XYZ_to_galcencyl(
        X, Y, Z, Xsun=numpy.array([8.0, 7.0]), Zsun=numpy.array([0.0, 0.0])
    )
    assert n.all(
        n.fabs(gcRpZ[:, 0] - 5.0) < 10.0**-5.0
    ), "XYZ_to_galcencyl conversion did not work as expected"
    assert n.all(
        n.fabs(gcRpZ[:, 1] - numpy.arctan(4.0 / 3.0)) < 10.0**-5.0
    ), "XYZ_to_galcencyl conversion did not work as expected"
    assert n.all(
        n.fabs(gcRpZ[:, 2] + 2.0) < 10.0**-4.8
    ), "XYZ_to_galcencyl conversion did not work as expected"
    return None
//  [python]
def test_XYZ_to_galcencyl_vecSun():
    X, Y, Z = (
        numpy.array([5.0, 4.0]),
        numpy.array([4.0, 4.0]),
        numpy.array([-2.0, -2.0]),
    )
    gcRpZ = coords.XYZ_to_galcencyl(
        X, Y, Z, Xsun=numpy.array([8.0, 7.0]), Zsun=numpy.array([0.0, 0.0])
    )
    assert numpy.all(
        numpy.fabs(gcRpZ[:, 0] - 5.0) < 10.0**-5.0
    ), "XYZ_to_galcencyl conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(gcRpZ[:, 1] - numpy.arctan(4.0 / 3.0)) < 10.0**-5.0
    ), "XYZ_to_galcencyl conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(gcRpZ[:, 2] + 2.0) < 10.0**-4.8
    ), "XYZ_to_galcencyl conversion did not work as expected"
    return None
//  [python]
def test_radec_to_lb_ncp_j2000():
    _turn_off_apy()
    ra, dec = 180.0, 90.0
    lb = coords.radec_to_lb(ra, dec, degree=True, epoch=2000.0)
    assert (
        numpy.fabs(lb[0] - 122.9319185680026) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 122.9319185680026"
    # Also test this for degree=False
    lb = coords.radec_to_lb(
        ra / 180.0 * numpy.pi, dec / 180.0 * numpy.pi, degree=False, epoch=2000.0
    )
    assert (
        numpy.fabs(lb[0] - 122.9319185680026 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 122.9319185680026"
    # Also test the latter for vector inputs
    os = numpy.ones(2)
    lb = coords.radec_to_lb(
        os * ra / 180.0 * numpy.pi,
        os * dec / 180.0 * numpy.pi,
        degree=False,
        epoch=2000.0,
    )
    assert n.all(
        numpy.fabs(lb[:, 0] - 122.9319185680026 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 122.9319185680026"
    _turn_on_apy()
    return None
//  [python]
def test_radec_to_lb_ncp_j2000():
    _turn_off_apy()
    ra, dec = 180.0, 90.0
    lb = coords.radec_to_lb(ra, dec, degree=True, epoch=2000.0)
    assert (
        numpy.fabs(lb[0] - 122.9319185680026) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 122.9319185680026"
    # Also test this for degree=False
    lb = coords.radec_to_lb(
        ra / 180.0 * numpy.pi, dec / 180.0 * numpy.pi, degree=False, epoch=2000.0
    )
    assert (
        numpy.fabs(lb[0] - 122.9319185680026 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 122.9319185680026"
    # Also test the latter for vector inputs
    os = numpy.ones(2)
    lb = coords.radec_to_lb(
        os * ra / 180.0 * numpy.pi,
        os * dec / 180.0 * numpy.pi,
        degree=False,
        epoch=2000.0,
    )
    assert numpy.all(
        numpy.fabs(lb[:, 0] - 122.9319185680026 / 180.0 * numpy.pi) < 10.0**-8.0
    ), "Galactic longitude of the NCP given in ra,dec is not 122.9319185680026"
    _turn_on_apy()
    return None
//  [python]
def test_vxvyvz_to_galcenrect_vecXsun():
    vx, vy, vz = (
        numpy.array([10.0, 10.0]),
        numpy.array([-20.0, -20.0]),
        numpy.array([30.0, 30.0]),
    )
    vgc = coords.vxvyvz_to_galcenrect(
        vx,
        vy,
        vz,
        vsun=[-5.0, 10.0, 5.0],
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
    )
    assert n.all(
        n.fabs(vgc[:, 0] + 15.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(vgc[:, 1] + 10.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(vgc[:, 2] - 35.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_vxvyvz_to_galcenrect_vecXsun():
    vx, vy, vz = (
        numpy.array([10.0, 10.0]),
        numpy.array([-20.0, -20.0]),
        numpy.array([30.0, 30.0]),
    )
    vgc = coords.vxvyvz_to_galcenrect(
        vx,
        vy,
        vz,
        vsun=[-5.0, 10.0, 5.0],
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
    )
    assert numpy.all(
        numpy.fabs(vgc[:, 0] + 15.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vgc[:, 1] + 10.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vgc[:, 2] - 35.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_vxvyvz_to_galcenrect_vecvsun():
    vx, vy, vz = (
        numpy.array([10.0, 5.0]),
        numpy.array([-20.0, -10.0]),
        numpy.array([30.0, 25.0]),
    )
    vgc = coords.vxvyvz_to_galcenrect(
        vx, vy, vz, vsun=numpy.array([[-5.0, 10.0, 5.0], [-10.0, 0.0, 10.0]]).T
    )
    assert n.all(
        n.fabs(vgc[:, 0] + 15.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(vgc[:, 1] + 10.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(vgc[:, 2] - 35.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_vxvyvz_to_galcenrect_vecvsun():
    vx, vy, vz = (
        numpy.array([10.0, 5.0]),
        numpy.array([-20.0, -10.0]),
        numpy.array([30.0, 25.0]),
    )
    vgc = coords.vxvyvz_to_galcenrect(
        vx, vy, vz, vsun=numpy.array([[-5.0, 10.0, 5.0], [-10.0, 0.0, 10.0]]).T
    )
    assert numpy.all(
        numpy.fabs(vgc[:, 0] + 15.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vgc[:, 1] + 10.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vgc[:, 2] - 35.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_negXsun():
    vxg, vyg, vzg = -15.0, -10.0, 35.0
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg, vyg, vzg, vsun=[-5.0, 10.0, 5.0], Xsun=1.1, Zsun=0.2
    )
    vxyzn = coords.galcenrect_to_vxvyvz(
        -vxg, vyg, vzg, vsun=[5.0, 10.0, 5.0], Xsun=-1.1, Zsun=0.2
    )
    assert n.all(
        n.fabs(n.array(vxyz) - n.array(vxyzn)) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_negXsun():
    vxg, vyg, vzg = -15.0, -10.0, 35.0
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg, vyg, vzg, vsun=[-5.0, 10.0, 5.0], Xsun=1.1, Zsun=0.2
    )
    vxyzn = coords.galcenrect_to_vxvyvz(
        -vxg, vyg, vzg, vsun=[5.0, 10.0, 5.0], Xsun=-1.1, Zsun=0.2
    )
    assert numpy.all(
        numpy.fabs(numpy.array(vxyz) - numpy.array(vxyzn)) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_vxvyvz_to_galcenrect_vecXsunvsun():
    vx, vy, vz = (
        numpy.array([10.0, 5.0]),
        numpy.array([-20.0, -10.0]),
        numpy.array([30.0, 25.0]),
    )
    vgc = coords.vxvyvz_to_galcenrect(
        vx,
        vy,
        vz,
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
        vsun=numpy.array([[-5.0, 10.0, 5.0], [-10.0, 0.0, 10.0]]).T,
    )
    assert n.all(
        n.fabs(vgc[:, 0] + 15.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(vgc[:, 1] + 10.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert n.all(
        n.fabs(vgc[:, 2] - 35.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_vxvyvz_to_galcenrect_vecXsunvsun():
    vx, vy, vz = (
        numpy.array([10.0, 5.0]),
        numpy.array([-20.0, -10.0]),
        numpy.array([30.0, 25.0]),
    )
    vgc = coords.vxvyvz_to_galcenrect(
        vx,
        vy,
        vz,
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
        vsun=numpy.array([[-5.0, 10.0, 5.0], [-10.0, 0.0, 10.0]]).T,
    )
    assert numpy.all(
        numpy.fabs(vgc[:, 0] + 15.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vgc[:, 1] + 10.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vgc[:, 2] - 35.0) < 10.0**-4.0
    ), "vxvyvz_to_galcenrect conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_vecXsun():
    vxg, vyg, vzg = (
        numpy.array([-15.0, -15.0]),
        numpy.array([-10.0, -10.0]),
        numpy.array([35.0, 35.0]),
    )
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg,
        vyg,
        vzg,
        vsun=[-5.0, 10.0, 5.0],
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
    )
    assert n.all(
        n.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert n.all(
        n.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert n.all(
        n.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_vecXsun():
    vxg, vyg, vzg = (
        numpy.array([-15.0, -15.0]),
        numpy.array([-10.0, -10.0]),
        numpy.array([35.0, 35.0]),
    )
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg,
        vyg,
        vzg,
        vsun=[-5.0, 10.0, 5.0],
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
    )
    assert numpy.all(
        numpy.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_vecvsun():
    vxg, vyg, vzg = (
        numpy.array([-15.0, -5.0]),
        numpy.array([-10.0, -20.0]),
        numpy.array([35.0, 32.5]),
    )
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg, vyg, vzg, vsun=numpy.array([[-5.0, 10.0, 5.0], [5.0, 0.0, 2.5]]).T
    )
    assert n.all(
        n.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert n.all(
        n.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert n.all(
        n.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_vecvsun():
    vxg, vyg, vzg = (
        numpy.array([-15.0, -5.0]),
        numpy.array([-10.0, -20.0]),
        numpy.array([35.0, 32.5]),
    )
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg, vyg, vzg, vsun=numpy.array([[-5.0, 10.0, 5.0], [5.0, 0.0, 2.5]]).T
    )
    assert numpy.all(
        numpy.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz():
    vxg, vyg, vzg = -15.0, -10.0, 35.0
    vxyz = coords.galcenrect_to_vxvyvz(vxg, vyg, vzg, vsun=[-5.0, 10.0, 5.0])
    assert (
        numpy.fabs(vxyz[0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert (
        numpy.fabs(vxyz[1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert (
        numpy.fabs(vxyz[2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    # Also for arrays
    os = numpy.ones(2)
    vxyz = coords.galcenrect_to_vxvyvz(
        os * vxg, os * vyg, os * vzg, vsun=[-5.0, 10.0, 5.0]
    )
    assert numpy.alltrue(
        numpy.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.alltrue(
        numpy.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.alltrue(
        numpy.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz():
    vxg, vyg, vzg = -15.0, -10.0, 35.0
    vxyz = coords.galcenrect_to_vxvyvz(vxg, vyg, vzg, vsun=[-5.0, 10.0, 5.0])
    assert (
        numpy.fabs(vxyz[0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert (
        numpy.fabs(vxyz[1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert (
        numpy.fabs(vxyz[2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    # Also for arrays
    os = numpy.ones(2)
    vxyz = coords.galcenrect_to_vxvyvz(
        os * vxg, os * vyg, os * vzg, vsun=[-5.0, 10.0, 5.0]
    )
    assert numpy.all(
        numpy.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_vecXsunvsun():
    vxg, vyg, vzg = (
        numpy.array([-15.0, -5.0]),
        numpy.array([-10.0, -20.0]),
        numpy.array([35.0, 32.5]),
    )
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg,
        vyg,
        vzg,
        vsun=numpy.array([[-5.0, 10.0, 5.0], [5.0, 0.0, 2.5]]).T,
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
    )
    assert n.all(
        n.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert n.all(
        n.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert n.all(
        n.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_galcenrect_to_vxvyvz_vecXsunvsun():
    vxg, vyg, vzg = (
        numpy.array([-15.0, -5.0]),
        numpy.array([-10.0, -20.0]),
        numpy.array([35.0, 32.5]),
    )
    vxyz = coords.galcenrect_to_vxvyvz(
        vxg,
        vyg,
        vzg,
        vsun=numpy.array([[-5.0, 10.0, 5.0], [5.0, 0.0, 2.5]]).T,
        Xsun=numpy.array([1.1, 1.0]),
        Zsun=numpy.array([0.0, 0.0]),
    )
    assert numpy.all(
        numpy.fabs(vxyz[:, 0] - 10.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 1] + 20.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vxyz[:, 2] - 30.0) < 10.0**-4.0
    ), "galcenrect_to_vxvyvz conversion did not work as expected"
    return None
//  [python]
def test_uv_to_Rz():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 6.0
    R, z = coords.uv_to_Rz(u, v, delta=3.0)
    assert (
        numpy.fabs(R - 2.0) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    assert (
        numpy.fabs(z - 2.5 * numpy.sqrt(3.0)) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    # Also test for arrays
    os = numpy.ones(2)
    R, z = coords.uv_to_Rz(os * u, os * v, delta=3.0)
    assert numpy.all(
        numpy.fabs(R - 2.0) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(z - 2.5 * numpy.sqrt(3.0)) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    return None
//  [python]
def test_Rz_to_uv():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 6.0
    ut, vt = coords.Rz_to_uv(*coords.uv_to_Rz(u, v, delta=3.0), delta=3.0)
    assert (
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert (
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    # Also test for arrays
    os = numpy.ones(2)
    ut, vt = coords.Rz_to_uv(*coords.uv_to_Rz(u * os, v * os, delta=3.0), delta=3.0)
    assert numpy.alltrue(
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert numpy.alltrue(
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    return None
//  [python]
def test_Rz_to_uv():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 6.0
    ut, vt = coords.Rz_to_uv(*coords.uv_to_Rz(u, v, delta=3.0), delta=3.0)
    assert (
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert (
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    # Also test for arrays
    os = numpy.ones(2)
    ut, vt = coords.Rz_to_uv(*coords.uv_to_Rz(u * os, v * os, delta=3.0), delta=3.0)
    assert numpy.all(
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    return None
//  [python]
def test_Rz_to_coshucosv():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 3.0
    R, z = coords.uv_to_Rz(u, v, delta=3.0)
    coshu, cosv = coords.Rz_to_coshucosv(R, z, delta=3.0)
    assert (
        numpy.fabs(coshu - 5.0 / 3.0) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    assert (
        numpy.fabs(cosv - 0.5) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    # Also test for arrays
    os = numpy.ones(2)
    coshu, cosv = coords.Rz_to_coshucosv(R * os, z * os, delta=3.0)
    assert n.all(
        numpy.fabs(coshu - 5.0 / 3.0) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    assert n.all(
        numpy.fabs(cosv - 0.5) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    return None
//  [python]
def test_Rz_to_coshucosv():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 3.0
    R, z = coords.uv_to_Rz(u, v, delta=3.0)
    coshu, cosv = coords.Rz_to_coshucosv(R, z, delta=3.0)
    assert (
        numpy.fabs(coshu - 5.0 / 3.0) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    assert (
        numpy.fabs(cosv - 0.5) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    # Also test for arrays
    os = numpy.ones(2)
    coshu, cosv = coords.Rz_to_coshucosv(R * os, z * os, delta=3.0)
    assert numpy.all(
        numpy.fabs(coshu - 5.0 / 3.0) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    assert numpy.all(
        numpy.fabs(cosv - 0.5) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    return None
//  [python]
def test_uv_to_Rz_oblate():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 6.0
    R, z = coords.uv_to_Rz(u, v, delta=3.0, oblate=True)
    assert (
        numpy.fabs(R - 2.5) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    assert (
        numpy.fabs(z - 2.0 * numpy.sqrt(3.0)) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    # Also test for arrays
    os = numpy.ones(2)
    R, z = coords.uv_to_Rz(os * u, os * v, delta=3.0, oblate=True)
    assert numpy.all(
        numpy.fabs(R - 2.5) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(z - 2.0 * numpy.sqrt(3.0)) < 10.0**-10.0
    ), "uv_to_Rz conversion did not work as expected"
    return None
//  [python]
def test_Rz_to_uv_oblate():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 6.0
    ut, vt = coords.Rz_to_uv(
        *coords.uv_to_Rz(u, v, delta=3.0, oblate=True), delta=3.0, oblate=True
    )
    assert (
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert (
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    # Also test for arrays
    os = numpy.ones(2)
    ut, vt = coords.Rz_to_uv(
        *coords.uv_to_Rz(u * os, v * os, delta=3.0, oblate=True), delta=3.0, oblate=True
    )
    assert numpy.alltrue(
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert numpy.alltrue(
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    return None
//  [python]
def test_Rz_to_uv_oblate():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 6.0
    ut, vt = coords.Rz_to_uv(
        *coords.uv_to_Rz(u, v, delta=3.0, oblate=True), delta=3.0, oblate=True
    )
    assert (
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert (
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    # Also test for arrays
    os = numpy.ones(2)
    ut, vt = coords.Rz_to_uv(
        *coords.uv_to_Rz(u * os, v * os, delta=3.0, oblate=True), delta=3.0, oblate=True
    )
    assert numpy.all(
        numpy.fabs(ut - u) < 10.0**-10.0
    ), "Rz_to_uvz conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(vt - v) < 10.0**-10.0
    ), "Rz_to_uv conversion did not work as expected"
    return None
//  [python]
def test_dl_to_rphi_2d():
    # This is a tangent point
    l = numpy.arcsin(0.75)
    d = 6.0 / numpy.tan(l)
    r, phi = coords.dl_to_rphi_2d(d, l, degree=False, ro=8.0, phio=0.0)
    assert (
        numpy.fabs(r - 6.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    assert (
        numpy.fabs(phi - numpy.arccos(0.75)) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    # This is a different point
    d, l = 2.0, 45.0
    r, phi = coords.dl_to_rphi_2d(
        d, l, degree=True, ro=2.0 * numpy.sqrt(2.0), phio=10.0
    )
    assert (
        numpy.fabs(r - 2.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    assert (
        numpy.fabs(phi - 55.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    # This is a different point, for array
    d, l = 2.0, 45.0
    os = numpy.ones(2)
    r, phi = coords.dl_to_rphi_2d(
        os * d, os * l, degree=True, ro=2.0 * numpy.sqrt(2.0), phio=0.0
    )
    assert numpy.all(
        numpy.fabs(r - 2.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(phi - 45.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    # This is a different point, for list (which I support for some reason)
    d, l = 2.0, 45.0
    r, phi = coords.dl_to_rphi_2d(
        [d, d], [l, l], degree=True, ro=2.0 * numpy.sqrt(2.0), phio=0.0
    )
    r = numpy.array(r)
    phi = numpy.array(phi)
    assert numpy.all(
        numpy.fabs(r - 2.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    assert numpy.all(
        numpy.fabs(phi - 45.0) < 10.0**-10.0
    ), "dl_to_rphi_2d conversion did not work as expected"
    return None
//  [python]
def test_pmrapmdec_to_pmllpmbb():
    # This is a random ra,dec
    ra, dec = 132.0, -20.4
    pmra, pmdec = 10.0, 20.0
    pmll, pmbb = coords.pmrapmdec_to_pmllpmbb(
        pmra, pmdec, ra, dec, degree=True, epoch=1950.0
    )
    assert (
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected"
    # This is close to the NGP at 1950.
    ra, dec = 192.24, 27.39
    pmra, pmdec = 10.0, 20.0
    os = numpy.ones(2)
    pmllpmbb = coords.pmrapmdec_to_pmllpmbb(
        os * pmra, os * pmdec, os * ra, os * dec, degree=True, epoch=1950.0
    )

    pmll = pmllpmbb[:, 0]
    pmbb = pmllpmbb[:, 1]
    assert numpy.alltrue(
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected close to the NGP"
    # This is the NGP at 1950.
    ra, dec = 192.25, 27.4
    pmra, pmdec = 10.0, 20.0
    os = numpy.ones(2)
    pmllpmbb = coords.pmrapmdec_to_pmllpmbb(
        os * pmra, os * pmdec, os * ra, os * dec, degree=True, epoch=1950.0
    )

    pmll = pmllpmbb[:, 0]
    pmbb = pmllpmbb[:, 1]
    assert numpy.alltrue(
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected for the NGP"
    # This is the NCP
    ra, dec = numpy.pi, numpy.pi / 2.0
    pmra, pmdec = 10.0, 20.0
    pmll, pmbb = coords.pmrapmdec_to_pmllpmbb(
        pmra, pmdec, ra, dec, degree=False, epoch=1950.0
    )
    assert (
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected for the NCP"
    return None
//  [python]
def test_pmrapmdec_to_pmllpmbb():
    # This is a random ra,dec
    ra, dec = 132.0, -20.4
    pmra, pmdec = 10.0, 20.0
    pmll, pmbb = coords.pmrapmdec_to_pmllpmbb(
        pmra, pmdec, ra, dec, degree=True, epoch=1950.0
    )
    assert (
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected"
    # This is close to the NGP at 1950.
    ra, dec = 192.24, 27.39
    pmra, pmdec = 10.0, 20.0
    os = numpy.ones(2)
    pmllpmbb = coords.pmrapmdec_to_pmllpmbb(
        os * pmra, os * pmdec, os * ra, os * dec, degree=True, epoch=1950.0
    )

    pmll = pmllpmbb[:, 0]
    pmbb = pmllpmbb[:, 1]
    assert numpy.all(
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected close to the NGP"
    # This is the NGP at 1950.
    ra, dec = 192.25, 27.4
    pmra, pmdec = 10.0, 20.0
    os = numpy.ones(2)
    pmllpmbb = coords.pmrapmdec_to_pmllpmbb(
        os * pmra, os * pmdec, os * ra, os * dec, degree=True, epoch=1950.0
    )

    pmll = pmllpmbb[:, 0]
    pmbb = pmllpmbb[:, 1]
    assert numpy.all(
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected for the NGP"
    # This is the NCP
    ra, dec = numpy.pi, numpy.pi / 2.0
    pmra, pmdec = 10.0, 20.0
    pmll, pmbb = coords.pmrapmdec_to_pmllpmbb(
        pmra, pmdec, ra, dec, degree=False, epoch=1950.0
    )
    assert (
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmrapmdec_to_pmllpmbb conversion did not work as expected for the NCP"
    return None
//  [python]
def test_pmllpmbb_to_pmrapmdec():
    # This is a random l,b
    ll, bb = 132.0, -20.4
    pmll, pmbb = 10.0, 20.0
    pmra, pmdec = coords.pmllpmbb_to_pmrapmdec(
        pmll, pmbb, ll, bb, degree=True, epoch=1950.0
    )
    assert (
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmllpmbb_to_pmrapmdec conversion did not work as expected for a random l,b"
    # This is close to the NGP
    ll, bb = numpy.pi - 0.001, numpy.pi / 2.0 - 0.001
    pmll, pmbb = 10.0, 20.0
    os = numpy.ones(2)
    pmrapmdec = coords.pmllpmbb_to_pmrapmdec(
        os * pmll, os * pmbb, os * ll, os * bb, degree=False, epoch=1950.0
    )
    pmra = pmrapmdec[:, 0]
    pmdec = pmrapmdec[:, 1]
    assert numpy.all(
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmllpmbb_to_pmrapmdec conversion did not work as expected close to the NGP"
    # This is the NGP
    ll, bb = numpy.pi, numpy.pi / 2.0
    pmll, pmbb = 10.0, 20.0
    os = numpy.ones(2)
    pmrapmdec = coords.pmllpmbb_to_pmrapmdec(
        os * pmll, os * pmbb, os * ll, os * bb, degree=False, epoch=1950.0
    )
    pmra = pmrapmdec[:, 0]
    pmdec = pmrapmdec[:, 1]
    assert numpy.all(
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmllpmbb_to_pmrapmdec conversion did not work as expected at the NGP"
    # This is the NCP
    ra, dec = numpy.pi, numpy.pi / 2.0
    ll, bb = coords.radec_to_lb(ra, dec, degree=False, epoch=1950.0)
    pmll, pmbb = 10.0, 20.0
    pmra, pmdec = coords.pmllpmbb_to_pmrapmdec(
        pmll, pmbb, ll, bb, degree=False, epoch=1950.0
    )
    assert (
        numpy.fabs(
            numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0)
        )
        < 10.0**-10.0
    ), "pmllpmbb_to_pmrapmdec conversion did not work as expected at the NCP"
    return None
//  [python]
def test_Rz_to_coshucosv_oblate():
    u, v = numpy.arccosh(5.0 / 3.0), numpy.pi / 3.0
    R, z = coords.uv_to_Rz(u, v, delta=3.0, oblate=True)
    coshu, cosv = coords.Rz_to_coshucosv(R, z, delta=3.0, oblate=True)
    assert (
        numpy.fabs(coshu - 5.0 / 3.0) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    assert (
        numpy.fabs(cosv - 0.5) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    # Also test for arrays
    os = numpy.ones(2)
    coshu, cosv = coords.Rz_to_coshucosv(R * os, z * os, delta=3.0, oblate=True)
    assert numpy.all(
        numpy.fabs(coshu - 5.0 / 3.0) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    assert numpy.all(
        numpy.fabs(cosv - 0.5) < 10.0**-10.0
    ), "Rz_to_coshucosv conversion did notwork as expected"
    return None
//  [python]
def is_fully_finite(self, a):
        return np.all(np.isfinite(a))
//  [python]
def has_trivial_timedependence(self):
        """
        `True` if all the data in this DataSet occurs at time 0.

        Returns
        -------
        bool
        """
        return all([n.all(self.timeData[gsi] == 0) for gsi in self.cirIndex.values()])
//  [python]
def has_trivial_timedependence(self):
        """
        `True` if all the data in this DataSet occurs at time 0.

        Returns
        -------
        bool
        """
        return all([_np.all(self.timeData[gsi] == 0) for gsi in self.cirIndex.values()])
//  [python]
def _fit(self, X, handle_unknown='error'):
        X_list, n_samples, n_features = self._check_X(X)
        
        if self.categories != 'auto':
            if len(self.categories) != n_features:
                raise ValueError("Shape mismatch: if categories is an array,"
                                 " it has to be of shape (n_features,).")
        
        if self.max_levels is not None:
            if (not isinstance(self.max_levels, Integral) or
                    self.max_levels <= 0):
                raise ValueError("max_levels must be None or a strictly "
                                 "positive int, got {}.".format(
                                     self.max_levels))
        
        self.categories_ = []
        self.infrequent_indices_ = []
        
        for i in range(n_features):
            Xi = X_list[i]
            if self.categories == 'auto':
                cats = _encode(Xi)
            else:
                cats = np.array(self.categories[i], dtype=Xi.dtype)
                if Xi.dtype != object:
                    if not n.all(np.sort(cats) == cats):
                        raise ValueError("Unsorted categories are not "
                                         "supported for numerical categories")
                if handle_unknown == 'error':
                    diff = _encode_check_unknown(Xi, cats)
                    if diff:
                        msg = ("Found unknown categories {0} in column {1}"
                               " during fit".format(diff, i))
                        raise ValueError(msg)
            self.categories_.append(cats)
            
            if self.max_levels is not None:
                infrequent_indices = self._find_infrequent_category_indices(Xi)
            else:
                infrequent_indices = np.array([])
            self.infrequent_indices_.append(infrequent_indices)
//  [python]
def _fit(self, X, handle_unknown='error'):
        X_list, n_samples, n_features = self._check_X(X)
        
        if self.categories != 'auto':
            if len(self.categories) != n_features:
                raise ValueError("Shape mismatch: if categories is an array,"
                                 " it has to be of shape (n_features,).")
        
        if self.max_levels is not None:
            if (not isinstance(self.max_levels, Integral) or
                    self.max_levels <= 0):
                raise ValueError("max_levels must be None or a strictly "
                                 "positive int, got {}.".format(
                                     self.max_levels))
        
        self.categories_ = []
        self.infrequent_indices_ = []
        
        for i in range(n_features):
            Xi = X_list[i]
            if self.categories == 'auto':
                cats = _encode(Xi)
            else:
                cats = np.array(self.categories[i], dtype=Xi.dtype)
                if Xi.dtype != object:
                    if not np.all(np.sort(cats) == cats):
                        raise ValueError("Unsorted categories are not "
                                         "supported for numerical categories")
                if handle_unknown == 'error':
                    diff = _encode_check_unknown(Xi, cats)
                    if diff:
                        msg = ("Found unknown categories {0} in column {1}"
                               " during fit".format(diff, i))
                        raise ValueError(msg)
            self.categories_.append(cats)
            
            if self.max_levels is not None:
                infrequent_indices = self._find_infrequent_category_indices(Xi)
            else:
                infrequent_indices = np.array([])
            self.infrequent_indices_.append(infrequent_indices)
//  [python]
def test_cumproduct(self):
        self.assert_deprecated(lambda: np.cumproduct(np.array([1, 2, 3])))
//  [python]
def test_cumproduct(self):
        self.assert_deprecated(lambda: np.cumprod(np.array([1, 2, 3])))
//  [python]
def validate_module(self, pipeline):
        """If using rules, validate them"""
        for flag in self.flags:
            for measurement_setting in flag.measurement_settings:
                if measurement_setting.source_choice == S_RULES:
                    try:
                        rules = self.get_rules(measurement_setting)
                    except Exception as instance:
                        LOGGER.warning(
                            "Failed to load rules: %s", str(instance), exc_info=True
                        )
                        raise ValidationError(
                            str(instance), measurement_setting.rules_file_name
                        )
                    if not n.all([r.object_name == IMAGE for r in rules.rules]):
                        raise ValidationError(
                            "The rules listed in %s describe objects instead of images."
                            % measurement_setting.rules_file_name.value,
                            measurement_setting.rules_file_name,
                        )
                    for r in rules.rules:
                        if self.rules.Rule.return_fuzzy_measurement_name(
                            pipeline.get_measurement_columns(self),
                            "Image",
                            r.feature,
                            True,
                            measurement_setting.allow_fuzzy
                            ) == '':
                                raise ValidationError(
                                    "The rule described by %s has not been measured earlier in the pipeline."
                                    %r.feature,
                                    measurement_setting.rules_file_name,
                                )
                elif measurement_setting.source_choice == S_CLASSIFIER:
                    try:
                        self.get_classifier(measurement_setting)
                        self.get_classifier_features(measurement_setting)
                        self.get_bin_labels(measurement_setting)
                    except IOError:
                        raise ValidationError(
                            "Failed to load classifier file %s"
                            % measurement_setting.rules_file_name.value,
                            measurement_setting.rules_file_name,
                        )
                    except:
                        raise ValidationError(
                            "Unable to load %s as a classifier file"
                            % measurement_setting.rules_file_name.value,
                            measurement_setting.rules_file_name,
                        )
//  [python]
def validate_module(self, pipeline):
        """If using rules, validate them"""
        for flag in self.flags:
            for measurement_setting in flag.measurement_settings:
                if measurement_setting.source_choice == S_RULES:
                    try:
                        rules = self.get_rules(measurement_setting)
                    except Exception as instance:
                        LOGGER.warning(
                            "Failed to load rules: %s", str(instance), exc_info=True
                        )
                        raise ValidationError(
                            str(instance), measurement_setting.rules_file_name
                        )
                    if not numpy.all([r.object_name == IMAGE for r in rules.rules]):
                        raise ValidationError(
                            "The rules listed in %s describe objects instead of images."
                            % measurement_setting.rules_file_name.value,
                            measurement_setting.rules_file_name,
                        )
                    for r in rules.rules:
                        if self.rules.Rule.return_fuzzy_measurement_name(
                            pipeline.get_measurement_columns(self),
                            "Image",
                            r.feature,
                            True,
                            measurement_setting.allow_fuzzy
                            ) == '':
                                raise ValidationError(
                                    "The rule described by %s has not been measured earlier in the pipeline."
                                    %r.feature,
                                    measurement_setting.rules_file_name,
                                )
                elif measurement_setting.source_choice == S_CLASSIFIER:
                    try:
                        self.get_classifier(measurement_setting)
                        self.get_classifier_features(measurement_setting)
                        self.get_bin_labels(measurement_setting)
                    except IOError:
                        raise ValidationError(
                            "Failed to load classifier file %s"
                            % measurement_setting.rules_file_name.value,
                            measurement_setting.rules_file_name,
                        )
                    except:
                        raise ValidationError(
                            "Unable to load %s as a classifier file"
                            % measurement_setting.rules_file_name.value,
                            measurement_setting.rules_file_name,
                        )
//  [python]
def tall(x: T.Tensor, axis: int=None, keepdims: bool=False) -> T.Boolean:
    """
    Return True if all elements of the input tensor are true along the
    specified axis.

    Args:
        x: A float or tensor.
        axis (optional): The axis of interest.
        keepdims (optional): If this is set to true, the dimension of the tensor
                             is unchanged. Otherwise, the reduced axis is removed
                             and the dimension of the array is 1 less.

    Returns:
        if axis is None:
            bool: 'all' applied to all elements in the tensor
        else:
            tensor (of bools): 'all' applied to the elements in the tensor
                                along axis

    """
    return n.all(x, axis=axis, keepdims=keepdims)
//  [python]
def tall(x: T.Tensor, axis: int=None, keepdims: bool=False) -> T.Boolean:
    """
    Return True if all elements of the input tensor are true along the
    specified axis.

    Args:
        x: A float or tensor.
        axis (optional): The axis of interest.
        keepdims (optional): If this is set to true, the dimension of the tensor
                             is unchanged. Otherwise, the reduced axis is removed
                             and the dimension of the array is 1 less.

    Returns:
        if axis is None:
            bool: 'all' applied to all elements in the tensor
        else:
            tensor (of bools): 'all' applied to the elements in the tensor
                                along axis

    """
    return numpy.all(x, axis=axis, keepdims=keepdims)