# General Usage

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

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

**Page:** 184

---

## [Why would \`\<:\` in Unions for keyword arguments create allocations](https://discourse.julialang.org/t/why-would-in-unions-for-keyword-arguments-create-allocations/112390)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 2\
**Last updated:** [April 2, 2024, 12:56am UTC](https://discourse.julialang.org/t/why-would-in-unions-for-keyword-arguments-create-allocations/112390 "2024-04-02T00:56:50Z")

</div>

Take this MWE function which simply returns the argument at the specified index idx or y in the vector v: function foo(v::Vector{Int}, idx::Union{Nothing,Int}=nothing; y::Union{Nothing,Integer}=nothing) if !xor(isnoth…

---

## [How to use @sprintf with "parametric" format string?](https://discourse.julialang.org/t/how-to-use-sprintf-with-parametric-format-string/70364)

<div class="topic-metadata">

**Author:** [@ryszard314159](https://discourse.julialang.org/u/ryszard314159)\
**Replies:** 5\
**Last updated:** [April 1, 2024, 9:01pm UTC](https://discourse.julialang.org/t/how-to-use-sprintf-with-parametric-format-string/70364 "2024-04-01T21:01:33Z")

</div>

Is there a way to use @sprintf with “parametric” format string? or it has to be hardcoded? This is an example: julia\> @sprintf(“test: %s”, “test”) “test: test” julia\> fmt = “test: %s”; @sprintf(fmt, “test”) ERROR: L…

---

## [Revise and commenting out lines in package](https://discourse.julialang.org/t/revise-and-commenting-out-lines-in-package/112385)

<div class="topic-metadata">

**Author:** [@p\_f](https://discourse.julialang.org/u/p_f)\
**Replies:** 0\
**Last updated:** [April 1, 2024, 6:22pm UTC](https://discourse.julialang.org/t/revise-and-commenting-out-lines-in-package/112385 "2024-04-01T18:22:26Z")

</div>

Say I have a package that looks like this: module test\_pkg include("file1.jl") # include("file2.jl") export f end # module test\_pkg ##file1.jl: f() = print("file 1") ##file2.jl f() = print("file 2") Revis…

---

## [What is the fastest way of making a vector of dictionaries?](https://discourse.julialang.org/t/what-is-the-fastest-way-of-making-a-vector-of-dictionaries/112363)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 11\
**Last updated:** [April 1, 2024, 3:36pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-way-of-making-a-vector-of-dictionaries/112363 "2024-04-01T15:36:47Z")

</div>

I know the type (Dict{Int,Int}) and I know the size of the vector. How do I make the vector quickly? (Just to be explicit, all those dictionaries are independent; I do not want to fill the vector with just a single dic…

---

## [Using vs import](https://discourse.julialang.org/t/using-vs-import/112366)

<div class="topic-metadata">

**Author:** [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Replies:** 2\
**Last updated:** [April 1, 2024, 3:20pm UTC](https://discourse.julialang.org/t/using-vs-import/112366 "2024-04-01T15:20:58Z")

</div>

Why can I load some modules/packages like this using LinearAlgebra but if I make my own module named test.jl (located in subdirectory “modules”), I can’t load it like this: push!(LOAD\_PATH,"./modules") using test Ins…

---

## [What is faster: sparse vector or a dictionary?](https://discourse.julialang.org/t/what-is-faster-sparse-vector-or-a-dictionary/112341)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 14\
**Last updated:** [April 1, 2024, 1:40pm UTC](https://discourse.julialang.org/t/what-is-faster-sparse-vector-or-a-dictionary/112341 "2024-04-01T13:40:00Z")

</div>

Sparse vector uses binary search. Dictionary uses a hash. Anyone has an experience to share?

---

## [Base.nullspace for general matrices](https://discourse.julialang.org/t/base-nullspace-for-general-matrices/112356)

<div class="topic-metadata">

**Author:** [@azoviktor](https://discourse.julialang.org/u/azoviktor)\
**Replies:** 5\
**Last updated:** [April 1, 2024, 1:24pm UTC](https://discourse.julialang.org/t/base-nullspace-for-general-matrices/112356 "2024-04-01T13:24:34Z")

</div>

Let’s say I would like to use the nullspace method from julia Base module for a matrix of type AbstractMatrix{MyNumberType}. What interface should I implement in order to make it work? Does such an interface technically …

---

## [Correct way to create dataset with DataToolkit.jl programmatically](https://discourse.julialang.org/t/correct-way-to-create-dataset-with-datatoolkit-jl-programmatically/112368)

<div class="topic-metadata">

**Author:** [@myrddin89](https://discourse.julialang.org/u/myrddin89)\
**Replies:** 0\
**Last updated:** [April 1, 2024, 5:48am UTC](https://discourse.julialang.org/t/correct-way-to-create-dataset-with-datatoolkit-jl-programmatically/112368 "2024-04-01T05:48:36Z")

</div>

Hi! I have been trying the DataToolkit.jl package for my workflow. I have encountered some issues when creating datasets programmatically. Specifically, I am having trouble adding storage drivers, resulting always in a…

---

## [Unexpected behavior when returning DifferentialEquations solve() solution from external .jl file](https://discourse.julialang.org/t/unexpected-behavior-when-returning-differentialequations-solve-solution-from-external-jl-file/112263)

<div class="topic-metadata">

**Author:** [@thedeyan](https://discourse.julialang.org/u/thedeyan)\
**Replies:** 1\
**Last updated:** [April 1, 2024, 2:01am UTC](https://discourse.julialang.org/t/unexpected-behavior-when-returning-differentialequations-solve-solution-from-external-jl-file/112263 "2024-04-01T02:01:14Z")

</div>

I am new to Julia. I am trying to use the DifferentialEquations.jl to solve, well, some ODEs, via Python. I can, for example, use the following python script to solve the Lorenz attractor: from diffeqpy import de from j…

---

## [Guidelines for wrapping a simple C library in Julia](https://discourse.julialang.org/t/guidelines-for-wrapping-a-simple-c-library-in-julia/112335)

<div class="topic-metadata">

**Author:** [@pjssilva](https://discourse.julialang.org/u/pjssilva)\
**Replies:** 6\
**Last updated:** [March 31, 2024, 11:57pm UTC](https://discourse.julialang.org/t/guidelines-for-wrapping-a-simple-c-library-in-julia/112335 "2024-03-31T23:57:53Z")

</div>

I am scratching my own itch here and decided to write a wrapper to a small C library I wrote to solve the problem of projecting a point onto the intersection of a box and a hyperplane. Is there a good “best practices” d…

---

## [Is there a differentiable implementation of matrix square root?](https://discourse.julialang.org/t/is-there-a-differentiable-implementation-of-matrix-square-root/112334)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 5\
**Last updated:** [March 31, 2024, 10:15pm UTC](https://discourse.julialang.org/t/is-there-a-differentiable-implementation-of-matrix-square-root/112334 "2024-03-31T22:15:47Z")

</div>

Hello! I’m trying to make the following code work: using ForwardDiff, LinearAlgebra # Fidelity between two density matrices function fidelity(ρ::AbstractMatrix, σ::AbstractMatrix) sqrt\_ρ = sqrt(ρ) abs2(tr(sqrt…

---

## [What the differences of the 6 solutions please](https://discourse.julialang.org/t/what-the-differences-of-the-6-solutions-please/112300)

<div class="topic-metadata">

**Author:** [@ajsagit](https://discourse.julialang.org/u/ajsagit)\
**Replies:** 6\
**Last updated:** [March 31, 2024, 5:51pm UTC](https://discourse.julialang.org/t/what-the-differences-of-the-6-solutions-please/112300 "2024-03-31T17:51:41Z")

</div>

using BenchmarkTools datasize = 10000000 data = randn(Float32, datasize) #recip\_vector = similar(data, Float32) recip\_vector = similar(data) # 1）0.007099 seconds (1 allocation: 32 bytes) @timev recip\_vector .= 1 ./ dat…

---

## [Possible to speed up this function for calculating cartesian indices?](https://discourse.julialang.org/t/possible-to-speed-up-this-function-for-calculating-cartesian-indices/112333)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 19\
**Last updated:** [March 31, 2024, 5:08pm UTC](https://discourse.julialang.org/t/possible-to-speed-up-this-function-for-calculating-cartesian-indices/112333 "2024-03-31T17:08:23Z")

</div>

Hello! I have a small function which I call a lot: function BatchExtractCells!(Cells, Points, CutOff) @batch per=thread for i ∈ eachindex(Cells) ci = CartesianIndex(@. Int(fld(Points\[i\], CutOff))...) …

---

## [Efficient bit rotate functions: ror, rol...what is the official way for Julia v1?](https://discourse.julialang.org/t/efficient-bit-rotate-functions-ror-rol-what-is-the-official-way-for-julia-v1/19062)

<div class="topic-metadata">

**Author:** [@rapasite](https://discourse.julialang.org/u/rapasite)\
**Replies:** 5\
**Last updated:** [March 31, 2024, 1:30pm UTC](https://discourse.julialang.org/t/efficient-bit-rotate-functions-ror-rol-what-is-the-official-way-for-julia-v1/19062 "2024-03-31T13:30:39Z")

</div>

Hi, I found this https://github.com/JuliaLang/julia/issues/11592 but I can not understand what should I do for a UInt64 or any other arbitrary 0b.... Am I missing something in the doc? Thanks you

---

## [Weird floating point under/overflow behavior](https://discourse.julialang.org/t/weird-floating-point-under-overflow-behavior/112340)

<div class="topic-metadata">

**Author:** [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Replies:** 3\
**Last updated:** [March 31, 2024, 3:00am UTC](https://discourse.julialang.org/t/weird-floating-point-under-overflow-behavior/112340 "2024-03-31T03:00:28Z")

</div>

Expect to underflow to 0 and overflow to biggest value, but results below seem opposite? I train ML and had nan from dividing by big # in gradients julia\> 1f0/2^64 Inf32 julia\> 1f0/(2^64) Inf32 julia\> 1f0\*(2^64) 0.0f0…

---

## [Using a type parameter vs abstract type in function signature](https://discourse.julialang.org/t/using-a-type-parameter-vs-abstract-type-in-function-signature/112339)

<div class="topic-metadata">

**Author:** [@mdsalerno](https://discourse.julialang.org/u/mdsalerno)\
**Replies:** 2\
**Last updated:** [March 31, 2024, 12:18am UTC](https://discourse.julialang.org/t/using-a-type-parameter-vs-abstract-type-in-function-signature/112339 "2024-03-31T00:18:52Z")

</div>

I’ve written the following function: function all\_your\_base(digits::Vector{Integer}, base\_in, base\_out) sum(digits) ≠ 0 || return(\[0\]) n = digits .\* base\_in .^ (length(digits)-1:-1:0) |\> sum res = \[\] fo…

---

## [Slow and Memory intensive For Loop](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304)

<div class="topic-metadata">

**Author:** [@soumen261](https://discourse.julialang.org/u/soumen261)\
**Replies:** 6\
**Last updated:** [March 30, 2024, 10:44pm UTC](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304 "2024-03-30T22:44:51Z")

</div>

Hi Julians, I am still a novice in Julia. I am writing a code to import/read a total 16 data (.txt) files each having 504\*1025 matrix. Essentially trying to make a 3D data cube from the 2D datasets using a For loop. But…

---

## [How to leave only unique rows of array](https://discourse.julialang.org/t/how-to-leave-only-unique-rows-of-array/112332)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 5\
**Last updated:** [March 30, 2024, 8:26pm UTC](https://discourse.julialang.org/t/how-to-leave-only-unique-rows-of-array/112332 "2024-03-30T20:26:26Z")

</div>

These are two columns of a string matrix. How to leave only unique rows of these 12 array rows? : Kalinka surname Kalinka surname Kalinka surname Kalinka geographical\_name Kalinka geographical\_name Kalinka geographical\_…

---

## [ApproxFun.jl multiplying fourier series and cosine/sine series issue](https://discourse.julialang.org/t/approxfun-jl-multiplying-fourier-series-and-cosine-sine-series-issue/110937)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 4\
**Last updated:** [March 30, 2024, 7:48pm UTC](https://discourse.julialang.org/t/approxfun-jl-multiplying-fourier-series-and-cosine-sine-series-issue/110937 "2024-03-30T19:48:12Z")

</div>

Hi @dlfivefifty I am using ApproxFun.jl along with Num type from SYmbolics to work with sin/cosine/Fourier series as follows: julia\> myg =Fun(CosSpace(), rand(10)); myf = Fun(SinSpace(), rand(10)); using Symbolics a…

---

## [How to delete dataset in hdf5 file ? GPT dont know!](https://discourse.julialang.org/t/how-to-delete-dataset-in-hdf5-file-gpt-dont-know/112322)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 1\
**Last updated:** [March 30, 2024, 5:10pm UTC](https://discourse.julialang.org/t/how-to-delete-dataset-in-hdf5-file-gpt-dont-know/112322 "2024-03-30T17:10:29Z")

</div>

How to delete dataset “y” from group “male” ? julia\> fid\["male"\] ?? HDF5.Group: /male (file: miasta.h5) ├─ ?? x └─ ?? y Paul

---

## [How to improve the performance of a function generating a Jacobian with "Toeplitz" structure](https://discourse.julialang.org/t/how-to-improve-the-performance-of-a-function-generating-a-jacobian-with-toeplitz-structure/112286)

<div class="topic-metadata">

**Author:** [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)\
**Replies:** 5\
**Last updated:** [March 30, 2024, 2:41pm UTC](https://discourse.julialang.org/t/how-to-improve-the-performance-of-a-function-generating-a-jacobian-with-toeplitz-structure/112286 "2024-03-30T14:41:37Z")

</div>

I have a single variable function g(x) where x(t) is a periodic function. I am interested in obtaining the jacobian of the Fourier harmonics of g when differentiated with respect to the harmonics of x(t). It is well kno…

---

## [How to pass an arbitrary number of macro arguments from one macro to another? (a bit like splatting)](https://discourse.julialang.org/t/how-to-pass-an-arbitrary-number-of-macro-arguments-from-one-macro-to-another-a-bit-like-splatting/112288)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 7\
**Last updated:** [March 29, 2024, 11:27pm UTC](https://discourse.julialang.org/t/how-to-pass-an-arbitrary-number-of-macro-arguments-from-one-macro-to-another-a-bit-like-splatting/112288 "2024-03-29T23:27:05Z")

</div>

I have a macro which does stuff depending on how many inputs there are macro my\_macro(arg1) println("We got one argument.") sum = 1 if arg1 isa Int64 sum = sum + arg1 end sum end macro my\_mac…

---

## [Type stability and heterogeneous collections](https://discourse.julialang.org/t/type-stability-and-heterogeneous-collections/112293)

<div class="topic-metadata">

**Author:** [@andreapasquale94](https://discourse.julialang.org/u/andreapasquale94)\
**Replies:** 5\
**Last updated:** [March 29, 2024, 5:36pm UTC](https://discourse.julialang.org/t/type-stability-and-heterogeneous-collections/112293 "2024-03-29T17:36:09Z")

</div>

I am working on a library where I cannot avoid heterogeneous collections, and I want type-stable code. I’m trying to improve my understanding of how the compiler behaves in those cases (and in general). There are alrea…

---

## [Libgobject-2.0.so.0: undefined symbol: g\_dir\_unref](https://discourse.julialang.org/t/libgobject-2-0-so-0-undefined-symbol-g-dir-unref/112301)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [March 29, 2024, 4:58pm UTC](https://discourse.julialang.org/t/libgobject-2-0-so-0-undefined-symbol-g-dir-unref/112301 "2024-03-29T16:58:01Z")

</div>

I currently get the following error when I try to create a system image: ERROR: LoadError: InitError: could not load library “/home/ufechner/.julia/artifacts/648a32a349aac06f19b6bfed47f0b822b4ef28c3/lib/libgio-2.0.so” …

---

## [How to embed Julia in interactive mode](https://discourse.julialang.org/t/how-to-embed-julia-in-interactive-mode/112264)

<div class="topic-metadata">

**Author:** [@droodman](https://discourse.julialang.org/u/droodman)\
**Replies:** 4\
**Last updated:** [March 29, 2024, 1:50pm UTC](https://discourse.julialang.org/t/how-to-embed-julia-in-interactive-mode/112264 "2024-03-29T13:50:42Z")

</div>

Another in my continuing series of questions about how to embed Julia… @mkitti and @GunnarFarneback have been very helpful in the past. I am embedding Julia in another program and am trying to approximately simulate th…

---

## [Memory usage blow up on julia 1.9](https://discourse.julialang.org/t/memory-usage-blow-up-on-julia-1-9/103869)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 5\
**Last updated:** [March 29, 2024, 10:32am UTC](https://discourse.julialang.org/t/memory-usage-blow-up-on-julia-1-9/103869 "2024-03-29T10:32:10Z")

</div>

Our in-house application has been seeing huge memory usage spikes since our upgrade to 1.9 (5x what was used before). Has anyone else experienced that? The new feature is a likely culprit, but we’re still early in our in…

---

## [Packages with \`\_\_init()\_\_\` screws up PackageCompiler.jl?](https://discourse.julialang.org/t/packages-with-init-screws-up-packagecompiler-jl/112243)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 2\
**Last updated:** [March 29, 2024, 9:50am UTC](https://discourse.julialang.org/t/packages-with-init-screws-up-packagecompiler-jl/112243 "2024-03-29T09:50:46Z")

</div>

Cross-posted on PackageCompiler.jl. I’m building binaries with PackageCompiler.create\_app(), but I get an alarming warning message whenever a dependency has an \_\_init()\_\_ function that includes a @require block, exempli…

---

## [Testing a string macro](https://discourse.julialang.org/t/testing-a-string-macro/112244)

<div class="topic-metadata">

**Author:** [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Replies:** 10\
**Last updated:** [March 29, 2024, 9:12am UTC](https://discourse.julialang.org/t/testing-a-string-macro/112244 "2024-03-29T09:12:30Z")

</div>

The code using Test xx = Dict{String,String}() macro x\_str(str,suf) return str \* xx\[suf\] end @testset "a" begin xx\["a"\] = "apple" @test x"tasty "a == "tasty apple" end Throws an error: ERROR: LoadError:…

---

## [The improvement of memory management in multithreading Julia 1.10beta is amazing!](https://discourse.julialang.org/t/the-improvement-of-memory-management-in-multithreading-julia-1-10beta-is-amazing/102468)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 6\
**Last updated:** [March 29, 2024, 2:30am UTC](https://discourse.julialang.org/t/the-improvement-of-memory-management-in-multithreading-julia-1-10beta-is-amazing/102468 "2024-03-29T02:30:54Z")

</div>

I am so happy and can not help to share here. I have a multithreading script that reads tons of CSV files, processes them, and saves each back to disk. before 1.10, I see a continuous growing of memory usage like insanel…

---

## [Sparse matrix error with forward diff](https://discourse.julialang.org/t/sparse-matrix-error-with-forward-diff/108170)

<div class="topic-metadata">

**Author:** [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Replies:** 16\
**Last updated:** [March 29, 2024, 1:53am UTC](https://discourse.julialang.org/t/sparse-matrix-error-with-forward-diff/108170 "2024-03-29T01:53:38Z")

</div>

Hi all. I have the following MWE. I get a stackoverflow error when using a sparse matrix in a function that I am using ForwardDiff to find the gradient of. When using a dense matrix (i.e. change W1s to W1d in the anonymo…

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

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