function getReshaped(inputShape, blockShape, prod, batchToSpace = true) {
    let reshaped = [];
    if (batchToSpace) {
        reshaped = reshaped.concat(blockShape.slice(0));
        reshaped.push(inputShape[0] / prod);
        reshaped = reshaped.concat(inputShape.slice(1));
    } else {
        reshaped = reshaped.concat(inputShape[0]);
        const spatialLength = blockShape.length;
        for(let i = 0; i < spatialLength; ++i)reshaped = reshaped.concat([
            inputShape[i + 1] / blockShape[i],
            blockShape[i]
        ]);
        reshaped = reshaped.concat(inputShape.slice(spatialLength + 1));
    }
    return reshaped;
}
Converts the crops argument into the size of a slice operation.  When
combined with getSliceBeginCoords this function allows the reshaped and
permuted Tensor to be cropped to its final output shape of:

inputShape[1] * blockShape[0] - crops[0,0] - crops[0,1], ...,
inputShape[M] * blockShape[M-1] -crops[M-1,0] -
crops[M-1,1],inputShape[M+1], ..., inputShape[N-1]]

See step 4: https://www.tensorflow.org/api_docs/python/tf/batch_to_space_nd