# General Usage

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

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

**Page:** 186

---

## [Redirect a plot type in Makie while keeping color consistent](https://discourse.julialang.org/t/redirect-a-plot-type-in-makie-while-keeping-color-consistent/111975)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 8\
**Last updated:** [March 22, 2024, 9:11pm UTC](https://discourse.julialang.org/t/redirect-a-plot-type-in-makie-while-keeping-color-consistent/111975 "2024-03-22T21:11:38Z")

</div>

I have a histogram type that I’d like to customize its plotting for a few type of plots: Scatter, BarPlot, Hist, StepHist etc. For some of them, this is very straight forward: julia\> using CairoMakie julia\> struct MyH…

---

## [Parsing a string with quotations](https://discourse.julialang.org/t/parsing-a-string-with-quotations/112052)

<div class="topic-metadata">

**Author:** [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Replies:** 5\
**Last updated:** [March 25, 2024, 8:11pm UTC](https://discourse.julialang.org/t/parsing-a-string-with-quotations/112052 "2024-03-25T20:11:47Z")

</div>

I’m writing a small package involving some user interaction in the style of unix command line interactive utilities. The package SimpleArgParse.jl with some adaptations would do the parsing, however it needs to be provid…

---

## [I don't understand how to do self-referencial parametric typing](https://discourse.julialang.org/t/i-dont-understand-how-to-do-self-referencial-parametric-typing/112080)

<div class="topic-metadata">

**Author:** [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Replies:** 7\
**Last updated:** [March 25, 2024, 4:25pm UTC](https://discourse.julialang.org/t/i-dont-understand-how-to-do-self-referencial-parametric-typing/112080 "2024-03-25T16:25:48Z")

</div>

I’m trying to build two tree node types that keep track of a set of instances of each other. FooNode{T, C \<: Set} childs::C foo::T end BarNode{G, D \<: Set} childs::D bar::G end T and G are other parametr…

---

## [TerminalUserInterfaces.jl question](https://discourse.julialang.org/t/terminaluserinterfaces-jl-question/112043)

<div class="topic-metadata">

**Author:** [@oheil](https://discourse.julialang.org/u/oheil)\
**Replies:** 6\
**Last updated:** [March 25, 2024, 1:51pm UTC](https://discourse.julialang.org/t/terminaluserinterfaces-jl-question/112043 "2024-03-25T13:51:21Z")

</div>

I try to use TerminalUserInterfaces.jl and the list example: TerminalUserInterfaces.jl/examples/list.jl at main · kdheepak/TerminalUserInterfaces.jl · GitHub to create a list of options. This part is fine and works. No…

---

## [Update Problem-Julia in Mac OS](https://discourse.julialang.org/t/update-problem-julia-in-mac-os/112064)

<div class="topic-metadata">

**Author:** [@Sharara](https://discourse.julialang.org/u/Sharara)\
**Replies:** 10\
**Last updated:** [March 25, 2024, 8:57am UTC](https://discourse.julialang.org/t/update-problem-julia-in-mac-os/112064 "2024-03-25T08:57:49Z")

</div>

Hello everybody I tried to update my Julia and then update JuMP, Because I have the following Error in my code: ERROR: UndefVarError: \`Model\` not defined Stacktrace: \[1\] solve\_are(A::Matrix{Float64}, B::Matrix{Float6…

---

## [Any way of doing \`f(::T) where Base.issingletontype(T)\`?](https://discourse.julialang.org/t/any-way-of-doing-f-t-where-base-issingletontype-t/112066)

<div class="topic-metadata">

**Author:** [@putianyi888](https://discourse.julialang.org/u/putianyi888)\
**Replies:** 4\
**Last updated:** [March 25, 2024, 7:57am UTC](https://discourse.julialang.org/t/any-way-of-doing-f-t-where-base-issingletontype-t/112066 "2024-03-25T07:57:28Z")

</div>

Basically I want a dynamic union of singleton types.

---

## [How to speed up this Kronecker Multiplication?](https://discourse.julialang.org/t/how-to-speed-up-this-kronecker-multiplication/112063)

<div class="topic-metadata">

**Author:** [@vikram\_backup](https://discourse.julialang.org/u/vikram_backup)\
**Replies:** 7\
**Last updated:** [March 25, 2024, 7:21am UTC](https://discourse.julialang.org/t/how-to-speed-up-this-kronecker-multiplication/112063 "2024-03-25T07:21:06Z")

</div>

I am writing a code that gives me tensor product of the required Pauli matrices, and I am doing this using kron function. using StaticArrays #%% We are definig the Pauli matrices here. σˣ=SA\[0 1.0; 1 0\] #\\sigma^x σᶻ=…

---

## [Package for implementing regression with spatial correlation](https://discourse.julialang.org/t/package-for-implementing-regression-with-spatial-correlation/111893)

<div class="topic-metadata">

**Author:** [@JedPhillips](https://discourse.julialang.org/u/JedPhillips)\
**Replies:** 1\
**Last updated:** [March 24, 2024, 11:03pm UTC](https://discourse.julialang.org/t/package-for-implementing-regression-with-spatial-correlation/111893 "2024-03-24T23:03:59Z")

</div>

Are there any Julia packages that allow one to specify spatial correlation (or any correlation structure) when implementing generalizes least squares regression? I’m looking for something akin to the gls() function in th…

---

## [Deepcopy dangers and drawbacks for nested data structures](https://discourse.julialang.org/t/deepcopy-dangers-and-drawbacks-for-nested-data-structures/111998)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 9\
**Last updated:** [March 24, 2024, 10:10pm UTC](https://discourse.julialang.org/t/deepcopy-dangers-and-drawbacks-for-nested-data-structures/111998 "2024-03-24T22:10:59Z")

</div>

Since reading this issue: Should \`copy\` be renamed \`shallowcopy\`? · Issue #42796 · JuliaLang/julia · GitHub I have always avoided using deepcopy. Now I have a situation in which to define custom copy methods for my type…

---

## [Define another function in the definition of a function](https://discourse.julialang.org/t/define-another-function-in-the-definition-of-a-function/112016)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 9\
**Last updated:** [March 24, 2024, 9:52pm UTC](https://discourse.julialang.org/t/define-another-function-in-the-definition-of-a-function/112016 "2024-03-24T21:52:31Z")

</div>

I learned from somewhere I can’t remember that Julia allows defining a function in the definition of another function. Is there any detailed introduction for this usage? Thanks in advance!

---

## [NN Getting Same Training and Testing Accuracies?](https://discourse.julialang.org/t/nn-getting-same-training-and-testing-accuracies/111952)

<div class="topic-metadata">

**Author:** [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Replies:** 20\
**Last updated:** [March 24, 2024, 5:22pm UTC](https://discourse.julialang.org/t/nn-getting-same-training-and-testing-accuracies/111952 "2024-03-24T17:22:13Z")

</div>

Hi folks, Background: I am having a bit of trouble training a deep neural network. My data is comprised of grayscale images with a dimension of 128x128. For training data, I have 128x128x5116 images and for testing data…

---

## [Makie, how to move \`xlabel\` to the right?](https://discourse.julialang.org/t/makie-how-to-move-xlabel-to-the-right/93793)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 10\
**Last updated:** [March 24, 2024, 5:17pm UTC](https://discourse.julialang.org/t/makie-how-to-move-xlabel-to-the-right/93793 "2024-03-24T17:17:00Z")

</div>

For example: the X \[GeV\]

---

## [Performance of persistent variables](https://discourse.julialang.org/t/performance-of-persistent-variables/112044)

<div class="topic-metadata">

**Author:** [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Replies:** 0\
**Last updated:** [March 24, 2024, 4:33pm UTC](https://discourse.julialang.org/t/performance-of-persistent-variables/112044 "2024-03-24T16:33:09Z")

</div>

Hello, I have a simple toy example in which I compare two methods of creating persistent variables. In my case, both methods exhibit identical performance. Are there any differences to consider regarding safety, compil…

---

## [Call different functions depending on input](https://discourse.julialang.org/t/call-different-functions-depending-on-input/112042)

<div class="topic-metadata">

**Author:** [@phyxmeow](https://discourse.julialang.org/u/phyxmeow)\
**Replies:** 3\
**Last updated:** [March 24, 2024, 2:55pm UTC](https://discourse.julialang.org/t/call-different-functions-depending-on-input/112042 "2024-03-24T14:55:45Z")

</div>

Hello! I’m writing some code including call different functions depend on whether the input string match certain pattern. Currently I’m writing code like this: struct MyOperation fun::Symbol re::Regex end const…

---

## [Why does sortperm! allocate here?](https://discourse.julialang.org/t/why-does-sortperm-allocate-here/112028)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 4\
**Last updated:** [March 24, 2024, 1:47pm UTC](https://discourse.julialang.org/t/why-does-sortperm-allocate-here/112028 "2024-03-24T13:47:39Z")

</div>

Hello! I think I am missing something really simple, I just don’t get why allocations occur, when I have preallocated index array. function main() Cartesians = Vector{CartesianIndex{2}}(undef, 100) SortedInd…

---

## [Using TimerOutputs, registers allocs, where @allocated does not?](https://discourse.julialang.org/t/using-timeroutputs-registers-allocs-where-allocated-does-not/111995)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 2\
**Last updated:** [March 24, 2024, 11:17am UTC](https://discourse.julialang.org/t/using-timeroutputs-registers-allocs-where-allocated-does-not/111995 "2024-03-24T11:17:44Z")

</div>

Hello! I have a bit of a complex code, where I use TimerOutputs to track progress. I have the following code bit: In Line 343 I am updating the position variable. Position, Velocity, Acceleration are SVectors inside…

---

## [Modeling deformation in Julia](https://discourse.julialang.org/t/modeling-deformation-in-julia/111941)

<div class="topic-metadata">

**Author:** [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Replies:** 4\
**Last updated:** [March 23, 2024, 11:58pm UTC](https://discourse.julialang.org/t/modeling-deformation-in-julia/111941 "2024-03-23T23:58:50Z")

</div>

Hi everyone, a general question here about Finite elements in Julia. I am trying to do something rather “simple”. Imaging a large body (3D), fully constrained. In side there is a fault/fracture/weak zone inside. There …

---

## [Deepcopy() of Dict has same mallocs as deepcopy() of Vector inside mutable Struct](https://discourse.julialang.org/t/deepcopy-of-dict-has-same-mallocs-as-deepcopy-of-vector-inside-mutable-struct/53420)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 1\
**Last updated:** [March 23, 2024, 11:03pm UTC](https://discourse.julialang.org/t/deepcopy-of-dict-has-same-mallocs-as-deepcopy-of-vector-inside-mutable-struct/53420 "2024-03-23T23:03:22Z")

</div>

I had a struct that had a Dict as one of its fields. I deepcopy the struct objects a lot, and that was the bottleneck in the program. I then realized that I could replace the Dict with a Vector, which I know has a smalle…

---

## [How to build typed StructArrays from NTuples](https://discourse.julialang.org/t/how-to-build-typed-structarrays-from-ntuples/112023)

<div class="topic-metadata">

**Author:** [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Replies:** 0\
**Last updated:** [March 23, 2024, 4:34pm UTC](https://discourse.julialang.org/t/how-to-build-typed-structarrays-from-ntuples/112023 "2024-03-23T16:34:52Z")

</div>

In the documentation of StructArrays, the Advanced techniques · StructArrays section describes how custom structs could be passed to a StructArray constructor by overloading component, createinstance and staticschema. H…

---

## [Surprising type result with @](https://discourse.julialang.org/t/surprising-type-result-with/112012)

<div class="topic-metadata">

**Author:** [@CM1](https://discourse.julialang.org/u/CM1)\
**Replies:** 5\
**Last updated:** [March 23, 2024, 11:18am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012 "2024-03-23T11:18:36Z")

</div>

Hi everyone, I am quite confused about the resulting types in below snippet: N = 5 T = Float32 # edit, forgot to mention these variables μ = rand(T, N\_states, 1) σ = rand(T, N\_states, 1) E₀ = fill(T(0.5), N, 1) …

---

## [Error while using Optimization.jl](https://discourse.julialang.org/t/error-while-using-optimization-jl/112002)

<div class="topic-metadata">

**Author:** [@npsasikumar](https://discourse.julialang.org/u/npsasikumar)\
**Replies:** 7\
**Last updated:** [March 23, 2024, 9:29am UTC](https://discourse.julialang.org/t/error-while-using-optimization-jl/112002 "2024-03-23T09:29:45Z")

</div>

function errorfunction(data, p1) \*\* ddprob, ddprob\_response = data\*\* \*\* error = 0.0\*\* \*\* for i in 1:length(ddprob)\*\* \*\* error += sum(abs2, ddprob\_response\[i\]\[:\] - ddprob\[i\]\[:\])\*\* \*\* end\*\* \*\* retu…

---

## [Github actions deprecated](https://discourse.julialang.org/t/github-actions-deprecated/111630)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [March 23, 2024, 2:47am UTC](https://discourse.julialang.org/t/github-actions-deprecated/111630 "2024-03-23T02:47:23Z")

</div>

I get the following warnings: Julia 1 - ubuntu-latest - x64 - push Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v3, julia-actions/setup-julia@v1, actions/ca…

---

## [Programmatically adding multiple colums to a dataframe](https://discourse.julialang.org/t/programmatically-adding-multiple-colums-to-a-dataframe/111983)

<div class="topic-metadata">

**Author:** [@pascal](https://discourse.julialang.org/u/pascal)\
**Replies:** 4\
**Last updated:** [March 22, 2024, 7:10pm UTC](https://discourse.julialang.org/t/programmatically-adding-multiple-colums-to-a-dataframe/111983 "2024-03-22T19:10:39Z")

</div>

Suppose I have the following code: n = \["a\_" \* string(i) for i in 1:3\] v = \[1,2,3\] df = DataFrame(a = \[1, 2\], b = \[3, 4\]) df\_new = @chain df begin @transform $(n\[1\]) = v\[1\] end Can I change the @transform to add 3 …

---

## [Does calling a function with no memory allocations create an allocation?](https://discourse.julialang.org/t/does-calling-a-function-with-no-memory-allocations-create-an-allocation/111987)

<div class="topic-metadata">

**Author:** [@OmerPaz](https://discourse.julialang.org/u/OmerPaz)\
**Replies:** 5\
**Last updated:** [March 22, 2024, 7:54pm UTC](https://discourse.julialang.org/t/does-calling-a-function-with-no-memory-allocations-create-an-allocation/111987 "2024-03-22T19:54:47Z")

</div>

Hi all, I am running a numerical simulation in which I document my results in a pre-allocated structure, Obs: mutable struct Obs{T} name::String data::Array{T} num\_of\_measure::Int64 c\_num\_of\_measure::In…

---

## [Help understand boxing](https://discourse.julialang.org/t/help-understand-boxing/111829)

<div class="topic-metadata">

**Author:** [@jlamb](https://discourse.julialang.org/u/jlamb)\
**Replies:** 17\
**Last updated:** [March 22, 2024, 10:21am UTC](https://discourse.julialang.org/t/help-understand-boxing/111829 "2024-03-22T10:21:37Z")

</div>

I am trying to resolve a type stability problem in a function where some local variables are showing up as the type Core.Box when I run @code\_warntype. I’ve narrowed the cause to where I use a comprehension or generator …

---

## [Annotations?](https://discourse.julialang.org/t/annotations/111949)

<div class="topic-metadata">

**Author:** [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Replies:** 5\
**Last updated:** [March 21, 2024, 10:50pm UTC](https://discourse.julialang.org/t/annotations/111949 "2024-03-21T22:50:09Z")

</div>

What is the best way to annotate code that is both machine and human readable? My first thought would be parseable structured docstrings, but this seems too fragile. My second thought is macros that just emit the main e…

---

## [Derivative of user-defined function with variables as arguments in a PDE system](https://discourse.julialang.org/t/derivative-of-user-defined-function-with-variables-as-arguments-in-a-pde-system/111597)

<div class="topic-metadata">

**Author:** [@ehintz3](https://discourse.julialang.org/u/ehintz3)\
**Replies:** 1\
**Last updated:** [March 21, 2024, 10:47pm UTC](https://discourse.julialang.org/t/derivative-of-user-defined-function-with-variables-as-arguments-in-a-pde-system/111597 "2024-03-21T22:47:36Z")

</div>

Hello, I am new to Julia, so apologies if I am missing something basic, but I wasn’t getting any replies in New To Julia, so I’m not sure that was the right place for this post. I am trying to solve a system of PDEs usin…

---

## [Color gradient doesn't work](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 6\
**Last updated:** [March 21, 2024, 9:39pm UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734 "2024-03-21T21:39:50Z")

</div>

I have a for loop. I want the color used to be evenly spaced from a color gradient such as inferno. I read various stuff online, but none works. for example trying the palette = : inferno in ax.plot of pythonplot gives: …

---

## [Documenter.jl: misplaced docstrings when using method signatures](https://discourse.julialang.org/t/documenter-jl-misplaced-docstrings-when-using-method-signatures/111951)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 0\
**Last updated:** [March 21, 2024, 9:06pm UTC](https://discourse.julialang.org/t/documenter-jl-misplaced-docstrings-when-using-method-signatures/111951 "2024-03-21T21:06:36Z")

</div>

I get repeated docstrings in the output of Documenter.jl when I try to select methods by their signatures. Here is an example: Take this package module DocumenterTestPkg export f "vector doc" f(x::Vector{T}) where T =…

---

## [How to return a non-allocating view from a function?](https://discourse.julialang.org/t/how-to-return-a-non-allocating-view-from-a-function/111946)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 3\
**Last updated:** [March 21, 2024, 8:11pm UTC](https://discourse.julialang.org/t/how-to-return-a-non-allocating-view-from-a-function/111946 "2024-03-21T20:11:39Z")

</div>

Hello! I have a function in which I do a small amount of operations, before returning a view of the final result as such: # some operations .. ParticleRanges = view(ParticleSplitterLinearIndices, ParticleSplitt…

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

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