function diag (x) {
  return NdArray.new(x).diag();
}
Extract a diagonal or construct a diagonal array.

@param {Array|NdArray} x
@returns {NdArray} a view a of the original array when possible, a new array otherwise