The shape of the two result arrays (*val and *pos) must be must be obtained from the shape of the source array by deleting dimension dim (see section 4.4).