# General Usage

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

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

**Page:** 75

---

## [Quirks when benchmarking allocations of StaticArrays in anonymous functions](https://discourse.julialang.org/t/quirks-when-benchmarking-allocations-of-staticarrays-in-anonymous-functions/127695)

<div class="topic-metadata">

**Author:** [@mxhbl](https://discourse.julialang.org/u/mxhbl)\
**Replies:** 2\
**Last updated:** [April 4, 2025, 9:48am UTC](https://discourse.julialang.org/t/quirks-when-benchmarking-allocations-of-staticarrays-in-anonymous-functions/127695 "2025-04-04T09:48:50Z")

</div>

While benchmarking allocations I stumbled upon some strange behavior that I cannot explain. I reduced it to the following example. using StaticArrays, BenchmarkTools vec = \[1, 2, 3\] svec = SA\[1, 2, 3\] fnamed(x) = 0 fan…

---

## [How do I break out of an infinite loop in REPL in 1.12?](https://discourse.julialang.org/t/how-do-i-break-out-of-an-infinite-loop-in-repl-in-1-12/127691)

<div class="topic-metadata">

**Author:** [@R.T.A.M](https://discourse.julialang.org/u/R.T.A.M)\
**Replies:** 4\
**Last updated:** [April 4, 2025, 2:14am UTC](https://discourse.julialang.org/t/how-do-i-break-out-of-an-infinite-loop-in-repl-in-1-12/127691 "2025-04-04T02:14:39Z")

</div>

While testing the new 1.12 features I tried the following in a REPL: f(x) = while x end f(true) The infinite loop works, so is there a way to break out of it in the REPL using CTRL+ D? Now that there are interactive a…

---

## [Including Gradient Term in Optimization.jl](https://discourse.julialang.org/t/including-gradient-term-in-optimization-jl/126965)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 4\
**Last updated:** [April 3, 2025, 9:39pm UTC](https://discourse.julialang.org/t/including-gradient-term-in-optimization-jl/126965 "2025-04-03T21:39:40Z")

</div>

Hi everyone :grinning:, I’m trying to solve an optimization problem using Optimization.jl, but I’m struggling with incorporating a gradient term \\nabla in the process. My cost function to minimize is: \\text{Cost} \\lef…

---

## [Creating a new package with the same environment as an existing package](https://discourse.julialang.org/t/creating-a-new-package-with-the-same-environment-as-an-existing-package/127684)

<div class="topic-metadata">

**Author:** [@curious](https://discourse.julialang.org/u/curious)\
**Replies:** 0\
**Last updated:** [April 3, 2025, 7:21pm UTC](https://discourse.julialang.org/t/creating-a-new-package-with-the-same-environment-as-an-existing-package/127684 "2025-04-03T19:21:38Z")

</div>

Hello, I want to create a new package that has exactly the same environment as an existing package. I would appreciate some help with how to do this. I have read Working with Julia projects | Julia programming notes and…

---

## [Incremental testing](https://discourse.julialang.org/t/incremental-testing/127680)

<div class="topic-metadata">

**Author:** [@langestefan](https://discourse.julialang.org/u/langestefan)\
**Replies:** 4\
**Last updated:** [April 3, 2025, 6:12pm UTC](https://discourse.julialang.org/t/incremental-testing/127680 "2025-04-03T18:12:15Z")

</div>

Hi, I was reading the page on unit testing and I found that the suggested method \] test was rather slow due to pre-compilation, making it unusable for me during development. There is a much faster way to incrementally …

---

## [Deleting and inspecting elements while iterating over object](https://discourse.julialang.org/t/deleting-and-inspecting-elements-while-iterating-over-object/127630)

<div class="topic-metadata">

**Author:** [@mateuszwilinski](https://discourse.julialang.org/u/mateuszwilinski)\
**Replies:** 5\
**Last updated:** [April 3, 2025, 4:34pm UTC](https://discourse.julialang.org/t/deleting-and-inspecting-elements-while-iterating-over-object/127630 "2025-04-03T16:34:56Z")

</div>

I know that deleting elements and iterating over an object at the same time is against good programming practices (regardless, whether we use Julia or other language). I learnt my lesson the hard way. Regardless, I am re…

---

## [Silent type promotion when creating range using \`a🅱c\`](https://discourse.julialang.org/t/silent-type-promotion-when-creating-range-using-ac/127671)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 2\
**Last updated:** [April 3, 2025, 2:41pm UTC](https://discourse.julialang.org/t/silent-type-promotion-when-creating-range-using-ac/127671 "2025-04-03T14:41:09Z")

</div>

I was meddling with ranges and found the following strange behaviour: suppose I want to create a range starting at 0, with step of 1 and length 10. If I want to work with Float32s, I’d type something like r1 = 0.0f0:1.0…

---

## [Install Python dependencies for PyCall.jl](https://discourse.julialang.org/t/install-python-dependencies-for-pycall-jl/127546)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 1\
**Last updated:** [April 3, 2025, 1:53pm UTC](https://discourse.julialang.org/t/install-python-dependencies-for-pycall-jl/127546 "2025-04-03T13:53:40Z")

</div>

I have an in-house package which, for legacy reasons, uses PyCall.jl instead of PythonCall.jl. My package includes a deps/build.jl which installs Python dependencies with e.g. Conda.add("somepackage"). However, PyCall.jl…

---

## [Failure to detect repeated names with splatted keyword args](https://discourse.julialang.org/t/failure-to-detect-repeated-names-with-splatted-keyword-args/127675)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 1\
**Last updated:** [April 3, 2025, 1:42pm UTC](https://discourse.julialang.org/t/failure-to-detect-repeated-names-with-splatted-keyword-args/127675 "2025-04-03T13:42:25Z")

</div>

Consider the following: julia\> kwargs = Dict(:a =\> 0) Dict{Symbol, Int64} with 1 entry: :a =\> 0 julia\> f(; a=1) = a f (generic function with 1 method) julia\> f(; a=2, kwargs...) 0 julia\> f(; a=2, a=0) ERROR: syntax…

---

## [Relation between type parameter](https://discourse.julialang.org/t/relation-between-type-parameter/127664)

<div class="topic-metadata">

**Author:** [@FerreolS](https://discourse.julialang.org/u/FerreolS)\
**Replies:** 7\
**Last updated:** [April 3, 2025, 1:37pm UTC](https://discourse.julialang.org/t/relation-between-type-parameter/127664 "2025-04-03T13:37:54Z")

</div>

Hi, I was wondering if there was a mean to enforce some kind of relation between parameter types. Here is an example: I can define the structure: struct mystruct{N,M} A::Array{Float64,N} B…

---

## [Discrete callback is triggered twice each time](https://discourse.julialang.org/t/discrete-callback-is-triggered-twice-each-time/127059)

<div class="topic-metadata">

**Author:** [@amynang](https://discourse.julialang.org/u/amynang)\
**Replies:** 15\
**Last updated:** [April 3, 2025, 1:26pm UTC](https://discourse.julialang.org/t/discrete-callback-is-triggered-twice-each-time/127059 "2025-04-03T13:26:35Z")

</div>

I am working on a Lotka-Volterra type competition system. I am trying to specify a rule such that at pre-specified time-points the (one) species with the lowest abundance at that time-step is eliminated. I am using a dis…

---

## [Getting MutableNamedTuple keys from an empty array](https://discourse.julialang.org/t/getting-mutablenamedtuple-keys-from-an-empty-array/127387)

<div class="topic-metadata">

**Author:** [@s\_amap](https://discourse.julialang.org/u/s_amap)\
**Replies:** 18\
**Last updated:** [April 3, 2025, 8:58am UTC](https://discourse.julialang.org/t/getting-mutablenamedtuple-keys-from-an-empty-array/127387 "2025-04-03T08:58:29Z")

</div>

Hmm, I have an empty Vector of MutableNamedTuples with a specific signature, ie if the array has a single element, then I can recover the keys of the underlying NamedTuple by inspecting the element. But what if the arr…

---

## [Anonymous Functions and Overwriting Arguments](https://discourse.julialang.org/t/anonymous-functions-and-overwriting-arguments/127586)

<div class="topic-metadata">

**Author:** [@phK3](https://discourse.julialang.org/u/phK3)\
**Replies:** 7\
**Last updated:** [April 3, 2025, 4:41am UTC](https://discourse.julialang.org/t/anonymous-functions-and-overwriting-arguments/127586 "2025-04-03T04:41:38Z")

</div>

I’ve stumbled upon the following (in my mind) weird behavior: If you define a named function that returns a function f1 based on a parameter a, the returned function stays the same, even if a gets assigned another value…

---

## [Why \`sprand\` does not accept a Distribution arg?](https://discourse.julialang.org/t/why-sprand-does-not-accept-a-distribution-arg/127255)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 10\
**Last updated:** [April 3, 2025, 4:02am UTC](https://discourse.julialang.org/t/why-sprand-does-not-accept-a-distribution-arg/127255 "2025-04-03T04:02:18Z")

</div>

Hi there, I wonder why this cannot work out (What is the available method currently then?). julia\> import SparseArrays.sprand as sprand julia\> import Distributions.Uniform as UD julia\> sprand(5, 6, .7) 5×6 SparseArra…

---

## [Makie plot with arrows to follow the trajectory of optimization solver](https://discourse.julialang.org/t/makie-plot-with-arrows-to-follow-the-trajectory-of-optimization-solver/127612)

<div class="topic-metadata">

**Author:** [@00krishna](https://discourse.julialang.org/u/00krishna)\
**Replies:** 3\
**Last updated:** [April 2, 2025, 6:30pm UTC](https://discourse.julialang.org/t/makie-plot-with-arrows-to-follow-the-trajectory-of-optimization-solver/127612 "2025-04-02T18:30:16Z")

</div>

I am trying write a notebook to display some nonlinear optimization descent solvers. Using CairoMakie, I wanted to make a plot that looks something like this. The arrows should have their tail at the current point in…

---

## [GraphMakie distance between nodes](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624)

<div class="topic-metadata">

**Author:** [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Replies:** 3\
**Last updated:** [April 2, 2025, 6:15pm UTC](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624 "2025-04-02T18:15:11Z")

</div>

Is there a way to adjust the distance between nodes? I have a simple graph like this that works: begin g2 = cycle\_digraph(3) fg=Figure(size=(800,800)) axg=Axis(fg\[1,1\]) GraphMakie.graphplot!(axg,g2; …

---

## [Multi-line expressions](https://discourse.julialang.org/t/multi-line-expressions/16096)

<div class="topic-metadata">

**Author:** [@albi3ro](https://discourse.julialang.org/u/albi3ro)\
**Replies:** 5\
**Last updated:** [April 2, 2025, 2:39pm UTC](https://discourse.julialang.org/t/multi-line-expressions/16096 "2025-04-02T14:39:51Z")

</div>

I remember being able to extend expressions over multiple lines without a problem in earlier versions of julia. How do I wrap an expression over multiple lines now when it gets too long? Particularly, I want to break a…

---

## [@defined "not working" inside macro](https://discourse.julialang.org/t/defined-not-working-inside-macro/127621)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 8\
**Last updated:** [April 2, 2025, 12:03pm UTC](https://discourse.julialang.org/t/defined-not-working-inside-macro/127621 "2025-04-02T12:03:42Z")

</div>

Predictably, when I do metaprogramming, I end up confused. I create functions that take user-defined function as an input - very flexible. But when the user writes a script to use my function, each time they parse the …

---

## [Facing problem in computing error in transient problem](https://discourse.julialang.org/t/facing-problem-in-computing-error-in-transient-problem/127628)

<div class="topic-metadata">

**Author:** [@Stayal](https://discourse.julialang.org/u/Stayal)\
**Replies:** 0\
**Last updated:** [April 2, 2025, 1:24pm UTC](https://discourse.julialang.org/t/facing-problem-in-computing-error-in-transient-problem/127628 "2025-04-02T13:24:06Z")

</div>

Hello everyone using Gridap using Printf domain = (0.0, 1.0, 0.0, 1.0) partition = (4, 4) model = CartesianDiscreteModel(domain, partition) order = 1 reffe = ReferenceFE(lagrangian, Float64, order) u\_ex(t) = x -\> t\*t…

---

## [Efficient way compute do WX+b?](https://discourse.julialang.org/t/efficient-way-compute-do-wx-b/127385)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 7\
**Last updated:** [April 2, 2025, 12:36pm UTC](https://discourse.julialang.org/t/efficient-way-compute-do-wx-b/127385 "2025-04-02T12:36:57Z")

</div>

Which is in Julia the most efficient CPU-way to compute Wx+b where W is a (JxI) matrix, X is a I-dimensional vector and b is a J dimensional vector ? (context: NN layers) I have saw this thread but I can’t understand…

---

## [Why does the Sobol Sensitivity (S1) so large in my model](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 18\
**Last updated:** [April 2, 2025, 12:12pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507 "2025-04-02T12:12:44Z")

</div>

I am running a model in Julia with 42 parameters (they are somehow inner-correlated with each other) and 6 outputs, and trying to use the function gsa from the package GlobalSensitivity.jl to diagnose the ST and S1 sensi…

---

## [Catalyst and BifurcationKit](https://discourse.julialang.org/t/catalyst-and-bifurcationkit/127087)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 11\
**Last updated:** [April 2, 2025, 12:12pm UTC](https://discourse.julialang.org/t/catalyst-and-bifurcationkit/127087 "2025-04-02T12:12:43Z")

</div>

Hi, Is there any reason why BifurcationKit is blocked at 0.4.4 in Catalyst?

---

## [IOError: close: i/o error (EIO) when using Pkg on cluster](https://discourse.julialang.org/t/ioerror-close-i-o-error-eio-when-using-pkg-on-cluster/127620)

<div class="topic-metadata">

**Author:** [@kira](https://discourse.julialang.org/u/kira)\
**Replies:** 0\
**Last updated:** [April 2, 2025, 7:14am UTC](https://discourse.julialang.org/t/ioerror-close-i-o-error-eio-when-using-pkg-on-cluster/127620 "2025-04-02T07:14:59Z")

</div>

I am trying to use Julia on an HPC cluster. However, when I try to add any packages, I get the error message below. The same error happens with any command in Pkg (status, activate environment, add). When I launch Julia …

---

## [Why does explicit declaration of ::INT save 40% runtime?](https://discourse.julialang.org/t/why-does-explicit-declaration-of-int-save-40-runtime/127575)

<div class="topic-metadata">

**Author:** [@uwestoehr](https://discourse.julialang.org/u/uwestoehr)\
**Replies:** 17\
**Last updated:** [April 2, 2025, 6:14am UTC](https://discourse.julialang.org/t/why-does-explicit-declaration-of-int-save-40-runtime/127575 "2025-04-02T06:14:08Z")

</div>

I am relatively new to Julia and I wrote some scripts my main issue is that my scripts perform always poor and I don’t understand why or what I am doing wrong. Take this code as example where I am failing: dimension = …

---

## [Subset a NamedTuple?](https://discourse.julialang.org/t/subset-a-namedtuple/127085)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 26\
**Last updated:** [April 2, 2025, 2:57am UTC](https://discourse.julialang.org/t/subset-a-namedtuple/127085 "2025-04-02T02:57:10Z")

</div>

Is there a function to subset a NamedTuple? Like nt = (a = 1, b = "hello", c = 3.14) s = Base.subset(nt, :a, :c) The above code, which doesn’t work, was generate by ChatGPT. It also generated another solution, which do…

---

## [Cdf for multinomial](https://discourse.julialang.org/t/cdf-for-multinomial/103917)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 21\
**Last updated:** [April 2, 2025, 1:35am UTC](https://discourse.julialang.org/t/cdf-for-multinomial/103917 "2025-04-02T01:35:33Z")

</div>

Is it possible to get a cdf for the multinomial distribution? julia\> let n = 1000000 k = 10 d = Multinomial(n,k) r = rand(1:k,n) cdf(d, r) end ERROR: MethodError: n…

---

## [A semicolon (;) fails to suppress showing in Julia REPL](https://discourse.julialang.org/t/a-semicolon-fails-to-suppress-showing-in-julia-repl/127583)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 5\
**Last updated:** [April 1, 2025, 5:27pm UTC](https://discourse.julialang.org/t/a-semicolon-fails-to-suppress-showing-in-julia-repl/127583 "2025-04-01T17:27:15Z")

</div>

The title is observed by the behavior like this julia\> JuMP.@constraint(lpr, c\_rlt\[r in 1:R1, c in 1:R2\], sm(A1\[r, :\] \* A2\[c, :\]', cross\_multrix) \>= 0); # 8×18 Matrix{JuMP.ConstraintRef{JuMP.Model, MathOptInterface.Cons…

---

## [Plots.jl: how to savefig the plot that VSCode displays](https://discourse.julialang.org/t/plots-jl-how-to-savefig-the-plot-that-vscode-displays/127545)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 6\
**Last updated:** [April 1, 2025, 11:52am UTC](https://discourse.julialang.org/t/plots-jl-how-to-savefig-the-plot-that-vscode-displays/127545 "2025-04-01T11:52:04Z")

</div>

When I plot a figure (with Plots/GR) in VSCode, I get this: Now if I try to save it with savefig, I get: The saved figure does not correspond to the one VSCode displays. I tried saving the figure in different for…

---

## [How to properly generate a function based on a condition?](https://discourse.julialang.org/t/how-to-properly-generate-a-function-based-on-a-condition/127573)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 13\
**Last updated:** [April 1, 2025, 11:17am UTC](https://discourse.julialang.org/t/how-to-properly-generate-a-function-based-on-a-condition/127573 "2025-04-01T11:17:55Z")

</div>

Hello! I have some pseudo code from a package I am working on: function GenerateOutputKernelValues(SimMetaData) flag = SimMetaData.FlagOutputKernelValues if flag # Return a func…

---

## [The best way(s) to encode binary type parameter choices](https://discourse.julialang.org/t/the-best-way-s-to-encode-binary-type-parameter-choices/127434)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 9\
**Last updated:** [March 31, 2025, 8:06pm UTC](https://discourse.julialang.org/t/the-best-way-s-to-encode-binary-type-parameter-choices/127434 "2025-03-31T20:06:42Z")

</div>

Say I have a parametric type Foo{B} and I want to restrict B to two possible values. I can think of a couple of ways to do this: Have B take on a Boolean value and use an assertion in the inner constructor to verify th…

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

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