# General Usage

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

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

**Page:** 761

---

## [Unit testing that depends on random number generation](https://discourse.julialang.org/t/unit-testing-that-depends-on-random-number-generation/38187)

<div class="topic-metadata">

**Author:** [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Replies:** 8\
**Last updated:** [April 27, 2020, 6:38am UTC](https://discourse.julialang.org/t/unit-testing-that-depends-on-random-number-generation/38187 "2020-04-27T06:38:19Z")

</div>

I have a package, DependentBootstrap, where the unit tests rely explicitly on values generated by randn. Currently, I set the seed before each test to ensure each run is identical. Of course, this runs into problems when…

---

## [Variable scope in IJulia Jupyter notebook](https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264)

<div class="topic-metadata">

**Author:** [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)\
**Replies:** 2\
**Last updated:** [April 27, 2020, 12:57am UTC](https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264 "2020-04-27T00:57:26Z")

</div>

I’m using Jupyter notebook by doing: using IJulia notebook() Now, if I try the following code: a = 1 for i = 1:2 a = a+1 end and the value of a would be 3. Isn’t it supposed to be an error as for loop can not mod…

---

## [Creating a type from a Symbol inside a macro of a submodule?](https://discourse.julialang.org/t/creating-a-type-from-a-symbol-inside-a-macro-of-a-submodule/38247)

<div class="topic-metadata">

**Author:** [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Replies:** 3\
**Last updated:** [April 26, 2020, 11:48pm UTC](https://discourse.julialang.org/t/creating-a-type-from-a-symbol-inside-a-macro-of-a-submodule/38247 "2020-04-26T23:48:00Z")

</div>

I am sorry if this is trivial, but I am trying to access the fields of a type, which is passed as a Symbol to a macro inside a submodule (in an imported one). Here is what I mean: struct Foo end ​ macro macro1(ex) …

---

## [Error when using a PackageCompiler sys image in a different container](https://discourse.julialang.org/t/error-when-using-a-packagecompiler-sys-image-in-a-different-container/38074)

<div class="topic-metadata">

**Author:** [@mmiller](https://discourse.julialang.org/u/mmiller)\
**Replies:** 2\
**Last updated:** [April 26, 2020, 10:59pm UTC](https://discourse.julialang.org/t/error-when-using-a-packagecompiler-sys-image-in-a-different-container/38074 "2020-04-26T22:59:05Z")

</div>

Hi, I’m getting the following error when trying to use a system image in a Python 3.8 container (with Julia installed). The system image was built using the Julia 1.4.1 docker image, using PackageCompiler ( incremental=…

---

## [Show off Julia performance on your PC!](https://discourse.julialang.org/t/show-off-julia-performance-on-your-pc/33606)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 53\
**Last updated:** [April 26, 2020, 9:21pm UTC](https://discourse.julialang.org/t/show-off-julia-performance-on-your-pc/33606 "2020-04-26T21:21:39Z")

</div>

I just built a new PC and, after asking some questions here about performance and getting some interesting answers, I thought it would be fun to start a thread where people can show off their builds and, more importantly…

---

## [Scope of @time](https://discourse.julialang.org/t/scope-of-time/38261)

<div class="topic-metadata">

**Author:** [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)\
**Replies:** 2\
**Last updated:** [April 26, 2020, 9:18pm UTC](https://discourse.julialang.org/t/scope-of-time/38261 "2020-04-26T21:18:15Z")

</div>

Is the scope of @time supposed to be local? If I do the following: x = 1 @time x = 2 Then the value of x will be 2. Why can I modify the value of a global variable x in a local scope @time? Similarly, I can declare v…

---

## [Include debug symbols in sysimage from PackageCompiler.jl?](https://discourse.julialang.org/t/include-debug-symbols-in-sysimage-from-packagecompiler-jl/38034)

<div class="topic-metadata">

**Author:** [@OliverEvans96](https://discourse.julialang.org/u/OliverEvans96)\
**Replies:** 2\
**Last updated:** [April 26, 2020, 6:25pm UTC](https://discourse.julialang.org/t/include-debug-symbols-in-sysimage-from-packagecompiler-jl/38034 "2020-04-26T18:25:11Z")

</div>

I’m attempting to use PackageCompiler.jl to produce a .so containing Julia functions that can be called directly from C (after some julia initialization in the C code), as suggested by @kristoffer.carlsson in this githu…

---

## [Precompiling of parametric constructors](https://discourse.julialang.org/t/precompiling-of-parametric-constructors/38243)

<div class="topic-metadata">

**Author:** [@Isaia\_Nisoli](https://discourse.julialang.org/u/Isaia_Nisoli)\
**Replies:** 1\
**Last updated:** [April 26, 2020, 5:07pm UTC](https://discourse.julialang.org/t/precompiling-of-parametric-constructors/38243 "2020-04-26T17:07:31Z")

</div>

Dear all, I am trying to implement some variable tracking types in a package colled DiffCheckNumbers.jl. The main issue I’m facing now is the slowdown that is generated by the compilation of the constructors. struct D…

---

## [How to query key presses](https://discourse.julialang.org/t/how-to-query-key-presses/38242)

<div class="topic-metadata">

**Author:** [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Replies:** 1\
**Last updated:** [April 26, 2020, 4:51pm UTC](https://discourse.julialang.org/t/how-to-query-key-presses/38242 "2020-04-26T16:51:24Z")

</div>

Is there a library which is able to query if a key is currently being pressed or not? I guess this would usually be done using OS-specific calls. The goal would be to detect multiple simultaneous key presses of a keybo…

---

## [Extend a varargs function for mixed types](https://discourse.julialang.org/t/extend-a-varargs-function-for-mixed-types/38233)

<div class="topic-metadata">

**Author:** [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Replies:** 2\
**Last updated:** [April 26, 2020, 2:57pm UTC](https://discourse.julialang.org/t/extend-a-varargs-function-for-mixed-types/38233 "2020-04-26T14:57:51Z")

</div>

Is it possible to specialize on a varargs function if at least one of the arguments is of a certain type? Maybe best explained with an MWE: # Assume this is defined in another package which the code below depends on j…

---

## [Type and methods info in macro](https://discourse.julialang.org/t/type-and-methods-info-in-macro/38199)

<div class="topic-metadata">

**Author:** [@bpou](https://discourse.julialang.org/u/bpou)\
**Replies:** 0\
**Last updated:** [April 25, 2020, 4:40pm UTC](https://discourse.julialang.org/t/type-and-methods-info-in-macro/38199 "2020-04-25T16:40:01Z")

</div>

Hello, I’ve been attempting to implement a simple APL in julia. Something similar has been done here: https://github.com/shashi/APL.jl, but that is an interpreter. I wanted to do it as a syntax transformation to use as …

---

## [Manually specialized function is faster than the generic version](https://discourse.julialang.org/t/manually-specialized-function-is-faster-than-the-generic-version/38223)

<div class="topic-metadata">

**Author:** [@fjarri](https://discourse.julialang.org/u/fjarri)\
**Replies:** 2\
**Last updated:** [April 26, 2020, 6:58am UTC](https://discourse.julialang.org/t/manually-specialized-function-is-faster-than-the-generic-version/38223 "2020-04-26T06:58:36Z")

</div>

The code: using BenchmarkTools function adc(a::T, b::T, carry::T) where T T2 = widen(T) ret = (a % T2) + (b % T2) + (carry % T2) ret % T, (ret \>\> 64) % T end function mac(a::T, b::T, c::T, carry::T) wher…

---

## [How to make TCP socket listening more robust to errors?](https://discourse.julialang.org/t/how-to-make-tcp-socket-listening-more-robust-to-errors/38184)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 1\
**Last updated:** [April 26, 2020, 6:52am UTC](https://discourse.julialang.org/t/how-to-make-tcp-socket-listening-more-robust-to-errors/38184 "2020-04-26T06:52:03Z")

</div>

I’ve written a simple package for evaluating functions and passing data between Julia processes using TCP sockets. It works pretty well, as long as the function evaluations don’t produce any errors. If the an error occ…

---

## [ERROR: LoadError: UndefVarError: A not defined](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116)

<div class="topic-metadata">

**Author:** [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)\
**Replies:** 6\
**Last updated:** [April 25, 2020, 9:03pm UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-a-not-defined/38116 "2020-04-25T21:03:15Z")

</div>

Hey all, I have the following code: function POMDPs.action(pol::MyCustomType,s::S)::A where {S,A} # ignore end This code works on Julia 1.1.1 but errors on Julia 1.3 + and says “ERROR: LoadError: UndefVarError: A no…

---

## [ArgumentError y = \[y;df\[:,Symbol(v)\]\]](https://discourse.julialang.org/t/argumenterror-y-y-df-symbol-v/38198)

<div class="topic-metadata">

**Author:** [@bujun\_mei](https://discourse.julialang.org/u/bujun_mei)\
**Replies:** 1\
**Last updated:** [April 25, 2020, 7:25pm UTC](https://discourse.julialang.org/t/argumenterror-y-y-df-symbol-v/38198 "2020-04-25T19:25:29Z")

</div>

y = Array{Float64,1}() print(mme.depVarVec) for v in mme.depVarVec y = \[y;df\[:,Symbol(v)\]\] end output: AbstractString\[“y1”, “y2”\] ArgumentError: column name :y1 not found in the data frame; existing most similar n…

---

## [Why julia is not using all my CPU?](https://discourse.julialang.org/t/why-julia-is-not-using-all-my-cpu/38106)

<div class="topic-metadata">

**Author:** [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Replies:** 18\
**Last updated:** [April 25, 2020, 4:29pm UTC](https://discourse.julialang.org/t/why-julia-is-not-using-all-my-cpu/38106 "2020-04-25T16:29:10Z")

</div>

I am running the following (test) code on a 24 core machine julia\> Threads.nthreads() 24 julia\> using LinearAlgebra julia\> function foo() Threads.@threads for i in 1:1000000 H = rand(100, 100…

---

## [How to broadcast already defined function to all worker processes in jupyter？](https://discourse.julialang.org/t/how-to-broadcast-already-defined-function-to-all-worker-processes-in-jupyter/38194)

<div class="topic-metadata">

**Author:** [@Pingzi\_Kang](https://discourse.julialang.org/u/Pingzi_Kang)\
**Replies:** 1\
**Last updated:** [April 25, 2020, 2:18pm UTC](https://discourse.julialang.org/t/how-to-broadcast-already-defined-function-to-all-worker-processes-in-jupyter/38194 "2020-04-25T14:18:24Z")

</div>

Hello everyone, I am a beginner for Julia. When I use Distributed to speed up my program, I found such a problem: I have defined a large number of functions and constants in Jupyter, if I need to use Distributed, then I…

---

## [Savefig not searchable pdf in 1.4](https://discourse.julialang.org/t/savefig-not-searchable-pdf-in-1-4/38172)

<div class="topic-metadata">

**Author:** [@Varghese](https://discourse.julialang.org/u/Varghese)\
**Replies:** 2\
**Last updated:** [April 25, 2020, 2:08pm UTC](https://discourse.julialang.org/t/savefig-not-searchable-pdf-in-1-4/38172 "2020-04-25T14:08:50Z")

</div>

In Julia 1.2 savefig to pdf creates low file size with searchable text. With Julia 1.4, the file size is a lot bigger and the text is not searchable, (but the png images are prettier). How do I create searchable pdf in 1…

---

## [Submodules discouraged?](https://discourse.julialang.org/t/submodules-discouraged/38190)

<div class="topic-metadata">

**Author:** [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Replies:** 3\
**Last updated:** [April 25, 2020, 1:06pm UTC](https://discourse.julialang.org/t/submodules-discouraged/38190 "2020-04-25T13:06:11Z")

</div>

I think I’ve heard on Discourse and Slack that using submodules as internal helper modules for code organization is discouraged, tends to cause more problems than it solves, etc. This seems quite surprising to me. Is it…

---

## [How to parse a string as a Date where the year is a leap one, if the year is not specified in the string?](https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 2\
**Last updated:** [April 25, 2020, 5:22am UTC](https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176 "2020-04-25T05:22:59Z")

</div>

I have a series of date strings of the form "01 Feb", "02 Feb". I am trying to parse these as Date objects, except it fails as it doesn’t recognize that there were 29 days in Feb this year. Since the year is not specifi…

---

## [Dispatch on parametric type](https://discourse.julialang.org/t/dispatch-on-parametric-type/37978)

<div class="topic-metadata">

**Author:** [@mzilhao](https://discourse.julialang.org/u/mzilhao)\
**Replies:** 11\
**Last updated:** [April 24, 2020, 10:05pm UTC](https://discourse.julialang.org/t/dispatch-on-parametric-type/37978 "2020-04-24T22:05:31Z")

</div>

I’m writing an application where I’ve found it convenient to dispatch on the parameters of some structs. Something like the following: abstract type MyType end abstract type A \<: MyType end abstract type B \<: MyType end…

---

## [This made me smile](https://discourse.julialang.org/t/this-made-me-smile/38064)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 5\
**Last updated:** [April 24, 2020, 9:12pm UTC](https://discourse.julialang.org/t/this-made-me-smile/38064 "2020-04-24T21:12:57Z")

</div>

Forgive me for patting myself on the back here, but I am so happy with the outcome. In an SEIR simulation of the COVID-19 outbreak (Susceptible, Exposed, Infected, Removed (Recovery or Death), I use a decision tree to t…

---

## [3D polygons in Plots.jl](https://discourse.julialang.org/t/3d-polygons-in-plots-jl/9761)

<div class="topic-metadata">

**Author:** [@rcnlee](https://discourse.julialang.org/u/rcnlee)\
**Replies:** 4\
**Last updated:** [April 24, 2020, 8:55pm UTC](https://discourse.julialang.org/t/3d-polygons-in-plots-jl/9761 "2020-04-24T20:55:01Z")

</div>

Is there an equivalent to Matlab’s fill3 in Plots.jl to create filled shapes in 3D? I see Plots.Shape, but it looks like it only supports 2D. Thanks!

---

## [High CPU Usage on Startup - VSCode OSX](https://discourse.julialang.org/t/high-cpu-usage-on-startup-vscode-osx/33280)

<div class="topic-metadata">

**Author:** [@loki](https://discourse.julialang.org/u/loki)\
**Replies:** 7\
**Last updated:** [April 24, 2020, 7:20pm UTC](https://discourse.julialang.org/t/high-cpu-usage-on-startup-vscode-osx/33280 "2020-04-24T19:20:57Z")

</div>

Hello, I was forced to switch over from Atom to VSCode and noticed some strange behavior when starting VSCode. Whenever I start up VSCode a Julia process is created that uses 100% CPU usage even before Julia/REPL is sta…

---

## [Avoid repeated memory allocation by defining an Array{Float64} outside of optimize() using Optim.jl, ForwardDiff.jl](https://discourse.julialang.org/t/avoid-repeated-memory-allocation-by-defining-an-array-float64-outside-of-optimize-using-optim-jl-forwarddiff-jl/37357)

<div class="topic-metadata">

**Author:** [@Maximilian](https://discourse.julialang.org/u/Maximilian)\
**Replies:** 7\
**Last updated:** [April 24, 2020, 6:58pm UTC](https://discourse.julialang.org/t/avoid-repeated-memory-allocation-by-defining-an-array-float64-outside-of-optimize-using-optim-jl-forwarddiff-jl/37357 "2020-04-24T18:58:01Z")

</div>

I am using Optim.jl with an objective that is computed by multipliying, transposing and inverting some matrices (maximum size of about 500x500). However, I have only a few parameters (maximum 200), each one having a fixe…

---

## [Automatic generation of parametric functions](https://discourse.julialang.org/t/automatic-generation-of-parametric-functions/38151)

<div class="topic-metadata">

**Author:** [@Isaia\_Nisoli](https://discourse.julialang.org/u/Isaia_Nisoli)\
**Replies:** 5\
**Last updated:** [April 24, 2020, 6:24pm UTC](https://discourse.julialang.org/t/automatic-generation-of-parametric-functions/38151 "2020-04-24T18:24:08Z")

</div>

Dear all, I have a parametric Type, for simplicity suppose something like struct Foo{T} x::T end a list of function symbols (i.e. :sin, :cos, etc) and I would like to generate a function for each element in my …

---

## [Date(year + quarter)?](https://discourse.julialang.org/t/date-year-quarter/37782)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 3\
**Last updated:** [April 18, 2020, 12:00am UTC](https://discourse.julialang.org/t/date-year-quarter/37782 "2020-04-18T00:00:35Z")

</div>

Good day. I have a quarterly dataset. Would you suggest, How I can keep dates in format: year + quarter. For instance: 2010Y3Q. So Dates allow creating date by date(year, month). Is it some way to create date by date(y…

---

## [A couple of questions about Artifacts](https://discourse.julialang.org/t/a-couple-of-questions-about-artifacts/33367)

<div class="topic-metadata">

**Author:** [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Replies:** 11\
**Last updated:** [April 24, 2020, 3:40pm UTC](https://discourse.julialang.org/t/a-couple-of-questions-about-artifacts/33367 "2020-04-24T15:40:25Z")

</div>

Coming from an R background where it is common to have data sets included with packages I have been thinking about similar capabilities for Julia packages. One approach would be to use Artifacts as described in Pkg + Bin…

---

## [Using IOStreams with Distributed parallelism](https://discourse.julialang.org/t/using-iostreams-with-distributed-parallelism/37966)

<div class="topic-metadata">

**Author:** [@Ward9250](https://discourse.julialang.org/u/Ward9250)\
**Replies:** 2\
**Last updated:** [April 24, 2020, 1:38pm UTC](https://discourse.julialang.org/t/using-iostreams-with-distributed-parallelism/37966 "2020-04-24T13:38:57Z")

</div>

I’ve got a serial function: function serial\_mem(::Type{M}, input::DatastoreBuffer{\<:ReadDatastore}, count\_mode::CountMode, range::AbstractRange = 1:length(input)) where {M\<:AbstractMer} @info "\[Process: $(myid())\] C…

---

## [Macro for binary data deserialization into tuples of variable types](https://discourse.julialang.org/t/macro-for-binary-data-deserialization-into-tuples-of-variable-types/38088)

<div class="topic-metadata">

**Author:** [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Replies:** 9\
**Last updated:** [April 24, 2020, 10:34am UTC](https://discourse.julialang.org/t/macro-for-binary-data-deserialization-into-tuples-of-variable-types/38088 "2020-04-24T10:34:08Z")

</div>

Can somebody help with this case? ## I've started with reinterpreting some complex types from a binary stream: bytevec = UInt8\[0x01, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00\] reinterpret(Tuple{Int8, Int16, Int32}, bytevec) #…

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

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