# General Usage

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

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

**Page:** 250

---

## [How do libraries compiled by PackageCompiler.jl interact with Preferences.jl?](https://discourse.julialang.org/t/how-do-libraries-compiled-by-packagecompiler-jl-interact-with-preferences-jl/103479)

<div class="topic-metadata">

**Author:** [@sloede](https://discourse.julialang.org/u/sloede)\
**Replies:** 4\
**Last updated:** [September 12, 2023, 7:26am UTC](https://discourse.julialang.org/t/how-do-libraries-compiled-by-packagecompiler-jl-interact-with-preferences-jl/103479 "2023-09-12T07:26:58Z")

</div>

How do Preferences.jl work together libraries created by PackageCompiler.jl? For example, where do I have to put the Preferences.jl file such that the choice of system MPI library with MPI.jl is respected while compilin…

---

## [How to send a response at arbitrary code points in Genie route?](https://discourse.julialang.org/t/how-to-send-a-response-at-arbitrary-code-points-in-genie-route/103766)

<div class="topic-metadata">

**Author:** [@John\_Boik](https://discourse.julialang.org/u/John_Boik)\
**Replies:** 2\
**Last updated:** [September 12, 2023, 3:44am UTC](https://discourse.julialang.org/t/how-to-send-a-response-at-arbitrary-code-points-in-genie-route/103766 "2023-09-12T03:44:35Z")

</div>

I’m trying to use Genie.jl for a fairly simple REST API. Given a route, I would like to be able to send a response at arbitrary code points, depending on conditions. For example, if an exception is raised part way throug…

---

## [Julia VegaLite and ElectronDisplay - controlling sandboxing?](https://discourse.julialang.org/t/julia-vegalite-and-electrondisplay-controlling-sandboxing/103649)

<div class="topic-metadata">

**Author:** [@hatmatrix](https://discourse.julialang.org/u/hatmatrix)\
**Replies:** 2\
**Last updated:** [September 12, 2023, 12:36am UTC](https://discourse.julialang.org/t/julia-vegalite-and-electrondisplay-controlling-sandboxing/103649 "2023-09-12T00:36:43Z")

</div>

I’m using Julia 1.9.3 on WSL2 Ubuntu Linux, working through the REPL (actually through Emacs Julia-Snail, but the plotting commands are sent to the REPL). So wanted to try out ElectronDisplay for VegaLite. using DataFra…

---

## [How do I append row vectors into an array when I don't know the exact dimension of the array before calculations end?](https://discourse.julialang.org/t/how-do-i-append-row-vectors-into-an-array-when-i-dont-know-the-exact-dimension-of-the-array-before-calculations-end/103762)

<div class="topic-metadata">

**Author:** [@Hugo](https://discourse.julialang.org/u/Hugo)\
**Replies:** 4\
**Last updated:** [September 11, 2023, 11:27pm UTC](https://discourse.julialang.org/t/how-do-i-append-row-vectors-into-an-array-when-i-dont-know-the-exact-dimension-of-the-array-before-calculations-end/103762 "2023-09-11T23:27:24Z")

</div>

I’m using a while statement to carry out calculations for as long as a condition holds. At every iteration, I calculate a vector v. I want to append every new v vector as a row vector to the previous v vector. The probl…

---

## [Makie Basic Overloads for Composite Type](https://discourse.julialang.org/t/makie-basic-overloads-for-composite-type/103757)

<div class="topic-metadata">

**Author:** [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Replies:** 5\
**Last updated:** [September 11, 2023, 9:25pm UTC](https://discourse.julialang.org/t/makie-basic-overloads-for-composite-type/103757 "2023-09-11T21:25:26Z")

</div>

I have a simple composite type I use to keep track of a 3D vector that looks like this. abstract type AbstractVec{T\<:Number} end " xyzVecT is the object definition to contain the cartesian information " struct xyzVecT{…

---

## [Type instability for broadcast with abstract type](https://discourse.julialang.org/t/type-instability-for-broadcast-with-abstract-type/103727)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 4\
**Last updated:** [September 11, 2023, 7:20pm UTC](https://discourse.julialang.org/t/type-instability-for-broadcast-with-abstract-type/103727 "2023-09-11T19:20:04Z")

</div>

I have encountered a type instability when defining broadcasting for an abstract type. Consider the following (silly) example: import Base.Broadcast: Broadcasted, BroadcastStyle, broadcastable, broadcasted, instantiate …

---

## [Trying to understand macro scope (Tidier package)](https://discourse.julialang.org/t/trying-to-understand-macro-scope-tidier-package/103635)

<div class="topic-metadata">

**Author:** [@hatmatrix](https://discourse.julialang.org/u/hatmatrix)\
**Replies:** 20\
**Last updated:** [September 11, 2023, 1:26pm UTC](https://discourse.julialang.org/t/trying-to-understand-macro-scope-tidier-package/103635 "2023-09-11T13:26:40Z")

</div>

Very excited about the direction of the Tidier package as I am coming from R. However, I’m not understanding some of the errors I’m getting and I believe it has to do with the scope of some macros and variables/functions…

---

## [Fixed distribution in Turing](https://discourse.julialang.org/t/fixed-distribution-in-turing/103540)

<div class="topic-metadata">

**Author:** [@99dB](https://discourse.julialang.org/u/99dB)\
**Replies:** 2\
**Last updated:** [September 11, 2023, 1:07pm UTC](https://discourse.julialang.org/t/fixed-distribution-in-turing/103540 "2023-09-11T13:07:29Z")

</div>

Hi all, Is it possible to sample a distribution in Turing without updating it? For example from this tutorial: https://turing.ml/dev/tutorials/10-bayesian-differential-equations/ @model function fitlv(data, prob) …

---

## [Simplify expression with symbolics.jl](https://discourse.julialang.org/t/simplify-expression-with-symbolics-jl/103733)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [September 11, 2023, 9:40am UTC](https://discourse.julialang.org/t/simplify-expression-with-symbolics-jl/103733 "2023-09-11T09:40:35Z")

</div>

Why is the following expression not getting simplified? julia\> using Symbolics julia\> @variables a, b julia\> expr=2.25e-7(2.701832006722774e6a - 1.0131921447234855e6(b + 7.999959398007795a)) julia\> simplify(expr) 2.25e…

---

## [Functions with independent (global) scopes](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703)

<div class="topic-metadata">

**Author:** [@lieskjur](https://discourse.julialang.org/u/lieskjur)\
**Replies:** 12\
**Last updated:** [September 11, 2023, 7:22am UTC](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703 "2023-09-11T07:22:17Z")

</div>

Hi, recently I was working on a project for which I had to learn a bit of C and one thing I came to value quite a bit was that main() itself is a function and therefore its variables are not visible inside an arbitrary f…

---

## [Exported functions do not update](https://discourse.julialang.org/t/exported-functions-do-not-update/103725)

<div class="topic-metadata">

**Author:** [@A\_C](https://discourse.julialang.org/u/A_C)\
**Replies:** 6\
**Last updated:** [September 11, 2023, 4:58am UTC](https://discourse.julialang.org/t/exported-functions-do-not-update/103725 "2023-09-11T04:58:20Z")

</div>

I am using the REPL workflow described in REPL Workflow. Suppose the contents of Tmp.jl are as follows: module Tmp export say\_hello say\_hello() = println("Hello!") # your other definitions here end And the contents…

---

## [Unrolling loops over tuples - why so hard?](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 14\
**Last updated:** [September 10, 2023, 10:58pm UTC](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428 "2023-09-10T22:58:11Z")

</div>

Unrolling loops over tuple elements can bring easy performance gains. Here’s a trivial example of a 250x speed-up, just by adding an @unroll macro to the code: import Unroll.@unroll using BenchmarkTools function nounro…

---

## [How would macros make this code clearer?](https://discourse.julialang.org/t/how-would-macros-make-this-code-clearer/103702)

<div class="topic-metadata">

**Author:** [@jburgy](https://discourse.julialang.org/u/jburgy)\
**Replies:** 2\
**Last updated:** [September 10, 2023, 8:32pm UTC](https://discourse.julialang.org/t/how-would-macros-make-this-code-clearer/103702 "2023-09-10T20:32:45Z")

</div>

I have been mildly obsessed with the Thompson’s construction algorithm and recently implemented a version of it in julia. I also wrote a couple blog posts for additional context. This code works but feels like it could…

---

## [Unable to solve a differential equation using neural network](https://discourse.julialang.org/t/unable-to-solve-a-differential-equation-using-neural-network/103723)

<div class="topic-metadata">

**Author:** [@Shashank](https://discourse.julialang.org/u/Shashank)\
**Replies:** 2\
**Last updated:** [September 10, 2023, 5:43pm UTC](https://discourse.julialang.org/t/unable-to-solve-a-differential-equation-using-neural-network/103723 "2023-09-10T17:43:05Z")

</div>

I am trying to solve a simple differential equation dy/dt=-y using neural networks. The following code runs but the loss remains at 2.0 and I get a output of zero. Am I doing something wrong here? using Flux using Flux:…

---

## [How to calculate the full width half maximum (FWHM) of a function or vector?](https://discourse.julialang.org/t/how-to-calculate-the-full-width-half-maximum-fwhm-of-a-function-or-vector/103720)

<div class="topic-metadata">

**Author:** [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Replies:** 1\
**Last updated:** [September 10, 2023, 1:33pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-full-width-half-maximum-fwhm-of-a-function-or-vector/103720 "2023-09-10T13:33:21Z")

</div>

In a number of different domains, one is interested in the width of a peak. Two common functions one might want to know the width of are probability distributions (statstics) and intensity distributions (optics and more)…

---

## [Is splitting the Julia code into smaller scripts impacting performance?](https://discourse.julialang.org/t/is-splitting-the-julia-code-into-smaller-scripts-impacting-performance/103613)

<div class="topic-metadata">

**Author:** [@CrisCool](https://discourse.julialang.org/u/CrisCool)\
**Replies:** 5\
**Last updated:** [September 10, 2023, 9:13am UTC](https://discourse.julialang.org/t/is-splitting-the-julia-code-into-smaller-scripts-impacting-performance/103613 "2023-09-10T09:13:44Z")

</div>

Hei there julians! Let’s say I’m working on a Julia App and I organize my code in a MAIN.jl script and mayn other scripts, which I call from the MAIN.jl with include(). The structure can be nested, so the scripts include…

---

## [Could a Julia fine tuned version of Llama 2 code be created](https://discourse.julialang.org/t/could-a-julia-fine-tuned-version-of-llama-2-code-be-created/103440)

<div class="topic-metadata">

**Author:** [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Replies:** 14\
**Last updated:** [September 10, 2023, 9:12am UTC](https://discourse.julialang.org/t/could-a-julia-fine-tuned-version-of-llama-2-code-be-created/103440 "2023-09-10T09:12:43Z")

</div>

As I’m the only person working in my team in Julia I find AI code assistance helpful (copilot, chat:copilot, Llama 2 code), effectively like talking to a colleague. Although, I find chat:copilots results a mixed bag and…

---

## [How to get source printing from \`include()\`](https://discourse.julialang.org/t/how-to-get-source-printing-from-include/103699)

<div class="topic-metadata">

**Author:** [@pao](https://discourse.julialang.org/u/pao)\
**Replies:** 9\
**Last updated:** [September 10, 2023, 6:56am UTC](https://discourse.julialang.org/t/how-to-get-source-printing-from-include/103699 "2023-09-10T06:56:58Z")

</div>

Hi guys, I have a problem that I’m unable to solve. I’m tried any trick with no results. I’m writing a lot of Julia snippets (function definitions and unit tests) embedded in a book draft. Therefore, I write small fi…

---

## [How does the string pkg"..." work?](https://discourse.julialang.org/t/how-does-the-string-pkg-work/103711)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 6\
**Last updated:** [September 10, 2023, 3:16am UTC](https://discourse.julialang.org/t/how-does-the-string-pkg-work/103711 "2023-09-10T03:16:50Z")

</div>

What magic is involved when I write macro pkg\_str(s) return esc(s) end @info pkg"Top of the morning to you, squire!" Does the macro compiler “know” that this means “call @pkg\_str when you see pkg as a string prefix…

---

## [How to initialize an array of structs](https://discourse.julialang.org/t/how-to-initialize-an-array-of-structs/83674)

<div class="topic-metadata">

**Author:** [@fft](https://discourse.julialang.org/u/fft)\
**Replies:** 9\
**Last updated:** [September 9, 2023, 12:47pm UTC](https://discourse.julialang.org/t/how-to-initialize-an-array-of-structs/83674 "2023-09-09T12:47:01Z")

</div>

I want to create an array of structs like shown below mutable struct mystruct a::Float32 b::Float32 c::UInt32 end mystruct() = mystruct(0,0,0) size = 3 a = Array{mystruct, 3}(undef, size, size, size) fo…

---

## [Calculation of Hessian of a loss function w.r.t. dense layer weight matrices](https://discourse.julialang.org/t/calculation-of-hessian-of-a-loss-function-w-r-t-dense-layer-weight-matrices/103697)

<div class="topic-metadata">

**Author:** [@Harsh\_Choudhary](https://discourse.julialang.org/u/Harsh_Choudhary)\
**Replies:** 0\
**Last updated:** [September 9, 2023, 7:23am UTC](https://discourse.julialang.org/t/calculation-of-hessian-of-a-loss-function-w-r-t-dense-layer-weight-matrices/103697 "2023-09-09T07:23:51Z")

</div>

Hi, I am trying to train a dummy Neural Net which is given as: y = transpose(W1)sigmoid(W2x) where W1 and W2 are 10x1 and x is a scalar input. I am using second-order optimization and for that purpose, I need to calculat…

---

## [Type Instability when composing functor and function](https://discourse.julialang.org/t/type-instability-when-composing-functor-and-function/103680)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 3\
**Last updated:** [September 8, 2023, 9:46pm UTC](https://discourse.julialang.org/t/type-instability-when-composing-functor-and-function/103680 "2023-09-08T21:46:33Z")

</div>

I am training a neural net using Flux.jl. I have a custom function that normalizes inputs before evaluating the model: function normalize(state) state\_min = \[-1.2f0, -0.07f0\] state\_max = \[0.6f0, 0.07f0\] norm…

---

## [When do type constructors \*not\* return an instance of the type?](https://discourse.julialang.org/t/when-do-type-constructors-not-return-an-instance-of-the-type/103672)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 7\
**Last updated:** [September 8, 2023, 3:33pm UTC](https://discourse.julialang.org/t/when-do-type-constructors-not-return-an-instance-of-the-type/103672 "2023-09-08T15:33:49Z")

</div>

The call T(x) is type-unstable if x is type-unstable, requiring an additional type assertion T(x)::T to be inferable. My understanding of the reason is T(x)'s return value isn’t required to be an instance of T. But I can…

---

## [Matching for interpolation](https://discourse.julialang.org/t/matching-for-interpolation/103636)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 4\
**Last updated:** [September 8, 2023, 2:49pm UTC](https://discourse.julialang.org/t/matching-for-interpolation/103636 "2023-09-08T14:49:24Z")

</div>

Is there a matching package that can do something like V = \[1.1, 2, 4.8, 6, 9, 11\] x = 5.1 @match begin V\[i\] ≤ x \< V\[i+1\] =\> #some interp function of V\[i\] and V\[i+i\]

---

## [Parse Float32 string](https://discourse.julialang.org/t/parse-float32-string/103667)

<div class="topic-metadata">

**Author:** [@johnbb](https://discourse.julialang.org/u/johnbb)\
**Replies:** 9\
**Last updated:** [September 8, 2023, 2:46pm UTC](https://discourse.julialang.org/t/parse-float32-string/103667 "2023-09-08T14:46:05Z")

</div>

How can I parse strings like “1.23f-4” to Float32? julia\> parse(Float64, "1.23e-4") 0.000123 julia\> parse(Float32, "1.23f-4") ERROR: ArgumentError: cannot parse "1.23f-4" as Float32 Stacktrace: \[1\] \_parse\_failure(T::T…

---

## [How to use pictures in plot to show area preservation using julia?](https://discourse.julialang.org/t/how-to-use-pictures-in-plot-to-show-area-preservation-using-julia/103570)

<div class="topic-metadata">

**Author:** [@khaledharizb](https://discourse.julialang.org/u/khaledharizb)\
**Replies:** 8\
**Last updated:** [September 8, 2023, 9:42am UTC](https://discourse.julialang.org/t/how-to-use-pictures-in-plot-to-show-area-preservation-using-julia/103570 "2023-09-08T09:42:24Z")

</div>

I have a data of symplectic Euler method using Plots h = 0.05; N = 200; const g = 9; const ℓ = 1.46; θ = zeros(N+1) v = zeros(N+1) θ\[1\] = 1.0; # this is θ₀ v\[1\] = 0.5; # this is v₀ for k in 1:N θ\[k+1\] = θ\[k\] + h…

---

## [Packages aren't found on worker processors](https://discourse.julialang.org/t/packages-arent-found-on-worker-processors/46820)

<div class="topic-metadata">

**Author:** [@smickus](https://discourse.julialang.org/u/smickus)\
**Replies:** 9\
**Last updated:** [September 8, 2023, 9:18am UTC](https://discourse.julialang.org/t/packages-arent-found-on-worker-processors/46820 "2023-09-08T09:18:31Z")

</div>

When I upgraded to Julia v1.5.1-1 using JuliaPro , the distributed processors no longer can find any of the packages that have been imported. The following is the error message that I receive. ERROR: LoadError: On work…

---

## [Is there a simple way to swap the x and y axes in \`Plots.jl\` after a figure is plotted?](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 4\
**Last updated:** [September 8, 2023, 7:43am UTC](https://discourse.julialang.org/t/is-there-a-simple-way-to-swap-the-x-and-y-axes-in-plots-jl-after-a-figure-is-plotted/103599 "2023-09-08T07:43:11Z")

</div>

Note this is not flip, which flips the x and y axes by themselves. I want to exchange the y and x axes, like a transposition of the figure.

---

## [Using ChatGPT to get code for training a neural net](https://discourse.julialang.org/t/using-chatgpt-to-get-code-for-training-a-neural-net/103648)

<div class="topic-metadata">

**Author:** [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Replies:** 0\
**Last updated:** [September 8, 2023, 7:24am UTC](https://discourse.julialang.org/t/using-chatgpt-to-get-code-for-training-a-neural-net/103648 "2023-09-08T07:24:01Z")

</div>

I recently discovered an amazing tool, chatgpt :wink: I have found that it’s pretty useful for preparing class notes, and translating them to other languages. I also was aware of discussion here about how well it does f…

---

## [Automatic differentiation in Julia for gradient computation](https://discourse.julialang.org/t/automatic-differentiation-in-julia-for-gradient-computation/103643)

<div class="topic-metadata">

**Author:** [@Harsh\_Choudhary](https://discourse.julialang.org/u/Harsh_Choudhary)\
**Replies:** 1\
**Last updated:** [September 8, 2023, 4:53am UTC](https://discourse.julialang.org/t/automatic-differentiation-in-julia-for-gradient-computation/103643 "2023-09-08T04:53:55Z")

</div>

Hi, I am new to Julia and I am trying to get my head around with the Automatic Differentiation in Julia. I have a decent experience with Pytorch Autograd libraries and I wanted to ask if there is an Analog of loss.backwa…

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

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