function getPermuted(reshapedRank, blockShapeRank, batchToSpace) {
	  if (batchToSpace === void 0) {
	    batchToSpace = true;
	  }

	  var permuted = [];

	  if (batchToSpace) {
	    permuted.push(blockShapeRank);

	    for (var i = blockShapeRank + 1; i < reshapedRank; ++i) {
	      if (i <= 2 * blockShapeRank) {
	        permuted.push(i);
	        permuted.push(i - (blockShapeRank + 1));
	      } else {
	        permuted.push(i);
	      }
	    }
	  } else {
	    var permutedBeforeBatch = [];
	    var permutedAfterBatch = [];

	    for (var _i = 1; _i < reshapedRank; ++_i) {
	      if (_i >= blockShapeRank * 2 + 1 || _i % 2 === 1) {
	        permutedAfterBatch.push(_i);
	      } else {
	        permutedBeforeBatch.push(_i);
	      }
	    }

	    permuted.push.apply(permuted, permutedBeforeBatch);
	    permuted.push(0);
	    permuted.push.apply(permuted, permutedAfterBatch);
	  }

	  return permuted;
	}
Gets the permutation that will transpose the dimensions of the
reshaped tensor to shape:

[batch / prod(block_shape),inputShape[1], blockShape[0], ...,
inputShape[M], blockShape[M-1],inputShape[M+1], ..., inputShape[N-1]]

see step 2: https://www.tensorflow.org/api_docs/python/tf/batch_to_space_nd