# General Usage

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

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

**Page:** 297

---

## [Is startup.jl an acceptable place to store credentials for interactive scripts?](https://discourse.julialang.org/t/is-startup-jl-an-acceptable-place-to-store-credentials-for-interactive-scripts/98343)

<div class="topic-metadata">

**Author:** [@mkjohnson](https://discourse.julialang.org/u/mkjohnson)\
**Replies:** 6\
**Last updated:** [May 5, 2023, 5:56am UTC](https://discourse.julialang.org/t/is-startup-jl-an-acceptable-place-to-store-credentials-for-interactive-scripts/98343 "2023-05-05T05:56:28Z")

</div>

Hi ya’ll! I had a question about using startup.jl in the home directory (not the project) to store credentials as environment variables. I come from an R background, and I’m used to storing credentials in the .Renviron …

---

## [Why does Flux.Chain creates Exprs to get type stability?](https://discourse.julialang.org/t/why-does-flux-chain-creates-exprs-to-get-type-stability/98346)

<div class="topic-metadata">

**Author:** [@Ian\_L](https://discourse.julialang.org/u/Ian_L)\
**Replies:** 1\
**Last updated:** [May 5, 2023, 1:19am UTC](https://discourse.julialang.org/t/why-does-flux-chain-creates-exprs-to-get-type-stability/98346 "2023-05-05T01:19:15Z")

</div>

Hi. Upon trying to understand how Flux.Chains evaluates inputs, I saw the two following definitions: @generated function \_applychain(layers::Tuple{Vararg{Any,N}}, x) where {N} symbols = vcat(:x, \[gensym() for \_ in 1:N…

---

## [Failed to create a usable precompiled cache file for various packages](https://discourse.julialang.org/t/failed-to-create-a-usable-precompiled-cache-file-for-various-packages/98353)

<div class="topic-metadata">

**Author:** [@Gattu\_Mytraya](https://discourse.julialang.org/u/Gattu_Mytraya)\
**Replies:** 1\
**Last updated:** [May 5, 2023, 12:38am UTC](https://discourse.julialang.org/t/failed-to-create-a-usable-precompiled-cache-file-for-various-packages/98353 "2023-05-05T00:38:21Z")

</div>

I am trying to run some jobs on my work cluster of the form: ‘’’ julia -t 8 my\_code.jl i ‘’‘’ i is an integer between 1 to 12. I keep getting this error: Failed to create a usable precompiled cache file for Multiva…

---

## [Matrix division \`\\\` vs compute by hand, why such big difference?](https://discourse.julialang.org/t/matrix-division-vs-compute-by-hand-why-such-big-difference/98288)

<div class="topic-metadata">

**Author:** [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Replies:** 0\
**Last updated:** [May 4, 2023, 1:32am UTC](https://discourse.julialang.org/t/matrix-division-vs-compute-by-hand-why-such-big-difference/98288 "2023-05-04T01:32:47Z")

</div>

In the following example, it seems that the Matrix division \\ does not provide an intended computation. Let x= A'\\b, then if norm(A'\*x-b, Inf) is zero such that A'x-b == 0, then b is a linear combination of rows from A …

---

## [Is there a more efficient way to compute the log-density of a Multivariate normal with a Symmetric Woodbury Covariance?](https://discourse.julialang.org/t/is-there-a-more-efficient-way-to-compute-the-log-density-of-a-multivariate-normal-with-a-symmetric-woodbury-covariance/98336)

<div class="topic-metadata">

**Author:** [@schwob](https://discourse.julialang.org/u/schwob)\
**Replies:** 3\
**Last updated:** [May 4, 2023, 9:12pm UTC](https://discourse.julialang.org/t/is-there-a-more-efficient-way-to-compute-the-log-density-of-a-multivariate-normal-with-a-symmetric-woodbury-covariance/98336 "2023-05-04T21:12:13Z")

</div>

Suppose that I have \\mathbf{y}\\sim N(\\boldsymbol{\\mu}, \\mathbf{A} + \\mathbf{UCU'}), where \\mathbf{A} and \\mathbf{C} are diagonal matrices. Fortunately, the covariance term follows the pattern of a sparse symmetric Woodb…

---

## [Long stack trace, identify precise error location](https://discourse.julialang.org/t/long-stack-trace-identify-precise-error-location/98285)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 17\
**Last updated:** [May 4, 2023, 8:37pm UTC](https://discourse.julialang.org/t/long-stack-trace-identify-precise-error-location/98285 "2023-05-04T20:37:12Z")

</div>

I am trying to solve a UODE where the neural network uses a tensor-basis neural net. Here are the first few lines of my stack trace (the details are not important since I am not asking you to debug my code :slight\_smile: …

---

## [LSP and EMACS and VSCode and Sublime Text: why the differences?](https://discourse.julialang.org/t/lsp-and-emacs-and-vscode-and-sublime-text-why-the-differences/98339)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 4\
**Last updated:** [May 4, 2023, 8:30pm UTC](https://discourse.julialang.org/t/lsp-and-emacs-and-vscode-and-sublime-text-why-the-differences/98339 "2023-05-04T20:30:03Z")

</div>

It seems to me that there are plenty of examples of the Julia LSP not working right. I’m aware of VSCode and Sublime Text as not being quite able to make the LSP work. What I wonder is: does it work for Emacs users? One …

---

## [How to efficiently save and read dictionaries in Julia?](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337)

<div class="topic-metadata">

**Author:** [@F\_A](https://discourse.julialang.org/u/F_A)\
**Replies:** 3\
**Last updated:** [May 4, 2023, 7:02pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337 "2023-05-04T19:02:43Z")

</div>

Hi, I’d like to save a dictionary to a file with more than 12500 entries. I’ve read some suggestion here and here. But I was wondering whether these are the most efficient way to do so? Thanks a lot.

---

## [How to do xor(all bits from an Integer) efficiently?](https://discourse.julialang.org/t/how-to-do-xor-all-bits-from-an-integer-efficiently/98338)

<div class="topic-metadata">

**Author:** [@putianyi888](https://discourse.julialang.org/u/putianyi888)\
**Replies:** 1\
**Last updated:** [May 4, 2023, 6:35pm UTC](https://discourse.julialang.org/t/how-to-do-xor-all-bits-from-an-integer-efficiently/98338 "2023-05-04T18:35:47Z")

</div>

For example, I want a function fun such that fun(0b0101) = xor(false, true, false, true) A solution for Int64 would be sufficient. Solutions for short integers are more welcome.

---

## [What's the most performant way to return some bit of an Int in Bool?](https://discourse.julialang.org/t/whats-the-most-performant-way-to-return-some-bit-of-an-int-in-bool/98184)

<div class="topic-metadata">

**Author:** [@putianyi888](https://discourse.julialang.org/u/putianyi888)\
**Replies:** 6\
**Last updated:** [May 4, 2023, 6:27pm UTC](https://discourse.julialang.org/t/whats-the-most-performant-way-to-return-some-bit-of-an-int-in-bool/98184 "2023-05-04T18:27:17Z")

</div>

Shifting left and right takes two operations and the result needs to be converted. Is there a method with one operation or that can skip the conversion?

---

## [Dot syntax](https://discourse.julialang.org/t/dot-syntax/96789)

<div class="topic-metadata">

**Author:** [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Replies:** 6\
**Last updated:** [May 4, 2023, 5:53pm UTC](https://discourse.julialang.org/t/dot-syntax/96789 "2023-05-04T17:53:33Z")

</div>

I can’t see why these three statements do different things: data = \[4;3;2;1;5\] x = data .- findmin(data)\[1\] # Subtract the min from each value. Does what I want. x = @. data - findmin(data)\[1\] # Error, can't broadcast …

---

## [Fast \`diag(A' \* B \* A)\`](https://discourse.julialang.org/t/fast-diag-a-b-a/98216)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 22\
**Last updated:** [May 4, 2023, 3:32pm UTC](https://discourse.julialang.org/t/fast-diag-a-b-a/98216 "2023-05-04T15:32:22Z")

</div>

Let A be a k \\times n matrix and B a k\\times k matrix, with k \\ll n. I want to compute the diagonal diag(A' \* B \* A) in a faster way. Here A' \* B \* A is a large n \\times n matrix, which I would like to avoid instantia…

---

## [Visualization of Jason agent-based system using InteractiveDyamics](https://discourse.julialang.org/t/visualization-of-jason-agent-based-system-using-interactivedyamics/98321)

<div class="topic-metadata">

**Author:** [@aidbar](https://discourse.julialang.org/u/aidbar)\
**Replies:** 1\
**Last updated:** [May 4, 2023, 2:51pm UTC](https://discourse.julialang.org/t/visualization-of-jason-agent-based-system-using-interactivedyamics/98321 "2023-05-04T14:51:44Z")

</div>

Hello everyone, I’m new here! :slight\_smile: Is there a way to visualize an agent-based system written in Jason (Jason | a Java-based interpreter for an extended version of AgentSpeak) using InteractiveDynamics? …

---

## [Absolute value of a matrix](https://discourse.julialang.org/t/absolute-value-of-a-matrix/98301)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 3\
**Last updated:** [May 4, 2023, 11:59am UTC](https://discourse.julialang.org/t/absolute-value-of-a-matrix/98301 "2023-05-04T11:59:27Z")

</div>

Let A be a symmetric (or Hermitian) matrix. I want to compute abs(A). By this I mean taking the absolute value of the eigenvalues. See for instance linear algebra - Understanding the absolute value of a matrix. - Mathema…

---

## [Eulerian number or Euler triangle](https://discourse.julialang.org/t/eulerian-number-or-euler-triangle/98304)

<div class="topic-metadata">

**Author:** [@stephans3](https://discourse.julialang.org/u/stephans3)\
**Replies:** 0\
**Last updated:** [May 4, 2023, 8:29am UTC](https://discourse.julialang.org/t/eulerian-number-or-euler-triangle/98304 "2023-05-04T08:29:33Z")

</div>

Hi all, as I could not find an implementation for the Eulerian number / Eulerian triangle I developed it briefly. There exists an recursive algorithm and an explicit formula. More infos could be found on Wikipedia: ht…

---

## [Vector{Vector} indices](https://discourse.julialang.org/t/vector-vector-indices/87418)

<div class="topic-metadata">

**Author:** [@unhandyandy](https://discourse.julialang.org/u/unhandyandy)\
**Replies:** 22\
**Last updated:** [September 19, 2022, 5:36am UTC](https://discourse.julialang.org/t/vector-vector-indices/87418 "2022-09-19T05:36:00Z")

</div>

This is a trivial issue, but it puzzles me, and makes me think I don’t understand Julia arrays. With julia\> test = \[\[1,2\],\[3,4\]\] 2-element Vector{Vector{Int64}}: \[1, 2\] \[3, 4\] then julia\> test\[1\] 2-element Vector{I…

---

## [Early exit from Threads.@threads](https://discourse.julialang.org/t/early-exit-from-threads-threads/98267)

<div class="topic-metadata">

**Author:** [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Replies:** 0\
**Last updated:** [May 3, 2023, 6:08pm UTC](https://discourse.julialang.org/t/early-exit-from-threads-threads/98267 "2023-05-03T18:08:22Z")

</div>

So I think I follow how Threads.@threads works in typical cases. I.e. this pattern: Threads.@threads for i = 1:N something(i) end where the something(i) will be called N times with concurrency by being scheduled to, …

---

## [How to deal with Vector{Function} for type inference?](https://discourse.julialang.org/t/how-to-deal-with-vector-function-for-type-inference/98248)

<div class="topic-metadata">

**Author:** [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Replies:** 4\
**Last updated:** [May 3, 2023, 5:43pm UTC](https://discourse.julialang.org/t/how-to-deal-with-vector-function-for-type-inference/98248 "2023-05-03T17:43:52Z")

</div>

I have the following two functions: function foo1!(v::Vector{Float64}, b::Vector{Float64}) for i in eachindex(v) v\[i\] = 2 \* v\[i\] + 3 \* b\[i\] end end function foo2!(v::Vector{Float64}, b::Vector{Float64})…

---

## [Creating Fixed Width Output Files](https://discourse.julialang.org/t/creating-fixed-width-output-files/98260)

<div class="topic-metadata">

**Author:** [@andrewkhardy](https://discourse.julialang.org/u/andrewkhardy)\
**Replies:** 2\
**Last updated:** [May 3, 2023, 5:43pm UTC](https://discourse.julialang.org/t/creating-fixed-width-output-files/98260 "2023-05-03T17:43:27Z")

</div>

I am unsatisfied with the discussion here, so am opening a new thread to find a solution to this. In Python, it is quite simple to save a data frame or dictionary with fixed width columns as a .dat file. This usability …

---

## [Which matrix types are defined?](https://discourse.julialang.org/t/which-matrix-types-are-defined/98224)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 8\
**Last updated:** [May 3, 2023, 5:03pm UTC](https://discourse.julialang.org/t/which-matrix-types-are-defined/98224 "2023-05-03T17:03:42Z")

</div>

Base Julia knows at least three types of vectors: julia\> x=rand(3) 3-element Vector{Float64}: 0.9378913600546382 0.04174077280647481 0.7608954281716017 julia\> x' 1×3 adjoint(::Vector{Float64}) with eltype Float64: …

---

## [Write fixed-width table](https://discourse.julialang.org/t/write-fixed-width-table/23689)

<div class="topic-metadata">

**Author:** [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Replies:** 7\
**Last updated:** [May 3, 2023, 3:09pm UTC](https://discourse.julialang.org/t/write-fixed-width-table/23689 "2023-05-03T15:09:29Z")

</div>

Hi! I cannot find a simple way to write a dataframe/array of tuples/… to file with fixed-width columns. CSV package does not support fixed width or formatting in general; manually looping over rows and calling @sprintf m…

---

## [PkgTemplates does not execute my plugin](https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812)

<div class="topic-metadata">

**Author:** [@Mrion](https://discourse.julialang.org/u/Mrion)\
**Replies:** 2\
**Last updated:** [May 3, 2023, 2:17pm UTC](https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812 "2023-05-03T14:17:22Z")

</div>

Hi! I create my own plugin: struct Dependencies \<: Plugin deps::Vector{AbstractString} = \[\] end dependencies(d::Dependencies) = d.deps function posthook(d::Dependencies, t::Template, pkg\_dir::AbstractString) Pk…

---

## [Using multiple packages in extensions for Julia 1.9](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237)

<div class="topic-metadata">

**Author:** [@April-Hannah-Lena](https://discourse.julialang.org/u/April-Hannah-Lena)\
**Replies:** 4\
**Last updated:** [May 3, 2023, 12:25pm UTC](https://discourse.julialang.org/t/using-multiple-packages-in-extensions-for-julia-1-9/98237 "2023-05-03T12:25:54Z")

</div>

I’m very excited to see the new features in Julia 1.9. I’m interested in how it is decided which packages are required for loading extensions. Specifically, consider an example: A package “MyPackage” has an optional dep…

---

## [Error saving MCMC Chain](https://discourse.julialang.org/t/error-saving-mcmc-chain/98225)

<div class="topic-metadata">

**Author:** [@ALIAN\_LI\_MARTIN](https://discourse.julialang.org/u/ALIAN_LI_MARTIN)\
**Replies:** 0\
**Last updated:** [May 3, 2023, 1:04am UTC](https://discourse.julialang.org/t/error-saving-mcmc-chain/98225 "2023-05-03T01:04:03Z")

</div>

Hello, I have an error when saving the MCMC strings. Could someone help me with this problem. Thank you so much. MethodError: no method matching write(::IOStream, ::Chains{Float64, AxisArrays.AxisArray{Float64, 3, Array…

---

## [Compiler Can't Optimize Away Unnecessary Memory Allocs with Convenience Variables](https://discourse.julialang.org/t/compiler-cant-optimize-away-unnecessary-memory-allocs-with-convenience-variables/98045)

<div class="topic-metadata">

**Author:** [@ejmeitz](https://discourse.julialang.org/u/ejmeitz)\
**Replies:** 14\
**Last updated:** [May 3, 2023, 12:09am UTC](https://discourse.julialang.org/t/compiler-cant-optimize-away-unnecessary-memory-allocs-with-convenience-variables/98045 "2023-05-03T00:09:58Z")

</div>

I have code doing some broadcasted operations and it takes ~2 microseconds which is great ΔU2 += sum((Δuᵢ .\* u .\* @view F2\[:,i\]) .+ (Δuⱼ .\* u .\* @view F2\[:,j\]) .+ (Δuₖ .\* u .\* @view F2\[:,k\])) However, this is entirely …

---

## [How do I call a function in a lookup table while ensure type stability?](https://discourse.julialang.org/t/how-do-i-call-a-function-in-a-lookup-table-while-ensure-type-stability/98212)

<div class="topic-metadata">

**Author:** [@Kino](https://discourse.julialang.org/u/Kino)\
**Replies:** 4\
**Last updated:** [May 2, 2023, 7:08pm UTC](https://discourse.julialang.org/t/how-do-i-call-a-function-in-a-lookup-table-while-ensure-type-stability/98212 "2023-05-02T19:08:43Z")

</div>

A simple example is: julia\> f() = 1 f (generic function with 1 method) julia\> g() = 2 g (generic function with 1 method) julia\> table = (f=f, g=g) (f = f, g = g) julia\> get\_val(x::Symbol) = table\[x\]()::Int get\_val (g…

---

## [FastDense, FastChain](https://discourse.julialang.org/t/fastdense-fastchain/98210)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 4\
**Last updated:** [May 2, 2023, 5:29pm UTC](https://discourse.julialang.org/t/fastdense-fastchain/98210 "2023-05-02T17:29:13Z")

</div>

Which package contains FastChain and FastDense? I am using Julia 1.9.rc1. Even though I loaded DiffEqFluxn and Flux, FastChain and FastDense are not found. Any insight is appreciated. Thanks.

---

## [How to include a column with a constant value in a DataFrames select](https://discourse.julialang.org/t/how-to-include-a-column-with-a-constant-value-in-a-dataframes-select/98203)

<div class="topic-metadata">

**Author:** [@kobusherbst](https://discourse.julialang.org/u/kobusherbst)\
**Replies:** 3\
**Last updated:** [May 2, 2023, 2:58pm UTC](https://discourse.julialang.org/t/how-to-include-a-column-with-a-constant-value-in-a-dataframes-select/98203 "2023-05-02T14:58:13Z")

</div>

I have the following working example: using DataFrames # Create a DataFrame data = DataFrame(Name=\["Alice", "Bob", "Cathy", "David"\], Age=\[30, 25, 27, 28\], City=\["New York", "San Franc…

---

## [Is Cthulhu wrong? Or is it the compiler?](https://discourse.julialang.org/t/is-cthulhu-wrong-or-is-it-the-compiler/98071)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 17\
**Last updated:** [May 2, 2023, 2:42pm UTC](https://discourse.julialang.org/t/is-cthulhu-wrong-or-is-it-the-compiler/98071 "2023-05-02T14:42:21Z")

</div>

In this fragment, Cthulhu concludes that all types are concrete, known. Yet, at the bottom it suddenly springs on me csuml is Any. I considered log, and used abs for its argument. To no avail. Any idea how to fix it, a…

---

## [Correct way to ccall a Fortran subroutine requiring pointers](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191)

<div class="topic-metadata">

**Author:** [@lucifer1004](https://discourse.julialang.org/u/lucifer1004)\
**Replies:** 3\
**Last updated:** [May 2, 2023, 11:27am UTC](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191 "2023-05-02T11:27:01Z")

</div>

Given the following Fortran code: MODULE PTR IMPLICIT NONE REAL, SAVE, TARGET, ALLOCATABLE :: A(:, :), B(:, :) CONTAINS SUBROUTINE INIT(AP, BP) REAL, POINTER :: AP(:, :), BP(:, :) ALLOCATE(A(6, 6…

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

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