def cielab_to_xyz (cielab, refwhite):
    """Convert CIE L*a*b* color values to CIE XYZ,

    *cielab* should be of shape (*, 3). *refwhite* is the reference white
    value in the L*a*b* color space, of shape (3, ).

    Return value has same shape as *cielab*

    """
    def func (t):
        pow = t**3
        scale = 0.128419 * t - 0.0177129
        return np.where (t > 0.206897, pow, scale)

    xyz = np.empty_like (cielab)
    lscale = 1./116 * (cielab[...,L] + 16)
    xyz[...,X] = func (lscale + 0.002 * cielab[...,A])
    xyz[...,Y] = func (lscale)
    xyz[...,Z] = func (lscale - 0.005 * cielab[...,B])
    xyz *= refwhite
    return xyz