# General Usage

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

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

**Page:** 583

---

## [Immutable reference](https://discourse.julialang.org/t/immutable-reference/63405)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 4\
**Last updated:** [June 27, 2021, 8:56am UTC](https://discourse.julialang.org/t/immutable-reference/63405 "2021-06-27T08:56:23Z")

</div>

I want to pass a mutable object or array into a function and be sure that the object won’t be changed by that function. Is there an immutable wrapper I can use like f(immutableview(x))? I know there are conventions like…

---

## [Errors in packages with julia v1.7-beta2: problem with package or julia?](https://discourse.julialang.org/t/errors-in-packages-with-julia-v1-7-beta2-problem-with-package-or-julia/63642)

<div class="topic-metadata">

**Author:** [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Replies:** 2\
**Last updated:** [June 27, 2021, 5:28pm UTC](https://discourse.julialang.org/t/errors-in-packages-with-julia-v1-7-beta2-problem-with-package-or-julia/63642 "2021-06-27T17:28:21Z")

</div>

I have seen a couple of places where code runs with julia 1.6, but not 1.7-beta2. In particular: MCMCChains.jl, the Chains function. chn=Chains(rand(10,2), \["a", "b"\]) works fine on 1.6, errors on 1.7 BSON.jl: load…

---

## [Package version conflict troubleshooting](https://discourse.julialang.org/t/package-version-conflict-troubleshooting/63647)

<div class="topic-metadata">

**Author:** [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Replies:** 2\
**Last updated:** [June 27, 2021, 3:29pm UTC](https://discourse.julialang.org/t/package-version-conflict-troubleshooting/63647 "2021-06-27T15:29:53Z")

</div>

Hi all, Not sure if this is a local issue on my machine or something to do with how we’ve put together our \[compat\] section. Here’s a MWE Project.toml of my problem: name = "makie\_compat" uuid = "bacbe515-7035-49b6-9f…

---

## [Problem about parameter in NearestNeighbors.jl](https://discourse.julialang.org/t/problem-about-parameter-in-nearestneighbors-jl/63533)

<div class="topic-metadata">

**Author:** [@zlq178](https://discourse.julialang.org/u/zlq178)\
**Replies:** 2\
**Last updated:** [June 27, 2021, 11:56am UTC](https://discourse.julialang.org/t/problem-about-parameter-in-nearestneighbors-jl/63533 "2021-06-27T11:56:02Z")

</div>

I find an example from NearestNeighbors.jl package, But I can’t find the explaination to “idxs”. What does it mean? What’s more, how to get nearest neighbors and get the predicted value? The example is as follow: using …

---

## [\[ANN\] IRViewer.jl: A small package for visualization of Julia's LLVM IR](https://discourse.julialang.org/t/ann-irviewer-jl-a-small-package-for-visualization-of-julias-llvm-ir/63633)

<div class="topic-metadata">

**Author:** [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Replies:** 1\
**Last updated:** [June 27, 2021, 8:08am UTC](https://discourse.julialang.org/t/ann-irviewer-jl-a-small-package-for-visualization-of-julias-llvm-ir/63633 "2021-06-27T08:08:54Z")

</div>

Recently when I try to optimize some Julia codes, I find that Julia’s LLVM IR output is rather long and hard to read in terminal. So I make this small package IRViewer to visualize LLVM IR by graphviz. You can install it…

---

## [New abstract supertype of existing type](https://discourse.julialang.org/t/new-abstract-supertype-of-existing-type/63624)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 1\
**Last updated:** [June 27, 2021, 2:22am UTC](https://discourse.julialang.org/t/new-abstract-supertype-of-existing-type/63624 "2021-06-27T02:22:39Z")

</div>

Can a type have more than one immediate supertype? If not, why not? If it can, then can one define an abstract supertype of e.g. Float64? \[ I sense from Make an existing type a child of an abstract type - #2 by Ra…

---

## [Why is this small \`@inline\` function much slower than an equivalent macro?](https://discourse.julialang.org/t/why-is-this-small-inline-function-much-slower-than-an-equivalent-macro/63620)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 2\
**Last updated:** [June 26, 2021, 11:19pm UTC](https://discourse.julialang.org/t/why-is-this-small-inline-function-much-slower-than-an-equivalent-macro/63620 "2021-06-26T23:19:50Z")

</div>

My understanding is that in Julia macros are meant to be used for expressiveness and to make DSLs, not for performance hacks. But in this bit-fiddling SIMD loop, a macro is much faster than the corresponding inline funct…

---

## [Pkg.jl internal API changes in Julia v1.7](https://discourse.julialang.org/t/pkg-jl-internal-api-changes-in-julia-v1-7/63607)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 3\
**Last updated:** [June 26, 2021, 4:43pm UTC](https://discourse.julialang.org/t/pkg-jl-internal-api-changes-in-julia-v1-7/63607 "2021-06-26T16:43:57Z")

</div>

An awesome contributor implemented programmatic Project.toml creation in Genie - but now the corresponding test breaks in Julia v1.7. It’s this line: Pkg.project(Pkg.API.Context(), name, tmpdir) # generate tmp in Genie…

---

## [How to create a linear regression model for each of the group](https://discourse.julialang.org/t/how-to-create-a-linear-regression-model-for-each-of-the-group/63592)

<div class="topic-metadata">

**Author:** [@Tiger\_Zheng](https://discourse.julialang.org/u/Tiger_Zheng)\
**Replies:** 4\
**Last updated:** [June 26, 2021, 3:33pm UTC](https://discourse.julialang.org/t/how-to-create-a-linear-regression-model-for-each-of-the-group/63592 "2021-06-26T15:33:52Z")

</div>

I want to do this code in Julia, is there any way to achieve it? Thank you for your help!

---

## [How to take the gradient of one output and keep the other outputs?](https://discourse.julialang.org/t/how-to-take-the-gradient-of-one-output-and-keep-the-other-outputs/63597)

<div class="topic-metadata">

**Author:** [@SvenDummer](https://discourse.julialang.org/u/SvenDummer)\
**Replies:** 0\
**Last updated:** [June 26, 2021, 8:59am UTC](https://discourse.julialang.org/t/how-to-take-the-gradient-of-one-output-and-keep-the-other-outputs/63597 "2021-06-26T08:59:30Z")

</div>

Hi all. I have a (relatively) small question regarding automatic differentiation packages. The problem: I have a function that outputs a Hessian and the corresponding Laplacian. I want to take the gradient concerning t…

---

## [Okay to disable tag checking in this example?](https://discourse.julialang.org/t/okay-to-disable-tag-checking-in-this-example/63581)

<div class="topic-metadata">

**Author:** [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Replies:** 0\
**Last updated:** [June 25, 2021, 9:02pm UTC](https://discourse.julialang.org/t/okay-to-disable-tag-checking-in-this-example/63581 "2021-06-25T21:02:59Z")

</div>

I have a function that depends on two inputs, but I only want to differentiate with respect to the first. But I also want to compute the gradient for different values of the second input. Is it okay to use the same Gradi…

---

## [LoadError when using interpolations as input for a neural ode](https://discourse.julialang.org/t/loaderror-when-using-interpolations-as-input-for-a-neural-ode/51224)

<div class="topic-metadata">

**Author:** [@Gregor](https://discourse.julialang.org/u/Gregor)\
**Replies:** 24\
**Last updated:** [June 25, 2021, 8:46pm UTC](https://discourse.julialang.org/t/loaderror-when-using-interpolations-as-input-for-a-neural-ode/51224 "2021-06-25T20:46:50Z")

</div>

Hello, I am trying to train a simple nn with an external input that depends on time. The input is interpolated using: broadband = LinearInterpolation(time, U) The network runs without any problem for the first iterati…

---

## [MCMC algorithm standard output datatype (MCMCChains or others?)](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 6\
**Last updated:** [June 25, 2021, 8:24pm UTC](https://discourse.julialang.org/t/mcmc-algorithm-standard-output-datatype-mcmcchains-or-others/63149 "2021-06-25T20:24:42Z")

</div>

I’ve got an MCMC algorithm I want to do some research on. It’d be great if I could hand my functions some model function, and get back a data type that fits well into the ecosystem. Since I haven’t had the opportunity to…

---

## [Zygote dropgrad for all function numerical arguments that are non-differentiable (e.g., Int)](https://discourse.julialang.org/t/zygote-dropgrad-for-all-function-numerical-arguments-that-are-non-differentiable-e-g-int/63563)

<div class="topic-metadata">

**Author:** [@mhmodzoka](https://discourse.julialang.org/u/mhmodzoka)\
**Replies:** 1\
**Last updated:** [June 25, 2021, 5:18pm UTC](https://discourse.julialang.org/t/zygote-dropgrad-for-all-function-numerical-arguments-that-are-non-differentiable-e-g-int/63563 "2021-06-25T17:18:27Z")

</div>

Is there a way I can tell Zygote to automatically apply Zygote.dropgrad() for all function numerical arguments that are non-differentiable? Example: julia\> import Zygote julia\> # naiively defining my function, and usi…

---

## [Trying to understand ProfileView output](https://discourse.julialang.org/t/trying-to-understand-profileview-output/63561)

<div class="topic-metadata">

**Author:** [@Arrigo\_Benedetti](https://discourse.julialang.org/u/Arrigo_Benedetti)\
**Replies:** 2\
**Last updated:** [June 25, 2021, 4:37pm UTC](https://discourse.julialang.org/t/trying-to-understand-profileview-output/63561 "2021-06-25T16:37:32Z")

</div>

I am trying to figure what’s going on with some code that i am profiling. As you can see there from the graph below, there is a very large area at the left showing code that is clearly part of the Julia system (type\_infe…

---

## [Macro to automatically add method with default\_rng() for functions using RNGs](https://discourse.julialang.org/t/macro-to-automatically-add-method-with-default-rng-for-functions-using-rngs/63556)

<div class="topic-metadata">

**Author:** [@Luapulu](https://discourse.julialang.org/u/Luapulu)\
**Replies:** 1\
**Last updated:** [June 25, 2021, 3:57pm UTC](https://discourse.julialang.org/t/macro-to-automatically-add-method-with-default-rng-for-functions-using-rngs/63556 "2021-06-25T15:57:38Z")

</div>

Does anybody have a macro so I can write something like @with\_default\_rng function my\_func(rng::AbstractRNG, x, y, z) out = # do something with rng, x, y, z return out end and it will automatically add the met…

---

## [Cant compile CUDA v3.3.1 on PowerPC : TypeError in Atomic](https://discourse.julialang.org/t/cant-compile-cuda-v3-3-1-on-powerpc-typeerror-in-atomic/63537)

<div class="topic-metadata">

**Author:** [@jdad](https://discourse.julialang.org/u/jdad)\
**Replies:** 2\
**Last updated:** [June 25, 2021, 3:35pm UTC](https://discourse.julialang.org/t/cant-compile-cuda-v3-3-1-on-powerpc-typeerror-in-atomic/63537 "2021-06-25T15:35:54Z")

</div>

Hi, running on a powerPC arch, I was previously with CUDA v3.2.1, upgrading to v3.3.1 I get ulia\> using CUDA \[ Info: Precompiling CUDA \[052768ef-5323-5732-b1bb-66c8b64840ba\] ERROR: LoadError: LoadError: TypeError: in At…

---

## [In place assignment of scalars vs vectors](https://discourse.julialang.org/t/in-place-assignment-of-scalars-vs-vectors/63542)

<div class="topic-metadata">

**Author:** [@lorenzo.a.ricciardi](https://discourse.julialang.org/u/lorenzo.a.ricciardi)\
**Replies:** 20\
**Last updated:** [June 25, 2021, 2:40pm UTC](https://discourse.julialang.org/t/in-place-assignment-of-scalars-vs-vectors/63542 "2021-06-25T14:40:06Z")

</div>

Hi all, I’m writing a performance critical function that will be called many times within an optimization loop. I have several questions regarding how to make it as efficient as possible, but I’ll break those down so t…

---

## [Error precompiling DataFrames: UndefVarError: ComposedFunction not defined](https://discourse.julialang.org/t/error-precompiling-dataframes-undefvarerror-composedfunction-not-defined/63555)

<div class="topic-metadata">

**Author:** [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Replies:** 2\
**Last updated:** [June 25, 2021, 2:39pm UTC](https://discourse.julialang.org/t/error-precompiling-dataframes-undefvarerror-composedfunction-not-defined/63555 "2021-06-25T14:39:03Z")

</div>

Dear folks, I work in a project using a specific Project.toml in which I have not updated the packages for a while because everything was working fine. When I start that project now and instantiate it with Pkg, there i…

---

## [Two y-axis overlaps in pyplot](https://discourse.julialang.org/t/two-y-axis-overlaps-in-pyplot/63540)

<div class="topic-metadata">

**Author:** [@Fred\_He](https://discourse.julialang.org/u/Fred_He)\
**Replies:** 4\
**Last updated:** [June 25, 2021, 1:13pm UTC](https://discourse.julialang.org/t/two-y-axis-overlaps-in-pyplot/63540 "2021-06-25T13:13:33Z")

</div>

I expect to have two y-axis one on the left and another on the right. but it shows overlapped y-axis on the left. @show backend() x = 1:10 y1 = log.(x) y2 = y1 + 0.05\*randn(10) plot(x, y1, xlabel="x", ylabel="log(x)", t…

---

## [Conditional array comprehension vs. simple for loop - 750k allocations vs. 1 allocation - why?](https://discourse.julialang.org/t/conditional-array-comprehension-vs-simple-for-loop-750k-allocations-vs-1-allocation-why/63249)

<div class="topic-metadata">

**Author:** [@jlawrie](https://discourse.julialang.org/u/jlawrie)\
**Replies:** 14\
**Last updated:** [June 25, 2021, 8:26am UTC](https://discourse.julialang.org/t/conditional-array-comprehension-vs-simple-for-loop-750k-allocations-vs-1-allocation-why/63249 "2021-06-25T08:26:54Z")

</div>

Hello! Thanks for taking a moment to have a look at my question :slight\_smile: Full disclosure: I’m only a few weeks into learning Julia, brand new to Discourse and an interdisciplinary engineer (not a computer scienti…

---

## [GRPC, ProtoBuf, and HTTP](https://discourse.julialang.org/t/grpc-protobuf-and-http/14547)

<div class="topic-metadata">

**Author:** [@pazzo83](https://discourse.julialang.org/u/pazzo83)\
**Replies:** 5\
**Last updated:** [June 25, 2021, 10:34am UTC](https://discourse.julialang.org/t/grpc-protobuf-and-http/14547 "2021-06-25T10:34:15Z")

</div>

Hi all, I am wondering if anyone has had some experience writing a GRPC client and/or server using the ProtoBuf.jl and HTTP.jl packages (both of which appear to be in good working order for 1.0). I found an old GRPC.jl …

---

## [Will the use of \`@code\_native\` compile and cache function?](https://discourse.julialang.org/t/will-the-use-of-code-native-compile-and-cache-function/63534)

<div class="topic-metadata">

**Author:** [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)\
**Replies:** 1\
**Last updated:** [June 25, 2021, 9:42am UTC](https://discourse.julialang.org/t/will-the-use-of-code-native-compile-and-cache-function/63534 "2021-06-25T09:42:45Z")

</div>

I want to compile and cache some of the functions at the start of Julia session - I find it less disruptive compared to the slow first run. Will calling them with @code\_native and passing dummy arguments of appropriate …

---

## [Unexpected index of Unicode subscript \`char\` in \`string\`?](https://discourse.julialang.org/t/unexpected-index-of-unicode-subscript-char-in-string/63515)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 8\
**Last updated:** [June 25, 2021, 9:29am UTC](https://discourse.julialang.org/t/unexpected-index-of-unicode-subscript-char-in-string/63515 "2021-06-25T09:29:42Z")

</div>

It seems that in some cases the indexing of subscript char is wrong: julia\> "a₁"\[1\] 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase) julia\> "a₁"\[2\] '₁': Unicode U+2081 (category No: Number, other) julia\> "α₁…

---

## [Tell the compiler that two code paths yield the same type](https://discourse.julialang.org/t/tell-the-compiler-that-two-code-paths-yield-the-same-type/63535)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 4\
**Last updated:** [June 25, 2021, 9:09am UTC](https://discourse.julialang.org/t/tell-the-compiler-that-two-code-paths-yield-the-same-type/63535 "2021-06-25T09:09:31Z")

</div>

Every now and then I have code like this: function calculate\_or\_lookup(...) if iscached(...) return load\_from\_cache(...) # cheap else return calculate(...) # expensive end end As a programme…

---

## [Pkg, private registries and corporate firewalls?](https://discourse.julialang.org/t/pkg-private-registries-and-corporate-firewalls/63065)

<div class="topic-metadata">

**Author:** [@gleyland](https://discourse.julialang.org/u/gleyland)\
**Replies:** 8\
**Last updated:** [June 25, 2021, 8:44am UTC](https://discourse.julialang.org/t/pkg-private-registries-and-corporate-firewalls/63065 "2021-06-25T08:44:46Z")

</div>

Hi, At work we’re behind a firewall, we build Julia code into docker images, and we now have a private registry and some packages on Bitbucket (thanks to LocalRegistry.jl!) This combination, along with some documented …

---

## [Is there a Julia equivalent for this Python syntax](https://discourse.julialang.org/t/is-there-a-julia-equivalent-for-this-python-syntax/63439)

<div class="topic-metadata">

**Author:** [@james-garfield](https://discourse.julialang.org/u/james-garfield)\
**Replies:** 17\
**Last updated:** [June 25, 2021, 12:47am UTC](https://discourse.julialang.org/t/is-there-a-julia-equivalent-for-this-python-syntax/63439 "2021-06-25T00:47:09Z")

</div>

I like how in python I can set a variable in a function as None if I don’t always need to use it. And if the function does end up being called with that variable passed in I can check in the function body by doing: id =…

---

## [Suggestions for discrete event simulation](https://discourse.julialang.org/t/suggestions-for-discrete-event-simulation/63497)

<div class="topic-metadata">

**Author:** [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Replies:** 2\
**Last updated:** [June 24, 2021, 10:45pm UTC](https://discourse.julialang.org/t/suggestions-for-discrete-event-simulation/63497 "2021-06-24T22:45:25Z")

</div>

I’m trying to put together a simple discrete event simulation of a transport network. You can think of the model as a set of nodes, with shipments between nodes based on random orders coming into each node at each point…

---

## [Problems scaling jl\_alloc\_array\_2d C API](https://discourse.julialang.org/t/problems-scaling-jl-alloc-array-2d-c-api/63341)

<div class="topic-metadata">

**Author:** [@sdeoras](https://discourse.julialang.org/u/sdeoras)\
**Replies:** 18\
**Last updated:** [June 24, 2021, 10:29pm UTC](https://discourse.julialang.org/t/problems-scaling-jl-alloc-array-2d-c-api/63341 "2021-06-24T22:29:00Z")

</div>

I am observing a strange behavior with jl\_alloc\_array\_2d C API when matrix size is \> 300x300 float64. This is very strange because I am not seeing any issue creating a matrix and passing to a function for sizes lower tha…

---

## [Numpy to Julia conversion questions](https://discourse.julialang.org/t/numpy-to-julia-conversion-questions/63509)

<div class="topic-metadata">

**Author:** [@Phil\_Tomson](https://discourse.julialang.org/u/Phil_Tomson)\
**Replies:** 1\
**Last updated:** [June 24, 2021, 6:02pm UTC](https://discourse.julialang.org/t/numpy-to-julia-conversion-questions/63509 "2021-06-24T18:02:07Z")

</div>

As an exercise I’m converting this Python Differential Evolution tutorial code to Julia (https://machinelearningmastery.com/differential-evolution-from-scratch-in-python/) Here’s enough of the python to get going: fro…

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

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