# General Usage

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

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

**Page:** 224

---

## [In Makie, how do I change the background for parts of the axis](https://discourse.julialang.org/t/in-makie-how-do-i-change-the-background-for-parts-of-the-axis/107136)

<div class="topic-metadata">

**Author:** [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)\
**Replies:** 1\
**Last updated:** [December 5, 2023, 1:51am UTC](https://discourse.julialang.org/t/in-makie-how-do-i-change-the-background-for-parts-of-the-axis/107136 "2023-12-05T01:51:37Z")

</div>

I would like to change the background e.g. from x=a to x=b to purple, I can sort of use the band! to achieve the visual, using GLMakie ts = 0:0.01:2π dat = sin.(ts) fig = Figure() ylims = extrema(dat) .+ (-0.1, 0.1) …

---

## [Compiler matmul optimization prevents constant folding?](https://discourse.julialang.org/t/compiler-matmul-optimization-prevents-constant-folding/107121)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 18\
**Last updated:** [December 4, 2023, 5:50pm UTC](https://discourse.julialang.org/t/compiler-matmul-optimization-prevents-constant-folding/107121 "2023-12-04T17:50:29Z")

</div>

I have a use case where I iterate over a container of small vectors. Say vs is a Vector{SVector{2, Float64}}, M is a global constant SMatrix{2,2,Float64,4}, and an illustrative use case is function f(vs) total = zero(el…

---

## [Sizehint！, explanation of the naming?](https://discourse.julialang.org/t/sizehint-explanation-of-the-naming/106978)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 3\
**Last updated:** [December 4, 2023, 4:31pm UTC](https://discourse.julialang.org/t/sizehint-explanation-of-the-naming/106978 "2023-12-04T16:31:43Z")

</div>

I am new to Julia. I am wondering why the function “sizehint!” is named so. Many functions are named in a self-evident way. But I cannot make sense of it for “sizehint!”. Could anyone give a hint?

---

## [Symbolic regression fails this exponential pattern](https://discourse.julialang.org/t/symbolic-regression-fails-this-exponential-pattern/107095)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 2\
**Last updated:** [December 4, 2023, 7:48am UTC](https://discourse.julialang.org/t/symbolic-regression-fails-this-exponential-pattern/107095 "2023-12-04T07:48:58Z")

</div>

MWE: import SymbolicRegression: SRRegressor import MLJ: machine, fit!, predict, report X = (a=\[(10.0-x)^x for x in 1:5\],) Y = \[1.0,2.0,3.0,4.0,5.0\] model = SRRegressor( niterations=50, binary\_operators=\[+, -…

---

## [Should function-like objects be subtypes of Function?](https://discourse.julialang.org/t/should-function-like-objects-be-subtypes-of-function/107081)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 1\
**Last updated:** [December 3, 2023, 7:58pm UTC](https://discourse.julialang.org/t/should-function-like-objects-be-subtypes-of-function/107081 "2023-12-03T19:58:23Z")

</div>

For a function-like object, aka callable/functor, is there any problem with making it a subtype of Function? As in, struct Polynomial{R} \<: Function # XXX coeffs::Vector{R} end (p::Polynomial)(t) = evaluate\_polyn…

---

## [How can I redirect the output from a function that calls \`ProgressMeter\` to an \`Observable\` variable?](https://discourse.julialang.org/t/how-can-i-redirect-the-output-from-a-function-that-calls-progressmeter-to-an-observable-variable/107092)

<div class="topic-metadata">

**Author:** [@zapiano](https://discourse.julialang.org/u/zapiano)\
**Replies:** 1\
**Last updated:** [December 4, 2023, 3:22am UTC](https://discourse.julialang.org/t/how-can-i-redirect-the-output-from-a-function-that-calls-progressmeter-to-an-observable-variable/107092 "2023-12-04T03:22:10Z")

</div>

I have a function that uses ProgressMeter. I need the output from @showprogress that is called inside that function to be redirected to an Observable. Something like the following (except that the following code doesn’t …

---

## [What is 'Val'](https://discourse.julialang.org/t/what-is-val/107088)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 4\
**Last updated:** [December 3, 2023, 11:43pm UTC](https://discourse.julialang.org/t/what-is-val/107088 "2023-12-03T23:43:52Z")

</div>

What does ‘Val’ mean here: function num\_chunks(::Val{B}) where {B} if B ≤ 0 throw(ArgumentError("\`B\` must be positive!")) elseif B ≤ 8 return 1, UInt8 elseif B ≤ 16 return 1, UInt16 …

---

## [How to check out the details of a suspected struct?](https://discourse.julialang.org/t/how-to-check-out-the-details-of-a-suspected-struct/107087)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 1\
**Last updated:** [December 3, 2023, 11:42pm UTC](https://discourse.julialang.org/t/how-to-check-out-the-details-of-a-suspected-struct/107087 "2023-12-03T23:42:51Z")

</div>

I suspect a variable is a struct. How can I get the details of it? Its fields and values.

---

## [How can I test for v"0.4.x"?](https://discourse.julialang.org/t/how-can-i-test-for-v-0-4-x/107084)

<div class="topic-metadata">

**Author:** [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Replies:** 1\
**Last updated:** [December 3, 2023, 9:25pm UTC](https://discourse.julialang.org/t/how-can-i-test-for-v-0-4-x/107084 "2023-12-03T21:25:30Z")

</div>

I would like to test if a VersionNumber is 0.4.x or less. v"0.4.1" \<= v"0.4" returns false Is x \< v"0.5.0-DEV" the best way to do this, (and would it be guaranteed to work)?

---

## [Removing type instability causes the code slower](https://discourse.julialang.org/t/removing-type-instability-causes-the-code-slower/107074)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 8\
**Last updated:** [December 3, 2023, 6:10pm UTC](https://discourse.julialang.org/t/removing-type-instability-causes-the-code-slower/107074 "2023-12-03T18:10:26Z")

</div>

I have to typed code: @code\_warntype get\_magnetic\_symmetry\_from\_database(1242, 434); MethodInstance for Spglib.get\_magnetic\_symmetry\_from\_database(::Int64, ::Int64) from get\_magnetic\_symmetry\_from\_database(uni\_number,…

---

## [Plotting graphs side by side VegaLite](https://discourse.julialang.org/t/plotting-graphs-side-by-side-vegalite/106361)

<div class="topic-metadata">

**Author:** [@rajmac](https://discourse.julialang.org/u/rajmac)\
**Replies:** 5\
**Last updated:** [December 3, 2023, 4:08pm UTC](https://discourse.julialang.org/t/plotting-graphs-side-by-side-vegalite/106361 "2023-12-03T16:08:26Z")

</div>

I have been plotting data from local traffic flows in VagaLite,jl in Pluto. Most of this involves simple line or scatter plots of numerical data stored in dataframes. When I want to show plots side by side I plot data fr…

---

## [Coding challenge, smallest Julia code (and/or fastest)](https://discourse.julialang.org/t/coding-challenge-smallest-julia-code-and-or-fastest/107078)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 0\
**Last updated:** [December 3, 2023, 3:32pm UTC](https://discourse.julialang.org/t/coding-challenge-smallest-julia-code-and-or-fastest/107078 "2023-12-03T15:32:38Z")

</div>

At the Debian Banechmark game, Julia is almost always fastest already, if best optimized (and precompiled) would be allowed, but the rules disallow, at least most often close. But there’s also another way to win, on the…

---

## [Why tuples are immutable?](https://discourse.julialang.org/t/why-tuples-are-immutable/107071)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 3\
**Last updated:** [December 3, 2023, 3:11pm UTC](https://discourse.julialang.org/t/why-tuples-are-immutable/107071 "2023-12-03T15:11:30Z")

</div>

What is the fundamental reason behind? Is it because the elements can be of any datatype, so modification incurs a lot of memory relocation?

---

## [Check out the functions in a module](https://discourse.julialang.org/t/check-out-the-functions-in-a-module/107075)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 2\
**Last updated:** [December 3, 2023, 2:33pm UTC](https://discourse.julialang.org/t/check-out-the-functions-in-a-module/107075 "2023-12-03T14:33:51Z")

</div>

In the console, after using some\_peoples\_package How can I obtain a list of all the functions imported?

---

## [Coding style - upper or lower case for enum elements?](https://discourse.julialang.org/t/coding-style-upper-or-lower-case-for-enum-elements/107077)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 0\
**Last updated:** [December 3, 2023, 2:25pm UTC](https://discourse.julialang.org/t/coding-style-upper-or-lower-case-for-enum-elements/107077 "2023-12-03T14:25:43Z")

</div>

The Julia manual for enum has the example @enum Fruit apple=1 orange=2 kiwi=3 According to some style guides for Julia, global constants should be UPPER\_CASE, so should I write @enum Fruit APPLE=1 ORANGE=2 KIWI=3 ins…

---

## [How to read a textfile directly as \`Matrix{Char}\`](https://discourse.julialang.org/t/how-to-read-a-textfile-directly-as-matrix-char/107070)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 3\
**Last updated:** [December 3, 2023, 9:44am UTC](https://discourse.julialang.org/t/how-to-read-a-textfile-directly-as-matrix-char/107070 "2023-12-03T09:44:20Z")

</div>

it’s that time of the year again, say we have: 467..114.. ...\*...... ..35..633. ......#... 617\*...... .....+.58. ..592..... ......755. ...$.\*.... .664.598.. in a file, and we want: julia\> mapreduce(permutedims∘collect…

---

## [No more 'isprime' function in Julia 1.9.3？](https://discourse.julialang.org/t/no-more-isprime-function-in-julia-1-9-3/107069)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 5\
**Last updated:** [December 3, 2023, 7:21am UTC](https://discourse.julialang.org/t/no-more-isprime-function-in-julia-1-9-3/107069 "2023-12-03T07:21:39Z")

</div>

I typed ?, then isprime, and got the message Couldn’t find isprime But I saw this function in the video Is the function deleted?

---

## [Why does eltype not return upper type bound?](https://discourse.julialang.org/t/why-does-eltype-not-return-upper-type-bound/107054)

<div class="topic-metadata">

**Author:** [@tscode](https://discourse.julialang.org/u/tscode)\
**Replies:** 7\
**Last updated:** [December 3, 2023, 6:22am UTC](https://discourse.julialang.org/t/why-does-eltype-not-return-upper-type-bound/107054 "2023-12-03T06:22:35Z")

</div>

My code just stumbled over eltype(Array{F} where {F \<: Integer}) returning Any instead of Integer. Has this just not been implemented yet (i.e., should I open an issue?), or are there good reasons for this behavior that …

---

## [Column alignment and spacing in BrowseTables.HTMLTable](https://discourse.julialang.org/t/column-alignment-and-spacing-in-browsetables-htmltable/107068)

<div class="topic-metadata">

**Author:** [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Replies:** 0\
**Last updated:** [December 3, 2023, 4:49am UTC](https://discourse.julialang.org/t/column-alignment-and-spacing-in-browsetables-htmltable/107068 "2023-12-03T04:49:57Z")

</div>

There are 2 formatting options I would like to have and I don’t know if they are available. 1.Can HTMLTable take arguments that define alignment? If so, can someone provide a simple example to demonstrate the syntax? …

---

## [How to read large matrices in Julia?](https://discourse.julialang.org/t/how-to-read-large-matrices-in-julia/107062)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 9\
**Last updated:** [December 3, 2023, 3:37am UTC](https://discourse.julialang.org/t/how-to-read-large-matrices-in-julia/107062 "2023-12-03T03:37:51Z")

</div>

I’m trying to read text files defining matrices of the form q = Int\[1 0 0 1; 0 1 1 1; 1 0 1 0; 0 0 1 1\] via julia matrix.jl or julia -L matrix.jl. It breaks down for matrices slightly larger than 1000x1000. For example…

---

## [Perplexing behavior when computing the matmul smoke test on GPU in Julia](https://discourse.julialang.org/t/perplexing-behavior-when-computing-the-matmul-smoke-test-on-gpu-in-julia/106994)

<div class="topic-metadata">

**Author:** [@Aakhash\_Sundaresan](https://discourse.julialang.org/u/Aakhash_Sundaresan)\
**Replies:** 5\
**Last updated:** [December 3, 2023, 3:33am UTC](https://discourse.julialang.org/t/perplexing-behavior-when-computing-the-matmul-smoke-test-on-gpu-in-julia/106994 "2023-12-03T03:33:51Z")

</div>

@avikpal , @ChrisRackauckas Why is that when I compute the matmul smoke test for the first time and time it, it takes long time than the CPU computation, and also the allocations are huge. When I again try to compute …

---

## [Fortran calling convention when passing an array with unknown size](https://discourse.julialang.org/t/fortran-calling-convention-when-passing-an-array-with-unknown-size/107057)

<div class="topic-metadata">

**Author:** [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Replies:** 2\
**Last updated:** [December 2, 2023, 10:26pm UTC](https://discourse.julialang.org/t/fortran-calling-convention-when-passing-an-array-with-unknown-size/107057 "2023-12-02T22:26:59Z")

</div>

In modern Fortran when an array is passed to a subroutine, we don’t really need to specify its size: the size can be read from size(arr). So the follows function my\_length(arr) real(8), intent(in), dimensio…

---

## [Performance difference depending on order of comparison in loop](https://discourse.julialang.org/t/performance-difference-depending-on-order-of-comparison-in-loop/107040)

<div class="topic-metadata">

**Author:** [@wheeheee](https://discourse.julialang.org/u/wheeheee)\
**Replies:** 3\
**Last updated:** [December 2, 2023, 1:05pm UTC](https://discourse.julialang.org/t/performance-difference-depending-on-order-of-comparison-in-loop/107040 "2023-12-02T13:05:14Z")

</div>

Unexpectedly, the following function has very different performance depending on the argument order of two matrices, which should be equivalent function f2(x, y; init=0) total = init for i in eachindex(x, y) …

---

## [Can rand generate random vectors with custom type entries?](https://discourse.julialang.org/t/can-rand-generate-random-vectors-with-custom-type-entries/107028)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 5\
**Last updated:** [December 2, 2023, 4:41am UTC](https://discourse.julialang.org/t/can-rand-generate-random-vectors-with-custom-type-entries/107028 "2023-12-02T04:41:09Z")

</div>

I’m trying to understand how to implement rand for custom types. After looking at the documentation, I’ve come up with the following: using Random struct A{T} x::T end Random.rand(rng::AbstractRNG, ::Type{A{T}}) w…

---

## [How to save the output from Pkg.status() as a string variable?](https://discourse.julialang.org/t/how-to-save-the-output-from-pkg-status-as-a-string-variable/107027)

<div class="topic-metadata">

**Author:** [@yhchang96](https://discourse.julialang.org/u/yhchang96)\
**Replies:** 5\
**Last updated:** [December 2, 2023, 1:41am UTC](https://discourse.julialang.org/t/how-to-save-the-output-from-pkg-status-as-a-string-variable/107027 "2023-12-02T01:41:40Z")

</div>

If I do something like version = Pkg.status(), then version is nothing. How do I save the output from Pkg.status() to a string variable? All I need is just the package name with the version number in a human readable fo…

---

## [Functions as a struct Field](https://discourse.julialang.org/t/functions-as-a-struct-field/107013)

<div class="topic-metadata">

**Author:** [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Replies:** 11\
**Last updated:** [December 2, 2023, 12:09am UTC](https://discourse.julialang.org/t/functions-as-a-struct-field/107013 "2023-12-02T00:09:01Z")

</div>

I am aware of some related discussion (Have a function field in a structure, using another field in the structure and Alternative to function as field in struct), but the discussion there is insufficient for my case. The…

---

## [LinearAlgebra.gemv! vs BLAS.gemv!](https://discourse.julialang.org/t/linearalgebra-gemv-vs-blas-gemv/107017)

<div class="topic-metadata">

**Author:** [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Replies:** 3\
**Last updated:** [December 1, 2023, 10:11pm UTC](https://discourse.julialang.org/t/linearalgebra-gemv-vs-blas-gemv/107017 "2023-12-01T22:11:50Z")

</div>

I am trying to understand what julia uses in a call to mul! in the following example: using LinearAlgebra m,n = 10,5; A = randn(m,n); x = randn(n); Ax = zeros(m); @code\_lowered mul!(Ax, A, x, true, false) @code\_lowered …

---

## [Difference between \`for ... end\` and \`\[... for ...\]\`?](https://discourse.julialang.org/t/difference-between-for-end-and-for/106965)

<div class="topic-metadata">

**Author:** [@nabla](https://discourse.julialang.org/u/nabla)\
**Replies:** 6\
**Last updated:** [December 1, 2023, 9:12pm UTC](https://discourse.julialang.org/t/difference-between-for-end-and-for/106965 "2023-12-01T21:12:28Z")

</div>

I encounter a very strange bug when calling an external library (say a function foo) with the two syntaxes in the title: julia\> data = Any\[\]; for \_=1:10000 push!(data,foo()) end # OK julia\> data = \[foo() for \_=1:10000\] …

---

## [Docstring for existing functions](https://discourse.julialang.org/t/docstring-for-existing-functions/107019)

<div class="topic-metadata">

**Author:** [@MarDiehl](https://discourse.julialang.org/u/MarDiehl)\
**Replies:** 1\
**Last updated:** [December 1, 2023, 9:12pm UTC](https://discourse.julialang.org/t/docstring-for-existing-functions/107019 "2023-12-01T21:12:12Z")

</div>

I have a function that is called view but does not provide a view on an array. Unfortunately, the help on this function starts with the documentation of the build-in view and only adds my docstring later. Since the gene…

---

## [Gradient to jacobian in type stable way with ForwardDiff](https://discourse.julialang.org/t/gradient-to-jacobian-in-type-stable-way-with-forwarddiff/107015)

<div class="topic-metadata">

**Author:** [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Replies:** 0\
**Last updated:** [December 1, 2023, 8:01pm UTC](https://discourse.julialang.org/t/gradient-to-jacobian-in-type-stable-way-with-forwarddiff/107015 "2023-12-01T20:01:19Z")

</div>

I have a function f(x,y) where x and y are both vectors, and I would like to calculate the matrix of mixed partials. The following works but is not type stable using ForwardDiff f(x,y) = sum(x)\*sum(y) x0 = \[1.0, 2.0, 3.…

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

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