def ctr_mass(geom, masses):
    import numpy as np
    from .base import safe_cast as scast
    if len(geom.shape) != 1:
        raise ValueError("Geometry is not a vector")
    if len(masses.shape) != 1:
        raise ValueError("Masses cannot be parsed as a vector")
    if not geom.shape[0] % 3 == 0:
        raise ValueError("Geometry is not length-3N")
    if geom.shape[0] != 3*masses.shape[0] and geom.shape[0] != masses.shape[0]:
        raise ValueError("Inconsistent geometry and masses vector lengths")
    if geom.shape[0] == 3*masses.shape[0]:
        masses = masses.repeat(3)
    ctr = np.multiply(geom, masses).reshape((geom.shape[0]//3, 3)) \
                                .sum(axis=0).squeeze() / (masses.sum() / 3)
    return ctr