# Common LAPACK/Blas utility functions

**URL:** https://discourse.julialang.org/t/common-lapack-blas-utility-functions/62530
**Category:** General Usage
**Created:** [June 7, 2021, 4:32pm UTC](https://discourse.julialang.org/t/common-lapack-blas-utility-functions/62530 "2021-06-07T16:32:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dgleich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dgleich/32/1494_2.png) [@dgleich](https://discourse.julialang.org/u/dgleich)
#### Post date: [June 7, 2021, 4:32pm UTC](https://discourse.julialang.org/t/common-lapack-blas-utility-functions/62530/1 "2021-06-07T16:32:46Z")

</div>

LAPACK and Blas have all these handy little routines like

dlascl - scale an array between two normalized quantities handling overflow/underflow/etc.

```julia
# _dlascl(from, to, x)
# This will compute x .*= x (to/from) and handle special cases 
julia> _dlascl(1e-300, 1e300, [1e-300, 1e-301, 1e-299]) 
3-element Vector{Float64}:
 1.0000000000000002e300
 1.0000000000000002e299
 1.0000000000000002e301

```

dlapy2 - computer sqrt(x^2+y^2) handling underflow/overflow

```julia
julia> _dlapy2(1e300,1e200)
1.0e300

julia> sqrt(1e300^2+1e200^2)
Inf

```

Am I missing some package/scenario in Julia where these exist? (I realize I can call BLAS/LAPACK directly, but I want to know if there’s another place I should be looking for these little micro-utilities.)

Each routine isn’t very complicated, but they are often somewhat subtle, e.g.

```julia
@inline function _dlapy2(x::T, y::T) where T 
  !isnan(x) || return x
  !isnan(y) || return y
  w = max(abs(x),abs(y))
  z = min(abs(x),abs(y))
  if z == 0
    return w
  else
    return w*sqrt(1+(z/w)^2)
  end
end

```

Apologies if I haven’t found _just the right google search_ or my list of what I would search for wasn’t quite expansive enough.

PS - Edited for code blocks

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [June 7, 2021, 4:35pm UTC](https://discourse.julialang.org/t/common-lapack-blas-utility-functions/62530/2 "2021-06-07T16:35:32Z")

</div>

> [@dgleich](#):
>
> dlapy2 - computer sqrt(x^2+y^2) handling underflow/overflow

This is the `hypot` function.

`dlascl` would be easy enough to implement, but there doesn’t seem to have been any demand for it.

PS. Technically, these are [LAPACK auxiliary routines](http://www.netlib.org/lapack/explore-html-3.6.1/d7/d43/group__aux_o_t_h_e_rauxiliary.html). The generally useful ones (e.g. `dlamch`, `dsecnd`, `dlisnan`, `dlapy2`, `dlapy3`, `dlarnv`, etc.) seem to mostly already have Julia equivalents.
