# General Usage

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

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

**Page:** 268

---

## [Printf with custom format (custom data type)](https://discourse.julialang.org/t/printf-with-custom-format-custom-data-type/101782)

<div class="topic-metadata">

**Author:** [@shiroghost](https://discourse.julialang.org/u/shiroghost)\
**Replies:** 2\
**Last updated:** [July 19, 2023, 2:52pm UTC](https://discourse.julialang.org/t/printf-with-custom-format-custom-data-type/101782 "2023-07-19T14:52:43Z")

</div>

Hi all, Is it possible to add format specifiers to printf for custom data types? Thanks

---

## [How does copying slices work?](https://discourse.julialang.org/t/how-does-copying-slices-work/101777)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 6\
**Last updated:** [July 19, 2023, 12:46pm UTC](https://discourse.julialang.org/t/how-does-copying-slices-work/101777 "2023-07-19T12:46:29Z")

</div>

julia\> data=\[1,2,3,4,5,6,0,0,0\] 9-element Vector{Int64}: julia\> data\[6:9\].=data\[3:6\] julia\> data 9-element Vector{Int64}: 1 2 3 4 5 3 4 5 6 why in this example data\[9\] =6 and not =data\[3\]? I’m fine with it w…

---

## [Building a strong Julia chess engine](https://discourse.julialang.org/t/building-a-strong-julia-chess-engine/101726)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 14\
**Last updated:** [July 19, 2023, 12:39pm UTC](https://discourse.julialang.org/t/building-a-strong-julia-chess-engine/101726 "2023-07-19T12:39:39Z")

</div>

Should we build a strong chess engine? How do I go about it? I need to get started by interfacing with UCI, but how? Then, what next? Any idea to leverage Julia’s strength? For example, I’m thinking of generating code us…

---

## [Capture stdout and stderr in case a command fails](https://discourse.julialang.org/t/capture-stdout-and-stderr-in-case-a-command-fails/101772)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 2\
**Last updated:** [July 19, 2023, 8:59am UTC](https://discourse.julialang.org/t/capture-stdout-and-stderr-in-case-a-command-fails/101772 "2023-07-19T08:59:11Z")

</div>

What is the current recommended pattern for capturing the output of stdout and stderr of a command? I tried something like log = IOBuffer() redirect\_stdio(; stdout = log, stderr = log) do if success(cmd) no…

---

## [Libcurl error when adding new package with Julia 1.9.2 Linux System](https://discourse.julialang.org/t/libcurl-error-when-adding-new-package-with-julia-1-9-2-linux-system/101755)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 4\
**Last updated:** [July 19, 2023, 8:31am UTC](https://discourse.julialang.org/t/libcurl-error-when-adding-new-package-with-julia-1-9-2-linux-system/101755 "2023-07-19T08:31:19Z")

</div>

Hi all, so I delete .julia directory from old Julia -1.7.3 then I download Julia 1.9.2 and set the path to this new Julia, but then when I try to add a new package this error happens

---

## [Factorization with Symbolics package](https://discourse.julialang.org/t/factorization-with-symbolics-package/101773)

<div class="topic-metadata">

**Author:** [@Alf](https://discourse.julialang.org/u/Alf)\
**Replies:** 0\
**Last updated:** [July 19, 2023, 8:26am UTC](https://discourse.julialang.org/t/factorization-with-symbolics-package/101773 "2023-07-19T08:26:23Z")

</div>

I am starting to use the Julia package Symbolics for symbolic Maths but I can not figure out how to factorize a polynomial. I want to get the same as with SymPy. using SymPy @vars x factor(x^2 + 2x + 1) that returns …

---

## [Plot WIndow Does Not Show Up for Fresh Install Julia-1.9.2 with Plots](https://discourse.julialang.org/t/plot-window-does-not-show-up-for-fresh-install-julia-1-9-2-with-plots/101768)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 0\
**Last updated:** [July 19, 2023, 7:56am UTC](https://discourse.julialang.org/t/plot-window-does-not-show-up-for-fresh-install-julia-1-9-2-with-plots/101768 "2023-07-19T07:56:55Z")

</div>

I have installed Julia-1.9.2 and just add one package Plots try this simple code: using Plots gr() f(x) = exp(x) plot(f) the plot window / GUI window is not showing. How to fix this?

---

## [Incorrect coverage report that flags line with \`end\`](https://discourse.julialang.org/t/incorrect-coverage-report-that-flags-line-with-end/101767)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 0\
**Last updated:** [July 19, 2023, 7:30am UTC](https://discourse.julialang.org/t/incorrect-coverage-report-that-flags-line-with-end/101767 "2023-07-19T07:30:29Z")

</div>

See Codecov, where the line with end is flagged as uncovered, but lines leading up to it are covered. I wonder how to get the report working correctly?

---

## [Optimizing nested loops with conditional inside](https://discourse.julialang.org/t/optimizing-nested-loops-with-conditional-inside/101724)

<div class="topic-metadata">

**Author:** [@Luis\_Alberto\_R](https://discourse.julialang.org/u/Luis_Alberto_R)\
**Replies:** 10\
**Last updated:** [July 19, 2023, 3:30am UTC](https://discourse.julialang.org/t/optimizing-nested-loops-with-conditional-inside/101724 "2023-07-19T03:30:34Z")

</div>

Hello, I’m trying to build hydrodynamic codes in 1D, 2D and 3D in Julia. So far I have the codes working with first order solvers, and I’ve managed to make the 1D and 2D faster than Python and C++, now I’m trying to impl…

---

## [Empty dataframe from database query](https://discourse.julialang.org/t/empty-dataframe-from-database-query/101745)

<div class="topic-metadata">

**Author:** [@jonjilla](https://discourse.julialang.org/u/jonjilla)\
**Replies:** 1\
**Last updated:** [July 18, 2023, 6:03pm UTC](https://discourse.julialang.org/t/empty-dataframe-from-database-query/101745 "2023-07-18T18:03:49Z")

</div>

Hello I have a very common usage pattern for converting the output of a database query (LibPQ for example) So something like data = DataFrame(LibPQ.execute(pgconnection, "select column1,column2 from table1 where condi…

---

## [Reducedims for other ops](https://discourse.julialang.org/t/reducedims-for-other-ops/101736)

<div class="topic-metadata">

**Author:** [@fda-tome](https://discourse.julialang.org/u/fda-tome)\
**Replies:** 0\
**Last updated:** [July 18, 2023, 2:50pm UTC](https://discourse.julialang.org/t/reducedims-for-other-ops/101736 "2023-07-18T14:50:58Z")

</div>

I am currently implementing Dagger,jl distributed arrays and found out the problem with reduce using non associative operations such as ^ - /, is there someone working on it? I’d be happy to tackle it eventually thanks …

---

## [Is allocation inevitable when generating random numbers from a categorical distribution?](https://discourse.julialang.org/t/is-allocation-inevitable-when-generating-random-numbers-from-a-categorical-distribution/101718)

<div class="topic-metadata">

**Author:** [@taka255](https://discourse.julialang.org/u/taka255)\
**Replies:** 9\
**Last updated:** [July 18, 2023, 12:14pm UTC](https://discourse.julialang.org/t/is-allocation-inevitable-when-generating-random-numbers-from-a-categorical-distribution/101718 "2023-07-18T12:14:54Z")

</div>

Hi, I am trying to do in-place random number generation using Distributions.jl. However, for some reason, only the random number generation from the Categorical distribution takes extra computation time due to the extra…

---

## [Breaking notation convention - a potential anti-pattern?](https://discourse.julialang.org/t/breaking-notation-convention-a-potential-anti-pattern/101699)

<div class="topic-metadata">

**Author:** [@algunion](https://discourse.julialang.org/u/algunion)\
**Replies:** 16\
**Last updated:** [July 18, 2023, 9:21am UTC](https://discourse.julialang.org/t/breaking-notation-convention-a-potential-anti-pattern/101699 "2023-07-18T09:21:35Z")

</div>

I have a scenario where I think it might be warranted to depart from the end with an exclamation mark convention for function names that modify at least one of their arguments. However, I wouldn’t want to get into an an…

---

## [Better ways to deal with CompatHelper and compatibility upgrades](https://discourse.julialang.org/t/better-ways-to-deal-with-compathelper-and-compatibility-upgrades/88677)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 1\
**Last updated:** [July 18, 2023, 7:47am UTC](https://discourse.julialang.org/t/better-ways-to-deal-with-compathelper-and-compatibility-upgrades/88677 "2023-07-18T07:47:17Z")

</div>

After some time of innactivity, the CompatHelper bot stops working. Of course this is not an issue for large projects that are very active, but for smaller packages it is. Thus, I would like to know: Is there a way t…

---

## [Optimizing dinucleotides count in a DNA sequence type \`LongDNA\`](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583)

<div class="topic-metadata">

**Author:** [@camilogarciabotero](https://discourse.julialang.org/u/camilogarciabotero)\
**Replies:** 21\
**Last updated:** [July 17, 2023, 5:33pm UTC](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583 "2023-07-17T17:33:43Z")

</div>

I am working with the BioSequences.jl package, particularly a LongSequence{DNAAlphabet{4}} (a very efficient string) type like the following random DNA sequence seq = dna"ACACATCATCTACTATCAT" and I want a function that c…

---

## [Define multiple methods or one method with union types?](https://discourse.julialang.org/t/define-multiple-methods-or-one-method-with-union-types/101674)

<div class="topic-metadata">

**Author:** [@kunzaatko](https://discourse.julialang.org/u/kunzaatko)\
**Replies:** 4\
**Last updated:** [July 17, 2023, 2:03pm UTC](https://discourse.julialang.org/t/define-multiple-methods-or-one-method-with-union-types/101674 "2023-07-17T14:03:17Z")

</div>

What is the preferred way to implement methods that allow multiple types? Option A: function method(a::Union{Tuple{Integer,Integer}, Integer}, b::Union{Tuple{Integer,Integer}, Integer}) a = a isa Integer ? (a,a) : …

---

## [Lux.jl Neural ODE Initial Condition Optimization](https://discourse.julialang.org/t/lux-jl-neural-ode-initial-condition-optimization/95207)

<div class="topic-metadata">

**Author:** [@George\_Stepaniants](https://discourse.julialang.org/u/George_Stepaniants)\
**Replies:** 14\
**Last updated:** [July 17, 2023, 12:55pm UTC](https://discourse.julialang.org/t/lux-jl-neural-ode-initial-condition-optimization/95207 "2023-07-17T12:55:11Z")

</div>

How do we also optimize the initial condition of a neural ODE using Lux.jl? I have not been able to find any examples of this. Is there any way to just add the initial conditions as parameters to a neural ODE that is def…

---

## [How to analyse the complexity of a Julia project?](https://discourse.julialang.org/t/how-to-analyse-the-complexity-of-a-julia-project/101678)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 4\
**Last updated:** [July 16, 2023, 8:05pm UTC](https://discourse.julialang.org/t/how-to-analyse-the-complexity-of-a-julia-project/101678 "2023-07-16T20:05:54Z")

</div>

In the past I used sloccount, but it does not even know of Julia, it thinks it is lisp (ok, not totally wrong). I would like to know: number of source code files lines of source code dito without comments and blank li…

---

## [Documenter.jl: Missing Docstring (random?)](https://discourse.julialang.org/t/documenter-jl-missing-docstring-random/101619)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 4\
**Last updated:** [July 16, 2023, 6:41pm UTC](https://discourse.julialang.org/t/documenter-jl-missing-docstring-random/101619 "2023-07-16T18:41:29Z")

</div>

In this package, I reference some doc strings, as usual with @docs macro. Locally, using the LiveServer.servedocs(), some docstrings do not show up, but some of these show up when the documentation is actually deployed. …

---

## [How to perform Algrebraic operations on "IntervalBox.()"?](https://discourse.julialang.org/t/how-to-perform-algrebraic-operations-on-intervalbox/101661)

<div class="topic-metadata">

**Author:** [@Ashu](https://discourse.julialang.org/u/Ashu)\
**Replies:** 0\
**Last updated:** [July 15, 2023, 7:15pm UTC](https://discourse.julialang.org/t/how-to-perform-algrebraic-operations-on-intervalbox/101661 "2023-07-15T19:15:38Z")

</div>

Hello All, There are two interval box X = IntervalBox.(0..5, 5..10, 10..15) and Y=IntervalBox.(-5..3, 11..13, 7..11). Please let me know how to do elementwise union, and intersection between the two IntervalBoxes Inter…

---

## [Hcat without copy and stack overflow in type inference](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671)

<div class="topic-metadata">

**Author:** [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Replies:** 3\
**Last updated:** [July 16, 2023, 10:11am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671 "2023-07-16T10:11:48Z")

</div>

When using packages like ArrayPartition in GitHub - SciML/RecursiveArrayTools.jl: Tools for easily handling objects like arrays of arrays and deeper nestings in scientific machine learning (SciML) and other applications …

---

## [Random number generation from a power law](https://discourse.julialang.org/t/random-number-generation-from-a-power-law/100701)

<div class="topic-metadata">

**Author:** [@ABCD](https://discourse.julialang.org/u/ABCD)\
**Replies:** 6\
**Last updated:** [July 16, 2023, 7:09am UTC](https://discourse.julialang.org/t/random-number-generation-from-a-power-law/100701 "2023-07-16T07:09:15Z")

</div>

hello all, I am new to Julia. I need to generate random numbers from power law, broken power law and different distributions. Is there a package that do all of these? Thank you very much in advance.

---

## [Efficiently computing Hessians of Neural Networks output with respect to inputs](https://discourse.julialang.org/t/efficiently-computing-hessians-of-neural-networks-output-with-respect-to-inputs/101666)

<div class="topic-metadata">

**Author:** [@Baba\_Yara\_Fahiz](https://discourse.julialang.org/u/Baba_Yara_Fahiz)\
**Replies:** 1\
**Last updated:** [July 16, 2023, 5:29am UTC](https://discourse.julialang.org/t/efficiently-computing-hessians-of-neural-networks-output-with-respect-to-inputs/101666 "2023-07-16T05:29:44Z")

</div>

Hello everyone, I’m currently working on a problem that involves approximating a partial differential equation using neural networks. I’ve created a script that generates a set of neural networks, computes their outputs…

---

## [Get unit with @benchmark or set unit to "s"](https://discourse.julialang.org/t/get-unit-with-benchmark-or-set-unit-to-s/101664)

<div class="topic-metadata">

**Author:** [@Sisisi](https://discourse.julialang.org/u/Sisisi)\
**Replies:** 1\
**Last updated:** [July 16, 2023, 1:13am UTC](https://discourse.julialang.org/t/get-unit-with-benchmark-or-set-unit-to-s/101664 "2023-07-16T01:13:47Z")

</div>

Hello, I know how to get the mean, median… about @benchmark, nonetheless, those values are given in the suitable unit (ms, µs, ns) but I need to know with Julia what is this unit. Or, else, set the unit to “second”. I …

---

## [Why a vector with Expr and Symbols inside fails with ifelse?](https://discourse.julialang.org/t/why-a-vector-with-expr-and-symbols-inside-fails-with-ifelse/101665)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 2\
**Last updated:** [July 15, 2023, 11:49pm UTC](https://discourse.julialang.org/t/why-a-vector-with-expr-and-symbols-inside-fails-with-ifelse/101665 "2023-07-15T23:49:46Z")

</div>

This is probably a stupid question but I don’t understand why this doesn’t work, I’m using Julia 1.9.2: defining a = \[:f1, :(f2::Int)\] when I do \[ifelse(typeof(x) == Expr, x.args, x) for x in a\] I get ERROR: type S…

---

## [What does precompilation do on a package that does not use SnoopCompile at all?](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680)

<div class="topic-metadata">

**Author:** [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Replies:** 8\
**Last updated:** [July 15, 2023, 8:03pm UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680 "2023-07-15T20:03:49Z")

</div>

I’m dev’ing package does not use SnoopCompile or attempt any precompilation. I make frequent changes to the package locally, and everytime I do I suffer a decent precompilation delay (30 seconds) when using the package, …

---

## [Shortcut to load a package from another environment?](https://discourse.julialang.org/t/shortcut-to-load-a-package-from-another-environment/101620)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 4\
**Last updated:** [July 15, 2023, 5:41pm UTC](https://discourse.julialang.org/t/shortcut-to-load-a-package-from-another-environment/101620 "2023-07-15T17:41:51Z")

</div>

I more and more use this workflow to load some packages that are not part of a current development project, but are useful for testing (Plots, LiveSever, for example): mypkg\> activate @LiveServer # shared environment wi…

---

## [Modified loss function in NeuralPDE](https://discourse.julialang.org/t/modified-loss-function-in-neuralpde/101624)

<div class="topic-metadata">

**Author:** [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Replies:** 4\
**Last updated:** [July 15, 2023, 5:19pm UTC](https://discourse.julialang.org/t/modified-loss-function-in-neuralpde/101624 "2023-07-15T17:19:58Z")

</div>

Is it possible to modify the loss function in PINNs? like instead of loss function of variables, may I modify it to loss of sin or cos of variables?

---

## [Update source file with eval-resulted code](https://discourse.julialang.org/t/update-source-file-with-eval-resulted-code/101636)

<div class="topic-metadata">

**Author:** [@algunion](https://discourse.julialang.org/u/algunion)\
**Replies:** 3\
**Last updated:** [July 15, 2023, 10:33am UTC](https://discourse.julialang.org/t/update-source-file-with-eval-resulted-code/101636 "2023-07-15T10:33:19Z")

</div>

Imagine the following scenario: I have a function that generates an Expr, which is in turn processed by eval. To make it easier, let’s create a small example: function makeval() ex = Expr(:function, …

---

## [Testing the limit of the second law of thermodynamics with Julia](https://discourse.julialang.org/t/testing-the-limit-of-the-second-law-of-thermodynamics-with-julia/101560)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 5\
**Last updated:** [July 14, 2023, 7:30pm UTC](https://discourse.julialang.org/t/testing-the-limit-of-the-second-law-of-thermodynamics-with-julia/101560 "2023-07-14T19:30:02Z")

</div>

The second law of thermodynamics is an important rule in physics. Understanding it well gives us a crucial understanding in it. For more context, see the video here. The question becomes “what is entropy”, which become…

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

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