# General Usage

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

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

**Page:** 462

---

## [Best practice for array allocation in self-consistent calculations](https://discourse.julialang.org/t/best-practice-for-array-allocation-in-self-consistent-calculations/79371)

<div class="topic-metadata">

**Author:** [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Replies:** 10\
**Last updated:** [April 13, 2022, 1:48am UTC](https://discourse.julialang.org/t/best-practice-for-array-allocation-in-self-consistent-calculations/79371 "2022-04-13T01:48:30Z")

</div>

In computational physics, self-consistent calculations are frequently met. In such calchlations, a function might be called repeatedly, and there might be some auxiliary arrays that are used in the function, which will k…

---

## [Recursive call vs while loop](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723)

<div class="topic-metadata">

**Author:** [@anon61610682](https://discourse.julialang.org/u/anon61610682)\
**Replies:** 21\
**Last updated:** [April 12, 2022, 9:40pm UTC](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723 "2022-04-12T21:40:12Z")

</div>

I have been playing with parametric methods to imitate the template programming of, say, C++. I seem to have some performance overhead when I prefer using method recursion to using a loop. Compare, for instance, the bel…

---

## [Distinguish dictionary lookup from nothing and not found?](https://discourse.julialang.org/t/distinguish-dictionary-lookup-from-nothing-and-not-found/38654)

<div class="topic-metadata">

**Author:** [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Replies:** 22\
**Last updated:** [April 12, 2022, 5:49pm UTC](https://discourse.julialang.org/t/distinguish-dictionary-lookup-from-nothing-and-not-found/38654 "2022-04-12T17:49:46Z")

</div>

get(dict, key, nothing) can be ambiguous as it can means dict\[key\] === nothing or key not found. Without a get function returning Union{Some{T}, Nothing}, I have to choose the following options, which turns out to troub…

---

## [Creating a Static Array with a loop](https://discourse.julialang.org/t/creating-a-static-array-with-a-loop/79350)

<div class="topic-metadata">

**Author:** [@lzxnl](https://discourse.julialang.org/u/lzxnl)\
**Replies:** 10\
**Last updated:** [April 12, 2022, 3:32pm UTC](https://discourse.julialang.org/t/creating-a-static-array-with-a-loop/79350 "2022-04-12T15:32:52Z")

</div>

I am solving an ODE with my own version of a Dormand Prince solver, and previously I have been using an in-place version, which has worked well for me, in that the allocations come from allocating for the array containin…

---

## [Row and column major order for arrays of different shape](https://discourse.julialang.org/t/row-and-column-major-order-for-arrays-of-different-shape/79297)

<div class="topic-metadata">

**Author:** [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Replies:** 23\
**Last updated:** [April 12, 2022, 1:05pm UTC](https://discourse.julialang.org/t/row-and-column-major-order-for-arrays-of-different-shape/79297 "2022-04-12T13:05:12Z")

</div>

In the following code the functions r\_major and c\_major iterate over array a in the row and column major order: using BenchmarkTools function r\_major!(a) N1, N2 = size(a) for i=1:N1 for j=1:N2 a\[i,j…

---

## [Running commands over ssh](https://discourse.julialang.org/t/running-commands-over-ssh/27103)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 8\
**Last updated:** [April 12, 2022, 7:35am UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103 "2022-04-12T07:35:15Z")

</div>

I would like to run commands from julia over ssh. I know how to do this in an ad hoc way: Cmd(\`ssh user@remote 'ls'\`) However I wonder is there a way to use the full power of julia command running over ssh? That is I …

---

## [Julia versus MATLAB](https://discourse.julialang.org/t/julia-versus-matlab/79360)

<div class="topic-metadata">

**Author:** [@kumarbalachandran](https://discourse.julialang.org/u/kumarbalachandran)\
**Replies:** 5\
**Last updated:** [April 12, 2022, 2:12am UTC](https://discourse.julialang.org/t/julia-versus-matlab/79360 "2022-04-12T02:12:56Z")

</div>

I am trying Julia 1.7.2 on an M1 MacBook Air for bench marking Eigen against MATLAB 2022a a=randn(100,100) tic, for x=1:100; eig(a); end; toc Elapsed time is 0.295766 seconds. whereas Julia v1.7.2 a=randn(Float64, (10…

---

## [Custom Flux.jl loss function with Interpolations.jl evaluation Error](https://discourse.julialang.org/t/custom-flux-jl-loss-function-with-interpolations-jl-evaluation-error/79305)

<div class="topic-metadata">

**Author:** [@StefanBerger](https://discourse.julialang.org/u/StefanBerger)\
**Replies:** 3\
**Last updated:** [April 12, 2022, 12:21am UTC](https://discourse.julialang.org/t/custom-flux-jl-loss-function-with-interpolations-jl-evaluation-error/79305 "2022-04-12T00:21:10Z")

</div>

Hello, I am trying to implement a model with a custom loss function in the Flux.jl package. I include the code for a simplified model, but the error stays the same. I have an interpolator which takes a scalar value and…

---

## [Julia is very slow compared to python/numpy. What am I doing wrong here?](https://discourse.julialang.org/t/julia-is-very-slow-compared-to-python-numpy-what-am-i-doing-wrong-here/78598)

<div class="topic-metadata">

**Author:** [@Vahid\_Hosseinzadeh](https://discourse.julialang.org/u/Vahid_Hosseinzadeh)\
**Replies:** 25\
**Last updated:** [April 11, 2022, 6:41pm UTC](https://discourse.julialang.org/t/julia-is-very-slow-compared-to-python-numpy-what-am-i-doing-wrong-here/78598 "2022-04-11T18:41:34Z")

</div>

Hi guys, I wrote a recursive function which construct a matrix in python using Qutip module: (I just used the tensor function and Pauli matrices definitions from Qutip) import numpy as np from qutip import \* def psit…

---

## [Safe Usage of UnsafeArrays](https://discourse.julialang.org/t/safe-usage-of-unsafearrays/79285)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 2\
**Last updated:** [April 11, 2022, 3:13pm UTC](https://discourse.julialang.org/t/safe-usage-of-unsafearrays/79285 "2022-04-11T15:13:28Z")

</div>

Is the following a “safe” usage of \`UnsafeArrays? struct SafeUnsafeArray{T, N} \<: AbstractArray{T, N} A::UnsafeArray{T, N} \_A::Vector{UInt8} end x = zeros(UInt8, 800) ptr = Base.unsafe\_convert(Ptr{Float64}, x) u …

---

## [Alternatives to \`Base.hash\`?](https://discourse.julialang.org/t/alternatives-to-base-hash/79154)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 14\
**Last updated:** [April 11, 2022, 2:36pm UTC](https://discourse.julialang.org/t/alternatives-to-base-hash/79154 "2022-04-11T14:36:16Z")

</div>

Are there packages that implement alternatives to Base.hash? I am interested in a somewhat different set of tradeoffs than what Base.hash provides: Should be able to hash any object (like Base.hash) Should have a negli…

---

## [Calling Fortran subroutine from Julia passing array arguments](https://discourse.julialang.org/t/calling-fortran-subroutine-from-julia-passing-array-arguments/79340)

<div class="topic-metadata">

**Author:** [@Marie](https://discourse.julialang.org/u/Marie)\
**Replies:** 5\
**Last updated:** [April 11, 2022, 2:13pm UTC](https://discourse.julialang.org/t/calling-fortran-subroutine-from-julia-passing-array-arguments/79340 "2022-04-11T14:13:25Z")

</div>

Fortran subroutine looks like this: subroutine MatMult(a, b, m, n, k, answer) !DEC$ ATTRIBUTES DLLEXPORT :: MatMult !DEC$ ATTRIBUTES ALIAS: 'MatMult' :: MatMult !DEC$ ATTRIBUTES REFERENCE :: a …

---

## [Frustrating distributed task exception](https://discourse.julialang.org/t/frustrating-distributed-task-exception/68579)

<div class="topic-metadata">

**Author:** [@yiming\_zhang](https://discourse.julialang.org/u/yiming_zhang)\
**Replies:** 7\
**Last updated:** [April 11, 2022, 1:42pm UTC](https://discourse.julialang.org/t/frustrating-distributed-task-exception/68579 "2022-04-11T13:42:13Z")

</div>

Progress: 0%|▏ | ETA: 1:48:49Worker 41 terminated. Progress: 99%|████████████████████████████████████████▍| ETA: 0:00:01ERROR: LoadError: TaskFailedException Stacktrace: \[1\] w…

---

## [Access DataFrames index](https://discourse.julialang.org/t/access-dataframes-index/79342)

<div class="topic-metadata">

**Author:** [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Replies:** 1\
**Last updated:** [April 11, 2022, 12:22pm UTC](https://discourse.julialang.org/t/access-dataframes-index/79342 "2022-04-11T12:22:18Z")

</div>

I’m sure this a trivial task but I cannot find the answer. I have a Julia DataFrame and I’d like the index as an array, in pandas I can do: \>\>\> import pandas as pd \>\>\> df = pd.DataFrame(\[1,2,3,4,5\]) \>\>\> df.index RangeIn…

---

## [How to specifiy 1.8-beta in CI.yaml](https://discourse.julialang.org/t/how-to-specifiy-1-8-beta-in-ci-yaml/79339)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [April 11, 2022, 11:43am UTC](https://discourse.julialang.org/t/how-to-specifiy-1-8-beta-in-ci-yaml/79339 "2022-04-11T11:43:00Z")

</div>

I have the following in my CI.yaml file: matrix: version: - '1.6' - '1' - 'nightly' os: - ubuntu-latest But how can I specify testing on 1.8-beta instead of ‘nightly’?

---

## [Iterators.flatmap optimization attempt](https://discourse.julialang.org/t/iterators-flatmap-optimization-attempt/79265)

<div class="topic-metadata">

**Author:** [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Replies:** 2\
**Last updated:** [April 11, 2022, 11:38am UTC](https://discourse.julialang.org/t/iterators-flatmap-optimization-attempt/79265 "2022-04-11T11:38:47Z")

</div>

Following the nice conversation at #44792 I’m trying to investigate the question of whether flatmap functions might offer performance benefits. I suspect that in general flatten(x) cannot do better than a flatmap(identit…

---

## [Unexpected : isstructtype( Vector{Float64}) =\> true](https://discourse.julialang.org/t/unexpected-isstructtype-vector-float64-true/79283)

<div class="topic-metadata">

**Author:** [@reumle](https://discourse.julialang.org/u/reumle)\
**Replies:** 13\
**Last updated:** [April 11, 2022, 11:06am UTC](https://discourse.julialang.org/t/unexpected-isstructtype-vector-float64-true/79283 "2022-04-11T11:06:23Z")

</div>

According to the help, it should not happen… isstructtype(T) -\> Bool Determine whether type T was declared as a struct type (i.e. using the struct or mutable struct keyword). Is this a bug? Or am I misunderstanding so…

---

## [How to avoid type instability in the return type of my function?](https://discourse.julialang.org/t/how-to-avoid-type-instability-in-the-return-type-of-my-function/79291)

<div class="topic-metadata">

**Author:** [@ultrapoci](https://discourse.julialang.org/u/ultrapoci)\
**Replies:** 3\
**Last updated:** [April 11, 2022, 4:35am UTC](https://discourse.julialang.org/t/how-to-avoid-type-instability-in-the-return-type-of-my-function/79291 "2022-04-11T04:35:59Z")

</div>

I have a struct and a simple function: struct SU2Element \<: AbstractMatrix{ComplexF64} t₁::ComplexF64 t₂::ComplexF64 function SU2Element(t₁::Number, t₂::Number) SU2Element(ComplexF64(t₁), ComplexF64(t₂)) end fu…

---

## [Pivoting in sparse QR](https://discourse.julialang.org/t/pivoting-in-sparse-qr/79306)

<div class="topic-metadata">

**Author:** [@00shiv](https://discourse.julialang.org/u/00shiv)\
**Replies:** 6\
**Last updated:** [April 11, 2022, 3:11am UTC](https://discourse.julialang.org/t/pivoting-in-sparse-qr/79306 "2022-04-11T03:11:43Z")

</div>

I have a skinny sparse matrix that I have taken care to order its rows and columns in such a way as to ensure that the sparse QR factorization should be fast \[O(n) space and time\]. However when I call qr in Julia 1.7.2 i…

---

## [How to add a custom footer to my Documenter-generated pages?](https://discourse.julialang.org/t/how-to-add-a-custom-footer-to-my-documenter-generated-pages/79044)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 4\
**Last updated:** [April 10, 2022, 10:45pm UTC](https://discourse.julialang.org/t/how-to-add-a-custom-footer-to-my-documenter-generated-pages/79044 "2022-04-10T22:45:30Z")

</div>

Hello, I need to add a \`\`\`\`@raw HTML\` block at the end of each of my .md pages to embed a script that uses GitHub issues as page comments. I could add it manually to every page, but it is not elegant, and I don’t want t…

---

## [\[C-API\]: relocation against \`jl\_gc\_have\_ pending\_finalizers' in read-only section \`.text'](https://discourse.julialang.org/t/c-api-relocation-against-jl-gc-have-pending-finalizers-in-read-only-section-text/79314)

<div class="topic-metadata">

**Author:** [@Clemapfel](https://discourse.julialang.org/u/Clemapfel)\
**Replies:** 1\
**Last updated:** [April 10, 2022, 9:03pm UTC](https://discourse.julialang.org/t/c-api-relocation-against-jl-gc-have-pending-finalizers-in-read-only-section-text/79314 "2022-04-10T21:03:50Z")

</div>

Hi, I have a simple C++ executable using the julia C-API: CMakeLists.txt cmake\_minimum\_required(VERSION 3.12) project(MyProject VERSION 0.0.0 LANGUAGES CXX) add\_executable(hello\_world ${CMAKE\_SOURCE\_DIR}/main.cpp) tar…

---

## [Tullio seems two times slower than basic LoopVectorization](https://discourse.julialang.org/t/tullio-seems-two-times-slower-than-basic-loopvectorization/79298)

<div class="topic-metadata">

**Author:** [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Replies:** 3\
**Last updated:** [April 10, 2022, 5:44pm UTC](https://discourse.julialang.org/t/tullio-seems-two-times-slower-than-basic-loopvectorization/79298 "2022-04-10T17:44:01Z")

</div>

I wanted to use Tullio to get rid of lots of nested loops in my code and write Einstein notation instead. Code I’m trying to compute a simple sum: elbo\_tullio(G::AbstractMatrix, p::AbstractVector, mu::AbstractVector, v…

---

## [Writing Messages to a Log file](https://discourse.julialang.org/t/writing-messages-to-a-log-file/79266)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 2\
**Last updated:** [April 10, 2022, 1:05pm UTC](https://discourse.julialang.org/t/writing-messages-to-a-log-file/79266 "2022-04-10T13:05:58Z")

</div>

Hello, I’d like to write a function that will print all logging statements to a file. I’ve tried the following based on the Logging documentation but nothing gets written to the file. My naive first pass was to wrap my…

---

## [Why is matrix times matrix transpose not a Symmetric / Hermitian matrix](https://discourse.julialang.org/t/why-is-matrix-times-matrix-transpose-not-a-symmetric-hermitian-matrix/10538)

<div class="topic-metadata">

**Author:** [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)\
**Replies:** 12\
**Last updated:** [April 10, 2022, 10:19am UTC](https://discourse.julialang.org/t/why-is-matrix-times-matrix-transpose-not-a-symmetric-hermitian-matrix/10538 "2022-04-10T10:19:23Z")

</div>

I often write code like this: A \* A' where A is either a real or complex matrix. Obviously the outcome is a symmetric or a hermitian matrix respectively. I wondered why this is not saved as a Symmetric matrix, e.g. jul…

---

## [Sundials: High memory usage](https://discourse.julialang.org/t/sundials-high-memory-usage/79270)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [April 9, 2022, 9:57pm UTC](https://discourse.julialang.org/t/sundials-high-memory-usage/79270 "2022-04-09T21:57:52Z")

</div>

I am using the package Sundials, which belongs to DifferentialEquations. I have a residual function with zero memory allocations, but the IDA solver of Sundials has a quite high memory usage. I have the following code fo…

---

## [Require all arrays in struct to be of same kind and type](https://discourse.julialang.org/t/require-all-arrays-in-struct-to-be-of-same-kind-and-type/79237)

<div class="topic-metadata">

**Author:** [@Chiil](https://discourse.julialang.org/u/Chiil)\
**Replies:** 7\
**Last updated:** [April 9, 2022, 6:56pm UTC](https://discourse.julialang.org/t/require-all-arrays-in-struct-to-be-of-same-kind-and-type/79237 "2022-04-09T18:56:58Z")

</div>

I have a struct that I would like to consist of only Array or CuArray, but I would like a mix of different kinds to throw. I can enforce uniform types by using the {T}, but how do I define my struct to make the vel\_mix c…

---

## [\`PyCall\` throws \`PyImport\_ImportModule\` on continuous integration systems](https://discourse.julialang.org/t/pycall-throws-pyimport-importmodule-on-continuous-integration-systems/79239)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 3\
**Last updated:** [April 9, 2022, 7:36am UTC](https://discourse.julialang.org/t/pycall-throws-pyimport-importmodule-on-continuous-integration-systems/79239 "2022-04-09T07:36:10Z")

</div>

When I am trying to test my packages which use Python packages installed by PyCall.jl on remote continuous integration (CI) systems, sometimes it fails because the package cannot be imported. After an investigation, I th…

---

## [Syntax: invalid character literal](https://discourse.julialang.org/t/syntax-invalid-character-literal/20936)

<div class="topic-metadata">

**Author:** [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Replies:** 3\
**Last updated:** [April 8, 2022, 7:12pm UTC](https://discourse.julialang.org/t/syntax-invalid-character-literal/20936 "2022-04-08T19:12:36Z")

</div>

using PyCall @pyimport osmnx as ox @pyimport networkx as nx @pyimport geopandas as gpd @pyimport matplotlib.pyplot as plt @pyimport pandas as pd function getRoadGraph() place\_name = "Beijing, China" graph = ox.graph\_…

---

## [How to know if top-level](https://discourse.julialang.org/t/how-to-know-if-top-level/79234)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 3\
**Last updated:** [April 8, 2022, 6:24pm UTC](https://discourse.julialang.org/t/how-to-know-if-top-level/79234 "2022-04-08T18:24:44Z")

</div>

My macro expands into ... export foo, which causes a ERROR: syntax: "export" expression not at top level I can put it in a try/catch block, but is there an @is\_top\_level() magic macro that I could use instead?

---

## [Developing packages that are already in the loaded sysimage](https://discourse.julialang.org/t/developing-packages-that-are-already-in-the-loaded-sysimage/77950)

<div class="topic-metadata">

**Author:** [@thazhemadam](https://discourse.julialang.org/u/thazhemadam)\
**Replies:** 6\
**Last updated:** [April 8, 2022, 4:40pm UTC](https://discourse.julialang.org/t/developing-packages-that-are-already-in-the-loaded-sysimage/77950 "2022-04-08T16:40:04Z")

</div>

How can I develop a package, MyPkg, when a sysimage that contains MyPkg (among others) is already loaded? So far, the only thing that’s worked for me is locally changing the UUID and name of the development version of t…

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

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