# General Usage

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

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

**Page:** 228

---

## [Naming conventions for structs and constructors](https://discourse.julialang.org/t/naming-conventions-for-structs-and-constructors/106568)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 6\
**Last updated:** [November 22, 2023, 12:30pm UTC](https://discourse.julialang.org/t/naming-conventions-for-structs-and-constructors/106568 "2023-11-22T12:30:17Z")

</div>

I often have a struct and one or more constructors for the struct, e.g. """ mutable struct InitialState This struct stores the state of the model at the beginning of an iteration of the learning algorithm. It is up…

---

## [Could not spawn setenv ...7z.exe](https://discourse.julialang.org/t/could-not-spawn-setenv-7z-exe/80620)

<div class="topic-metadata">

**Author:** [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Replies:** 13\
**Last updated:** [November 22, 2023, 11:09am UTC](https://discourse.julialang.org/t/could-not-spawn-setenv-7z-exe/80620 "2023-11-22T11:09:06Z")

</div>

I got a fancy new laptop, heavily administered by the IT dept… When doing up or even just using VScode, the following error message pops up: ERROR: IOError: could not spawn setenv(\`'C:\\Users\\XX\\AppData\\Local\\Programs\\J…

---

## [Allocations with recursive function using kwargs and a callback](https://discourse.julialang.org/t/allocations-with-recursive-function-using-kwargs-and-a-callback/106560)

<div class="topic-metadata">

**Author:** [@tverho](https://discourse.julialang.org/u/tverho)\
**Replies:** 4\
**Last updated:** [November 22, 2023, 10:15am UTC](https://discourse.julialang.org/t/allocations-with-recursive-function-using-kwargs-and-a-callback/106560 "2023-11-22T10:15:07Z")

</div>

Allocations are often something that seem to appear rather unpredictably when you do more complicated things… Even if you’re aware of all the most typical causes of allocations, something new pops up every time. This ten…

---

## [Recursion and while loops: pros and cons](https://discourse.julialang.org/t/recursion-and-while-loops-pros-and-cons/106559)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 4\
**Last updated:** [November 22, 2023, 9:22am UTC](https://discourse.julialang.org/t/recursion-and-while-loops-pros-and-cons/106559 "2023-11-22T09:22:46Z")

</div>

This recursive function: function foo1(x) y = someoperations(y) if somecondition(y) return y else return foo1(y) end end does essentially the same as with the loop: function foo2(x) …

---

## [Prevent Unitful.jl conversion between monetary units](https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712)

<div class="topic-metadata">

**Author:** [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Replies:** 2\
**Last updated:** [November 22, 2023, 7:53am UTC](https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712 "2023-11-22T07:53:56Z")

</div>

I’ve tried defining two different monetary units using using Unitful: @dimension, @refunit, @u\_str, uconvert @dimension MU "MU" MonetaryUnit @refunit USD "USD" USDollar MU false @refunit EUR "EUR" Euro MU false which …

---

## [My julia code has segfault only on exit - is there a way to simply stop julia without calling into this finalization stuff](https://discourse.julialang.org/t/my-julia-code-has-segfault-only-on-exit-is-there-a-way-to-simply-stop-julia-without-calling-into-this-finalization-stuff/106538)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 1\
**Last updated:** [November 22, 2023, 7:08am UTC](https://discourse.julialang.org/t/my-julia-code-has-segfault-only-on-exit-is-there-a-way-to-simply-stop-julia-without-calling-into-this-finalization-stuff/106538 "2023-11-22T07:08:40Z")

</div>

I just opened an issue for a segmentation fault with RCall which only happens on exit I would like to find a workaround, i.e. somehow kill Julia without running into those finalizers which cause segmentation fault. It…

---

## [Strange behaviour in the NeuralPDE framework when implementing PINN](https://discourse.julialang.org/t/strange-behaviour-in-the-neuralpde-framework-when-implementing-pinn/106507)

<div class="topic-metadata">

**Author:** [@Aakhash\_Sundaresan](https://discourse.julialang.org/u/Aakhash_Sundaresan)\
**Replies:** 6\
**Last updated:** [November 22, 2023, 6:37am UTC](https://discourse.julialang.org/t/strange-behaviour-in-the-neuralpde-framework-when-implementing-pinn/106507 "2023-11-22T06:37:22Z")

</div>

When I try to train the Neural Network with the LBFGS or BFGS Optimization algorithm, I see that the training speed keeps fluctuating with time. Suddenly the iterations seems to have frozen and no updates are visible and…

---

## [How to push scalar into an empty vector](https://discourse.julialang.org/t/how-to-push-scalar-into-an-empty-vector/106555)

<div class="topic-metadata">

**Author:** [@PeX](https://discourse.julialang.org/u/PeX)\
**Replies:** 2\
**Last updated:** [November 22, 2023, 1:04am UTC](https://discourse.julialang.org/t/how-to-push-scalar-into-an-empty-vector/106555 "2023-11-22T01:04:34Z")

</div>

Hi all! I’m trying to create an empty vector that will be pushed with values inside a for loop. I tried the following: δ\_arr = Vector{Any}\[\] ϵ₀\_arr = Vector{Any}\[\] M\_arr = range(0.01e6, 0.9e6, 10) for i in 1:length(…

---

## [Get pixel array of a Char](https://discourse.julialang.org/t/get-pixel-array-of-a-char/106426)

<div class="topic-metadata">

**Author:** [@Yly](https://discourse.julialang.org/u/Yly)\
**Replies:** 5\
**Last updated:** [November 21, 2023, 10:59pm UTC](https://discourse.julialang.org/t/get-pixel-array-of-a-char/106426 "2023-11-21T22:59:18Z")

</div>

I am doing image processing work where I need to be able to manipulate images as arrays. I would like to make an array with values 0 or 1 such that the 1’s make the shape of a given letter. It is proving surprisingly d…

---

## [Multithreaded calculation slows down to 2 threads, debug how?](https://discourse.julialang.org/t/multithreaded-calculation-slows-down-to-2-threads-debug-how/106454)

<div class="topic-metadata">

**Author:** [@akhuettel](https://discourse.julialang.org/u/akhuettel)\
**Replies:** 10\
**Last updated:** [November 21, 2023, 9:45pm UTC](https://discourse.julialang.org/t/multithreaded-calculation-slows-down-to-2-threads-debug-how/106454 "2023-11-21T21:45:48Z")

</div>

Hi all, I’m running Julia on an AMD EPYC machine with 128 threads to solve a specific numerical problem. The code calculates a 2d coordinate grid and then loops over all the coordinates via Threads.@threads for (a,b) i…

---

## [Multi-threaded benchmarking is slow](https://discourse.julialang.org/t/multi-threaded-benchmarking-is-slow/106386)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 12\
**Last updated:** [November 21, 2023, 7:43pm UTC](https://discourse.julialang.org/t/multi-threaded-benchmarking-is-slow/106386 "2023-11-21T19:43:32Z")

</div>

Motivation Running many benchmarks can be slow. Since almost all of them are independent, they can theoretically run easily on parallel. Problem It turns out running the benchmarks in parallel takes more or less equal …

---

## [Nested macro interpolation](https://discourse.julialang.org/t/nested-macro-interpolation/106547)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 0\
**Last updated:** [November 21, 2023, 7:12pm UTC](https://discourse.julialang.org/t/nested-macro-interpolation/106547 "2023-11-21T19:12:57Z")

</div>

How to interpolate when having nested macros ? E.g., a toy example julia\> using Distributed julia\> using BenchmarkTools julia\> @everywhere function bencheverywhere() for k in 1:2 …

---

## [Gadfly min/max ranges](https://discourse.julialang.org/t/gadfly-min-max-ranges/106540)

<div class="topic-metadata">

**Author:** [@monty](https://discourse.julialang.org/u/monty)\
**Replies:** 0\
**Last updated:** [November 21, 2023, 4:59pm UTC](https://discourse.julialang.org/t/gadfly-min-max-ranges/106540 "2023-11-21T16:59:17Z")

</div>

The new version of Gadfly seems to be overriding the min/max values set in color\_continuous(). The code below plot(x=rand(12), y=rand(12), color=rand(12), Scale.color\_continuous(minvalue=-1, maxvalue=100)) produces a…

---

## [Documenter warning](https://discourse.julialang.org/t/documenter-warning/106475)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 3\
**Last updated:** [November 21, 2023, 11:17am UTC](https://discourse.julialang.org/t/documenter-warning/106475 "2023-11-21T11:17:41Z")

</div>

I want to build an html documentation locally, it will never be on any server. I execute the command: include("docs/make.jl") Content of make.jl: using Documenter: makedocs src="README.md" dst="docs/src/index.md" if…

---

## [Best practices for defining inner constructors for parametric types](https://discourse.julialang.org/t/best-practices-for-defining-inner-constructors-for-parametric-types/106494)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 3\
**Last updated:** [November 20, 2023, 11:31pm UTC](https://discourse.julialang.org/t/best-practices-for-defining-inner-constructors-for-parametric-types/106494 "2023-11-20T23:31:57Z")

</div>

In much of my development, I have parametric types that need inner constructors to be defined with some validation code: struct MyType{T\<:Number} a::T b::T # Inner constructor goes here. end However, I’m no…

---

## [Hash Collision in Memoization](https://discourse.julialang.org/t/hash-collision-in-memoization/106479)

<div class="topic-metadata">

**Author:** [@marco\_menarini](https://discourse.julialang.org/u/marco_menarini)\
**Replies:** 10\
**Last updated:** [November 20, 2023, 9:02pm UTC](https://discourse.julialang.org/t/hash-collision-in-memoization/106479 "2023-11-20T21:02:44Z")

</div>

Using the Caching.jl and LRUCache.jl packages and reading Tom Kwong’s book on the memorization pattern, I noticed an edge case that is never considered. No matter how big, a hash can be repeated for different data. Gran…

---

## [Inset axis on a LScene in Makie](https://discourse.julialang.org/t/inset-axis-on-a-lscene-in-makie/105125)

<div class="topic-metadata">

**Author:** [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Replies:** 6\
**Last updated:** [November 20, 2023, 4:12pm UTC](https://discourse.julialang.org/t/inset-axis-on-a-lscene-in-makie/105125 "2023-11-20T16:12:14Z")

</div>

I’m currently trying to display a background image behind a LScene. I tried to translate! the Axis containing the image behind the LScene as recommended for inset axes in Makie - Inset axes and their drawing order, but …

---

## [Best way to solve a highly ill-conditioned linear system](https://discourse.julialang.org/t/best-way-to-solve-a-highly-ill-conditioned-linear-system/106441)

<div class="topic-metadata">

**Author:** [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)\
**Replies:** 6\
**Last updated:** [November 20, 2023, 1:59pm UTC](https://discourse.julialang.org/t/best-way-to-solve-a-highly-ill-conditioned-linear-system/106441 "2023-11-20T13:59:29Z")

</div>

Hello, I would like for some advice to solve the following ill-conditioned linear system using Julia. My problem has the following form \\begin{pmatrix}x^+ \\\\ x^- \\end{pmatrix}=D\_1 AD\_2A^{-1}D\_1\\begin{pmatrix}y^+ \\\\ y^-…

---

## [Plots: replace curve](https://discourse.julialang.org/t/plots-replace-curve/106448)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 1\
**Last updated:** [November 20, 2023, 5:42am UTC](https://discourse.julialang.org/t/plots-replace-curve/106448 "2023-11-20T05:42:29Z")

</div>

How does one replace a curve with another one in a plot? I have this loop p = ptrans\[1\] pl = plot(vec(distances), vec(p), leg = false, ylims = (-1000, 1000)) for i in eachindex(d\["times"\]) p = ptrans\[i\]…

---

## [Recommendation for CI benchmark to catch regression](https://discourse.julialang.org/t/recommendation-for-ci-benchmark-to-catch-regression/104698)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 6\
**Last updated:** [November 19, 2023, 9:33pm UTC](https://discourse.julialang.org/t/recommendation-for-ci-benchmark-to-catch-regression/104698 "2023-11-19T21:33:29Z")

</div>

It’s pretty common for Julia package developers to want to monitor key usage latency / performance to avoid regression in PRs. Julia itself has nanosoldier, and some big package such as Makie has their own bot: Hardcode …

---

## [Optimizing counting number of occurrences of a given number in an array](https://discourse.julialang.org/t/optimizing-counting-number-of-occurrences-of-a-given-number-in-an-array/106418)

<div class="topic-metadata">

**Author:** [@vkv](https://discourse.julialang.org/u/vkv)\
**Replies:** 10\
**Last updated:** [November 19, 2023, 6:47pm UTC](https://discourse.julialang.org/t/optimizing-counting-number-of-occurrences-of-a-given-number-in-an-array/106418 "2023-11-19T18:47:09Z")

</div>

Is there a way to optimize the counter function? I’ve tried using LoopVectorization it complained saying ERROR: LoadError: Don't know how to handle expression. …

---

## [Why traits?](https://discourse.julialang.org/t/why-traits/105591)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 5\
**Last updated:** [November 19, 2023, 12:30pm UTC](https://discourse.julialang.org/t/why-traits/105591 "2023-11-19T12:30:20Z")

</div>

I’ve been trying to teach my students traits, only to realize that there is something I don’t fully understand. Is there any different between these two approaches to dispatch? struct A end struct B end ## Holy trait …

---

## [Julia and NumPy are linked with MKL, which may cause conflicts and crashes](https://discourse.julialang.org/t/julia-and-numpy-are-linked-with-mkl-which-may-cause-conflicts-and-crashes/105908)

<div class="topic-metadata">

**Author:** [@MartinOtter](https://discourse.julialang.org/u/MartinOtter)\
**Replies:** 8\
**Last updated:** [November 19, 2023, 11:39am UTC](https://discourse.julialang.org/t/julia-and-numpy-are-linked-with-mkl-which-may-cause-conflicts-and-crashes/105908 "2023-11-19T11:39:18Z")

</div>

I installed Julia 1.9.3 and made “\]update” on Windows. This gave the following warning: ┌ Warning: both Julia and NumPy are linked with MKL, which may cause conflicts and crashes (#433). └ @ PyCall D:\\otter\\home\\.julia\\…

---

## [Drop Length 1 Index in ITensors](https://discourse.julialang.org/t/drop-length-1-index-in-itensors/106305)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 3\
**Last updated:** [November 18, 2023, 8:07pm UTC](https://discourse.julialang.org/t/drop-length-1-index-in-itensors/106305 "2023-11-18T20:07:42Z")

</div>

What’s the canonical way to drop length 1 Indices in ITensors? Specifically, I for tensor train algorithms, it is convenient to have order-3 tensors on both ends, but with the first and last index being of length 1. Is t…

---

## [FEniCS Wrapper works with FEniCSx?](https://discourse.julialang.org/t/fenics-wrapper-works-with-fenicsx/106376)

<div class="topic-metadata">

**Author:** [@emmanuellfc](https://discourse.julialang.org/u/emmanuellfc)\
**Replies:** 1\
**Last updated:** [November 18, 2023, 6:15pm UTC](https://discourse.julialang.org/t/fenics-wrapper-works-with-fenicsx/106376 "2023-11-18T18:15:05Z")

</div>

Hello, I’m trying to use the wrapper FEniCS, but I have some questions, the chip of my computer is an M2 model and as far as I know, there are some issues installing the FEniCS legacy version on that kind of architecture…

---

## [Function as argument](https://discourse.julialang.org/t/function-as-argument/106385)

<div class="topic-metadata">

**Author:** [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Replies:** 7\
**Last updated:** [November 18, 2023, 1:47am UTC](https://discourse.julialang.org/t/function-as-argument/106385 "2023-11-18T01:47:55Z")

</div>

Please direct me to documentation on how to pass a function as argument to another function in type stable manner. Thx!

---

## [Pkg: not sure whats going on](https://discourse.julialang.org/t/pkg-not-sure-whats-going-on/106071)

<div class="topic-metadata">

**Author:** [@roh\_codeur](https://discourse.julialang.org/u/roh_codeur)\
**Replies:** 7\
**Last updated:** [November 18, 2023, 9:49am UTC](https://discourse.julialang.org/t/pkg-not-sure-whats-going-on/106071 "2023-11-18T09:49:23Z")

</div>

Hi I have a dockerfile with the below lines: WORKDIR /data/code/Olorin/ ENV JULIA\_PROJECT="/data/code/Olorin/" RUN cd /data/code/Olorin/ && \\ julia --project="/data/code/Olorin" -e 'using Pkg; Pkg.instantiate()' \> …

---

## [Flattening view of \`Vector{SVector{N}}\`](https://discourse.julialang.org/t/flattening-view-of-vector-svector-n/106353)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 11\
**Last updated:** [November 18, 2023, 7:39am UTC](https://discourse.julialang.org/t/flattening-view-of-vector-svector-n/106353 "2023-11-18T07:39:34Z")

</div>

Suppose that v is a Vector of SVector (a concrete type), eg using StaticArrays v = \[rand(SVector{3}) for \_ in 1:10\] Is there a package that implements a non-allocationg view equivalent to reduce(vcat, v)::Vector? Note…

---

## [Lazily fetch/load data into a DataFrame](https://discourse.julialang.org/t/lazily-fetch-load-data-into-a-dataframe/106283)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 4\
**Last updated:** [November 17, 2023, 10:35pm UTC](https://discourse.julialang.org/t/lazily-fetch-load-data-into-a-dataframe/106283 "2023-11-17T22:35:50Z")

</div>

What’s the best way to lazily fetch/load data into a DataFrame, only if/when needed? For example, if a user calls a function use\_data\_set1(), then I want to fetch/load data\_set1 from some remote URL and make it available…

---

## [Error after whole script runs](https://discourse.julialang.org/t/error-after-whole-script-runs/106393)

<div class="topic-metadata">

**Author:** [@astro-kevin](https://discourse.julialang.org/u/astro-kevin)\
**Replies:** 0\
**Last updated:** [November 18, 2023, 1:36am UTC](https://discourse.julialang.org/t/error-after-whole-script-runs/106393 "2023-11-18T01:36:14Z")

</div>

I am running a threaded script on a server managed by slurm. When the whole script finishes (the output from the last line of code is displayed in the outfile), the script doesn’t terminate, but continues until the allot…

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

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