# General Usage

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

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

**Page:** 63

---

## [How to make the most of SIMD.jl when number of data elements is not divisible by SIMD width](https://discourse.julialang.org/t/how-to-make-the-most-of-simd-jl-when-number-of-data-elements-is-not-divisible-by-simd-width/129226)

<div class="topic-metadata">

**Author:** [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Replies:** 5\
**Last updated:** [May 22, 2025, 10:51am UTC](https://discourse.julialang.org/t/how-to-make-the-most-of-simd-jl-when-number-of-data-elements-is-not-divisible-by-simd-width/129226 "2025-05-22T10:51:36Z")

</div>

Consider the following MWE that simply stores in c an elementwise vector multiplication (so c=a.\*b). Here I want to take SIMD chunks and do the operation in SIMD vectors. But the “naive solution” that I get is around 2x…

---

## [Permuting the rows of a matrix based on given a given permutation](https://discourse.julialang.org/t/permuting-the-rows-of-a-matrix-based-on-given-a-given-permutation/41444)

<div class="topic-metadata">

**Author:** [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Replies:** 12\
**Last updated:** [November 20, 2022, 11:11pm UTC](https://discourse.julialang.org/t/permuting-the-rows-of-a-matrix-based-on-given-a-given-permutation/41444 "2022-11-20T23:11:01Z")

</div>

Suppose I am given an mXn matrix A, and I have a permutation of {1,…,m}, for example by p = sortperm(A\[:,1\]); I now wish to rearrange the wors of A based on p. How do I do that ? The permute!() function only applies to…

---

## [ERROR: OutOfMemoryError()](https://discourse.julialang.org/t/error-outofmemoryerror/129229)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 10\
**Last updated:** [May 21, 2025, 9:44pm UTC](https://discourse.julialang.org/t/error-outofmemoryerror/129229 "2025-05-21T21:44:37Z")

</div>

I got ERROR: OutOfMemoryError() while running this code. How can i mitigate it? Here 872 is number of mesh blocks of whose coordinates are x, y and z. x = rand(16,872); y = rand(4,872); z = rand(18,872); r = reshape(x,…

---

## ["I don't like NumPy" - Julia equivalents to the numpy code?](https://discourse.julialang.org/t/i-dont-like-numpy-julia-equivalents-to-the-numpy-code/129052)

<div class="topic-metadata">

**Author:** [@MDSW](https://discourse.julialang.org/u/MDSW)\
**Replies:** 19\
**Last updated:** [May 21, 2025, 7:46pm UTC](https://discourse.julialang.org/t/i-dont-like-numpy-julia-equivalents-to-the-numpy-code/129052 "2025-05-21T19:46:36Z")

</div>

I came across this post and, not being an expert in either NumPy or the how it would be done in Julia, was curious if anyone here could weigh in with idiomatic Julia versions of some of these examples for comparison. No…

---

## [Struct with read-only and write-only properties](https://discourse.julialang.org/t/struct-with-read-only-and-write-only-properties/129179)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 7\
**Last updated:** [May 21, 2025, 7:15pm UTC](https://discourse.julialang.org/t/struct-with-read-only-and-write-only-properties/129179 "2025-05-21T19:15:16Z")

</div>

Suppose I have the following mutable struct @kwdef mutable struct Rectangle{T} x::T = 0 y::T = 0 function Rectangle(args...) return new{promote\_type(typeof.(args)...)}(args...) end end I would like for this…

---

## [Draw a random number through a probability distribution defined as an array](https://discourse.julialang.org/t/draw-a-random-number-through-a-probability-distribution-defined-as-an-array/129210)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 5\
**Last updated:** [May 21, 2025, 10:40am UTC](https://discourse.julialang.org/t/draw-a-random-number-through-a-probability-distribution-defined-as-an-array/129210 "2025-05-21T10:40:30Z")

</div>

If I have an NxM matrix with decimal values (normalised so that the sum is 1): prob\_dens::Matrix{Float64.Float64} is there a good way to randomly draw an index i,j with probability corresponding to the probability dist…

---

## [Launching REPL with older version in VSCode](https://discourse.julialang.org/t/launching-repl-with-older-version-in-vscode/129218)

<div class="topic-metadata">

**Author:** [@Bill\_Holmes](https://discourse.julialang.org/u/Bill_Holmes)\
**Replies:** 4\
**Last updated:** [May 21, 2025, 3:36pm UTC](https://discourse.julialang.org/t/launching-repl-with-older-version-in-vscode/129218 "2025-05-21T15:36:37Z")

</div>

Hello all. I have an older julia project that I need to work on. My current latest julia version is v1.11 but my project environment is built around v1.9. I want to launch a julia REPL within VSCode (e.g. Julia: Start RE…

---

## [CSV fails to precompile](https://discourse.julialang.org/t/csv-fails-to-precompile/129192)

<div class="topic-metadata">

**Author:** [@jcc3508](https://discourse.julialang.org/u/jcc3508)\
**Replies:** 3\
**Last updated:** [May 21, 2025, 3:15pm UTC](https://discourse.julialang.org/t/csv-fails-to-precompile/129192 "2025-05-21T15:15:48Z")

</div>

Packages currently installed: ⌃ \[336ed68f\] CSV v0.10.11 ⌃ \[a93c6f00\] DataFrames v1.6.1 ⌃ \[4c0ca9eb\] Gtk v1.3.0 \[9a3f8284\] Random Please submit a bug report with steps to reproduce this fault, and any error messages …

---

## [Is it possible to force a task to have a particular thread id?](https://discourse.julialang.org/t/is-it-possible-to-force-a-task-to-have-a-particular-thread-id/129172)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 4\
**Last updated:** [May 21, 2025, 3:08pm UTC](https://discourse.julialang.org/t/is-it-possible-to-force-a-task-to-have-a-particular-thread-id/129172 "2025-05-21T15:08:37Z")

</div>

I’m trying to make a GUI in QML.jl that does a lot of things asynchronously. In order to improve performance I would like to run Julia with multiple threads since everything is organized into tasks anyway. But QML.jl do…

---

## [Kwargs... and allocations](https://discourse.julialang.org/t/kwargs-and-allocations/129183)

<div class="topic-metadata">

**Author:** [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Replies:** 26\
**Last updated:** [May 21, 2025, 3:05pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183 "2025-05-21T15:05:49Z")

</div>

I recently was trying to overload some real-time code (meaning I don’t want any GC or allocations). I needed to add in some kwargs to the help with overloading some intermediate functions. This causes allocations becau…

---

## [A generic function (using higher order functions) with special implementation for specific functions (as input)?](https://discourse.julialang.org/t/a-generic-function-using-higher-order-functions-with-special-implementation-for-specific-functions-as-input/129213)

<div class="topic-metadata">

**Author:** [@Daniel\_Lincke](https://discourse.julialang.org/u/Daniel_Lincke)\
**Replies:** 6\
**Last updated:** [May 21, 2025, 1:14pm UTC](https://discourse.julialang.org/t/a-generic-function-using-higher-order-functions-with-special-implementation-for-specific-functions-as-input/129213 "2025-05-21T13:14:56Z")

</div>

Hi, I have the following situation: A complicated algorithm that works with a function as input parameter: function cool\_stuff(f :: Function, a::Real, b::Real) ... end cool\_stuff could be something like integrati…

---

## [Problem with VSCode connecting to language server](https://discourse.julialang.org/t/problem-with-vscode-connecting-to-language-server/129024)

<div class="topic-metadata">

**Author:** [@TimG](https://discourse.julialang.org/u/TimG)\
**Replies:** 5\
**Last updated:** [May 21, 2025, 1:10pm UTC](https://discourse.julialang.org/t/problem-with-vscode-connecting-to-language-server/129024 "2025-05-21T13:10:55Z")

</div>

This morning, I’m having a problem with VS Code. It seems unable to connect to the language server. It was fine yesterday. This is a work computer (but working from home). I do not see the same problem on my home compute…

---

## [Cannot convert Time to Time](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207)

<div class="topic-metadata">

**Author:** [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Replies:** 3\
**Last updated:** [May 21, 2025, 10:23am UTC](https://discourse.julialang.org/t/cannot-convert-time-to-time/129207 "2025-05-21T10:23:26Z")

</div>

Any idea what\`s happening? julia\> s = "18:59:00" "18:59:00" julia\> t0 = Time(s) 18:59:00 julia\> t = Time(t0) ERROR: MethodError: no method matching Int64(::Time) The type \`Int64\` exists, but no method is defined for t…

---

## [Unexpected closure behavior](https://discourse.julialang.org/t/unexpected-closure-behavior/129194)

<div class="topic-metadata">

**Author:** [@karei](https://discourse.julialang.org/u/karei)\
**Replies:** 4\
**Last updated:** [May 21, 2025, 7:18am UTC](https://discourse.julialang.org/t/unexpected-closure-behavior/129194 "2025-05-21T07:18:49Z")

</div>

using Logging, Cthulhu const glogger = Ref(ConsoleLogger()) function foo(a::Real, b::Real, c::Real, d::Real) x₁ = b + c + d e = b + c + d if e \>= 0 x₂ = b + c + d x₃ = b + c + d with\_l…

---

## [How to prevent arxiv from hyperlinking Julia package names in abstract metadata?](https://discourse.julialang.org/t/how-to-prevent-arxiv-from-hyperlinking-julia-package-names-in-abstract-metadata/129053)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 16\
**Last updated:** [May 20, 2025, 2:17pm UTC](https://discourse.julialang.org/t/how-to-prevent-arxiv-from-hyperlinking-julia-package-names-in-abstract-metadata/129053 "2025-05-20T14:17:19Z")

</div>

When a Julia package is named in an arxiv abstract, it .jl is interpreted as a web domain, and it attempts to create a hyperlink, which results in the package name not being displayed. See, for example: \[2504.21440\] Qua…

---

## [Clarifying the behavior of \`PLOTS\_DEFAULTS\` in Plots.jl](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110)

<div class="topic-metadata">

**Author:** [@shg](https://discourse.julialang.org/u/shg)\
**Replies:** 4\
**Last updated:** [May 21, 2025, 3:06am UTC](https://discourse.julialang.org/t/clarifying-the-behavior-of-plots-defaults-in-plots-jl/129110 "2025-05-21T03:06:39Z")

</div>

I’d like to set some default parameters for plotting using Plots.jl by defining the PLOTS\_DEFAULTS variable in my “startup.jl” . I have questions regarding its behavior: It appears that setting PLOTS\_DEFAULTS successf…

---

## [Findfirst and eachline](https://discourse.julialang.org/t/findfirst-and-eachline/129165)

<div class="topic-metadata">

**Author:** [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Replies:** 14\
**Last updated:** [May 20, 2025, 7:55pm UTC](https://discourse.julialang.org/t/findfirst-and-eachline/129165 "2025-05-20T19:55:42Z")

</div>

The following one liner identifies the text file row number where the word “Stack” first appears: findfirst(r -\> contains(r, "Stack"), readlines(file)) However, the following does not, perhaps surprisingly: findfirst(…

---

## [Running batch jobs on cluster](https://discourse.julialang.org/t/running-batch-jobs-on-cluster/129117)

<div class="topic-metadata">

**Author:** [@bulbul](https://discourse.julialang.org/u/bulbul)\
**Replies:** 3\
**Last updated:** [May 20, 2025, 2:04pm UTC](https://discourse.julialang.org/t/running-batch-jobs-on-cluster/129117 "2025-05-20T14:04:16Z")

</div>

I am trying to run a number of instances of a program on a cluster. The job submit script is as follows #!/bin/bash #SBATCH --job-name=open\_array #SBATCH --array=1-96 #SBATCH --nodes=1 #SBATCH --ntasks-per-node=1 #SBATC…

---

## [Creating a module that chooses different files](https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152)

<div class="topic-metadata">

**Author:** [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Replies:** 2\
**Last updated:** [May 20, 2025, 12:14pm UTC](https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152 "2025-05-20T12:14:39Z")

</div>

Hi all. I have written a module to process some data. Depending on the computer where it is running I would like to use different files for the plotting. If we are using a normal computer with a screen I would like to u…

---

## [Does revise work with extensions?](https://discourse.julialang.org/t/does-revise-work-with-extensions/129168)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 0\
**Last updated:** [May 20, 2025, 9:36am UTC](https://discourse.julialang.org/t/does-revise-work-with-extensions/129168 "2025-05-20T09:36:25Z")

</div>

Using it right now, but does not seem to work (which makes everything a pain). is this a known thing? I am working on modifying some plot recepies, you might also be because those are involved that it does not work.

---

## [Can't figure out/resolve what is timing out during WGLMakie button press](https://discourse.julialang.org/t/cant-figure-out-resolve-what-is-timing-out-during-wglmakie-button-press/129055)

<div class="topic-metadata">

**Author:** [@ethansigh](https://discourse.julialang.org/u/ethansigh)\
**Replies:** 1\
**Last updated:** [May 20, 2025, 6:53am UTC](https://discourse.julialang.org/t/cant-figure-out-resolve-what-is-timing-out-during-wglmakie-button-press/129055 "2025-05-20T06:53:31Z")

</div>

I have some code where I pull some data from a mysql database, do some minimal processing on it, and plot it in two different figures. I would include a “minimum code to recreate the issue” but the problem is that I cann…

---

## [Unmutated mutable type being corrupted?](https://discourse.julialang.org/t/unmutated-mutable-type-being-corrupted/129161)

<div class="topic-metadata">

**Author:** [@halleysfifthinc](https://discourse.julialang.org/u/halleysfifthinc)\
**Replies:** 4\
**Last updated:** [May 20, 2025, 5:41am UTC](https://discourse.julialang.org/t/unmutated-mutable-type-being-corrupted/129161 "2025-05-20T05:41:27Z")

</div>

MWE of what I think might be an issue in Julia itself: mutable struct Complete head::Union{Nothing,Int} end const null = Complete(nothing) function anydefined\_const(inds, maybes) for i in eachindex(inds) if !…

---

## [Constructing SVector with a loop](https://discourse.julialang.org/t/constructing-svector-with-a-loop/15372)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 17\
**Last updated:** [May 20, 2025, 1:21am UTC](https://discourse.julialang.org/t/constructing-svector-with-a-loop/15372 "2025-05-20T01:21:23Z")

</div>

Suppose I want to construct an SVector with known length S and type T, but a loop (with a known number of iterations) would be the most comfortable way of doing it. What is the standard idiom for this in 1.0? My problem…

---

## [Something weird is going on with \`DenseArray\`](https://discourse.julialang.org/t/something-weird-is-going-on-with-densearray/129156)

<div class="topic-metadata">

**Author:** [@akriegman](https://discourse.julialang.org/u/akriegman)\
**Replies:** 3\
**Last updated:** [May 19, 2025, 11:24pm UTC](https://discourse.julialang.org/t/something-weird-is-going-on-with-densearray/129156 "2025-05-19T23:24:22Z")

</div>

From base/boot.jl: # commented-out definitions are implemented in C ... #abstract type AbstractArray{T,N} end #abstract type DenseArray{T,N} \<: AbstractArray{T,N} end ... #mutable struct Array{T,N} \<: DenseArray{T,N…

---

## [How can I stop Symbolics.jl from splitting complex numbers into real and imaginary parts](https://discourse.julialang.org/t/how-can-i-stop-symbolics-jl-from-splitting-complex-numbers-into-real-and-imaginary-parts/129154)

<div class="topic-metadata">

**Author:** [@jaimece](https://discourse.julialang.org/u/jaimece)\
**Replies:** 1\
**Last updated:** [May 19, 2025, 8:25pm UTC](https://discourse.julialang.org/t/how-can-i-stop-symbolics-jl-from-splitting-complex-numbers-into-real-and-imaginary-parts/129154 "2025-05-19T20:25:49Z")

</div>

For some computations it is useful to keep “conj(z)” as it is. For instance: julia\> using Symbolics julia\> @variables z::Complex julia\> z\*conj(z) real(z)^2 + imag(z)^2 Is there a simple way to obtain “z\*conj(z)”? Tha…

---

## [Why 1-0.4 = 0.6 vs 1 - 1.4 = -0.399999999999](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 4\
**Last updated:** [May 19, 2025, 4:22pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148 "2025-05-19T16:22:56Z")

</div>

why 1-0.4 = 0.6 vs 1 - 1.4 = -0.399999999999 and 0.1 - 0.5 = -0.4 vs 0.2 - 0.6 = -0.3999999 How to make the calculation consistent? What the best way to deal with that to be able to compare (0.2 - 0.6) == (0.1 - 0.5)…

---

## [Separate Sparse Matrix Blocks into Matrices](https://discourse.julialang.org/t/separate-sparse-matrix-blocks-into-matrices/129147)

<div class="topic-metadata">

**Author:** [@wes648](https://discourse.julialang.org/u/wes648)\
**Replies:** 4\
**Last updated:** [May 19, 2025, 3:04pm UTC](https://discourse.julialang.org/t/separate-sparse-matrix-blocks-into-matrices/129147 "2025-05-19T15:04:13Z")

</div>

Is there an efficient way to convert a block diagonalizable sparse matrix into the separate dense/near dense sub-blocks? As a small example, I have the following matrix: julia\> mat 5×5 SparseMatrixCSC{Float64, Int64} w…

---

## [Clarification regarding \`Ref\` documentation](https://discourse.julialang.org/t/clarification-regarding-ref-documentation/129085)

<div class="topic-metadata">

**Author:** [@arbitrandomuser](https://discourse.julialang.org/u/arbitrandomuser)\
**Replies:** 8\
**Last updated:** [May 19, 2025, 2:21pm UTC](https://discourse.julialang.org/t/clarification-regarding-ref-documentation/129085 "2025-05-19T14:21:39Z")

</div>

The documentation for Ref says When passed as a ccall argument (either as a Ptr or Ref type), a Ref object will be converted to a native pointer to the data it references. For most T, or when converted to a Ptr{Cvoi…

---

## [Trouble precompiling with Enzyme](https://discourse.julialang.org/t/trouble-precompiling-with-enzyme/129143)

<div class="topic-metadata">

**Author:** [@jtravs](https://discourse.julialang.org/u/jtravs)\
**Replies:** 1\
**Last updated:** [May 19, 2025, 2:11pm UTC](https://discourse.julialang.org/t/trouble-precompiling-with-enzyme/129143 "2025-05-19T14:11:05Z")

</div>

Hi All, I am struggling to get precompilation working with Enzyme.jl. My package works fine without any precompile statements at the top level. But if I add some package function calls within my top-level module, I get …

---

## [Pkg servers frequently down in South America](https://discourse.julialang.org/t/pkg-servers-frequently-down-in-south-america/129145)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 3\
**Last updated:** [May 19, 2025, 1:43pm UTC](https://discourse.julialang.org/t/pkg-servers-frequently-down-in-south-america/129145 "2025-05-19T13:43:08Z")

</div>

The Pkg servers are frequently down in South America: What is causing this instability? How to avoid it? I am teaching a course in Brazil and am worried that participants will not be able to download the latest versi…

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

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