# General Usage

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

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

**Page:** 382

---

## [How to get the number of workers in a machine or cluster node?](https://discourse.julialang.org/t/how-to-get-the-number-of-workers-in-a-machine-or-cluster-node/88925)

<div class="topic-metadata">

**Author:** [@decarvalhojuniorfh](https://discourse.julialang.org/u/decarvalhojuniorfh)\
**Replies:** 1\
**Last updated:** [October 19, 2022, 3:54am UTC](https://discourse.julialang.org/t/how-to-get-the-number-of-workers-in-a-machine-or-cluster-node/88925 "2022-10-19T03:54:30Z")

</div>

In a distributed program, how do you programmatically obtain the number of workers on the node of a cluster where a code is running? For example, if there were 6 workers launched using addprocs (\[(“machine1", 4), (“mach…

---

## [@match string startswith endswith](https://discourse.julialang.org/t/match-string-startswith-endswith/87797)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 4\
**Last updated:** [October 19, 2022, 3:53am UTC](https://discourse.julialang.org/t/match-string-startswith-endswith/87797 "2022-10-19T03:53:10Z")

</div>

Is there a @match equivalent of this? type = startswith(ticker,"ABC") ? "M1" : startswith(ticker,"X") ? "M2" : contains(ticker,"123") ? "M3" : endswith(ticker,"end") …

---

## [JuliaInXL where is the installer?](https://discourse.julialang.org/t/juliainxl-where-is-the-installer/88795)

<div class="topic-metadata">

**Author:** [@DavidTaylor](https://discourse.julialang.org/u/DavidTaylor)\
**Replies:** 4\
**Last updated:** [October 19, 2022, 3:47am UTC](https://discourse.julialang.org/t/juliainxl-where-is-the-installer/88795 "2022-10-19T03:47:51Z")

</div>

JuliaInXL; where is the windows installer?

---

## [Performant Alternatives to mapslices](https://discourse.julialang.org/t/performant-alternatives-to-mapslices/84651)

<div class="topic-metadata">

**Author:** [@bmit](https://discourse.julialang.org/u/bmit)\
**Replies:** 4\
**Last updated:** [October 18, 2022, 11:30pm UTC](https://discourse.julialang.org/t/performant-alternatives-to-mapslices/84651 "2022-10-18T23:30:37Z")

</div>

There are a few discussions I’ve found on this already, but I’m hoping my use case is simple enough that a solution already exists. Related: enumerate() like equivalents for iterating over columns/rows of a matrix · Iss…

---

## [Advice for efficient code containing many lookup table access values](https://discourse.julialang.org/t/advice-for-efficient-code-containing-many-lookup-table-access-values/86522)

<div class="topic-metadata">

**Author:** [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Replies:** 9\
**Last updated:** [October 18, 2022, 11:24pm UTC](https://discourse.julialang.org/t/advice-for-efficient-code-containing-many-lookup-table-access-values/86522 "2022-10-18T23:24:24Z")

</div>

Dear Julians, I want to speed up the following code that iterates over a matrix containing n\_examples vectors of size n\_features. These vectors, stored in PQ, have eltype Integer with values in the range 1 to n\_clust…

---

## [Time to first plot with system image not as good as expected](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 11\
**Last updated:** [October 18, 2022, 10:36pm UTC](https://discourse.julialang.org/t/time-to-first-plot-with-system-image-not-as-good-as-expected/87428 "2022-10-18T22:36:28Z")

</div>

I am trying to reduce the time-to-first-plot by using a system image. What I am doing is explained in detail here: GitHub - ufechner7/Plotting: Demo for using InspectDR If you are using Linux you can easily reproduce my…

---

## [Could I change the type of a declared variable?](https://discourse.julialang.org/t/could-i-change-the-type-of-a-declared-variable/88933)

<div class="topic-metadata">

**Author:** [@swish47](https://discourse.julialang.org/u/swish47)\
**Replies:** 3\
**Last updated:** [October 18, 2022, 9:58pm UTC](https://discourse.julialang.org/t/could-i-change-the-type-of-a-declared-variable/88933 "2022-10-18T21:58:03Z")

</div>

It is known that we cannot clear a variable after set them. However is it possible to change a decleared variable? For example: a::Int16=1001; Then what ever we set: a=nothing or a=1.000001 will both receive Inex…

---

## [How to directly specify datatype when reading from excel? Matrix{Any} to Vector{Int64}](https://discourse.julialang.org/t/how-to-directly-specify-datatype-when-reading-from-excel-matrix-any-to-vector-int64/88853)

<div class="topic-metadata">

**Author:** [@Mike\_comen](https://discourse.julialang.org/u/Mike_comen)\
**Replies:** 4\
**Last updated:** [October 18, 2022, 9:51pm UTC](https://discourse.julialang.org/t/how-to-directly-specify-datatype-when-reading-from-excel-matrix-any-to-vector-int64/88853 "2022-10-18T21:51:45Z")

</div>

I’d like to have some coulmns of an excel sheet in Julia in a Vector{Int64} format. However, it gives me Matrix{Any}. My try: xf = XLSX.readxlsx(\`"C:/Data/sales.xlsx"\`) A = xf\["sheet1!A2:A100"\]) A\_vec = vec(A) …

---

## [Iterating over (key, value) with grouped DataFrame](https://discourse.julialang.org/t/iterating-over-key-value-with-grouped-dataframe/27360)

<div class="topic-metadata">

**Author:** [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Replies:** 8\
**Last updated:** [October 18, 2022, 9:36pm UTC](https://discourse.julialang.org/t/iterating-over-key-value-with-grouped-dataframe/27360 "2022-10-18T21:36:14Z")

</div>

Not sure if I’m being dense here, but is there a simple way to iterate over a GroupedDataFrame, having the grouping levels available at each iteration? i.e. something like df = DataFrame(a = \[1,1,2,2\], b = randn(4)) gdf…

---

## [Useful Julia script tips? (workaround shebang)](https://discourse.julialang.org/t/useful-julia-script-tips-workaround-shebang/15584)

<div class="topic-metadata">

**Author:** [@tkf](https://discourse.julialang.org/u/tkf)\
**Replies:** 6\
**Last updated:** [October 18, 2022, 2:48pm UTC](https://discourse.julialang.org/t/useful-julia-script-tips-workaround-shebang/15584 "2022-10-18T14:48:30Z")

</div>

I found a useful little hack so I share it here. It may already be discovered elsewhere, but it’s fun to re-discover a nice(?) trick! If you ever tried to write a julia script and put its options in the shebang, you mi…

---

## [Floor? Force magnitude amount?](https://discourse.julialang.org/t/floor-force-magnitude-amount/88833)

<div class="topic-metadata">

**Author:** [@theboiwholived](https://discourse.julialang.org/u/theboiwholived)\
**Replies:** 5\
**Last updated:** [October 18, 2022, 6:44pm UTC](https://discourse.julialang.org/t/floor-force-magnitude-amount/88833 "2022-10-18T18:44:17Z")

</div>

Hey all, Newer to julia and working with some very large numbers. Unfort conditioning of the system im using leads to numerical issues with numbers spanning more than 12 orders of magnitude. I’ve been working in bigInt…

---

## [Type Instability and Union Splitting](https://discourse.julialang.org/t/type-instability-and-union-splitting/88886)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 4\
**Last updated:** [October 18, 2022, 3:23pm UTC](https://discourse.julialang.org/t/type-instability-and-union-splitting/88886 "2022-10-18T15:23:23Z")

</div>

So I know the following code is not type stable: foo(x::Int64, y::Float64) = x \< y ? x : y As a human I understand that the return type of this function must be Union{Int64, Float64}. Does the compiler also understan…

---

## [Eigvals faster for ComplexF64 matrices than Float64](https://discourse.julialang.org/t/eigvals-faster-for-complexf64-matrices-than-float64/88846)

<div class="topic-metadata">

**Author:** [@ysh](https://discourse.julialang.org/u/ysh)\
**Replies:** 4\
**Last updated:** [October 18, 2022, 3:15pm UTC](https://discourse.julialang.org/t/eigvals-faster-for-complexf64-matrices-than-float64/88846 "2022-10-18T15:15:06Z")

</div>

I’ve noticed that when diagonalising real symmetric matrices, eigvals may perform faster if the input matrix is complex, i.e. Matrix{ComplexF64} rather than Matrix{Float64}. Here is my test code: using LinearAlgebra, Be…

---

## [How to handle unknown length returns in recursion without allocating](https://discourse.julialang.org/t/how-to-handle-unknown-length-returns-in-recursion-without-allocating/88909)

<div class="topic-metadata">

**Author:** [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Replies:** 3\
**Last updated:** [October 18, 2022, 1:45pm UTC](https://discourse.julialang.org/t/how-to-handle-unknown-length-returns-in-recursion-without-allocating/88909 "2022-10-18T13:45:35Z")

</div>

I have a recursive function f(x, data) which can return anywhere between 1 and length(x) elements. All I want to be able to do is iterate over the return value of f so the result doesn’t need to be instantiated into a Tu…

---

## [Fast check if a character "is" an integer](https://discourse.julialang.org/t/fast-check-if-a-character-is-an-integer/88750)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 23\
**Last updated:** [October 18, 2022, 12:28pm UTC](https://discourse.julialang.org/t/fast-check-if-a-character-is-an-integer/88750 "2022-10-18T12:28:38Z")

</div>

I need to check if the first character of a string is an integer, quickly. I’m doing a try-catch: julia\> function c(name) i0 = try parse(Int, name\[1\]) true catch …

---

## [Implicit Nonlinear Dynamics example in DataDrivenDiffEq doesn't work](https://discourse.julialang.org/t/implicit-nonlinear-dynamics-example-in-datadrivendiffeq-doesnt-work/88901)

<div class="topic-metadata">

**Author:** [@CurioMath](https://discourse.julialang.org/u/CurioMath)\
**Replies:** 2\
**Last updated:** [October 18, 2022, 11:36am UTC](https://discourse.julialang.org/t/implicit-nonlinear-dynamics-example-in-datadrivendiffeq-doesnt-work/88901 "2022-10-18T11:36:00Z")

</div>

Hi, I have a DAE system which when structurally simplified gives an ODE system with 7 Differential Equations and 21 parameters. I would like to recover this system from the simulated data. I tried DataDrivenDiffEq for t…

---

## [Performance problem on dual socket Xeon under Windows 11](https://discourse.julialang.org/t/performance-problem-on-dual-socket-xeon-under-windows-11/88772)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 6\
**Last updated:** [October 18, 2022, 6:51am UTC](https://discourse.julialang.org/t/performance-problem-on-dual-socket-xeon-under-windows-11/88772 "2022-10-18T06:51:05Z")

</div>

Hello, I have a question about parallelization in Julia. I am working on a Dell dual socket Xeon 5220r workstation ( 2x24 cores, 2x48 threads) running Windows 11. I was initially on Windows 10, but as this old post ( @…

---

## [Error with HTTP get requests](https://discourse.julialang.org/t/error-with-http-get-requests/88645)

<div class="topic-metadata">

**Author:** [@jonjilla](https://discourse.julialang.org/u/jonjilla)\
**Replies:** 6\
**Last updated:** [October 18, 2022, 6:14am UTC](https://discourse.julialang.org/t/error-with-http-get-requests/88645 "2022-10-18T06:14:22Z")

</div>

Hello all I have this error when using HTTP GET to retrieve data from a webservice. I have a properly formatted url and if I pass this url to curl like this, I can retrieve data correctly r = read(\`curl -s -k $url\`, S…

---

## [Sharing variables between Notebook and REPL in Visual Studio or JupyterLab](https://discourse.julialang.org/t/sharing-variables-between-notebook-and-repl-in-visual-studio-or-jupyterlab/88797)

<div class="topic-metadata">

**Author:** [@compleat](https://discourse.julialang.org/u/compleat)\
**Replies:** 2\
**Last updated:** [October 17, 2022, 10:04pm UTC](https://discourse.julialang.org/t/sharing-variables-between-notebook-and-repl-in-visual-studio-or-jupyterlab/88797 "2022-10-17T22:04:39Z")

</div>

Is it possible to share variables (or Julia instance) between a Jupyter-style notebook and a REPL, either in Visual Studio or JupyterLab? Thanks for any help.

---

## [Disabling DomainError (in sqrt())?](https://discourse.julialang.org/t/disabling-domainerror-in-sqrt/88755)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 21\
**Last updated:** [October 17, 2022, 9:20pm UTC](https://discourse.julialang.org/t/disabling-domainerror-in-sqrt/88755 "2022-10-17T21:20:30Z")

</div>

Is there any way one can remove the negative number check for sqrt(Float64)? Neither @inbounds or @fastmath seems to do the trick (by checking the generated @code\_native). However, it seems that, say, LinearAlgebra.norm(…

---

## [VSCode sysimage build hangs on my NFS home directory](https://discourse.julialang.org/t/vscode-sysimage-build-hangs-on-my-nfs-home-directory/88872)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 2\
**Last updated:** [October 17, 2022, 8:44pm UTC](https://discourse.julialang.org/t/vscode-sysimage-build-hangs-on-my-nfs-home-directory/88872 "2022-10-17T20:44:56Z")

</div>

I’m not really sure this is a bug with VSCode or Julia, so I’ll just throw it out there for discussion and file a bug if something comes of it. I tried building a sysimage for a project I’m working on this morning. Doin…

---

## [Enum type as field value performance](https://discourse.julialang.org/t/enum-type-as-field-value-performance/88867)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 1\
**Last updated:** [October 17, 2022, 7:49pm UTC](https://discourse.julialang.org/t/enum-type-as-field-value-performance/88867 "2022-10-17T19:49:22Z")

</div>

I know it is discouraged to use an abstract type for a field in a composite type due to the runtime overhead of looking up the type and method resolution. Does using an enum type suffer from the same problem? Or is it m…

---

## [Profiler hangs](https://discourse.julialang.org/t/profiler-hangs/88836)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 2\
**Last updated:** [October 17, 2022, 7:09pm UTC](https://discourse.julialang.org/t/profiler-hangs/88836 "2022-10-17T19:09:23Z")

</div>

I have a function, that terminates fine if I run it. f() # terminates after ~10s However if I profile it, it does not: using Profile @profile f() CPU usage goes down to 0% after a few seconds while and the function …

---

## [Performance of Fields with Union Type](https://discourse.julialang.org/t/performance-of-fields-with-union-type/88863)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 3\
**Last updated:** [October 17, 2022, 6:53pm UTC](https://discourse.julialang.org/t/performance-of-fields-with-union-type/88863 "2022-10-17T18:53:31Z")

</div>

The Manual \> Performance Tips documentation says that one should not use a field with an abstract type. This makes sense to me as otherwise a lot of type lookup and method resolution would have to happen at runtime when…

---

## [Does Julia have fast expectations over multivariate Gaussians?](https://discourse.julialang.org/t/does-julia-have-fast-expectations-over-multivariate-gaussians/88834)

<div class="topic-metadata">

**Author:** [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Replies:** 6\
**Last updated:** [October 17, 2022, 4:18pm UTC](https://discourse.julialang.org/t/does-julia-have-fast-expectations-over-multivariate-gaussians/88834 "2022-10-17T16:18:54Z")

</div>

The following approach using HCubature.jl seems rather slow. Is there an easy way to make this faster in Julia? using BenchmarkTools, HCubature, Distributions softplus(x) = log(exp(x) + 1) function integrand(r1, r2, u; …

---

## [Function with vector of Union-Type](https://discourse.julialang.org/t/function-with-vector-of-union-type/88850)

<div class="topic-metadata">

**Author:** [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Replies:** 4\
**Last updated:** [October 17, 2022, 3:43pm UTC](https://discourse.julialang.org/t/function-with-vector-of-union-type/88850 "2022-10-17T15:43:57Z")

</div>

This does work: function \_foo1(\_range::AbstractVector=\[1,2\]) println(\_range) end \_foo1(\[1, missing\]) This fails: function \_foo2(\_range::Vector{Union{\<:Number, Missing}}=\[1, 2\]) println(\_range) end \_foo2(\[1, m…

---

## [Creating Ensemble Model(s) with Flux](https://discourse.julialang.org/t/creating-ensemble-model-s-with-flux/88796)

<div class="topic-metadata">

**Author:** [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Replies:** 6\
**Last updated:** [October 17, 2022, 2:17pm UTC](https://discourse.julialang.org/t/creating-ensemble-model-s-with-flux/88796 "2022-10-17T14:17:11Z")

</div>

Hello, I am trying to build a very basic ensemble model with Flux. Since the network structure does not change, all weak learners are the same. I am facing a problem with loss function definitions. It seems like I have…

---

## [Type stability with user input](https://discourse.julialang.org/t/type-stability-with-user-input/88828)

<div class="topic-metadata">

**Author:** [@klafyvel](https://discourse.julialang.org/u/klafyvel)\
**Replies:** 3\
**Last updated:** [October 17, 2022, 2:12pm UTC](https://discourse.julialang.org/t/type-stability-with-user-input/88828 "2022-10-17T14:12:09Z")

</div>

Hi there! I am writing a small parser, and I use multiple-dispatch to make Julia use the right parser function depending on the type of token entered by the user. Here is a mock-up tokenizer that uses the same idea as m…

---

## [Finding charactersitic time in decaying dataset](https://discourse.julialang.org/t/finding-charactersitic-time-in-decaying-dataset/88849)

<div class="topic-metadata">

**Author:** [@greivin](https://discourse.julialang.org/u/greivin)\
**Replies:** 0\
**Last updated:** [October 17, 2022, 1:28pm UTC](https://discourse.julialang.org/t/finding-charactersitic-time-in-decaying-dataset/88849 "2022-10-17T13:28:57Z")

</div>

Hello! I have a dataset of N points with the x-axis in a log scale, representing time and the y-axis a correlation. The correlation decays and I want to interpolate, somehow, and find the value of t for which C has deca…

---

## [How to make a function store data to avoid repeating computation](https://discourse.julialang.org/t/how-to-make-a-function-store-data-to-avoid-repeating-computation/88396)

<div class="topic-metadata">

**Author:** [@natema](https://discourse.julialang.org/u/natema)\
**Replies:** 45\
**Last updated:** [October 17, 2022, 12:22pm UTC](https://discourse.julialang.org/t/how-to-make-a-function-store-data-to-avoid-repeating-computation/88396 "2022-10-17T12:22:49Z")

</div>

I have a function in a module that performs some heavy computation to produce a fixed output. It is hard to predict if the function will be called, and we want to avoid computing it if unnecessary. So, we would like th…

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

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