# General Usage

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

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

**Page:** 723

---

## [Printing from a task](https://discourse.julialang.org/t/printing-from-a-task/43698)

<div class="topic-metadata">

**Author:** [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Replies:** 1\
**Last updated:** [July 26, 2020, 9:57am UTC](https://discourse.julialang.org/t/printing-from-a-task/43698 "2020-07-26T09:57:38Z")

</div>

In testing my package I have problems to print from an asynchronous task to the REPL. Here is a MWE: struct Msg a b end function tpr(ch::Channel) while true msg = take!(ch) if msg isa Msg …

---

## [Gradient through categorical distribution slow and has many allocations](https://discourse.julialang.org/t/gradient-through-categorical-distribution-slow-and-has-many-allocations/43690)

<div class="topic-metadata">

**Author:** [@scottjordan](https://discourse.julialang.org/u/scottjordan)\
**Replies:** 0\
**Last updated:** [July 26, 2020, 1:21am UTC](https://discourse.julialang.org/t/gradient-through-categorical-distribution-slow-and-has-many-allocations/43690 "2020-07-26T01:21:18Z")

</div>

I am trying have performant gradients computations for a function the defines a conditional distribution over a discrete space. More specifically, I want the gradient of the following function: import Flux import Zygote…

---

## [Vector of Contiguous Booleans to Vector of Unit Ranges](https://discourse.julialang.org/t/vector-of-contiguous-booleans-to-vector-of-unit-ranges/43674)

<div class="topic-metadata">

**Author:** [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Replies:** 14\
**Last updated:** [July 25, 2020, 10:36pm UTC](https://discourse.julialang.org/t/vector-of-contiguous-booleans-to-vector-of-unit-ranges/43674 "2020-07-25T22:36:33Z")

</div>

So consider the following vector: \[true true, false, true, true , false\] we would want the code to return \[1:2,3:3,4:5,6:6\] or: \[true true, true, true, true, false\] → \[1:5, 6:6\] Basically its a groupby or chunk operati…

---

## [Updating Makie subscene mouse click limits when zooming and panning](https://discourse.julialang.org/t/updating-makie-subscene-mouse-click-limits-when-zooming-and-panning/43680)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 0\
**Last updated:** [July 25, 2020, 9:38pm UTC](https://discourse.julialang.org/t/updating-makie-subscene-mouse-click-limits-when-zooming-and-panning/43680 "2020-07-25T21:38:37Z")

</div>

This example: using Makie, Random scene = Scene(resolution = (1200, 1500)) scene1 = Scene(scene, IRect(0, 0, 1200, 900)) image = rand(1:4, 640, 480) imagenode = Node(image) image!(scene1, imagenode, scale\_plot = false…

---

## [Indexing an array with rounded array of floating point indexes](https://discourse.julialang.org/t/indexing-an-array-with-rounded-array-of-floating-point-indexes/43639)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 5\
**Last updated:** [July 25, 2020, 5:46pm UTC](https://discourse.julialang.org/t/indexing-an-array-with-rounded-array-of-floating-point-indexes/43639 "2020-07-25T17:46:48Z")

</div>

I have: a = rand(Int32, 10, 10) i = Float32\[8.47, 8.47\] and I want access an element e of a using rounded values in i as 2D index. Is there a more concise way of doing it than: j = Int.(round.(i)) e = a\[j\[1\], j\[2\]\]

---

## [When does a package activation/instantiation trigger a build?](https://discourse.julialang.org/t/when-does-a-package-activation-instantiation-trigger-a-build/43649)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 3\
**Last updated:** [July 25, 2020, 3:17pm UTC](https://discourse.julialang.org/t/when-does-a-package-activation-instantiation-trigger-a-build/43649 "2020-07-25T15:17:48Z")

</div>

When is a build triggered for a package that has a deps/build.jl? It is not triggered when I do activate/instantiate. Is there an automatic build? Or is an explicit build() required?

---

## [Mechanism for build() in mybinder?](https://discourse.julialang.org/t/mechanism-for-build-in-mybinder/43644)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 1\
**Last updated:** [July 25, 2020, 2:50am UTC](https://discourse.julialang.org/t/mechanism-for-build-in-mybinder/43644 "2020-07-25T02:50:11Z")

</div>

I have a package of tutorials. I can use the package locally by using Pkg; Pkg.activate("."); Pkg.instantiate() Pkg.build() This builds the tutorial notebooks. How do I get these notebooks built on mybinder?

---

## [Function methods based solely on element type of array of arbitrary dimension](https://discourse.julialang.org/t/function-methods-based-solely-on-element-type-of-array-of-arbitrary-dimension/43653)

<div class="topic-metadata">

**Author:** [@jerjorg](https://discourse.julialang.org/u/jerjorg)\
**Replies:** 6\
**Last updated:** [July 25, 2020, 12:10pm UTC](https://discourse.julialang.org/t/function-methods-based-solely-on-element-type-of-array-of-arbitrary-dimension/43653 "2020-07-25T12:10:11Z")

</div>

I’m new to Julia, so my question may be naive or obvious. I’ve searched the documentation and elsewhere but can’t find an answer. Is it possible to define a function in Julia that takes as an argument an array of arbitra…

---

## [One-pass NaN variance](https://discourse.julialang.org/t/one-pass-nan-variance/43622)

<div class="topic-metadata">

**Author:** [@Benjia](https://discourse.julialang.org/u/Benjia)\
**Replies:** 3\
**Last updated:** [July 25, 2020, 4:36am UTC](https://discourse.julialang.org/t/one-pass-nan-variance/43622 "2020-07-25T04:36:37Z")

</div>

I’d like to try and use the implementation of Welford’s algorithm in Base.Statistics, but filter out NaNs along the way. First thing I tried is the following: Statistics.var(Iterators.filter(!isnan, vals)) However, th…

---

## [Is there a way to reinterpret a Float64 to 2 Int32?](https://discourse.julialang.org/t/is-there-a-way-to-reinterpret-a-float64-to-2-int32/43596)

<div class="topic-metadata">

**Author:** [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Replies:** 3\
**Last updated:** [July 24, 2020, 11:24pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-reinterpret-a-float64-to-2-int32/43596 "2020-07-24T23:24:46Z")

</div>

I’m writing some manually vectorize some code (for computing exp), and I was looking for a way to view the memory as 2 int32s (if it helps, I only need the lower one). Is there a way to do this? The reason I want Int32 r…

---

## [Resolve GlobalRef in a generated function](https://discourse.julialang.org/t/resolve-globalref-in-a-generated-function/43645)

<div class="topic-metadata">

**Author:** [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Replies:** 2\
**Last updated:** [July 24, 2020, 11:45pm UTC](https://discourse.julialang.org/t/resolve-globalref-in-a-generated-function/43645 "2020-07-24T23:45:46Z")

</div>

I’m using @dynamo from IRTools to rewrite all calls inside a passed function. There is a set of functions - let’s call them primitives - that I don’t want to rewrite, and thus I need to check if a particular function is …

---

## [Get rid of a grid behind the text in Makie](https://discourse.julialang.org/t/get-rid-of-a-grid-behind-the-text-in-makie/43641)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 1\
**Last updated:** [July 24, 2020, 10:28pm UTC](https://discourse.julialang.org/t/get-rid-of-a-grid-behind-the-text-in-makie/43641 "2020-07-24T22:28:29Z")

</div>

Running this snippet: using Makie, Random scene = Scene(resolution = (1200, 1500)) scene1 = Scene(scene, IRect(0, 0, 1200, 900)) image = rand(1:4, 640, 480) imagenode = Node(image) image!(scene1, imagenode, scale\_plot…

---

## [ChainRules rrule for a fairly simple function](https://discourse.julialang.org/t/chainrules-rrule-for-a-fairly-simple-function/43593)

<div class="topic-metadata">

**Author:** [@omalled](https://discourse.julialang.org/u/omalled)\
**Replies:** 2\
**Last updated:** [July 24, 2020, 10:02pm UTC](https://discourse.julialang.org/t/chainrules-rrule-for-a-fairly-simple-function/43593 "2020-07-24T22:02:44Z")

</div>

I have some code that roughly follows this pattern where a function g iteratively calls a function f, stores the results in an array where the input to the next call to f involves the output of the last call to f, and re…

---

## [Memory allocation in broadcast assignment](https://discourse.julialang.org/t/memory-allocation-in-broadcast-assignment/43613)

<div class="topic-metadata">

**Author:** [@serenity4](https://discourse.julialang.org/u/serenity4)\
**Replies:** 3\
**Last updated:** [July 24, 2020, 8:05pm UTC](https://discourse.julialang.org/t/memory-allocation-in-broadcast-assignment/43613 "2020-07-24T20:05:33Z")

</div>

Hi! I am struggling to keep a certain level of flexibility and abstraction while optimizing for performance. For example, in the following function, I am doing some processing and modify an array arr in-place. arr = zer…

---

## [Avoiding type instabilities (with StaticKernels)](https://discourse.julialang.org/t/avoiding-type-instabilities-with-statickernels/43574)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 3\
**Last updated:** [July 24, 2020, 7:24pm UTC](https://discourse.julialang.org/t/avoiding-type-instabilities-with-statickernels/43574 "2020-07-24T19:24:38Z")

</div>

I am trying to construct a Kernel from StaticKernels.jl dynamically. I would like to pass the window range and the function to apply as variables. The problem is that the axes of the Kernel are a part of the type informa…

---

## [How can I implement positive Domain for sundials CVODE\_BDF ? Also, try to compare both isoutofdomain , with julia solvers, one question there, Thanks](https://discourse.julialang.org/t/how-can-i-implement-positive-domain-for-sundials-cvode-bdf-also-try-to-compare-both-isoutofdomain-with-julia-solvers-one-question-there-thanks/43390)

<div class="topic-metadata">

**Author:** [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Replies:** 4\
**Last updated:** [July 24, 2020, 5:40pm UTC](https://discourse.julialang.org/t/how-can-i-implement-positive-domain-for-sundials-cvode-bdf-also-try-to-compare-both-isoutofdomain-with-julia-solvers-one-question-there-thanks/43390 "2020-07-24T17:40:00Z")

</div>

On the below problem, I had two questions When applying kencarp4 isoutofdomain is being applied to both states rather than the second du2 like I want to , so the IC is being populated for both states, but I expect onl…

---

## [Best practices in dealing avoiding with precision/floating round of problems when solving ODE's? Thank you](https://discourse.julialang.org/t/best-practices-in-dealing-avoiding-with-precision-floating-round-of-problems-when-solving-odes-thank-you/43394)

<div class="topic-metadata">

**Author:** [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Replies:** 2\
**Last updated:** [July 24, 2020, 5:31pm UTC](https://discourse.julialang.org/t/best-practices-in-dealing-avoiding-with-precision-floating-round-of-problems-when-solving-odes-thank-you/43394 "2020-07-24T17:31:40Z")

</div>

Here is an extreme case I posed. Here, I end up with a domain error, because I start at 0.1 ( any higher ) one parameter will give a domain error, I chose du\[2\] to be 0 or close to it with a negative value. I get a domai…

---

## [Calculation of gradient not working for an ODEproblem that uses 2D or 3D arrays](https://discourse.julialang.org/t/calculation-of-gradient-not-working-for-an-odeproblem-that-uses-2d-or-3d-arrays/42877)

<div class="topic-metadata">

**Author:** [@yanz4](https://discourse.julialang.org/u/yanz4)\
**Replies:** 1\
**Last updated:** [July 24, 2020, 3:41pm UTC](https://discourse.julialang.org/t/calculation-of-gradient-not-working-for-an-odeproblem-that-uses-2d-or-3d-arrays/42877 "2020-07-24T15:41:03Z")

</div>

Solving a set of 30 coupled pairs of 2 differential equations with u, du a 2x30 2D array results in ERROR: DimensionMismatch(“arrays could not be broadcast to a common size; got a dimension with lengths 2 and 60”). T…

---

## [Do-block map with zero argument do-block](https://discourse.julialang.org/t/do-block-map-with-zero-argument-do-block/43585)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 6\
**Last updated:** [July 24, 2020, 3:23pm UTC](https://discourse.julialang.org/t/do-block-map-with-zero-argument-do-block/43585 "2020-07-24T15:23:03Z")

</div>

This section of the Julia manual says that a plain do would declare that what follows is an anonymous function of the form () -\> ... So I would expect this to work: julia\> map(1:3) do rand(10:99) …

---

## [How to achieve the greatest speed with nested loops?](https://discourse.julialang.org/t/how-to-achieve-the-greatest-speed-with-nested-loops/43578)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 10\
**Last updated:** [July 24, 2020, 2:47pm UTC](https://discourse.julialang.org/t/how-to-achieve-the-greatest-speed-with-nested-loops/43578 "2020-07-24T14:47:20Z")

</div>

I have a large three-dimensional array X and wish to compute the sum over i of X\[i,j,m\] \* X\[i,t,m\] producing a three-dimensional array Y. I’ve tried the following (my arrays will be larger than this). using BenchmarkT…

---

## [Question on functions as parameters](https://discourse.julialang.org/t/question-on-functions-as-parameters/43618)

<div class="topic-metadata">

**Author:** [@janrpeters](https://discourse.julialang.org/u/janrpeters)\
**Replies:** 2\
**Last updated:** [July 24, 2020, 2:44pm UTC](https://discourse.julialang.org/t/question-on-functions-as-parameters/43618 "2020-07-24T14:44:17Z")

</div>

Let’s assume I would like write a function that takes functions as parameters: function f1(f::Function) println("f maps from Float64 to Int64") end and I only want to allow functions function f(x:: Float64) :: In…

---

## [Incomplete initialization (control which fields are initialized in \`new\`)](https://discourse.julialang.org/t/incomplete-initialization-control-which-fields-are-initialized-in-new/43452)

<div class="topic-metadata">

**Author:** [@FedericoStra](https://discourse.julialang.org/u/FedericoStra)\
**Replies:** 33\
**Last updated:** [July 24, 2020, 11:17am UTC](https://discourse.julialang.org/t/incomplete-initialization-control-which-fields-are-initialized-in-new/43452 "2020-07-24T11:17:55Z")

</div>

Following the guidelines regarding incomplete initialization and parametric constructors, I can create a type struct P{T} x::T y::T P{T}(x::T, y::T) where T = new{T}(x, y) P{T}(x::T) where T = new{T}(x)…

---

## [Non-Unique sets of n elements with replacement](https://discourse.julialang.org/t/non-unique-sets-of-n-elements-with-replacement/43579)

<div class="topic-metadata">

**Author:** [@PT.303](https://discourse.julialang.org/u/PT.303)\
**Replies:** 3\
**Last updated:** [July 24, 2020, 6:07am UTC](https://discourse.julialang.org/t/non-unique-sets-of-n-elements-with-replacement/43579 "2020-07-24T06:07:39Z")

</div>

Given a vector v = \[1,…,n\], I am trying to compute all non-unique sets of k elements with replacement. For example, v = \[1, 2, 3, 4, 5\] and k = 3: should result in \[1,1,1\], \[1,1,2\], \[1,1,3\], \[1,1,4\], \[1,1,5\], \[1,2,1\],…

---

## [Using Unicode characters like \\to and \\ne instead of -\> and !=](https://discourse.julialang.org/t/using-unicode-characters-like-to-and-ne-instead-of-and/43597)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 3\
**Last updated:** [July 24, 2020, 3:55am UTC](https://discourse.julialang.org/t/using-unicode-characters-like-to-and-ne-instead-of-and/43597 "2020-07-24T03:55:09Z")

</div>

I just discovered that I can use Unicode characters like \\to and \\ne instead of -\> and !=. Is anyone using them in their daily coding? In official Julia packages?

---

## [Bug in DataFrames grouping](https://discourse.julialang.org/t/bug-in-dataframes-grouping/43599)

<div class="topic-metadata">

**Author:** [@affans](https://discourse.julialang.org/u/affans)\
**Replies:** 8\
**Last updated:** [July 24, 2020, 3:34am UTC](https://discourse.julialang.org/t/bug-in-dataframes-grouping/43599 "2020-07-24T03:34:25Z")

</div>

Here is a reproducible example, and I explain the bug at the end. I am just copying/pasting my code here, and some of the steps may not be needed. But it’s fully contained code, not very complicated, and documented. It s…

---

## [String pool / indirect array analogue to make a struct isbits?](https://discourse.julialang.org/t/string-pool-indirect-array-analogue-to-make-a-struct-isbits/43503)

<div class="topic-metadata">

**Author:** [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Replies:** 5\
**Last updated:** [July 23, 2020, 10:09pm UTC](https://discourse.julialang.org/t/string-pool-indirect-array-analogue-to-make-a-struct-isbits/43503 "2020-07-23T22:09:30Z")

</div>

I have a program which ingests JSON describe a list of objects. For the sake of example, let’s say each object is a Cartesian point with a name: struct NamedPoint x::Float64 y::Float64 name::String end The …

---

## [Fast math in NASA benchmark](https://discourse.julialang.org/t/fast-math-in-nasa-benchmark/43580)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 8\
**Last updated:** [July 23, 2020, 9:16pm UTC](https://discourse.julialang.org/t/fast-math-in-nasa-benchmark/43580 "2020-07-23T21:16:53Z")

</div>

I noticed in this benchmark that the --fast-math GCC option was far more effective in reducing the runtime then the --math-mode=fast Julia option. What do you think is the reason for that?

---

## [How to do "((1,2), 3) .+ ((1,2), 3)"?](https://discourse.julialang.org/t/how-to-do-1-2-3-1-2-3/43582)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 5\
**Last updated:** [July 23, 2020, 8:55pm UTC](https://discourse.julialang.org/t/how-to-do-1-2-3-1-2-3/43582 "2020-07-23T20:55:46Z")

</div>

TL;DR: How can we “broadcast” a function over several nested Tuples such as ((1,2), 3) .+ ((1,2), 3)? So, say I have several objects x\_i that are tuples of tuples and numbers (each of the tuples itself a tuple of tuples…

---

## [Irregularity in array definition API](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 4\
**Last updated:** [July 23, 2020, 7:18pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573 "2020-07-23T19:18:03Z")

</div>

I can define an uninitialized array this way: a = Array{Int32, 2}(undef, 10, 10) but I can’t define an initialized array the same way: a = Array{Int32, 2}(42, 10, 10) I have to use this form instead: a = fill(Int32(…

---

## [Will running Pkg.test compile all of the package functions? (for precompile\_execution\_file in PackageCompiler)](https://discourse.julialang.org/t/will-running-pkg-test-compile-all-of-the-package-functions-for-precompile-execution-file-in-packagecompiler/43571)

<div class="topic-metadata">

**Author:** [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Replies:** 0\
**Last updated:** [July 23, 2020, 5:46pm UTC](https://discourse.julialang.org/t/will-running-pkg-test-compile-all-of-the-package-functions-for-precompile-execution-file-in-packagecompiler/43571 "2020-07-23T17:46:05Z")

</div>

I’m developing a Docker image in which I want a specific package and its functions to be precompiled in the sysimage because precompilation takes quite a while. I’m using PackageCompiler to achieve this. I’m wondering, w…

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

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