function _resize (matrix, rows, columns, defaultValue) {
    // value to insert at the time of growing matrix
    let value = defaultValue || 0

    // equal signature to use
    let eq = equalScalar
    // zero value
    let zero = 0

    if (isString(matrix._datatype)) {
      // find signature that matches (datatype, datatype)
      eq = typed.find(equalScalar, [matrix._datatype, matrix._datatype]) || equalScalar
      // convert 0 to the same datatype
      zero = typed.convert(0, matrix._datatype)
      // convert value to the same datatype
      value = typed.convert(value, matrix._datatype)
    }

    // should we insert the value?
    const ins = !eq(value, zero)

    // old columns and rows
    const r = matrix._size[0]
    let c = matrix._size[1]

    let i, j, k

    // check we need to increase columns
    if (columns > c) {
      // loop new columns
      for (j = c; j < columns; j++) {
        // update matrix._ptr for current column
        matrix._ptr[j] = matrix._values.length
        // check we need to insert matrix._values
        if (ins) {
          // loop rows
          for (i = 0; i < r; i++) {
            // add new matrix._values
            matrix._values.push(value)
            // update matrix._index
            matrix._index.push(i)
          }
        }
      }
      // store number of matrix._values in matrix._ptr
      matrix._ptr[columns] = matrix._values.length
    } else if (columns < c) {
      // truncate matrix._ptr
      matrix._ptr.splice(columns + 1, c - columns)
      // truncate matrix._values and matrix._index
      matrix._values.splice(matrix._ptr[columns], matrix._values.length)
      matrix._index.splice(matrix._ptr[columns], matrix._index.length)
    }
    // update columns
    c = columns

    // check we need to increase rows
    if (rows > r) {
      // check we have to insert values
      if (ins) {
        // inserts
        let n = 0
        // loop columns
        for (j = 0; j < c; j++) {
          // update matrix._ptr for current column
          matrix._ptr[j] = matrix._ptr[j] + n
          // where to insert matrix._values
          k = matrix._ptr[j + 1] + n
          // pointer
          let p = 0
          // loop new rows, initialize pointer
          for (i = r; i < rows; i++, p++) {
            // add value
            matrix._values.splice(k + p, 0, value)
            // update matrix._index
            matrix._index.splice(k + p, 0, i)
            // increment inserts
            n++
          }
        }
        // store number of matrix._values in matrix._ptr
        matrix._ptr[c] = matrix._values.length
      }
    } else if (rows < r) {
      // deletes
      let d = 0
      // loop columns
      for (j = 0; j < c; j++) {
        // update matrix._ptr for current column
        matrix._ptr[j] = matrix._ptr[j] - d
        // where matrix._values start for next column
        const k0 = matrix._ptr[j]
        const k1 = matrix._ptr[j + 1] - d
        // loop matrix._index
        for (k = k0; k < k1; k++) {
          // row
          i = matrix._index[k]
          // check we need to delete value and matrix._index
          if (i > rows - 1) {
            // remove value
            matrix._values.splice(k, 1)
            // remove item from matrix._index
            matrix._index.splice(k, 1)
            // increase deletes
            d++
          }
        }
      }
      // update matrix._ptr for current column
      matrix._ptr[j] = matrix._values.length
    }
    // update matrix._size
    matrix._size[0] = rows
    matrix._size[1] = columns
    // return matrix
    return matrix
  }
Resize the matrix to the given size. Returns a copy of the matrix when
`copy=true`, otherwise return the matrix itself (resize in place).

@memberof SparseMatrix
@param {number[] | Matrix} size  The new size the matrix should have.
                                 Since sparse matrices are always two-dimensional,
                                 size must be two numbers in either an array or a matrix
@param {*} [defaultValue=0]      Default value, filled in on new entries.
                                 If not provided, the matrix elements will
                                 be filled with zeros.
@param {boolean} [copy]          Return a resized copy of the matrix

@return {Matrix}                 The resized matrix