# What is the idea of having a builtin function like 'axpy!'?

**URL:** https://discourse.julialang.org/t/what-is-the-idea-of-having-a-builtin-function-like-axpy/108453
**Category:** General Usage
**Tags:** question
**Created:** [January 7, 2024, 3:06am UTC](https://discourse.julialang.org/t/what-is-the-idea-of-having-a-builtin-function-like-axpy/108453 "2024-01-07T03:06:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)
#### Post date: [January 7, 2024, 3:06am UTC](https://discourse.julialang.org/t/what-is-the-idea-of-having-a-builtin-function-like-axpy/108453/1 "2024-01-07T03:06:07Z")

</div>

I am from matlab. I find that there are actually much more builtin functions in julia than in matlab. In julia, we even have a function like ‘axpy!’

It is of course handy to have such a builtin function, although it is simple to program it yourself.

What is the idea of having such small functions? Possibly matlab should have them too, as we pay more should get more.

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [January 7, 2024, 3:27am UTC](https://discourse.julialang.org/t/what-is-the-idea-of-having-a-builtin-function-like-axpy/108453/2 "2024-01-07T03:27:02Z")

</div>

The `axpy` function relates to the [BLAS](https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) standard. BLAS routines are the cornerstone of numerical computing and are often backed by vendor-specific highly optimized libraries like [MKL](https://en.wikipedia.org/wiki/Math_Kernel_Library). These are typically much faster than the equivalent handwritten routine.

---

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [January 7, 2024, 7:59am UTC](https://discourse.julialang.org/t/what-is-the-idea-of-having-a-builtin-function-like-axpy/108453/3 "2024-01-07T07:59:06Z")

</div>

To extend. bit on “why to have them”, using the high level functions is usually. just fine, especially when you write the code initially.  
Later, if you notice it can be done faster by using a low level function you could still optimise your code to get a bit more performance. Though for now I mainly have seen that with [`mul!`](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.mul!), specially its second variant.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [January 7, 2024, 8:43am UTC](https://discourse.julialang.org/t/what-is-the-idea-of-having-a-builtin-function-like-axpy/108453/4 "2024-01-07T08:43:18Z")

</div>

`LinearAlgebra.axpy!` is not [a built-in function](https://docs.julialang.org/en/v1/devdocs/functions/#Builtins), you can tell because it prints “generic function” in the REPL. A built-in function, like `getfield`, prints “built-in function” and lacks the multiple modifiable methods of a generic function. Built-in functions all belong to the `Core` module, which must be present for Julia to work at all. Even the `Base` module with basic features, like `getindex`, is only imported automatically in `module` block modules; `baremodule` block modules only import `Core` automatically. In both Julia [and MATLAB](https://www.mathworks.com/help/matlab/ref/builtin.html), a built-in function is implemented in a different language, often C; this does not imply that other functions must be entirely implemented in the base language, some like [`axpy!`](https://github.com/JuliaLang/julia/blob/e2b31cdb9f45b516fadbe39efc5adc29489de1ec/stdlib/LinearAlgebra/src/blas.jl#L500C1-L519C4) are not.
