# General Usage

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

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

**Page:** 251

---

## [When does concrete type inference not matter for performance?](https://discourse.julialang.org/t/when-does-concrete-type-inference-not-matter-for-performance/103603)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 6\
**Last updated:** [September 8, 2023, 12:05am UTC](https://discourse.julialang.org/t/when-does-concrete-type-inference-not-matter-for-performance/103603 "2023-09-08T00:05:44Z")

</div>

The docstring for code\_warntype states that Not all non-leaf types are particularly problematic for performance, and the performance characteristics of a particular type is an implementation detail of the compiler. cod…

---

## [Data First Pipeline](https://discourse.julialang.org/t/data-first-pipeline/103582)

<div class="topic-metadata">

**Author:** [@ShalokShalom](https://discourse.julialang.org/u/ShalokShalom)\
**Replies:** 5\
**Last updated:** [September 7, 2023, 9:10pm UTC](https://discourse.julialang.org/t/data-first-pipeline/103582 "2023-09-07T21:10:22Z")

</div>

As someone, who comes mainly from functional statically typed languages, I stumbled over this article, pointing out some potentially unique approach, and wondered how it would work in Julia. I have not had many experien…

---

## [Slow makie animations?](https://discourse.julialang.org/t/slow-makie-animations/103626)

<div class="topic-metadata">

**Author:** [@rkube](https://discourse.julialang.org/u/rkube)\
**Replies:** 9\
**Last updated:** [September 7, 2023, 7:27pm UTC](https://discourse.julialang.org/t/slow-makie-animations/103626 "2023-09-07T19:27:00Z")

</div>

Hi, I’m trying to animate some makie plots and performance seems to be a bit lacking. Animating this plot takes about 47 seconds on my machine 47.157643 seconds (30.39 M allocations: 3.480 GiB, 1.38% gc time, 3.92% co…

---

## [Alternative permutation/reducing for loops](https://discourse.julialang.org/t/alternative-permutation-reducing-for-loops/103554)

<div class="topic-metadata">

**Author:** [@Leticia-maria](https://discourse.julialang.org/u/Leticia-maria)\
**Replies:** 7\
**Last updated:** [September 7, 2023, 3:50pm UTC](https://discourse.julialang.org/t/alternative-permutation-reducing-for-loops/103554 "2023-09-07T15:50:07Z")

</div>

Hello, I am writing this function where I need to combine all terms in this structure (called Basis): struct GaussianBasisSet \<: AbstractBasisSet R α::Matrix{Float64} d::Matrix{Float64} ℓ::Int m::Int…

---

## [Getting Reproducible Results in Distributed Computing with Randomness](https://discourse.julialang.org/t/getting-reproducible-results-in-distributed-computing-with-randomness/103589)

<div class="topic-metadata">

**Author:** [@naonagas](https://discourse.julialang.org/u/naonagas)\
**Replies:** 2\
**Last updated:** [September 7, 2023, 3:43pm UTC](https://discourse.julialang.org/t/getting-reproducible-results-in-distributed-computing-with-randomness/103589 "2023-09-07T15:43:44Z")

</div>

I’m stuck on how to set different random seeds for each worker in distributed computation. using Distributed, SharedArrays # Start Julia with multiple workers addprocs() @everywhere using Random # Function to set a u…

---

## [(on hold): If you have a function called \`main\`, you may need to tweak it](https://discourse.julialang.org/t/on-hold-if-you-have-a-function-called-main-you-may-need-to-tweak-it/103519)

<div class="topic-metadata">

**Author:** [@Keno](https://discourse.julialang.org/u/Keno)\
**Replies:** 42\
**Last updated:** [September 7, 2023, 3:41pm UTC](https://discourse.julialang.org/t/on-hold-if-you-have-a-function-called-main-you-may-need-to-tweak-it/103519 "2023-09-07T15:41:07Z")

</div>

EDIT: The change is on hold for the time being.

---

## [Macro design recommendations for \`do-end\` like semantics](https://discourse.julialang.org/t/macro-design-recommendations-for-do-end-like-semantics/103610)

<div class="topic-metadata">

**Author:** [@kdheepak](https://discourse.julialang.org/u/kdheepak)\
**Replies:** 2\
**Last updated:** [September 7, 2023, 2:17pm UTC](https://discourse.julialang.org/t/macro-design-recommendations-for-do-end-like-semantics/103610 "2023-09-07T14:17:16Z")

</div>

In Julia, there’s a function do block syntax like so: foo() do x println(x) end where foo is defined like foo(f::Function) I’m interested in writing a macro that affects a block. i.e. I want user facing code to look…

---

## [Trait definitions: type level vs instance level](https://discourse.julialang.org/t/trait-definitions-type-level-vs-instance-level/103587)

<div class="topic-metadata">

**Author:** [@joaquinpelle](https://discourse.julialang.org/u/joaquinpelle)\
**Replies:** 3\
**Last updated:** [September 7, 2023, 1:30pm UTC](https://discourse.julialang.org/t/trait-definitions-type-level-vs-instance-level/103587 "2023-09-07T13:30:29Z")

</div>

Hi there, I’ve been thinking about trait-based dispatch, particularly from this book excerpt. The example there defines traits at the type level as follows # Default behavior is illiquid LiquidityStyle(::Type) = IsIlli…

---

## [How to evaluate symbol as a "variable" inside a macro?](https://discourse.julialang.org/t/how-to-evaluate-symbol-as-a-variable-inside-a-macro/103607)

<div class="topic-metadata">

**Author:** [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Replies:** 12\
**Last updated:** [September 7, 2023, 1:23pm UTC](https://discourse.julialang.org/t/how-to-evaluate-symbol-as-a-variable-inside-a-macro/103607 "2023-09-07T13:23:25Z")

</div>

Hello, I’m currently trying to implement merge on ComponentArrays. I’ve taken inspiration from NamedTuples in the stdlib here, and wrote a macro and a function: (instead of the Expr) using ComponentArrays c1 = Component…

---

## [Understanding output of @time and @btime under cgroup CPUQuota constrains](https://discourse.julialang.org/t/understanding-output-of-time-and-btime-under-cgroup-cpuquota-constrains/103571)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 6\
**Last updated:** [September 7, 2023, 9:38am UTC](https://discourse.julialang.org/t/understanding-output-of-time-and-btime-under-cgroup-cpuquota-constrains/103571 "2023-09-07T09:38:09Z")

</div>

Hello, I was testing cgroup CPU/ Memory quota in a Ubuntu 22.04 system and realised that while @time reacts to changes I do in terms of CPUQuota (and indeed the whole system does slow down, meaning the limit is enforced)…

---

## [How to compute the last column of Hessian (over and over) with autodiff without computing entire Hessian?](https://discourse.julialang.org/t/how-to-compute-the-last-column-of-hessian-over-and-over-with-autodiff-without-computing-entire-hessian/103588)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 5\
**Last updated:** [September 7, 2023, 5:27am UTC](https://discourse.julialang.org/t/how-to-compute-the-last-column-of-hessian-over-and-over-with-autodiff-without-computing-entire-hessian/103588 "2023-09-07T05:27:41Z")

</div>

Hi community, I have an extended question from this post. I have a loss function f(y, X, β)::Number which requires data y and X. Matrix X changes often and I want to compute: The last column of the Hessian of f with r…

---

## [How to express one type related to another](https://discourse.julialang.org/t/how-to-express-one-type-related-to-another/103416)

<div class="topic-metadata">

**Author:** [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Replies:** 8\
**Last updated:** [September 7, 2023, 12:58am UTC](https://discourse.julialang.org/t/how-to-express-one-type-related-to-another/103416 "2023-09-07T00:58:49Z")

</div>

I am trying to express something like this: struct C{T} foo::SomeTypeThatDependsOnT end In C++ one could just do T::FavoriteType but I’m not sure what the analogue is in julia. I can write a function that returns …

---

## [Is there any package/function equivalent to the pcg() in MATLAB?](https://discourse.julialang.org/t/is-there-any-package-function-equivalent-to-the-pcg-in-matlab/103593)

<div class="topic-metadata">

**Author:** [@Nova](https://discourse.julialang.org/u/Nova)\
**Replies:** 1\
**Last updated:** [September 6, 2023, 11:43pm UTC](https://discourse.julialang.org/t/is-there-any-package-function-equivalent-to-the-pcg-in-matlab/103593 "2023-09-06T23:43:14Z")

</div>

Is there any package/function equivalent to the pcg() in MATLAB?

---

## [Why does Theads.foreach only take Channels?](https://discourse.julialang.org/t/why-does-theads-foreach-only-take-channels/103592)

<div class="topic-metadata">

**Author:** [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Replies:** 1\
**Last updated:** [September 6, 2023, 10:18pm UTC](https://discourse.julialang.org/t/why-does-theads-foreach-only-take-channels/103592 "2023-09-06T22:18:55Z")

</div>

Below you can find some confusion I had earlier. Is there a reason that Threads.foreach can’t take an array? Previous confusion Can someone explain why this code isn’t printing each element of the array? julia\> functio…

---

## [Sorting a Table / DataFrame](https://discourse.julialang.org/t/sorting-a-table-dataframe/103475)

<div class="topic-metadata">

**Author:** [@Dan\_Micsa](https://discourse.julialang.org/u/Dan_Micsa)\
**Replies:** 12\
**Last updated:** [September 6, 2023, 4:54pm UTC](https://discourse.julialang.org/t/sorting-a-table-dataframe/103475 "2023-09-06T16:54:01Z")

</div>

I have a table like this: \* A B C A 1 2 3 B 2 3 4 C 3 4 5 And I want to sort descending both on columns and rows after the sum something like this: \* C B A S C 5 4 3 12 B 4 3 2 9 A 3 2 1 6 S 12 9 6 \* How can …

---

## [Fixing red bars at top of flame profile](https://discourse.julialang.org/t/fixing-red-bars-at-top-of-flame-profile/103316)

<div class="topic-metadata">

**Author:** [@ilanggear](https://discourse.julialang.org/u/ilanggear)\
**Replies:** 12\
**Last updated:** [September 6, 2023, 4:14pm UTC](https://discourse.julialang.org/t/fixing-red-bars-at-top-of-flame-profile/103316 "2023-09-06T16:14:41Z")

</div>

I’ve attached a screenshot of my flame profile. I’ve read that red bars near the top signal a problem with type instability. But I have specified the type of every struct member and the vast majority of my code relies …

---

## [Question about "in place" operations](https://discourse.julialang.org/t/question-about-in-place-operations/103573)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 1\
**Last updated:** [September 6, 2023, 3:50pm UTC](https://discourse.julialang.org/t/question-about-in-place-operations/103573 "2023-09-06T15:50:16Z")

</div>

Hello, At the moment I’m studying a little bit of code optimisation. I don’t understand why in case with sample() we have 16 bytes allocated and in the second case 0 (with the in place operation “sample!()”). Isn’t it p…

---

## [Macro to crate a struct and its external constructor](https://discourse.julialang.org/t/macro-to-crate-a-struct-and-its-external-constructor/103565)

<div class="topic-metadata">

**Author:** [@CrisCool](https://discourse.julialang.org/u/CrisCool)\
**Replies:** 5\
**Last updated:** [September 6, 2023, 2:49pm UTC](https://discourse.julialang.org/t/macro-to-crate-a-struct-and-its-external-constructor/103565 "2023-09-06T14:49:53Z")

</div>

Hi there. I’m new to metaprogramming and I’m running into trouble when trying to create a macro for replacing some bolier plate code. The code creates a series of structs and their corresponding external constructors. …

---

## [Short-form printing not working in vectors](https://discourse.julialang.org/t/short-form-printing-not-working-in-vectors/103520)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 6\
**Last updated:** [September 6, 2023, 4:31am UTC](https://discourse.julialang.org/t/short-form-printing-not-working-in-vectors/103520 "2023-09-06T04:31:51Z")

</div>

I’m trying to define short-form and long-form printing for a custom type. It seems to work as expected except when I put objects of the custom type in a vector. Here’s the code: struct Foo x::Int y::Int end fun…

---

## [Identical differential equations give different solutions when an independent equation is added](https://discourse.julialang.org/t/identical-differential-equations-give-different-solutions-when-an-independent-equation-is-added/103549)

<div class="topic-metadata">

**Author:** [@70Gage70](https://discourse.julialang.org/u/70Gage70)\
**Replies:** 4\
**Last updated:** [September 5, 2023, 9:45pm UTC](https://discourse.julialang.org/t/identical-differential-equations-give-different-solutions-when-an-independent-equation-is-added/103549 "2023-09-05T21:45:04Z")

</div>

I define the Lorenz system twice, once the standard way and once with an extra equation that depends only on u\_1. using DifferentialEquations using Makie, CairoMakie function lorenz!(du, u, p, t) du\[1\] = 10.0 \* (u\[…

---

## [Weave doctype = "md2html" without building figure sub-directory?](https://discourse.julialang.org/t/weave-doctype-md2html-without-building-figure-sub-directory/103552)

<div class="topic-metadata">

**Author:** [@matnbo](https://discourse.julialang.org/u/matnbo)\
**Replies:** 0\
**Last updated:** [September 5, 2023, 7:42pm UTC](https://discourse.julialang.org/t/weave-doctype-md2html-without-building-figure-sub-directory/103552 "2023-09-05T19:42:36Z")

</div>

When using function weave of Weave.jl to build an Html file from a Julia markdown file, such as: weave(“mypage.jmd”; out\_path = my\_out\_path, doctype = “md2html”) the function automtically creates a sub-directory (in …

---

## [Using Benchmarktools with in-place functions and a default mutable struct](https://discourse.julialang.org/t/using-benchmarktools-with-in-place-functions-and-a-default-mutable-struct/103545)

<div class="topic-metadata">

**Author:** [@arnerob](https://discourse.julialang.org/u/arnerob)\
**Replies:** 2\
**Last updated:** [September 5, 2023, 7:11pm UTC](https://discourse.julialang.org/t/using-benchmarktools-with-in-place-functions-and-a-default-mutable-struct/103545 "2023-09-05T19:11:10Z")

</div>

I want to benchmark a function by every time using the default value of a mutable struct. I tried to recreate a minimal working example of my code and what goes wrong: mutable struct myNum{T\<:Real} n::T; myN…

---

## [Sparse matrix vector faster than dense matrix vector?](https://discourse.julialang.org/t/sparse-matrix-vector-faster-than-dense-matrix-vector/103446)

<div class="topic-metadata">

**Author:** [@dgleich](https://discourse.julialang.org/u/dgleich)\
**Replies:** 9\
**Last updated:** [September 5, 2023, 2:15pm UTC](https://discourse.julialang.org/t/sparse-matrix-vector-faster-than-dense-matrix-vector/103446 "2023-09-05T14:15:44Z")

</div>

As I was teaching sparse matrices in class, I was humbled by a theory-practice gap. The idea in theory: don’t use sparse matrices when you really have dense matrix. The idea in practice: here, let me show you in Julia! …

---

## [Unexpected behavior when using Threads.@spawn](https://discourse.julialang.org/t/unexpected-behavior-when-using-threads-spawn/103497)

<div class="topic-metadata">

**Author:** [@chiion](https://discourse.julialang.org/u/chiion)\
**Replies:** 8\
**Last updated:** [September 5, 2023, 2:03pm UTC](https://discourse.julialang.org/t/unexpected-behavior-when-using-threads-spawn/103497 "2023-09-05T14:03:22Z")

</div>

Hi all, Since Threads.@spawn is encouraged over @async according to doc, so I decided to convert all @async to Threads.@spawn when reusing some of my old code. However, I’m getting some unexpected behaviors, for examp…

---

## [Inner join by comparing column values](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 3\
**Last updated:** [September 5, 2023, 1:25pm UTC](https://discourse.julialang.org/t/inner-join-by-comparing-column-values/103528 "2023-09-05T13:25:46Z")

</div>

I just wanted to check if we can do inner join and fetch result of matching rows by comparing column values of two data frames. Currently I’ve tried below code and getting error “ArgumentError: All elements of on argume…

---

## [Why are returned types different in comprehension over an empty range if called from a function vs top level?](https://discourse.julialang.org/t/why-are-returned-types-different-in-comprehension-over-an-empty-range-if-called-from-a-function-vs-top-level/103533)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [September 5, 2023, 1:13pm UTC](https://discourse.julialang.org/t/why-are-returned-types-different-in-comprehension-over-an-empty-range-if-called-from-a-function-vs-top-level/103533 "2023-09-05T13:13:26Z")

</div>

julia\> using ApproxFun julia\> rs = Jacobi(5,4); julia\> d = domain(rs); julia\> Sf = JacobiWeight(0,2,ConstantSpace(d)); julia\> using ApproxFun.ApproxFunSingularities: jacobiweight julia\> using ApproxFun.ApproxFunBase…

---

## [Why doesn't multi-dimensional Array have zero-argument constructor?](https://discourse.julialang.org/t/why-doesnt-multi-dimensional-array-have-zero-argument-constructor/103367)

<div class="topic-metadata">

**Author:** [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Replies:** 10\
**Last updated:** [September 5, 2023, 1:05pm UTC](https://discourse.julialang.org/t/why-doesnt-multi-dimensional-array-have-zero-argument-constructor/103367 "2023-09-05T13:05:35Z")

</div>

I can create an empty one-dimensional array with a zero-argument constructor: julia\> Vector{Float64}() Float64\[\] But I can’t create an empty multi-dimensional array with a zero-argument constructor: julia\> Array{Float…

---

## [I am unable to fit a simple 2d function using a neural network in Julia. Am I doing somethng wrong here?](https://discourse.julialang.org/t/i-am-unable-to-fit-a-simple-2d-function-using-a-neural-network-in-julia-am-i-doing-somethng-wrong-here/103517)

<div class="topic-metadata">

**Author:** [@Shashank](https://discourse.julialang.org/u/Shashank)\
**Replies:** 3\
**Last updated:** [September 5, 2023, 12:12pm UTC](https://discourse.julialang.org/t/i-am-unable-to-fit-a-simple-2d-function-using-a-neural-network-in-julia-am-i-doing-somethng-wrong-here/103517 "2023-09-05T12:12:25Z")

</div>

I am writing to write a code for interpolating a function using a neural network in Flux.jl, but the loss function does not decrease at all. Am I doing something wrong here? I am sorry if there is a trivial problem, as I…

---

## [PackageCompiler.jl does not support ARGS (arguments)?](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513)

<div class="topic-metadata">

**Author:** [@Miroslav-Stimac](https://discourse.julialang.org/u/Miroslav-Stimac)\
**Replies:** 3\
**Last updated:** [September 5, 2023, 6:14am UTC](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513 "2023-09-05T06:14:21Z")

</div>

Hello, It seems that PackageCompiler does not work with ARGS. I tried several ways and none worked: CASE 1: In precompile\_app.jl: MyProgram.julia\_main(\["CHECK\_DATA\_1", "DEV"\]) In MyProgram.jl: module MyProgram a…

---

## [How to compute Hessian sub-blocks with autodiff?](https://discourse.julialang.org/t/how-to-compute-hessian-sub-blocks-with-autodiff/103494)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 7\
**Last updated:** [September 4, 2023, 10:23pm UTC](https://discourse.julialang.org/t/how-to-compute-hessian-sub-blocks-with-autodiff/103494 "2023-09-04T22:23:51Z")

</div>

Hi community, I’m trying to use ForwardDiff.jl to compute a Hessian for a log likelihood function. Computing the full Hessian takes a long time, and I’m only interested in a sub-block of the Hessian anyway. Is there any…

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

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