* @param axis Axis from which the diagonals should be taken.
     * @return A 1-D array containing the diagonal.
     */
    // TODO This is a direct translation from Python -- need to figure it out.
    public static PyMultiarray diagonal(final PyObject o, int offset, final int axis) {
        // TODO Check arguments.
        // Leave debugging statements here, but turned off, until thoroughly
        // tested.
        final boolean debug_this = false;
        if (debug_this) {
            System.out
                    .println("\n************************\nDiagonal gets passed in 'o' = "
                            + o +
                            "with offset = " + offset + ", and axis = "
                            + axis);
        }
        PyMultiarray a = PyMultiarray.rotateAxes(PyMultiarray.asarray(o), -2
                - axis);
        if (debug_this) {
            System.out.println("\nDiagonal converts 'o' to " + a);
        }
        final int lastDimension = a.dimensions[a.dimensions.length - 1];
        if (debug_this) {
            System.out.println("\nLast dimension = a.dimensions[" +
                    a.dimensions.length + " -1] = " +
                    a.dimensions[a.dimensions.length - 1] + " = "
                    + lastDimension);
        }
        final int[] shape = new int[a.dimensions.length - 1];
        for (int i = 0; i < shape.length; i++) {
            shape[i] = a.dimensions[i];
        }
        if (debug_this) {
            System.out.println("shape[" + (shape.length - 1) + "] = " +
                    shape[shape.length - 1] + " becomes " +
                    shape[shape.length - 1] * lastDimension);
        }
        shape[shape.length - 1] *= lastDimension;
        final int oldAshape = a.dimensions[a.dimensions.length - 1];

        a = PyMultiarray.reshape(a, shape);
        // System.out.println("Reshaping a to " + a);
        // Need to adjust last dimension of shape to prevent
        // wrap-around on higher off-diagonals.
        final int shapeLastDim = shape[shape.length - 1] / lastDimension;
        if (debug_this) {
            System.out.println("offset = " + offset + ", shapeLastDim = "
                    + shapeLastDim
                    + ", a.dim[a.dim.len -2] = " + oldAshape
                    + ", lastDimension - shapeLastDim = "
                    + (lastDimension - shapeLastDim));
        }
        final int oldShape = shape[shape.length - 1];
        if (offset > 0 && offset > lastDimension - shapeLastDim) {
            shape[shape.length - 1] -= (offset - (lastDimension - shapeLastDim))
                    * lastDimension;
            if (debug_this) {
                System.out.println("Offset changes shape[shape.length-1] from "
                        + oldShape
                        + " to " + shape[shape.length - 1]);
            }
        }
        if (offset < 0) {
            offset = -lastDimension * offset;
        }
        if (debug_this) {
            System.out.println("\nArrayRange("
                    + offset
                    + ","
                    +
                    shape[shape.length - 1]
                    + ","
                    +
                    (lastDimension + 1)
                    + ") = "
                    + PyMultiarray.arrayRange(
                            offset,
                            shape[shape.length - 1],
                            lastDimension + 1,
                            'i'));
        }
        a = PyMultiarray.take(a, PyMultiarray.arrayRange(
                offset,
                shape[shape.length - 1],
                lastDimension + 1,
                'i'), -1);
        // System.out.println("\nTake(a, arrayRange) leaves us with " + a );
        return PyMultiarray.rotateAxes(a, 2 + axis);
    }