Method: NMatrix::BLAS.nrm2

Defined in:
lib/nmatrix/blas.rb

.nrm2(x, incx = 1, n = nil) ⇒ Object

call-seq:

nrm2(x, incx, n)

Calculate the 2-norm of a vector x of size n

  • Arguments :

    • x -> an NMatrix (will also allow an

      NMatrix, but will treat it as if it's a vector )
      
    • incx -> the skip size (defaults to 1)

    • n -> the size of x (defaults to x.size / incx)

  • Returns :

    • The 2-norm

  • Raises :

    • ArgumentError -> Expected dense NMatrix for arg 0

    • RangeError -> n out of range

Raises:

  • (ArgumentError)


326
327
328
329
330
331
332
333
334
# File 'lib/nmatrix/blas.rb', line 326

def nrm2(x, incx = 1, n = nil)
  n ||= x.size / incx
  raise(ArgumentError, "Expected dense NMatrix for arg 0") \
   unless x.is_a?(NMatrix)

  raise(RangeError, "n out of range") \
   if n*incx > x.size || n*incx <= 0 || n <= 0
   ::NMatrix::BLAS.cblas_nrm2(n, x, incx)
end