# General Usage

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

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

**Page:** 219

---

## [A jldoctest as a continuation of a previous jldoctest?](https://discourse.julialang.org/t/a-jldoctest-as-a-continuation-of-a-previous-jldoctest/107863)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 0\
**Last updated:** [December 20, 2023, 2:34pm UTC](https://discourse.julialang.org/t/a-jldoctest-as-a-continuation-of-a-previous-jldoctest/107863 "2023-12-20T14:34:24Z")

</div>

Is it possible to use a jldoctest block as a continuation of a previous one? Something like: Create data with: \`\`\`jldoctest julia\> using MyPkg julia\> my\_data = MyPkg.data() Created data! \`\`\`~ And now, run function \`foo…

---

## [Is Julia more suited as of now for classic ML rather than Gen Al, GNNs and evolutionary algorithms?](https://discourse.julialang.org/t/is-julia-more-suited-as-of-now-for-classic-ml-rather-than-gen-al-gnns-and-evolutionary-algorithms/107851)

<div class="topic-metadata">

**Author:** [@Rajaram\_Venkataraman](https://discourse.julialang.org/u/Rajaram_Venkataraman)\
**Replies:** 1\
**Last updated:** [December 20, 2023, 12:41pm UTC](https://discourse.julialang.org/t/is-julia-more-suited-as-of-now-for-classic-ml-rather-than-gen-al-gnns-and-evolutionary-algorithms/107851 "2023-12-20T12:41:22Z")

</div>

C++ and Python have packages for GNNs, generative AI, and genetic algorithms. It seems that Julia is currently more focused on classic ML and DNNs. Is that vorrect understanding? I am new to Julia.

---

## [Create \`ImmutableDict\` with values of differenrt types](https://discourse.julialang.org/t/create-immutabledict-with-values-of-differenrt-types/107831)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 3\
**Last updated:** [December 20, 2023, 11:02am UTC](https://discourse.julialang.org/t/create-immutabledict-with-values-of-differenrt-types/107831 "2023-12-20T11:02:22Z")

</div>

Simple MWE: d1 = Dict(:a =\> 1.0, :b =\> "Hello world") # Works d2 = Base.ImmutableDict(:a =\> 1.0, :b =\> "Hello world") # Fails How do I create an ImmutableDict where keys can have arbitrary values?

---

## [How can I learn SDL with Julia?](https://discourse.julialang.org/t/how-can-i-learn-sdl-with-julia/107798)

<div class="topic-metadata">

**Author:** [@Sabe](https://discourse.julialang.org/u/Sabe)\
**Replies:** 1\
**Last updated:** [December 20, 2023, 9:51am UTC](https://discourse.julialang.org/t/how-can-i-learn-sdl-with-julia/107798 "2023-12-20T09:51:27Z")

</div>

So, I have always wanted to use sdl but I don’t like C/C++ and I really want to use Julia but what should I look at for it? The only thing that the package gives you is the sdl wiki which is full of C++ code. What do I d…

---

## [Garbage collection and threading](https://discourse.julialang.org/t/garbage-collection-and-threading/107250)

<div class="topic-metadata">

**Author:** [@evan-wehi](https://discourse.julialang.org/u/evan-wehi)\
**Replies:** 17\
**Last updated:** [December 20, 2023, 4:57am UTC](https://discourse.julialang.org/t/garbage-collection-and-threading/107250 "2023-12-20T04:57:28Z")

</div>

I’ve been struggling with performance issues with my code for weeks. I’ve now narrowed down the primary problem to what seems to be a threading bottleneck in the garbage collector. Sorry, if this has been discussed alrea…

---

## [Suggestion on this plot](https://discourse.julialang.org/t/suggestion-on-this-plot/107723)

<div class="topic-metadata">

**Author:** [@Josa9321](https://discourse.julialang.org/u/Josa9321)\
**Replies:** 5\
**Last updated:** [December 19, 2023, 11:35pm UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723 "2023-12-19T23:35:31Z")

</div>

Is there any easier way of doing this kind of plot? Instead of just x\_1, I would put a value, x\_1 = 100 for example. The way I think it would need to adapt a little the quiver plot and another plots, as here Plottin…

---

## [Trouble Running Julia REPL in Git Bash on Windows](https://discourse.julialang.org/t/trouble-running-julia-repl-in-git-bash-on-windows/107790)

<div class="topic-metadata">

**Author:** [@rud-lucien](https://discourse.julialang.org/u/rud-lucien)\
**Replies:** 7\
**Last updated:** [December 19, 2023, 6:31pm UTC](https://discourse.julialang.org/t/trouble-running-julia-repl-in-git-bash-on-windows/107790 "2023-12-19T18:31:34Z")

</div>

Hello Julia Community, I’ve encountered an issue when trying to run the Julia REPL in Git Bash on my Windows machine and I’m hoping for some assistance in troubleshooting the problem. Issue Description: When I attempt …

---

## [Is it possible to suppress the chain of 'caused by' output when handling an exception?](https://discourse.julialang.org/t/is-it-possible-to-suppress-the-chain-of-caused-by-output-when-handling-an-exception/107823)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 3\
**Last updated:** [December 19, 2023, 5:20pm UTC](https://discourse.julialang.org/t/is-it-possible-to-suppress-the-chain-of-caused-by-output-when-handling-an-exception/107823 "2023-12-19T17:20:27Z")

</div>

When handling an exception that was ‘caused by’ another exception, Julia prints out a stack of exceptions. Normally this is helpful, but in this case I want to handle the exception, and give the user a helpful message. I…

---

## [Create a function as a attribute to a struct](https://discourse.julialang.org/t/create-a-function-as-a-attribute-to-a-struct/107817)

<div class="topic-metadata">

**Author:** [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Replies:** 5\
**Last updated:** [December 19, 2023, 4:44pm UTC](https://discourse.julialang.org/t/create-a-function-as-a-attribute-to-a-struct/107817 "2023-12-19T16:44:20Z")

</div>

I want to create a clock object with the attributes clock.initial, clock.current and clock.elapsed. I now want functions like initialize, update, play and pause. Is there a way to have something like clock.initialize(…

---

## [When precompiling Package extensions no error information is printed](https://discourse.julialang.org/t/when-precompiling-package-extensions-no-error-information-is-printed/106575)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 5\
**Last updated:** [December 19, 2023, 4:10pm UTC](https://discourse.julialang.org/t/when-precompiling-package-extensions-no-error-information-is-printed/106575 "2023-12-19T16:10:59Z")

</div>

Hi there, I am surprised by no error info when I instantiate a project of mine where one dependency uses PackageExtensions. even redoing import Pkg; Pkg.precompile() or import Pkg; Pkg.build("MyPackage") don’t print an…

---

## [Why can't I create an ImmutableDict from a vector of pairs (like for a normal cidt)](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 3\
**Last updated:** [December 19, 2023, 3:25pm UTC](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811 "2023-12-19T15:25:08Z")

</div>

Minimal example: pairs = \[:A =\> 1, :B =\>2\] d1 = Dict(pairs) # works d2 = Base.ImmutableDict(pairs) # errors d3 = Base.ImmutableDict(pairs...) # works It seems strange that d2 fails? Is there a reason, or a way to avoi…

---

## [Take the automatic differentiation with tensor contraction](https://discourse.julialang.org/t/take-the-automatic-differentiation-with-tensor-contraction/106995)

<div class="topic-metadata">

**Author:** [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Replies:** 2\
**Last updated:** [December 19, 2023, 1:04pm UTC](https://discourse.julialang.org/t/take-the-automatic-differentiation-with-tensor-contraction/106995 "2023-12-19T13:04:02Z")

</div>

When I was doing the automatic differentiation operation encountered some problems, let’s look at my examples firstly: Julia Version 1.9.3 julia\> using TensorRules julia\> using Zygote julia\> using TensorOperations ju…

---

## [Array Contraction, LoopVectorization & AD](https://discourse.julialang.org/t/array-contraction-loopvectorization-ad/107721)

<div class="topic-metadata">

**Author:** [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Replies:** 7\
**Last updated:** [December 18, 2023, 9:16pm UTC](https://discourse.julialang.org/t/array-contraction-loopvectorization-ad/107721 "2023-12-18T21:16:16Z")

</div>

Hi everyone, I have been using LoopVectorization.jl with very satisfactory results to speedup some calculations. Now, I have been hitting a problem: combining it with AD! Although my use case is not super complicated …

---

## [Swap agent positions in Agents.jl](https://discourse.julialang.org/t/swap-agent-positions-in-agents-jl/107774)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 4\
**Last updated:** [December 18, 2023, 9:05pm UTC](https://discourse.julialang.org/t/swap-agent-positions-in-agents-jl/107774 "2023-12-18T21:05:05Z")

</div>

Hello, My model uses a 2D grid called GridSpaceSingle, which restricts each cell to a maximum of one agent. I would like to switch the positions of two agents. Unfortunately, this functionality is not currently availabl…

---

## [Pairs index API](https://discourse.julialang.org/t/pairs-index-api/107786)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 1\
**Last updated:** [December 18, 2023, 8:04pm UTC](https://discourse.julialang.org/t/pairs-index-api/107786 "2023-12-18T20:04:49Z")

</div>

Why are these different? julia\> first(pairs(\[10,20,30\])) 1 =\> 10 julia\> pairs(\[10,20,30\])\[1\] 10

---

## [Efficient ways to raise an array by a scalar power](https://discourse.julialang.org/t/efficient-ways-to-raise-an-array-by-a-scalar-power/107688)

<div class="topic-metadata">

**Author:** [@valentin.m](https://discourse.julialang.org/u/valentin.m)\
**Replies:** 7\
**Last updated:** [December 18, 2023, 4:40pm UTC](https://discourse.julialang.org/t/efficient-ways-to-raise-an-array-by-a-scalar-power/107688 "2023-12-18T16:40:55Z")

</div>

Hello! I’m currently working on optimizing an algorithm to match the performance of an existing Fortran implementation. A key part of the algorithm involves computing the power of large arrays of floats raised to a scal…

---

## [Searchsorted by attribute](https://discourse.julialang.org/t/searchsorted-by-attribute/107754)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 5\
**Last updated:** [December 18, 2023, 2:29pm UTC](https://discourse.julialang.org/t/searchsorted-by-attribute/107754 "2023-12-18T14:29:02Z")

</div>

Suppose I have an array inventory::Vector{InventoryObject} that is sorted by the name attribute of each element (sort with by=(obj-\>obj.name)) The InventoryObject is defined as @kwdef struct InventoryObject name::S…

---

## [PINN in Julia](https://discourse.julialang.org/t/pinn-in-julia/107771)

<div class="topic-metadata">

**Author:** [@gagankaushikmanyam](https://discourse.julialang.org/u/gagankaushikmanyam)\
**Replies:** 0\
**Last updated:** [December 18, 2023, 2:11pm UTC](https://discourse.julialang.org/t/pinn-in-julia/107771 "2023-12-18T14:11:36Z")

</div>

Hello Flux Experts /Users I have been working recently with Flux.jl in Julia and have been trying to code an ANN that uses strain (from FEM as input to the ANN) and then calculates the residual based on the output of th…

---

## [Cannot use CUDA nor GLMakie](https://discourse.julialang.org/t/cannot-use-cuda-nor-glmakie/107742)

<div class="topic-metadata">

**Author:** [@Simone\_Gabbriellini](https://discourse.julialang.org/u/Simone_Gabbriellini)\
**Replies:** 4\
**Last updated:** [December 18, 2023, 12:06pm UTC](https://discourse.julialang.org/t/cannot-use-cuda-nor-glmakie/107742 "2023-12-18T12:06:58Z")

</div>

might be two problems for two questions, but I am not sure if they might be related. I have these nvidia drivers and CUDA: +-----------------------------------------------------------------------------+ | NVIDIA-SMI 52…

---

## [Reinterpret vector into single struct](https://discourse.julialang.org/t/reinterpret-vector-into-single-struct/107709)

<div class="topic-metadata">

**Author:** [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Replies:** 9\
**Last updated:** [December 18, 2023, 10:46am UTC](https://discourse.julialang.org/t/reinterpret-vector-into-single-struct/107709 "2023-12-18T10:46:03Z")

</div>

Hi, I’m optimizing a bit of code where I need to reinterpret a vector into a struct. For example, I have the MWE example below struct Test a1::Float64 a2::Float64 end vec = \[2.0, 1.0\] using BenchmarkTools @be…

---

## [Julia killed on Mac Pro](https://discourse.julialang.org/t/julia-killed-on-mac-pro/107748)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 5\
**Last updated:** [December 18, 2023, 6:36am UTC](https://discourse.julialang.org/t/julia-killed-on-mac-pro/107748 "2023-12-18T06:36:49Z")

</div>

Mac Pro - Tower: Apple M2 Ultra julia is run to execute a series of simulations. After a few, the shell kills the process with nothing more than zsh: killed. julia\> versioninfo() Julia Version 1.9.4 Commit 8e5136fa297 …

---

## [Continuation of Periodic Solutions - trouble with large predictor](https://discourse.julialang.org/t/continuation-of-periodic-solutions-trouble-with-large-predictor/107403)

<div class="topic-metadata">

**Author:** [@Mahnoor\_Pop](https://discourse.julialang.org/u/Mahnoor_Pop)\
**Replies:** 4\
**Last updated:** [December 17, 2023, 9:51pm UTC](https://discourse.julialang.org/t/continuation-of-periodic-solutions-trouble-with-large-predictor/107403 "2023-12-17T21:51:14Z")

</div>

Hi all! I’m trying to recreate a continuation figure from a paper using the package BifurcationKit.jl, and so far have done okay for the equilibrium solutions. However, now I’m trying to continue the periodic solutions,…

---

## [How to deal with vectors in NLsolve.jl](https://discourse.julialang.org/t/how-to-deal-with-vectors-in-nlsolve-jl/107488)

<div class="topic-metadata">

**Author:** [@khaledharizb](https://discourse.julialang.org/u/khaledharizb)\
**Replies:** 2\
**Last updated:** [December 17, 2023, 9:49pm UTC](https://discourse.julialang.org/t/how-to-deal-with-vectors-in-nlsolve-jl/107488 "2023-12-17T21:49:17Z")

</div>

Hi guys! I didn’t find a way to deal with vector using pkg NLSolve in the following problem. Let q=\[x,y\] and p=\[u,v\] and defining the functions f and g as f(q) = q / (√(q'\*q))^3,\\ g(p) = p. Now, giving q\_0=\[0.4,0\] an…

---

## [GPU gradient calculation with Zygote failling with an RTX 4060](https://discourse.julialang.org/t/gpu-gradient-calculation-with-zygote-failling-with-an-rtx-4060/107746)

<div class="topic-metadata">

**Author:** [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Replies:** 1\
**Last updated:** [December 17, 2023, 9:43pm UTC](https://discourse.julialang.org/t/gpu-gradient-calculation-with-zygote-failling-with-an-rtx-4060/107746 "2023-12-17T21:43:57Z")

</div>

Hello all, I’m having an issue with gradient calculation on gpu. The minimal code exemple is very minimal, using Flux,CUDA,cuDNN x = rand(Float32,1,1000) |\> gpu y = rand(Float32,1,1000) |\> gpu model = Flux.Chain( …

---

## [Incorrect Hessian when using \`exp\` function with complex input](https://discourse.julialang.org/t/incorrect-hessian-when-using-exp-function-with-complex-input/107739)

<div class="topic-metadata">

**Author:** [@rz.yu](https://discourse.julialang.org/u/rz.yu)\
**Replies:** 1\
**Last updated:** [December 17, 2023, 8:23pm UTC](https://discourse.julialang.org/t/incorrect-hessian-when-using-exp-function-with-complex-input/107739 "2023-12-17T20:23:32Z")

</div>

Incorrect Hessian by exp function · Issue #677 · JuliaDiff/ForwardDiff.jl (github.com) I was trying to calculate the Hessian of a simple function such as using ForwardDiff function busPQ(Ybus, Vθ) n = length(Vθ) …

---

## [How to correctly update a package?](https://discourse.julialang.org/t/how-to-correctly-update-a-package/107730)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 2\
**Last updated:** [December 17, 2023, 1:07pm UTC](https://discourse.julialang.org/t/how-to-correctly-update-a-package/107730 "2023-12-17T13:07:38Z")

</div>

I had a directory downloaded from Github. Previously, I can run the example codes in the directory. But yesterday, I noticed that they had a latest version of the package. So I updated the package julia\> using Pkg jul…

---

## ['\_' as an argument in function definition](https://discourse.julialang.org/t/as-an-argument-in-function-definition/107708)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 8\
**Last updated:** [December 17, 2023, 11:06am UTC](https://discourse.julialang.org/t/as-an-argument-in-function-definition/107708 "2023-12-17T11:06:48Z")

</div>

function myfun(x, i, val, \_) x\[i\]+ = val end What does the underscore ‘\_’ mean here?

---

## [How to update a package?](https://discourse.julialang.org/t/how-to-update-a-package/107727)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 1\
**Last updated:** [December 17, 2023, 7:35am UTC](https://discourse.julialang.org/t/how-to-update-a-package/107727 "2023-12-17T07:35:12Z")

</div>

julia\> Pkg.update("thepackage") ERROR: UndefVarError: \`Pkg\` not defined Stacktrace: \[1\] top-level scope @ REPL\[38\]:1 What is the correct way?

---

## [Get the structure of an arithmetic expression](https://discourse.julialang.org/t/get-the-structure-of-an-arithmetic-expression/107712)

<div class="topic-metadata">

**Author:** [@\_stla](https://discourse.julialang.org/u/_stla)\
**Replies:** 8\
**Last updated:** [December 17, 2023, 3:38am UTC](https://discourse.julialang.org/t/get-the-structure-of-an-arithmetic-expression/107712 "2023-12-17T03:38:46Z")

</div>

Hello, Given an arithmetic expression, for example x + y/z, I want to decompose it to something like +(x, /(y, z). Is it possible with Julia? I thought this was the result of :(x + y/z) but no. The reason is that I hav…

---

## [ModelingToolkit and normalize()](https://discourse.julialang.org/t/modelingtoolkit-and-normalize/107349)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 12\
**Last updated:** [December 17, 2023, 3:08am UTC](https://discourse.julialang.org/t/modelingtoolkit-and-normalize/107349 "2023-12-17T03:08:20Z")

</div>

The following code fails: using ModelingToolkit, OrdinaryDiffEq, PyPlot, LinearAlgebra G\_EARTH = Float64\[0.0, 0.0, -9.81\] # gravitational acceleration # model @parameters mass=1.0 c\_spring=50.0 damping=0.5 l0=10.0…

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

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