# General Usage

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

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

**Page:** 372

---

## [How to get the free variables of a function?](https://discourse.julialang.org/t/how-to-get-the-free-variables-of-a-function/89892)

<div class="topic-metadata">

**Author:** [@jt1](https://discourse.julialang.org/u/jt1)\
**Replies:** 3\
**Last updated:** [November 9, 2022, 4:52pm UTC](https://discourse.julialang.org/t/how-to-get-the-free-variables-of-a-function/89892 "2022-11-09T16:52:34Z")

</div>

Is there a way to get thefree variables of a function? For example: myfunc(a) = a+some\_func(b,a) free\_variables(myfunc) # returns (:b,) or (:b, :some\_func) is also fine A follow-up question (that I will likely have …

---

## [Add Test as a dependency of project](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 6\
**Last updated:** [November 9, 2022, 4:46pm UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043 "2022-11-09T16:46:16Z")

</div>

So I have a simple and small project that is completely standalone and doesn’t use anything outside of the standard library. The only thing in the standard library that I use is Test for my test suite which is located at…

---

## [Adding parameters to function definition avoids allocations](https://discourse.julialang.org/t/adding-parameters-to-function-definition-avoids-allocations/89975)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 3\
**Last updated:** [November 9, 2022, 3:43pm UTC](https://discourse.julialang.org/t/adding-parameters-to-function-definition-avoids-allocations/89975 "2022-11-09T15:43:32Z")

</div>

I’m trying to get a small piece of code that I’ll run millions of times to run without allocations. There is a small allocation that I cannot understand the cause of (for example, using Profile.Allocs cannot attribute th…

---

## [Error in creating a package using PkgTemplates.jl](https://discourse.julialang.org/t/error-in-creating-a-package-using-pkgtemplates-jl/48935)

<div class="topic-metadata">

**Author:** [@zoumuda](https://discourse.julialang.org/u/zoumuda)\
**Replies:** 7\
**Last updated:** [November 9, 2022, 3:03pm UTC](https://discourse.julialang.org/t/error-in-creating-a-package-using-pkgtemplates-jl/48935 "2022-11-09T15:03:27Z")

</div>

Hi, I would lile to learn to creat a package using PkgTemplates.jl When I try it according to the User Guilde: using PkgTemplates t = Template() t(“MyPkg”) It has the following error: Git: Git hosting service user…

---

## [Linear algebra -- block diagonal matrix?](https://discourse.julialang.org/t/linear-algebra-block-diagonal-matrix/89971)

<div class="topic-metadata">

**Author:** [@BLI](https://discourse.julialang.org/u/BLI)\
**Replies:** 3\
**Last updated:** [November 9, 2022, 10:28am UTC](https://discourse.julialang.org/t/linear-algebra-block-diagonal-matrix/89971 "2022-11-09T10:28:10Z")

</div>

In MATLAB, there is a constructor diagm for block diagonal matrices. I seem to recall that this is missing in Julia. If I am wrong, what is the most elegant way to create one?

---

## [Parsing ProtoBuf Text Format](https://discourse.julialang.org/t/parsing-protobuf-text-format/84721)

<div class="topic-metadata">

**Author:** [@FireCrumb](https://discourse.julialang.org/u/FireCrumb)\
**Replies:** 3\
**Last updated:** [November 9, 2022, 8:59am UTC](https://discourse.julialang.org/t/parsing-protobuf-text-format/84721 "2022-11-09T08:59:17Z")

</div>

Hi, I’m trying to use ProtoBuf.jl to deserialize objects. Managed to generate code from .proto files Now I want to read and write objects with Protocol Buffer Text Format Language Specification. However, I could only …

---

## [Puzzling behavior of "wrong" inner constructor](https://discourse.julialang.org/t/puzzling-behavior-of-wrong-inner-constructor/89954)

<div class="topic-metadata">

**Author:** [@simsurace](https://discourse.julialang.org/u/simsurace)\
**Replies:** 4\
**Last updated:** [November 9, 2022, 6:58am UTC](https://discourse.julialang.org/t/puzzling-behavior-of-wrong-inner-constructor/89954 "2022-11-09T06:58:08Z")

</div>

Today I was quite surprised by this mistake of mine in an inner constructor not throwing an error, but leading to a silent bug. My actual case had many arguments and I missed several, but here is a MWE: julia\> struct My…

---

## [Measure data movement Distributed](https://discourse.julialang.org/t/measure-data-movement-distributed/89966)

<div class="topic-metadata">

**Author:** [@jarbus](https://discourse.julialang.org/u/jarbus)\
**Replies:** 0\
**Last updated:** [November 9, 2022, 4:30am UTC](https://discourse.julialang.org/t/measure-data-movement-distributed/89966 "2022-11-09T04:30:17Z")

</div>

Is there any way to measure the amount of data getting sent to workers? For the example in the Data Movement section of the Distributed Manual, it would be very helpful to tell if a call is moving data or not, to directl…

---

## [Mixers.jl question](https://discourse.julialang.org/t/mixers-jl-question/89961)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 0\
**Last updated:** [November 9, 2022, 1:24am UTC](https://discourse.julialang.org/t/mixers-jl-question/89961 "2022-11-09T01:24:27Z")

</div>

I’m creating structs for exotic options (Barriers, Digitals etc), using Mixers to add the common fields (Expiry, Notional, Currency etc) Another option would be to create a common fields struct and include this as a fie…

---

## [Numerical intergration order problem (probably)](https://discourse.julialang.org/t/numerical-intergration-order-problem-probably/89960)

<div class="topic-metadata">

**Author:** [@swish47](https://discourse.julialang.org/u/swish47)\
**Replies:** 0\
**Last updated:** [November 8, 2022, 11:51pm UTC](https://discourse.julialang.org/t/numerical-intergration-order-problem-probably/89960 "2022-11-08T23:51:34Z")

</div>

This is a long example inspired by quantum physics. I tried to abstract the key points and write a typically similar and simpler example, however I failed. Thanks for read my naive and tedious codes in advance. using HC…

---

## [Independence of function from an input variable](https://discourse.julialang.org/t/independence-of-function-from-an-input-variable/89959)

<div class="topic-metadata">

**Author:** [@NicholasMueller](https://discourse.julialang.org/u/NicholasMueller)\
**Replies:** 0\
**Last updated:** [November 8, 2022, 11:29pm UTC](https://discourse.julialang.org/t/independence-of-function-from-an-input-variable/89959 "2022-11-08T23:29:07Z")

</div>

Hi I’m wondering if there is a way to check if a function is independent from one of its input variables. For example, if we consider the function f(x,μ) = x, I’m looking for a method that tells me that the function μ -\> …

---

## [How to update a JLL wrapper to support Mac M1](https://discourse.julialang.org/t/how-to-update-a-jll-wrapper-to-support-mac-m1/89936)

<div class="topic-metadata">

**Author:** [@Wikunia](https://discourse.julialang.org/u/Wikunia)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 10:20pm UTC](https://discourse.julialang.org/t/how-to-update-a-jll-wrapper-to-support-mac-m1/89936 "2022-11-08T22:20:51Z")

</div>

Hey everyone, I’m an extensive user of the Clipper.jl package and would like to use the M1 version of Julia and it seems it’s currently the only package that I can’t use with native M1 due to GitHub - JuliaBinaryWrapper…

---

## [\`sizehint!\` style approach for matrices](https://discourse.julialang.org/t/sizehint-style-approach-for-matrices/89951)

<div class="topic-metadata">

**Author:** [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 9:52pm UTC](https://discourse.julialang.org/t/sizehint-style-approach-for-matrices/89951 "2022-11-08T21:52:12Z")

</div>

My program has the following structure: for i in 1:1000 u = foo(i) # A 3xN Matrix{Float64} bar(u) end where N is usually between 100 and 150. Through profiling, I have learned that allocating memory in line 2 …

---

## [Is it possible to manually manage the memory without having to use C Standard Library?](https://discourse.julialang.org/t/is-it-possible-to-manually-manage-the-memory-without-having-to-use-c-standard-library/89881)

<div class="topic-metadata">

**Author:** [@phantomcraft](https://discourse.julialang.org/u/phantomcraft)\
**Replies:** 15\
**Last updated:** [November 8, 2022, 8:03pm UTC](https://discourse.julialang.org/t/is-it-possible-to-manually-manage-the-memory-without-having-to-use-c-standard-library/89881 "2022-11-08T20:03:21Z")

</div>

If I want maximum performance for a program written in Julia, one of my options would be manually managing the memory with help of Julia C Standard Library. But is it possible to do that in another way? Has Julia facili…

---

## [Status of database packages and tools for, e.g. ORM tools](https://discourse.julialang.org/t/status-of-database-packages-and-tools-for-e-g-orm-tools/89933)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 1\
**Last updated:** [November 8, 2022, 5:51pm UTC](https://discourse.julialang.org/t/status-of-database-packages-and-tools-for-e-g-orm-tools/89933 "2022-11-08T17:51:37Z")

</div>

You can use e.g. LibPQ.jl for PostgreSQL, i.e. it directly. There’s also a specific PostgresORM.jl But I want to know of the best tools for databases that work for all, FunSQL.jl seems to be one. FunSQL.jl allows yo…

---

## [Adding pdf/png into existing pgfplots](https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922)

<div class="topic-metadata">

**Author:** [@Elyco](https://discourse.julialang.org/u/Elyco)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 3:46pm UTC](https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922 "2022-11-08T15:46:52Z")

</div>

Hi, I’m trying to add a node to a pgfplot that contains a pdf/png file. Here is what I have until now using Plots pgfplotsx() fig1 = plot(1:5) savefig(fig1, "fig1.png") savefig(fig1, "fig1.pdf") # just to create a fig…

---

## [@inbounds equivalent for type assertions](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 3:31pm UTC](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107 "2022-11-08T15:31:17Z")

</div>

Is there an @inbounds equivalent for type assertions? That is allow the compiler to aggressively compile a specialization based on a type assertion that is unsafe if the type is not correct?

---

## [Computational time of appending an array and mutating an array](https://discourse.julialang.org/t/computational-time-of-appending-an-array-and-mutating-an-array/89118)

<div class="topic-metadata">

**Author:** [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Replies:** 4\
**Last updated:** [November 8, 2022, 1:41pm UTC](https://discourse.julialang.org/t/computational-time-of-appending-an-array-and-mutating-an-array/89118 "2022-11-08T13:41:06Z")

</div>

I want to transition from Zygote.jl to AbstractDifferentiation.jl so that I can mutate arrays instead of appending them. Before I do so, I want to make sure that mutating arrays is faster than appending an array. I’ve r…

---

## [Binding docstring to struct field](https://discourse.julialang.org/t/binding-docstring-to-struct-field/89439)

<div class="topic-metadata">

**Author:** [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 10:30am UTC](https://discourse.julialang.org/t/binding-docstring-to-struct-field/89439 "2022-11-08T10:30:25Z")

</div>

Why does field docstring generation depend on where it was defined? In a file: # MyModule.jl module MyModule "A docstring" struct A "a docstring" a::Int64 end end julia\> include("MyModule.jl") Main.MyModule he…

---

## [EquivalentCircuits: Plot fitted impedance curve](https://discourse.julialang.org/t/equivalentcircuits-plot-fitted-impedance-curve/89788)

<div class="topic-metadata">

**Author:** [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Replies:** 1\
**Last updated:** [November 8, 2022, 10:12am UTC](https://discourse.julialang.org/t/equivalentcircuits-plot-fitted-impedance-curve/89788 "2022-11-08T10:12:22Z")

</div>

Today I discovered a nice package to fit equivalent circuits: EquivalentCircuits.jl Everything works fine, I am able to fit the electrical values of the components. But I have not yet figured out, how to transfer the r…

---

## [How do you get all the first elements of a tuple in a struct array?](https://discourse.julialang.org/t/how-do-you-get-all-the-first-elements-of-a-tuple-in-a-struct-array/89897)

<div class="topic-metadata">

**Author:** [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Replies:** 4\
**Last updated:** [November 8, 2022, 9:51am UTC](https://discourse.julialang.org/t/how-do-you-get-all-the-first-elements-of-a-tuple-in-a-struct-array/89897 "2022-11-08T09:51:24Z")

</div>

adata = collect(1:10) bdata = collect(31:40) tmp2=StructArray((adata,bdata)) How can I get the numbers 1:10 as if they were an array from the StructArray?

---

## [Add a value to task local storage if it is not already present](https://discourse.julialang.org/t/add-a-value-to-task-local-storage-if-it-is-not-already-present/89909)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 7:43am UTC](https://discourse.julialang.org/t/add-a-value-to-task-local-storage-if-it-is-not-already-present/89909 "2022-11-08T07:43:54Z")

</div>

I have a workload that I want to multi thread. This involves calling a function in parallel, that needs some work space for computing. The following rules apply: There may never be two computations using the same works…

---

## [Progress bar, or printing during execution, in Jupyter/IJulia?](https://discourse.julialang.org/t/progress-bar-or-printing-during-execution-in-jupyter-ijulia/89916)

<div class="topic-metadata">

**Author:** [@amca01](https://discourse.julialang.org/u/amca01)\
**Replies:** 9\
**Last updated:** [November 8, 2022, 3:44am UTC](https://discourse.julialang.org/t/progress-bar-or-printing-during-execution-in-jupyter-ijulia/89916 "2022-11-08T03:44:47Z")

</div>

I’m not sure whether this is a Julia question, or a Jupyter question, but anyway … I’m working with Julia in a Jupyter notebook (within VSCode on Windows). This is an environment I’m very happy with, and it suits me wel…

---

## [ReverseDiff not using custom derivative from ChainRules](https://discourse.julialang.org/t/reversediff-not-using-custom-derivative-from-chainrules/89888)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 3\
**Last updated:** [November 7, 2022, 6:02pm UTC](https://discourse.julialang.org/t/reversediff-not-using-custom-derivative-from-chainrules/89888 "2022-11-07T18:02:18Z")

</div>

Hi there, I would like to use a custom derivative for a function - the cdf of a T distribution wrt to the data. I keep the parameter of this distribution fixed, so NoTangent for the parameter is enough for me here. Here…

---

## [How to set multiple arrays from a single array?](https://discourse.julialang.org/t/how-to-set-multiple-arrays-from-a-single-array/89851)

<div class="topic-metadata">

**Author:** [@zxm403089989](https://discourse.julialang.org/u/zxm403089989)\
**Replies:** 6\
**Last updated:** [November 7, 2022, 10:16pm UTC](https://discourse.julialang.org/t/how-to-set-multiple-arrays-from-a-single-array/89851 "2022-11-07T22:16:00Z")

</div>

Is there any way to directly define new array from a known larger array? For example: a1,a2=\[1 2;3 4\] 2×2 Matrix{Int64}: 1 2 3 4 a1 1 a2 2 This doesn’t give results I need. However, if I set array from a vector of …

---

## [My mental load using Julia is much higher than, e.g., in Python. How to reduce it?](https://discourse.julialang.org/t/my-mental-load-using-julia-is-much-higher-than-e-g-in-python-how-to-reduce-it/18902)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 50\
**Last updated:** [November 7, 2022, 9:03pm UTC](https://discourse.julialang.org/t/my-mental-load-using-julia-is-much-higher-than-e-g-in-python-how-to-reduce-it/18902 "2022-11-07T21:03:11Z")

</div>

Hi, I’m new to the language, and although I like so many aspects of Julia, I am struggling to start using it. I come from Python mostly, but have been looking for an alternative in which low-level function speed can be …

---

## [How to use Logging.jl?](https://discourse.julialang.org/t/how-to-use-logging-jl/89908)

<div class="topic-metadata">

**Author:** [@fksayaci](https://discourse.julialang.org/u/fksayaci)\
**Replies:** 0\
**Last updated:** [November 7, 2022, 8:42pm UTC](https://discourse.julialang.org/t/how-to-use-logging-jl/89908 "2022-11-07T20:42:51Z")

</div>

Hi all, We have an optimization model, which I can run successfully in my local computer and my HPC cluster account. My colleague in our research group recently installed Gurobi, Julia, and JuMP in his HPC cluster accou…

---

## [Plots.jl @layout specify width dynamically](https://discourse.julialang.org/t/plots-jl-layout-specify-width-dynamically/21017)

<div class="topic-metadata">

**Author:** [@nathancunn](https://discourse.julialang.org/u/nathancunn)\
**Replies:** 1\
**Last updated:** [November 7, 2022, 8:25pm UTC](https://discourse.julialang.org/t/plots-jl-layout-specify-width-dynamically/21017 "2022-11-07T20:25:15Z")

</div>

I assume this has a very simple solution, but I’m struggling. I’m trying to set up a grid of plots with a non-standard layout using Plots.jl which I can do as follows: x = rand(100, 4) l = @layout \[a{0.8w} grid(3, 1)\] …

---

## [Optimizer in Evolutionary.jl returns initial conditions as minimizer with default setting](https://discourse.julialang.org/t/optimizer-in-evolutionary-jl-returns-initial-conditions-as-minimizer-with-default-setting/89902)

<div class="topic-metadata">

**Author:** [@mylo19](https://discourse.julialang.org/u/mylo19)\
**Replies:** 1\
**Last updated:** [November 7, 2022, 7:33pm UTC](https://discourse.julialang.org/t/optimizer-in-evolutionary-jl-returns-initial-conditions-as-minimizer-with-default-setting/89902 "2022-11-07T19:33:57Z")

</div>

I want to use a genetic algorithm to minimize a function. After searching, I read that the best available option is Evolutionary.jl. Hence, I started reading the documentation. I tried running the examples found in the t…

---

## [Take a derivative with respect to an expression in Symbolics](https://discourse.julialang.org/t/take-a-derivative-with-respect-to-an-expression-in-symbolics/89900)

<div class="topic-metadata">

**Author:** [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Replies:** 0\
**Last updated:** [November 7, 2022, 6:05pm UTC](https://discourse.julialang.org/t/take-a-derivative-with-respect-to-an-expression-in-symbolics/89900 "2022-11-07T18:05:27Z")

</div>

The Symbolics documentation says (bold italic emphasis added) struct Differential \<: Symbolics.Operator Represents a differential operator. Fields x : The variable or expression to differentiate with respect to. T…

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

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