# General Usage

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

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

**Page:** 499

---

## [On modules and globals](https://discourse.julialang.org/t/on-modules-and-globals/74234)

<div class="topic-metadata">

**Author:** [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Replies:** 14\
**Last updated:** [January 8, 2022, 6:42pm UTC](https://discourse.julialang.org/t/on-modules-and-globals/74234 "2022-01-08T18:42:26Z")

</div>

Hello everybody. We have read everything we could find about globals, including this very helpful post How to correctly define and use global variables in the module in Julia? and are grappling with a use case that mak…

---

## [Function pmap multi-argument](https://discourse.julialang.org/t/function-pmap-multi-argument/74153)

<div class="topic-metadata">

**Author:** [@GalloLuigi](https://discourse.julialang.org/u/GalloLuigi)\
**Replies:** 10\
**Last updated:** [January 8, 2022, 5:44pm UTC](https://discourse.julialang.org/t/function-pmap-multi-argument/74153 "2022-01-08T17:44:23Z")

</div>

Hi I would like to use pmap for this function: function simulate( sim\_type::SIS, df::DataFrame, intervals::Dict{Int, Pair{DateTime, DateTime}}, user2vertex::Dict{String, Int}, loc…

---

## [Removing LineNumberNodes when displaying expressions with macros](https://discourse.julialang.org/t/removing-linenumbernodes-when-displaying-expressions-with-macros/20222)

<div class="topic-metadata">

**Author:** [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Replies:** 7\
**Last updated:** [January 8, 2022, 4:58pm UTC](https://discourse.julialang.org/t/removing-linenumbernodes-when-displaying-expressions-with-macros/20222 "2022-01-08T16:58:46Z")

</div>

I’m trying to define a function to filter LineNumberNodes from an expression to pretty-print it without annotations: filterLNN(x) = deepcopy(x) function filterLNN(e::Expr) Expr(e.head, filterLNN.(filter(x-\>!isa(x, …

---

## [How to wrap a vector so that it does simd?](https://discourse.julialang.org/t/how-to-wrap-a-vector-so-that-it-does-simd/74242)

<div class="topic-metadata">

**Author:** [@abulak](https://discourse.julialang.org/u/abulak)\
**Replies:** 0\
**Last updated:** [January 8, 2022, 2:40pm UTC](https://discourse.julialang.org/t/how-to-wrap-a-vector-so-that-it-does-simd/74242 "2022-01-08T14:40:14Z")

</div>

Hey, I’ve been recently hit with this issue: I have a very thin wrapper around Vector{T}, let’s say it’s struct MyVector{T} \<: AbstractVector{T} data::Vector{T} end # Array Interface Base.size(v::MyVector) = size(…

---

## [Confusion on Creating Gridded Interpolations](https://discourse.julialang.org/t/confusion-on-creating-gridded-interpolations/50205)

<div class="topic-metadata">

**Author:** [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Replies:** 23\
**Last updated:** [January 8, 2022, 1:29pm UTC](https://discourse.julialang.org/t/confusion-on-creating-gridded-interpolations/50205 "2022-01-08T13:29:22Z")

</div>

Hi everyone, I am have run into a problem with interpolating values across large arrays using Julia. I have read these Discourse discussions pertaining to my problem but have not been able to use them to create a solutio…

---

## [Mutex in inter-process communication](https://discourse.julialang.org/t/mutex-in-inter-process-communication/74223)

<div class="topic-metadata">

**Author:** [@brandsblair2020](https://discourse.julialang.org/u/brandsblair2020)\
**Replies:** 0\
**Last updated:** [January 7, 2022, 11:52pm UTC](https://discourse.julialang.org/t/mutex-in-inter-process-communication/74223 "2022-01-07T23:52:10Z")

</div>

hello, there is a package called InterProcessCommunication at https://github.com/emmt/InterProcessCommunication.jl Has anyone had any experience in making the Mutex to work with shared memory, i.e. in the lock.jl of the…

---

## [Can't get \`Preferences.set\_preferences!()\` to work](https://discourse.julialang.org/t/cant-get-preferences-set-preferences-to-work/74155)

<div class="topic-metadata">

**Author:** [@Di11on](https://discourse.julialang.org/u/Di11on)\
**Replies:** 2\
**Last updated:** [January 7, 2022, 11:36pm UTC](https://discourse.julialang.org/t/cant-get-preferences-set-preferences-to-work/74155 "2022-01-07T23:36:23Z")

</div>

Hi folks, I’m trying to use a custom binary with HiGHS.jl. I am following the instructions here: Custom binaries · JuMP These instructions involve using Preferences.set\_preferences!() to set the path to the custom bina…

---

## [Is the least significant bit from bitstring() correct?](https://discourse.julialang.org/t/is-the-least-significant-bit-from-bitstring-correct/74206)

<div class="topic-metadata">

**Author:** [@g2g](https://discourse.julialang.org/u/g2g)\
**Replies:** 1\
**Last updated:** [January 7, 2022, 6:36pm UTC](https://discourse.julialang.org/t/is-the-least-significant-bit-from-bitstring-correct/74206 "2022-01-07T18:36:28Z")

</div>

I don’t know if this is a bug but it isn’t what I was expecting: julia\> bitstring(Float32(0.777777777777777777777777777777777777777777777777)) "00111111010001110001110001110010" julia\> bitstring(Float64(0.7777777777777…

---

## [Apply interpolation functions on columns of a dataframe](https://discourse.julialang.org/t/apply-interpolation-functions-on-columns-of-a-dataframe/71257)

<div class="topic-metadata">

**Author:** [@corny85](https://discourse.julialang.org/u/corny85)\
**Replies:** 17\
**Last updated:** [January 7, 2022, 5:10pm UTC](https://discourse.julialang.org/t/apply-interpolation-functions-on-columns-of-a-dataframe/71257 "2022-01-07T17:10:09Z")

</div>

Hello, I’m a beginner in Julia… i have: a dataframe with 4 columns and 10 rows three functions u1, u2, u3 a vector of 3 weights And i want to create a function (arguments : the dataframe, the 3 functions and the wei…

---

## [Getting bins from Plots.jl histogram](https://discourse.julialang.org/t/getting-bins-from-plots-jl-histogram/55452)

<div class="topic-metadata">

**Author:** [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Replies:** 13\
**Last updated:** [January 7, 2022, 4:57pm UTC](https://discourse.julialang.org/t/getting-bins-from-plots-jl-histogram/55452 "2022-01-07T16:57:02Z")

</div>

I can make a histogram plot by histogram(rand(1000)) Can I get the values of the resulting binning?

---

## [Faster alternate to @views for passing subarrays to functions](https://discourse.julialang.org/t/faster-alternate-to-views-for-passing-subarrays-to-functions/74195)

<div class="topic-metadata">

**Author:** [@Arpit\_Babbar](https://discourse.julialang.org/u/Arpit_Babbar)\
**Replies:** 3\
**Last updated:** [January 7, 2022, 4:39pm UTC](https://discourse.julialang.org/t/faster-alternate-to-views-for-passing-subarrays-to-functions/74195 "2022-01-07T16:39:33Z")

</div>

Hi, I have got 4 arrays a,b,c,d each of size nvar X nx where nvar is a small Int64, but nx is a pretty large Int64. I wish to iteratively act a function over the arguments (a\[:,i\],a\[:,i-1\],a\[:,i+1\],b\[:,i\],b\[:,i-1\],b\[:,i+…

---

## [How to add values in a dictionary of lists?](https://discourse.julialang.org/t/how-to-add-values-in-a-dictionary-of-lists/74192)

<div class="topic-metadata">

**Author:** [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Replies:** 10\
**Last updated:** [January 7, 2022, 3:53pm UTC](https://discourse.julialang.org/t/how-to-add-values-in-a-dictionary-of-lists/74192 "2022-01-07T15:53:22Z")

</div>

Hello, good morning. How to add values in a dictionary that has type (int, vector(int))? Cant understand the error about conversion ERROR: LoadError: MethodError: Cannot \`convert\` an object of type Int64 to an object o…

---

## [ReadOnlyMemoryError() in an ODEProblem](https://discourse.julialang.org/t/readonlymemoryerror-in-an-odeproblem/74189)

<div class="topic-metadata">

**Author:** [@Frazze](https://discourse.julialang.org/u/Frazze)\
**Replies:** 6\
**Last updated:** [January 7, 2022, 2:58pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-an-odeproblem/74189 "2022-01-07T14:58:23Z")

</div>

Hi everyone I’m studying a pde (swift-hohenberg model) converting it in the ODE form. I’ve discretized the laplacian: function Laplacian2D(Nx, lx) hx = lx/Nx D2x = CenteredDifference(2, 2, hx, Nx) Qx = Periodi…

---

## [\[Review wanted\] Adam gradient descent with complicated gradient to fit multivariate gamma convolutions](https://discourse.julialang.org/t/review-wanted-adam-gradient-descent-with-complicated-gradient-to-fit-multivariate-gamma-convolutions/74183)

<div class="topic-metadata">

**Author:** [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Replies:** 2\
**Last updated:** [January 7, 2022, 2:33pm UTC](https://discourse.julialang.org/t/review-wanted-adam-gradient-descent-with-complicated-gradient-to-fit-multivariate-gamma-convolutions/74183 "2022-01-07T14:33:11Z")

</div>

Hi, I have written a code that fits a multivariate gamma convolution to a dataset using a stochastic gradient descent on a home-made loss. Most of the code is directed into the computation of the gradient, which is of c…

---

## [How to print a backtrace?](https://discourse.julialang.org/t/how-to-print-a-backtrace/74164)

<div class="topic-metadata">

**Author:** [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Replies:** 3\
**Last updated:** [January 7, 2022, 2:21pm UTC](https://discourse.julialang.org/t/how-to-print-a-backtrace/74164 "2022-01-07T14:21:46Z")

</div>

How can I print an error and backtrace from within a catch block, the same as if it had not been caught in the REPL?

---

## [Add new field to struct?](https://discourse.julialang.org/t/add-new-field-to-struct/73923)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 11\
**Last updated:** [January 7, 2022, 2:06pm UTC](https://discourse.julialang.org/t/add-new-field-to-struct/73923 "2022-01-07T14:06:03Z")

</div>

Hello! Is there any way to add a field to an already defined struct? I have a case where I have no idea of how many fields I will need, so I would like to be able to do something similar to Matlab’s structs i.e: Matlab…

---

## [String subscript given as integer](https://discourse.julialang.org/t/string-subscript-given-as-integer/17814)

<div class="topic-metadata">

**Author:** [@mforets](https://discourse.julialang.org/u/mforets)\
**Replies:** 6\
**Last updated:** [January 7, 2022, 2:12pm UTC](https://discourse.julialang.org/t/string-subscript-given-as-integer/17814 "2022-01-07T14:12:15Z")

</div>

I’d like to write a function f(n::Int)::String such that f(1) = "x₁", f(2) = "x₂" and so on (assume 1\<=n\<=9 for simplicity). Since julia\> 'x' \* '\\u2081' "x₁" Let n=3; the syntax 'x' \* '\\u' \* string(n + 2080) is invali…

---

## [Issues with Plots.contourf and logarithmic axes](https://discourse.julialang.org/t/issues-with-plots-contourf-and-logarithmic-axes/74185)

<div class="topic-metadata">

**Author:** [@leapsheep](https://discourse.julialang.org/u/leapsheep)\
**Replies:** 1\
**Last updated:** [January 7, 2022, 12:11pm UTC](https://discourse.julialang.org/t/issues-with-plots-contourf-and-logarithmic-axes/74185 "2022-01-07T12:11:15Z")

</div>

The contourf function behaves very strangely when plotting data points on a logarithmic grid. Supplying the x- and y-positions of the data points and setting scale=:log10 completely messes up the plot. Here is a minimal …

---

## [Dates DateTime parse string with microseconds (decimal 6 places)](https://discourse.julialang.org/t/dates-datetime-parse-string-with-microseconds-decimal-6-places/25653)

<div class="topic-metadata">

**Author:** [@Joshua\_Bowles](https://discourse.julialang.org/u/Joshua_Bowles)\
**Replies:** 3\
**Last updated:** [January 7, 2022, 9:48am UTC](https://discourse.julialang.org/t/dates-datetime-parse-string-with-microseconds-decimal-6-places/25653 "2022-01-07T09:48:11Z")

</div>

I’ve got files to import with postgres formatted timestamps to the microseconds (6 digits). I’m unable to find the proper date format. I’ve looked through Dates/test/io.jl as well in this forum. Curious if I’m missing so…

---

## [Improving performance on nested for loops (SparseArrays, LibGEOS)](https://discourse.julialang.org/t/improving-performance-on-nested-for-loops-sparsearrays-libgeos/74038)

<div class="topic-metadata">

**Author:** [@nbalasus](https://discourse.julialang.org/u/nbalasus)\
**Replies:** 10\
**Last updated:** [January 7, 2022, 4:41am UTC](https://discourse.julialang.org/t/improving-performance-on-nested-for-loops-sparsearrays-libgeos/74038 "2022-01-07T04:41:15Z")

</div>

I have two arrays of polygons, one with 9,000,000 polygons and the other with 60,000 polygons. I would like to find the intersecting area of each of these. In the MWE example below where I have reduced the example to 201…

---

## [How to create and fill a vector of Struct as in a Matrix?](https://discourse.julialang.org/t/how-to-create-and-fill-a-vector-of-struct-as-in-a-matrix/74156)

<div class="topic-metadata">

**Author:** [@Amro](https://discourse.julialang.org/u/Amro)\
**Replies:** 12\
**Last updated:** [January 6, 2022, 10:24pm UTC](https://discourse.julialang.org/t/how-to-create-and-fill-a-vector-of-struct-as-in-a-matrix/74156 "2022-01-06T22:24:47Z")

</div>

I have a struct of Rs and a vector R of it. Currently, I am using such the below code to construct R and then change the values of its fields. Base.@kwdef mutable struct Rs I::Vector{Float64} = \[2,2,2\] Dot::Arra…

---

## [Convert from abstract type to julia-type with cost](https://discourse.julialang.org/t/convert-from-abstract-type-to-julia-type-with-cost/73927)

<div class="topic-metadata">

**Author:** [@qiu\_lin](https://discourse.julialang.org/u/qiu_lin)\
**Replies:** 2\
**Last updated:** [January 6, 2022, 9:03pm UTC](https://discourse.julialang.org/t/convert-from-abstract-type-to-julia-type-with-cost/73927 "2022-01-06T21:03:24Z")

</div>

I need to use hypergeometric function define on the whole complex-plane. And I find that Arblib.jl and Nemo.jl fit for me but the problem is that they use abitary types both and thus whatever math manipulation put on the…

---

## [Random array of complex numbers how to do?](https://discourse.julialang.org/t/random-array-of-complex-numbers-how-to-do/30714)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 3\
**Last updated:** [January 6, 2022, 5:22pm UTC](https://discourse.julialang.org/t/random-array-of-complex-numbers-how-to-do/30714 "2022-01-06T17:22:55Z")

</div>

How to create random matrix od complex numer, this way is only for Real part of this. julia\> Complex.(rand(5)) 5-element Array{Complex{Float64},1 0.5247641513084038 + 0.0im 0.1119184762223755 + 0.0im 0.303719618358…

---

## [Macros with multiple parameters](https://discourse.julialang.org/t/macros-with-multiple-parameters/74120)

<div class="topic-metadata">

**Author:** [@gcv](https://discourse.julialang.org/u/gcv)\
**Replies:** 3\
**Last updated:** [January 6, 2022, 4:23pm UTC](https://discourse.julialang.org/t/macros-with-multiple-parameters/74120 "2022-01-06T16:23:14Z")

</div>

I’m having trouble with macros taking multiple parameters. Specifically, I’m writing a macro which needs to take @\_\_DIR\_\_ and an expression as its arguments. Here’s a simplified example: macro tm1(dir, action) :(begi…

---

## [Working with the recent stepplot() changes in ControlSystems.jl](https://discourse.julialang.org/t/working-with-the-recent-stepplot-changes-in-controlsystems-jl/74131)

<div class="topic-metadata">

**Author:** [@adeyemiadeoye](https://discourse.julialang.org/u/adeyemiadeoye)\
**Replies:** 2\
**Last updated:** [January 6, 2022, 2:56pm UTC](https://discourse.julialang.org/t/working-with-the-recent-stepplot-changes-in-controlsystems-jl/74131 "2022-01-06T14:56:08Z")

</div>

I am trying to run the example usage code provided in the README.md file of the ControlSystems.jl repository, but with the recent changes, it seems impossible to produce exactly the same stepplot() results with plot(step…

---

## [Width problem when using printf on chinese characters](https://discourse.julialang.org/t/width-problem-when-using-printf-on-chinese-characters/74124)

<div class="topic-metadata">

**Author:** [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Replies:** 1\
**Last updated:** [January 6, 2022, 1:44pm UTC](https://discourse.julialang.org/t/width-problem-when-using-printf-on-chinese-characters/74124 "2022-01-06T13:44:39Z")

</div>

A Chinese character will normally displays as 2 ascii width, but the format string in printf will treat it as 1 character. This may result in inconsistent string width with the same format string. This is a simple examp…

---

## [Best way to generate random floats over a wide range of magnitudes](https://discourse.julialang.org/t/best-way-to-generate-random-floats-over-a-wide-range-of-magnitudes/74129)

<div class="topic-metadata">

**Author:** [@swishmas](https://discourse.julialang.org/u/swishmas)\
**Replies:** 2\
**Last updated:** [January 6, 2022, 12:10pm UTC](https://discourse.julialang.org/t/best-way-to-generate-random-floats-over-a-wide-range-of-magnitudes/74129 "2022-01-06T12:10:15Z")

</div>

Simple question: rand() generally returns a random number rarely in the range (0,1E-1) and I am interested in a range of random numbers between (0,1E-2). I was wondering if anyone could verify that a solution like rand…

---

## [UnionAll wrapper not eq anymore to free UnionAll when Type lifted - is it a bug or not?](https://discourse.julialang.org/t/unionall-wrapper-not-eq-anymore-to-free-unionall-when-type-lifted-is-it-a-bug-or-not/74118)

<div class="topic-metadata">

**Author:** [@o314](https://discourse.julialang.org/u/o314)\
**Replies:** 3\
**Last updated:** [January 6, 2022, 7:35am UTC](https://discourse.julialang.org/t/unionall-wrapper-not-eq-anymore-to-free-unionall-when-type-lifted-is-it-a-bug-or-not/74118 "2022-01-06T07:35:17Z")

</div>

Let’s define struct A{U,V} end and observe some equalities on data using Test @test A == A{U,V} where {U,V} @test Type{A} == Type{A{U,V} where {U,V}} @test A === A{U,V} where {U,V} @test Type{A} === Type{A{U,V} wher…

---

## [When can tasks yield? Or, how to use SpinLocks safely](https://discourse.julialang.org/t/when-can-tasks-yield-or-how-to-use-spinlocks-safely/73740)

<div class="topic-metadata">

**Author:** [@zsunberg](https://discourse.julialang.org/u/zsunberg)\
**Replies:** 5\
**Last updated:** [January 6, 2022, 6:50am UTC](https://discourse.julialang.org/t/when-can-tasks-yield-or-how-to-use-spinlocks-safely/73740 "2022-01-06T06:50:26Z")

</div>

The following causes a deadlock when running Julia with one thread: l = Threads.SpinLock() function f(l) lock(l) sleep(5) unlock(l) end Threads.@spawn f(l) sleep(1) lock(l) I understand that this is becau…

---

## [JULIA\_DEPOT\_PATH and JULIA\_PROJECT](https://discourse.julialang.org/t/julia-depot-path-and-julia-project/73745)

<div class="topic-metadata">

**Author:** [@apg](https://discourse.julialang.org/u/apg)\
**Replies:** 58\
**Last updated:** [January 6, 2022, 3:28am UTC](https://discourse.julialang.org/t/julia-depot-path-and-julia-project/73745 "2022-01-06T03:28:45Z")

</div>

I am trying to automatically pick and choose which environment (and ultimately the packages therein) to use. For the purpose of testing only, I have ~/.julia and ~/.julia\_dev directories with packages and environments de…

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

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