# General Usage

**URL:** https://discourse.julialang.org/c/usage/6.md?page=367

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 368

---

## [Union{T,Nothing} vs multiple dispatch](https://discourse.julialang.org/t/union-t-nothing-vs-multiple-dispatch/90414)

<div class="topic-metadata">

**Author:** [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Replies:** 8\
**Last updated:** [November 17, 2022, 9:39pm UTC](https://discourse.julialang.org/t/union-t-nothing-vs-multiple-dispatch/90414 "2022-11-17T21:39:32Z")

</div>

For performance reasons, it is advised to avoid Unions. But on the topic of Nothing, the documentation suggests the compiler will emit efficient code. Is it preferred to use multiple dispatch, i.e., have two versions of …

---

## [Improving pullback speed with list comprehension](https://discourse.julialang.org/t/improving-pullback-speed-with-list-comprehension/90361)

<div class="topic-metadata">

**Author:** [@mhar](https://discourse.julialang.org/u/mhar)\
**Replies:** 4\
**Last updated:** [November 17, 2022, 8:50pm UTC](https://discourse.julialang.org/t/improving-pullback-speed-with-list-comprehension/90361 "2022-11-17T20:50:08Z")

</div>

Here is a MWE of the function I have that needs AD. N = 100 function compute\_many\_prods(f, g) return \[f \* g \* i for i = 1:N\] end function compute\_many\_prods2(f, g) return compute\_many\_prods(f, g) end function Ch…

---

## [Is previous function apply remove from base?](https://discourse.julialang.org/t/is-previous-function-apply-remove-from-base/90367)

<div class="topic-metadata">

**Author:** [@somranger](https://discourse.julialang.org/u/somranger)\
**Replies:** 8\
**Last updated:** [November 17, 2022, 7:39pm UTC](https://discourse.julialang.org/t/is-previous-function-apply-remove-from-base/90367 "2022-11-17T19:39:25Z")

</div>

In this link, https://stackoverflow.com/a/22873866/20438781 it seems that there was an apply function transfer a tuple to a function. However, it disappears in current version, and Varargs Functions still exists. Certai…

---

## [Suggestions to improve Zygote performance for simple vector map/broadcast/comprehension?](https://discourse.julialang.org/t/suggestions-to-improve-zygote-performance-for-simple-vector-map-broadcast-comprehension/35207)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 6\
**Last updated:** [November 9, 2022, 3:13am UTC](https://discourse.julialang.org/t/suggestions-to-improve-zygote-performance-for-simple-vector-map-broadcast-comprehension/35207 "2022-11-09T03:13:54Z")

</div>

I’ve got some code which is building some moderate sized vectors, which I’d like to derive through. Here’s an example building these vectors with a comprehension (the issue is the same if I use map or broadcast): build\_…

---

## [Any suggestion for speeding up my function?](https://discourse.julialang.org/t/any-suggestion-for-speeding-up-my-function/90393)

<div class="topic-metadata">

**Author:** [@tiZ](https://discourse.julialang.org/u/tiZ)\
**Replies:** 11\
**Last updated:** [November 17, 2022, 5:39pm UTC](https://discourse.julialang.org/t/any-suggestion-for-speeding-up-my-function/90393 "2022-11-17T17:39:01Z")

</div>

Hi, I have a function accepts 4 matrixs and do some caculations, it works well but very slow. I wonder to know how to improve its performance? I’m wondering if it’s possible to be faster, I just know that using @. the…

---

## [Output type from input function handle output type?](https://discourse.julialang.org/t/output-type-from-input-function-handle-output-type/90373)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 13\
**Last updated:** [November 17, 2022, 4:52pm UTC](https://discourse.julialang.org/t/output-type-from-input-function-handle-output-type/90373 "2022-11-17T16:52:36Z")

</div>

I have a recursive function that takes in a function handle, and eventually calls that function. It’s causing some allocations because the compiler can’t work out the output type of my recursive function. Is there a way …

---

## [Define a \`mapat\` function to map a function over specific indices](https://discourse.julialang.org/t/define-a-mapat-function-to-map-a-function-over-specific-indices/90392)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 3\
**Last updated:** [November 17, 2022, 3:02pm UTC](https://discourse.julialang.org/t/define-a-mapat-function-to-map-a-function-over-specific-indices/90392 "2022-11-17T15:02:42Z")

</div>

I have an Array and want to map a function over selected indices, I tried the following two implementations: # Map function \`f\` at specific indices of an array and update in-place function mapat!(f, array, indices...) …

---

## [Animations with PlotlyJS?](https://discourse.julialang.org/t/animations-with-plotlyjs/34633)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 6\
**Last updated:** [November 17, 2022, 1:17am UTC](https://discourse.julialang.org/t/animations-with-plotlyjs/34633 "2022-11-17T01:17:16Z")

</div>

Has anyone put together an animated plot using PlotlyJS to display the progress of a computation (so not a postprocessed gif and such)? If so, is there an example?

---

## [How to check if an imported name is used in a module?](https://discourse.julialang.org/t/how-to-check-if-an-imported-name-is-used-in-a-module/90400)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 0\
**Last updated:** [November 17, 2022, 2:13pm UTC](https://discourse.julialang.org/t/how-to-check-if-an-imported-name-is-used-in-a-module/90400 "2022-11-17T14:13:45Z")

</div>

I want to check if all the names being imported in a module are being used somewhere, and return a list of names that aren’t being used in the module. The simple way to do this is to grep for every name, but I was wonder…

---

## [Can \`Plots.jl\` \`heatmap\` coordinates start at 1 instead of 0.5?](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 4\
**Last updated:** [November 17, 2022, 1:25pm UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385 "2022-11-17T13:25:27Z")

</div>

For example, I want to heatmap the following matrix: julia\> m = \[ 1 1 -1 -1 -1 -1 -1 1 1 1 1 1 -1 -1 1 1 \] using Plots heatmap(m) But if I set xlims and y…

---

## [Mysterious allocations in nested scalar loops](https://discourse.julialang.org/t/mysterious-allocations-in-nested-scalar-loops/90380)

<div class="topic-metadata">

**Author:** [@gtgt](https://discourse.julialang.org/u/gtgt)\
**Replies:** 5\
**Last updated:** [November 17, 2022, 12:59pm UTC](https://discourse.julialang.org/t/mysterious-allocations-in-nested-scalar-loops/90380 "2022-11-17T12:59:29Z")

</div>

I am writing some code to solve Project Euler #60. Given an upper bound N, the program uses 5 nested for loops to find the smallest sum of quintuples (p\_1, p\_2, p\_3, p\_4, p\_5) of prime numbers, p\_i \\leqslant N such that …

---

## [Order of parameters in a function that has side effects](https://discourse.julialang.org/t/order-of-parameters-in-a-function-that-has-side-effects/90397)

<div class="topic-metadata">

**Author:** [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Replies:** 1\
**Last updated:** [November 17, 2022, 12:09pm UTC](https://discourse.julialang.org/t/order-of-parameters-in-a-function-that-has-side-effects/90397 "2022-11-17T12:09:09Z")

</div>

Is it a Julia convention to list the parameters with side effects first in the list of parameters, where those that have no side effects are listed last? I was looking at some of the code in base and the convention did n…

---

## [Interpreting output of Profile: Finding where code is called](https://discourse.julialang.org/t/interpreting-output-of-profile-finding-where-code-is-called/90396)

<div class="topic-metadata">

**Author:** [@renatobellotti](https://discourse.julialang.org/u/renatobellotti)\
**Replies:** 1\
**Last updated:** [November 17, 2022, 12:04pm UTC](https://discourse.julialang.org/t/interpreting-output-of-profile-finding-where-code-is-called/90396 "2022-11-17T12:04:18Z")

</div>

Dear Julia enthusiasts, I’m currently profiling an optimisation code that relies on Optim.jl and Zygote to calculate the gradients. Interestingly, about half of the runtime seems to be spent on creating and destroying t…

---

## [Random seeds in distributed computing](https://discourse.julialang.org/t/random-seeds-in-distributed-computing/88891)

<div class="topic-metadata">

**Author:** [@renatobellotti](https://discourse.julialang.org/u/renatobellotti)\
**Replies:** 4\
**Last updated:** [November 17, 2022, 11:14am UTC](https://discourse.julialang.org/t/random-seeds-in-distributed-computing/88891 "2022-11-17T11:14:47Z")

</div>

Hi, I’m currently trying to seed my RNG for a distributed code. I have tried this snippet, but it does not run reproducibly: using Distributed using Random # Distributed seeding: # We seed an RNG on the master, then g…

---

## [Julia ode: Jacobi function does not get called](https://discourse.julialang.org/t/julia-ode-jacobi-function-does-not-get-called/90389)

<div class="topic-metadata">

**Author:** [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Replies:** 2\
**Last updated:** [November 17, 2022, 10:21am UTC](https://discourse.julialang.org/t/julia-ode-jacobi-function-does-not-get-called/90389 "2022-11-17T10:21:36Z")

</div>

Hello, I have a problem with the following example. It just represents he problem from another code i wrote. I want to use the function f\_jac to supply the jacobian to the ode solver. But somehow the function does not ge…

---

## [Getting this type signature correct](https://discourse.julialang.org/t/getting-this-type-signature-correct/90383)

<div class="topic-metadata">

**Author:** [@torrance](https://discourse.julialang.org/u/torrance)\
**Replies:** 3\
**Last updated:** [November 17, 2022, 4:46am UTC](https://discourse.julialang.org/t/getting-this-type-signature-correct/90383 "2022-11-17T04:46:04Z")

</div>

Say I have a function that accepts at least one argument of Union{Int, Colon, OrdinalRange}. I can write this like: function test(i::Union{Int, Colon, OrdinalRange}, I::Union{Int, Colon, OrdinalRange}...) println((i…

---

## [Arpack 0.5.4 broken](https://discourse.julialang.org/t/arpack-0-5-4-broken/90381)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 0\
**Last updated:** [November 17, 2022, 4:14am UTC](https://discourse.julialang.org/t/arpack-0-5-4-broken/90381 "2022-11-17T04:14:11Z")

</div>

A PA for those who use Arpack: Arpack 0.5.4 for the generalized eigenvalue problem with positive definite sparse matrices and the smallest eigenvalues is broken. The solution converges for 0.5.3 but fails for 0.5.4. Iss…

---

## [Syntax error in parallel computing](https://discourse.julialang.org/t/syntax-error-in-parallel-computing/90378)

<div class="topic-metadata">

**Author:** [@marouane](https://discourse.julialang.org/u/marouane)\
**Replies:** 2\
**Last updated:** [November 17, 2022, 3:20am UTC](https://discourse.julialang.org/t/syntax-error-in-parallel-computing/90378 "2022-11-17T03:20:59Z")

</div>

I’m trying to learn parallel computing using Distributed and I tried the Pi computation as an example: using Distributed addprocs(4) function points\_inside(n) n\_in= 0 for i=1:n x,y= rand(), rand() …

---

## [Special environment for testing?](https://discourse.julialang.org/t/special-environment-for-testing/90306)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 9\
**Last updated:** [November 17, 2022, 2:51am UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306 "2022-11-17T02:51:29Z")

</div>

In order to test a package, I would like to use a test environment which would include many other packages, on which the tested package does not depend. I think it should be possible to have an ad hoc environment in the …

---

## [Avoiding allocations of small but non-trivial arrays (work array alternative?)](https://discourse.julialang.org/t/avoiding-allocations-of-small-but-non-trivial-arrays-work-array-alternative/90084)

<div class="topic-metadata">

**Author:** [@martin.d.maas](https://discourse.julialang.org/u/martin.d.maas)\
**Replies:** 38\
**Last updated:** [November 17, 2022, 12:52am UTC](https://discourse.julialang.org/t/avoiding-allocations-of-small-but-non-trivial-arrays-work-array-alternative/90084 "2022-11-17T00:52:01Z")

</div>

Hi everyone, I’m in the process of optimizing a portion of my code that has a general problem of too much memory allocation, and consequently poor threading efficiency and overall performance. This is a series of pretty…

---

## [Enum or struct?](https://discourse.julialang.org/t/enum-or-struct/90326)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 3\
**Last updated:** [November 17, 2022, 12:20am UTC](https://discourse.julialang.org/t/enum-or-struct/90326 "2022-11-17T00:20:43Z")

</div>

I would have chosen 1 but finance packages I’ve seen do something like 2. Is this better Julia ? more functional ? Option 1 - using enum @enum DayCount Actual360 Actual365 Year\_Fraction(d1::Date,d2::Date,dc::…

---

## [Gradient of 2D splines on irregular grid](https://discourse.julialang.org/t/gradient-of-2d-splines-on-irregular-grid/87575)

<div class="topic-metadata">

**Author:** [@Thomas\_Mikaelsen](https://discourse.julialang.org/u/Thomas_Mikaelsen)\
**Replies:** 2\
**Last updated:** [September 21, 2022, 2:29pm UTC](https://discourse.julialang.org/t/gradient-of-2d-splines-on-irregular-grid/87575 "2022-09-21T14:29:33Z")

</div>

Hello. I’m looking to (1) interpolate data where the x-axis is a log-spaced grid, the y-axis is a regular spaced grid and there is an array A(x,y) recording the function values in each point; and (2) take the gradient o…

---

## [Creating random \`MMatrix\` with large size is too slow](https://discourse.julialang.org/t/creating-random-mmatrix-with-large-size-is-too-slow/90323)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 5\
**Last updated:** [November 16, 2022, 3:57pm UTC](https://discourse.julialang.org/t/creating-random-mmatrix-with-large-size-is-too-slow/90323 "2022-11-16T15:57:52Z")

</div>

I want to create a StaticArrays.MMatrix with a somewhat medium or large size using rand, but it seems much slower than the plain Matrix and it took a long time for it to display: using StaticArray: MMatrix N = 10 m = r…

---

## [Calculating a pade approximant?](https://discourse.julialang.org/t/calculating-a-pade-approximant/74060)

<div class="topic-metadata">

**Author:** [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Replies:** 10\
**Last updated:** [November 16, 2022, 10:27pm UTC](https://discourse.julialang.org/t/calculating-a-pade-approximant/74060 "2022-11-16T22:27:03Z")

</div>

I’m assuming this must be hiding in a library somewhere… I found a pade appoximant evaluation in the Polynomials package, but it doesn’t look like there is any functionality for generating an approximant for an arbitrar…

---

## [Print errors untruncated and full precision](https://discourse.julialang.org/t/print-errors-untruncated-and-full-precision/90358)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 1\
**Last updated:** [November 16, 2022, 4:24pm UTC](https://discourse.julialang.org/t/print-errors-untruncated-and-full-precision/90358 "2022-11-16T16:24:18Z")

</div>

For a error thrown in some source location outside my control, is it possible to print the error object with full precision, untruncated, so that I can save the values from the REPL? MWE: julia\> throw(DomainError(rand(…

---

## [Improving performance with @sync @async macros](https://discourse.julialang.org/t/improving-performance-with-sync-async-macros/82822)

<div class="topic-metadata">

**Author:** [@mauri5566](https://discourse.julialang.org/u/mauri5566)\
**Replies:** 1\
**Last updated:** [November 16, 2022, 3:17pm UTC](https://discourse.julialang.org/t/improving-performance-with-sync-async-macros/82822 "2022-11-16T15:17:45Z")

</div>

I’m trying to parallelize this function by using @async @sync function INSR\_opt(f) function INSR0\_opt(seq) len = length(seq) res = seq\[end\] @inbounds @sync for i in range(len-2,step=-1,stop=0) @async res = f(\[…

---

## [Speed up very elemental functions](https://discourse.julialang.org/t/speed-up-very-elemental-functions/90342)

<div class="topic-metadata">

**Author:** [@Djoser42](https://discourse.julialang.org/u/Djoser42)\
**Replies:** 6\
**Last updated:** [November 16, 2022, 3:00pm UTC](https://discourse.julialang.org/t/speed-up-very-elemental-functions/90342 "2022-11-16T15:00:02Z")

</div>

Hey, I am still kind of new to Julia and I have a question about the performance and potential speed up of functions which are very elementar and/or “atomic” in my code, since they are used often and I figured that this …

---

## [Performance issues when working with dict](https://discourse.julialang.org/t/performance-issues-when-working-with-dict/74565)

<div class="topic-metadata">

**Author:** [@Deoch](https://discourse.julialang.org/u/Deoch)\
**Replies:** 11\
**Last updated:** [November 16, 2022, 2:05pm UTC](https://discourse.julialang.org/t/performance-issues-when-working-with-dict/74565 "2022-11-16T14:05:02Z")

</div>

Hello, I have some performance issues with dictionnaries, and I’m unsure about how to approach this problem. I profiled my code the other day, and I found that it spent a fair amount of time (that I wasn’t expecting) on…

---

## [GLMakie: how to refresh Menu object when item is selected via code?](https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 2\
**Last updated:** [November 16, 2022, 12:49pm UTC](https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341 "2022-11-16T12:49:27Z")

</div>

Consider the following code using GLMakie fig = Figure() b = Button(fig, label="Select ABC", textsize=20) m = Menu(fig, options=zip(\["A", "AB", "ABC"\], 1:3), default="A", textsize=20) panel = GridLayout() panel\[:v\] = \[…

---

## [Array of multiple differently sized vectors](https://discourse.julialang.org/t/array-of-multiple-differently-sized-vectors/90292)

<div class="topic-metadata">

**Author:** [@lukas\_r](https://discourse.julialang.org/u/lukas_r)\
**Replies:** 4\
**Last updated:** [November 16, 2022, 12:25pm UTC](https://discourse.julialang.org/t/array-of-multiple-differently-sized-vectors/90292 "2022-11-16T12:25:47Z")

</div>

I have an array of multiple vectors with different lengths. For further use I need them in one \[n, m\] Array. Is there a function to fill up the shorter vectors with missing/NaN?

[Previous page](https://discourse.julialang.org/c/usage/6.md?page=366)

[Next page](https://discourse.julialang.org/c/usage/6.md?page=368)
