# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/constants.py
# C_AUDAY = C * DAY_S / AU_M
# 
# Path: skyfield/functions.py
# def length_of(xyz):
#     """Given a 3-element array |xyz|, return its length.
# 
#     The three elements can be simple scalars, or the array can be two
#     dimensions and offer three whole series of x, y, and z coordinates.
# 
#     """
#     return sqrt((xyz * xyz).sum(axis=0))
# 
# def _reconcile(a, b):
#     """Coerce two NumPy generics-or-arrays to the same number of dimensions."""
#     an = getattr(a, 'ndim', 0)
#     bn = getattr(b, 'ndim', 0)
#     difference = bn - an
#     if difference > 0:
#         if an:
#             a.shape += (1,) * difference
#         else:
#             a = full_like(b, a)
#     elif difference < 0:
#         if bn:
#             b.shape += (1,) * -difference
#         else:
#             b = full_like(a, b)
#     return a, b


from numpy import array, max
from skyfield.api import load
from skyfield.constants import C_AUDAY
from skyfield.functions import length_of, _reconcile

    print('======', cposition.shape)
    # ?
    print('tdb_fraction before:', tdb_fraction.shape)
    tdb_fraction = tdb_fraction[:,None]
    print('tdb_fraction after:', tdb_fraction.shape)

    tposition, tvelocity, gcrs_position, message = target._at(t)

    distance = length_of(tposition - cposition)
    light_time0 = 0.0
    for i in range(10):
        print('i =', i)
        light_time = distance / C_AUDAY
        delta = light_time - light_time0
        if abs(max(delta)) < 1e-12:
            break

        # We assume a light travel time of at most a couple of days.  A
        # longer light travel time would best be split into a whole and
        # fraction, for adding to the whole and fraction of TDB.
        t2 = ts.tdb_jd(whole, tdb_fraction - light_time)

        tposition, tvelocity, gcrs_position, message = target._at(t2)
        distance = length_of(tposition - cposition)
        light_time0 = light_time
    else:
        raise ValueError('light-travel time failed to converge')
    return tposition - cposition, tvelocity - cvelocity, t, light_time


# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/constants.py
# C_AUDAY = C * DAY_S / AU_M
# 
# Path: skyfield/functions.py
# def length_of(xyz):
#     """Given a 3-element array |xyz|, return its length.
# 
#     The three elements can be simple scalars, or the array can be two
#     dimensions and offer three whole series of x, y, and z coordinates.
# 
#     """
#     return sqrt((xyz * xyz).sum(axis=0))
# 
# def _reconcile(a, b):
#     """Coerce two NumPy generics-or-arrays to the same number of dimensions."""
#     an = getattr(a, 'ndim', 0)
#     bn = getattr(b, 'ndim', 0)
#     difference = bn - an
#     if difference > 0:
#         if an:
#             a.shape += (1,) * difference
#         else:
#             a = full_like(b, a)
#     elif difference < 0:
#         if bn:
#             b.shape += (1,) * -difference
#         else:
#             b = full_like(a, b)
#     return a, b


# Path: design/broadcasting.py
from numpy import array, max
from skyfield.api import load
from skyfield.constants import C_AUDAY
from skyfield.functions import length_of, _reconcile


    print('======', cposition.shape)
    # ?
    print('tdb_fraction before:', tdb_fraction.shape)
    tdb_fraction = tdb_fraction[:,None]
    print('tdb_fraction after:', tdb_fraction.shape)

    tposition, tvelocity, gcrs_position, message = target._at(t)

    distance = length_of(tposition - cposition)
    light_time0 = 0.0
    for i in range(10):
        print('i =', i)
        light_time = distance / C_AUDAY
        delta = light_time - light_time0
        if abs(max(delta)) < 1e-12:
            break

        # We assume a light travel time of at most a couple of days.  A
        # longer light travel time would best be split into a whole and
        # fraction, for adding to the whole and fraction of TDB.
        t2 = ts.tdb_jd(whole, tdb_fraction - light_time)

        tposition, tvelocity, gcrs_position, message = target._at(t2)
        distance = length_of(tposition - cposition)
        light_time0 = light_time
    else:
        raise ValueError('light-travel time failed to converge')
    return tposition - cposition, tvelocity - cvelocity, t, light_time


_reconcile  # So CI will think we used it, whether use above is commented or not