# General Usage

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

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

**Page:** 433

---

## [Fetch part of an array with indexes known by the workers](https://discourse.julialang.org/t/fetch-part-of-an-array-with-indexes-known-by-the-workers/83170)

<div class="topic-metadata">

**Author:** [@EdTi](https://discourse.julialang.org/u/EdTi)\
**Replies:** 4\
**Last updated:** [June 22, 2022, 4:58pm UTC](https://discourse.julialang.org/t/fetch-part-of-an-array-with-indexes-known-by-the-workers/83170 "2022-06-22T16:58:32Z")

</div>

Hi everyone, I’m having some troubles with the Distributed functionalities of Julia. I want to declare a matrix A on the main process and give slices of A to the workers. I launch Julia with the command julia -p 8 @ev…

---

## [What's the best way to separate elements of a vector based on its values?](https://discourse.julialang.org/t/whats-the-best-way-to-separate-elements-of-a-vector-based-on-its-values/83121)

<div class="topic-metadata">

**Author:** [@Carlose](https://discourse.julialang.org/u/Carlose)\
**Replies:** 6\
**Last updated:** [June 22, 2022, 4:14pm UTC](https://discourse.julialang.org/t/whats-the-best-way-to-separate-elements-of-a-vector-based-on-its-values/83121 "2022-06-22T16:14:35Z")

</div>

Hi all, What’s the best way to separate elements of a vector based on the value of the last member? All = \[ (15,12,875), (25,132, 333), (7,9, 201), (147,92, 201), (77,59, 333), (15,11,875), (10,12,875), (4,12,875), (2…

---

## [How to search an array for the index coresponding to the nearest value?](https://discourse.julialang.org/t/how-to-search-an-array-for-the-index-coresponding-to-the-nearest-value/83190)

<div class="topic-metadata">

**Author:** [@TLTYNS](https://discourse.julialang.org/u/TLTYNS)\
**Replies:** 4\
**Last updated:** [June 22, 2022, 4:01pm UTC](https://discourse.julialang.org/t/how-to-search-an-array-for-the-index-coresponding-to-the-nearest-value/83190 "2022-06-22T16:01:34Z")

</div>

I have two separate data sets and each of them have a different time axis (distance between values). I want to write a function where I provide a time(float64) and it tells me the closest index value in both arrays. I …

---

## [Reported stacktrace are terrible for errors :-/](https://discourse.julialang.org/t/reported-stacktrace-are-terrible-for-errors/83193)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 2\
**Last updated:** [June 22, 2022, 3:44pm UTC](https://discourse.julialang.org/t/reported-stacktrace-are-terrible-for-errors/83193 "2022-06-22T15:44:59Z")

</div>

I am sure this must already have been discussed, but it’s a nice example… here I made a typo on Imputators.jl row 154, but nowhere in the stacktrace this position is reported… Is there any package that can help durin…

---

## [LinearAlgebra.det and symbolic variables](https://discourse.julialang.org/t/linearalgebra-det-and-symbolic-variables/83054)

<div class="topic-metadata">

**Author:** [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Replies:** 6\
**Last updated:** [June 22, 2022, 3:34pm UTC](https://discourse.julialang.org/t/linearalgebra-det-and-symbolic-variables/83054 "2022-06-22T15:34:08Z")

</div>

I am interested in the computation of the determinant of a (very sparse) matrix involving a symbolic variable. My code is using Symbolics, LinearAlgebra, SparseArrays N = 11 FloatType = Float64 c = zeros(FloatType, …

---

## [@async while loop not looping](https://discourse.julialang.org/t/async-while-loop-not-looping/83156)

<div class="topic-metadata">

**Author:** [@wiseac](https://discourse.julialang.org/u/wiseac)\
**Replies:** 2\
**Last updated:** [June 22, 2022, 2:17pm UTC](https://discourse.julialang.org/t/async-while-loop-not-looping/83156 "2022-06-22T14:17:33Z")

</div>

Im trying to loop two tasks but it will only run through it once and not loop. This is what my code looks like. I have the second task commented out because im trying to just get the first one working. If i remove the @…

---

## [Stipple.jl embedding of a local image in the html dashboard](https://discourse.julialang.org/t/stipple-jl-embedding-of-a-local-image-in-the-html-dashboard/83157)

<div class="topic-metadata">

**Author:** [@monty](https://discourse.julialang.org/u/monty)\
**Replies:** 1\
**Last updated:** [June 22, 2022, 12:26pm UTC](https://discourse.julialang.org/t/stipple-jl-embedding-of-a-local-image-in-the-html-dashboard/83157 "2022-06-22T12:26:12Z")

</div>

What will be the easiest way to embed a local image (generated on the compute server by Julia) in the HTML dashboard? I have found solutions using a “public” folder however it is unclear to me (1) where it should be loc…

---

## [Profiling compilation of a large generated expression?](https://discourse.julialang.org/t/profiling-compilation-of-a-large-generated-expression/83179)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 4\
**Last updated:** [June 22, 2022, 11:32am UTC](https://discourse.julialang.org/t/profiling-compilation-of-a-large-generated-expression/83179 "2022-06-22T11:32:34Z")

</div>

Hi @Julia, The team I’m working with is writing a simulation package, with a core dudt!(du, u, parameters, t) function given as an argument to ODEProblem and solve from DifferentialEquations. The code in dudt! is comple…

---

## [Solution at specific time points using a stiff ODE solver](https://discourse.julialang.org/t/solution-at-specific-time-points-using-a-stiff-ode-solver/83169)

<div class="topic-metadata">

**Author:** [@ajaydeepk](https://discourse.julialang.org/u/ajaydeepk)\
**Replies:** 2\
**Last updated:** [June 22, 2022, 10:57am UTC](https://discourse.julialang.org/t/solution-at-specific-time-points-using-a-stiff-ode-solver/83169 "2022-06-22T10:57:51Z")

</div>

While using stiff ODE solver like CVODE\_BDF() and radau(), can we use saveat to save solutions at specific time points. For example, since time step dt changes adaptively, thereby is it a good idea to do sol = solve(fun…

---

## [Julian way to "remove" missing type in the eltype of a Matrix?](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 7\
**Last updated:** [June 22, 2022, 8:48am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168 "2022-06-22T08:48:30Z")

</div>

julia\> A = \[1 2 missing; 4 5 6\] 2×3 Matrix{Union{Missing, Int64}}: 1 2 missing 4 5 6 julia\> A\[1,3\] = 3 3 julia\> A 2×3 Matrix{Union{Missing, Int64}}: 1 2 3 4 5 6 Now, I want to get rid of the missing in th…

---

## [Simple example of @threads](https://discourse.julialang.org/t/simple-example-of-threads/83049)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 17\
**Last updated:** [June 22, 2022, 6:11am UTC](https://discourse.julialang.org/t/simple-example-of-threads/83049 "2022-06-22T06:11:06Z")

</div>

How can I make this simple example thread safe? function func(R=5) s = 0.0 Threads.@threads :static for i in 1:R s += 1 end return s end If it makes any difference, in my application I am summin…

---

## [Canonical way on how to use something that is defined later in the code?](https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 2\
**Last updated:** [June 22, 2022, 5:21am UTC](https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142 "2022-06-22T05:21:38Z")

</div>

I have a package that is divided in several modules, says Utils and 'Algos\`, each on his file: MyPackage.jl: include("Utils.jl") include("Algos.jl") Up to now Algos was using something defined in Utils, and there were…

---

## [How to import custom module from file without include](https://discourse.julialang.org/t/how-to-import-custom-module-from-file-without-include/83139)

<div class="topic-metadata">

**Author:** [@Jack\_N](https://discourse.julialang.org/u/Jack_N)\
**Replies:** 5\
**Last updated:** [June 22, 2022, 4:27am UTC](https://discourse.julialang.org/t/how-to-import-custom-module-from-file-without-include/83139 "2022-06-22T04:27:35Z")

</div>

I made a custom module in a file database.jl called DecisionNode but I cannot seem to find a way to import the DecisionNode module without using the include function, which I do not want to do since I will be using the D…

---

## [Substitute powers and powers of fractions](https://discourse.julialang.org/t/substitute-powers-and-powers-of-fractions/80641)

<div class="topic-metadata">

**Author:** [@kjellqvist](https://discourse.julialang.org/u/kjellqvist)\
**Replies:** 4\
**Last updated:** [June 22, 2022, 2:36am UTC](https://discourse.julialang.org/t/substitute-powers-and-powers-of-fractions/80641 "2022-06-22T02:36:22Z")

</div>

I’m a bit stuck on substitutions, for example: @variables x y eq = (1/x)^2 substitute(eq, Dict(\[1/x =\> y\])) julia\> y^2 whereas @variables x y eq = 1/x^2 substitute(eq, Dict(\[1/x =\> y\])) julia\> 1 / (x^2) I w…

---

## [ERROR: TypeError: non-boolean (Missing) used in boolean context](https://discourse.julialang.org/t/error-typeerror-non-boolean-missing-used-in-boolean-context/83152)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 5\
**Last updated:** [June 22, 2022, 1:56am UTC](https://discourse.julialang.org/t/error-typeerror-non-boolean-missing-used-in-boolean-context/83152 "2022-06-22T01:56:59Z")

</div>

Why does this happen? julia\> 3 \< missing \< 5 ERROR: TypeError: non-boolean (Missing) used in boolean context Is it expanding to this? julia\> (3 \< missing) && (missing \< 5) ERROR: TypeError: non-boolean (Missing) used …

---

## [Array of pointers to struct vs. Array of struct](https://discourse.julialang.org/t/array-of-pointers-to-struct-vs-array-of-struct/83150)

<div class="topic-metadata">

**Author:** [@peter.wolf](https://discourse.julialang.org/u/peter.wolf)\
**Replies:** 2\
**Last updated:** [June 21, 2022, 11:29pm UTC](https://discourse.julialang.org/t/array-of-pointers-to-struct-vs-array-of-struct/83150 "2022-06-21T23:29:54Z")

</div>

I want to create a vector of structs. In my code I do something like this some\_vector = Vector{SomeStruct}(big\_number) for i in 1:big\_number some\_vector\[i\] = SomeStruct(some\_args) end I believe this is allocating …

---

## [Precompilation and package compiler](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 4\
**Last updated:** [June 21, 2022, 8:37pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141 "2022-06-21T20:37:06Z")

</div>

Hello, we’re creating binaries using PackageCompiler.jl, and it’s working well, but… right now we have a script create\_precompile.jl which we use to create a build/MyPackage\_precompile.jl file full of precompile statemen…

---

## [Prepending a type to an array](https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140)

<div class="topic-metadata">

**Author:** [@Yly](https://discourse.julialang.org/u/Yly)\
**Replies:** 2\
**Last updated:** [June 21, 2022, 7:33pm UTC](https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140 "2022-06-21T19:33:19Z")

</div>

In reading about mixture models in Distributions.jl, I found this code snippet: Normal\[ Normal(-2.0, 1.2), Normal(0.0, 1.0), Normal(3.0, 2.5)\] This syntax is unfamiliar to me. The only documentation I can fin…

---

## [Confusing plot titles with subplots](https://discourse.julialang.org/t/confusing-plot-titles-with-subplots/83127)

<div class="topic-metadata">

**Author:** [@polhager](https://discourse.julialang.org/u/polhager)\
**Replies:** 1\
**Last updated:** [June 21, 2022, 5:23pm UTC](https://discourse.julialang.org/t/confusing-plot-titles-with-subplots/83127 "2022-06-21T17:23:49Z")

</div>

Hello! I am trying to create a few rows of subplots, each row containing the same number of subplots as well as a title. I have done this with nested plots of lists. using Plots plotly() x = 0:0.01:10 n = 3 m = 5 plo…

---

## [Tracking down instant crashes with multithreading](https://discourse.julialang.org/t/tracking-down-instant-crashes-with-multithreading/82686)

<div class="topic-metadata">

**Author:** [@Jon\_Barker](https://discourse.julialang.org/u/Jon_Barker)\
**Replies:** 5\
**Last updated:** [June 21, 2022, 5:17pm UTC](https://discourse.julialang.org/t/tracking-down-instant-crashes-with-multithreading/82686 "2022-06-21T17:17:48Z")

</div>

Hi All, I’m working on converting a program from multi-process to multi-threading. I’ve been through the code and am very confident that everything works in its own memoryspace (not writing to the same variables at the…

---

## [Stop allocating memory when replacing structs in for-loops](https://discourse.julialang.org/t/stop-allocating-memory-when-replacing-structs-in-for-loops/83125)

<div class="topic-metadata">

**Author:** [@Joseph\_Bradley](https://discourse.julialang.org/u/Joseph_Bradley)\
**Replies:** 5\
**Last updated:** [June 21, 2022, 3:40pm UTC](https://discourse.julialang.org/t/stop-allocating-memory-when-replacing-structs-in-for-loops/83125 "2022-06-21T15:40:38Z")

</div>

I’m working on a project where I have to simulate many systems and track some observable across the many systems. When I try to create new systems in for-loops, I end up getting allocations of O(n\_trials) when it isn’t n…

---

## [Pushfirst! for Channel](https://discourse.julialang.org/t/pushfirst-for-channel/83113)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 7\
**Last updated:** [June 21, 2022, 1:38pm UTC](https://discourse.julialang.org/t/pushfirst-for-channel/83113 "2022-06-21T13:38:53Z")

</div>

Hi all :slight\_smile: Is there an reason why the is no pushfirst! for Channel? Cheers

---

## [Makie: RGB legend colors](https://discourse.julialang.org/t/makie-rgb-legend-colors/83086)

<div class="topic-metadata">

**Author:** [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Replies:** 5\
**Last updated:** [June 21, 2022, 12:16pm UTC](https://discourse.julialang.org/t/makie-rgb-legend-colors/83086 "2022-06-21T12:16:39Z")

</div>

How do I create legend entries in Makie using RBG colors? The following worked in CairoMakie 0.7: using CairoMakie, ColorSchemes f = Figure() Axis(f\[1, 1\]) labelV = \["lbl $j" for j = 1 : 3\]; n = length(labelV); elemen…

---

## [How to pretty print an InMemoryDataset?](https://discourse.julialang.org/t/how-to-pretty-print-an-inmemorydataset/82909)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [June 21, 2022, 4:02am UTC](https://discourse.julialang.org/t/how-to-pretty-print-an-inmemorydataset/82909 "2022-06-21T04:02:06Z")

</div>

When I print an InMemoryDataSet, how can I suppress the lines: Row │ time RTR addr d1 d2 data3 data4 data5 data6 │ identity identity hex hex2 hex2 hex2 hex2 …

---

## [Does Parameters.jl support a Varargs ... constuctor](https://discourse.julialang.org/t/does-parameters-jl-support-a-varargs-constuctor/83100)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 2\
**Last updated:** [June 21, 2022, 1:12am UTC](https://discourse.julialang.org/t/does-parameters-jl-support-a-varargs-constuctor/83100 "2022-06-21T01:12:07Z")

</div>

a,b,c = 1:3 @with\_kw mutable struct T a b end T(;a,b) works T(;a,b,c) fails Can the kwargs constructor have a Varargs component X... ? It allowed me to create one T(;a,b, X... ) = T(;a,b) B…

---

## [Type-Instability Caused by Wrapping Type-Stable Function](https://discourse.julialang.org/t/type-instability-caused-by-wrapping-type-stable-function/83089)

<div class="topic-metadata">

**Author:** [@dleather](https://discourse.julialang.org/u/dleather)\
**Replies:** 2\
**Last updated:** [June 20, 2022, 8:46pm UTC](https://discourse.julialang.org/t/type-instability-caused-by-wrapping-type-stable-function/83089 "2022-06-20T20:46:03Z")

</div>

The following results are puzzling to me. I have a type-stable function eval\_logprior stored in structure prior\_struct which I type as ::Function. Input: eval\_logprior = prior\_struct.eval\_logprior @code\_warntype eval\_l…

---

## [Finding patterns in vectors](https://discourse.julialang.org/t/finding-patterns-in-vectors/82833)

<div class="topic-metadata">

**Author:** [@duodenum](https://discourse.julialang.org/u/duodenum)\
**Replies:** 9\
**Last updated:** [June 20, 2022, 8:06pm UTC](https://discourse.julialang.org/t/finding-patterns-in-vectors/82833 "2022-06-20T20:06:39Z")

</div>

Hello, I’m trying to write a Julia implementation of Lempel-Ziv Complexity. Specifically I’m stuck at the pattern-finding part of the algorithm. Let’s say I have a vector: \[1, 0, 0, 1\]. It contains the pattern \[1, 0\] bu…

---

## [Meaning of 2 minimum times of \`@btime\`](https://discourse.julialang.org/t/meaning-of-2-minimum-times-of-btime/83041)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 13\
**Last updated:** [June 20, 2022, 7:25pm UTC](https://discourse.julialang.org/t/meaning-of-2-minimum-times-of-btime/83041 "2022-06-20T19:25:08Z")

</div>

I know that \<1ns @btime timings mean that the compiler hoisted the method call out of the benchmark loop completely, but it’s a consistent number ~0.034ns. What does that number mean, where does it come from? julia\> @bt…

---

## [Taking TTFX seriously: Can we make common packages faster to load and use](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949)

<div class="topic-metadata">

**Author:** [@Raf](https://discourse.julialang.org/u/Raf)\
**Replies:** 123\
**Last updated:** [June 20, 2022, 6:19pm UTC](https://discourse.julialang.org/t/taking-ttfx-seriously-can-we-make-common-packages-faster-to-load-and-use/74949 "2022-06-20T18:19:12Z")

</div>

So much work has been done to improve julia compilation and remove invalidations. Things really feel a lot snappier to use. But there is still the problem of packages that were written without much thought to startup ti…

---

## [\`First function call produced NaNs\` when using NUTS but not MH](https://discourse.julialang.org/t/first-function-call-produced-nans-when-using-nuts-but-not-mh/83024)

<div class="topic-metadata">

**Author:** [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Replies:** 7\
**Last updated:** [June 20, 2022, 4:29pm UTC](https://discourse.julialang.org/t/first-function-call-produced-nans-when-using-nuts-but-not-mh/83024 "2022-06-20T16:29:16Z")

</div>

Hello everyone, I’m having trouble fitting a Cucker-Smaile ODE model with Turing. \\Psi is positive, non-increasing and smooth, in my model ψ(r, K, β) = K / ((1 + r^2)^β). Even though I can solve the ODE system fine,…

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

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