function _diag(x, k, size, format) {
    if (!isInteger(k)) {
      throw new TypeError('Second parameter in function diag must be an integer');
    }

    var kSuper = k > 0 ? k : 0;
    var kSub = k < 0 ? -k : 0; // check dimensions

    switch (size.length) {
      case 1:
        return _createDiagonalMatrix(x, k, format, size[0], kSub, kSuper);

      case 2:
        return _getDiagonal(x, k, format, size, kSub, kSuper);
    }

    throw new RangeError('Matrix for function diag must be 2 dimensional');
  }
Creeate diagonal matrix from a vector or vice versa
@param {Array | Matrix} x
@param {number} k
@param {string} format Storage format for matrix. If null,
                         an Array is returned
@returns {Array | Matrix}
@private