# General Usage

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

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

**Page:** 487

---

## [Trying to write a macro for simple debugging](https://discourse.julialang.org/t/trying-to-write-a-macro-for-simple-debugging/75943)

<div class="topic-metadata">

**Author:** [@bcsj](https://discourse.julialang.org/u/bcsj)\
**Replies:** 3\
**Last updated:** [February 7, 2022, 12:57pm UTC](https://discourse.julialang.org/t/trying-to-write-a-macro-for-simple-debugging/75943 "2022-02-07T12:57:02Z")

</div>

I’m trying to wrap my head around macros and wanted to make (what I assumed is) a simple macro which you prefix to an expression in order to get the expression printed with its evaluated value. Example Let us call the m…

---

## [Efficient way of doing linear regression](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232)

<div class="topic-metadata">

**Author:** [@Johncowk](https://discourse.julialang.org/u/Johncowk)\
**Replies:** 44\
**Last updated:** [February 7, 2022, 9:35am UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232 "2022-02-07T09:35:17Z")

</div>

Hello, I need an efficient way to performs linear regression because I have to fit several segments in a big for loops which takes time to achieve. In the past, their was a linreg function which has been depreciated. Cu…

---

## [User-defined gradient and hessian ADNLPModels.jl](https://discourse.julialang.org/t/user-defined-gradient-and-hessian-adnlpmodels-jl/75940)

<div class="topic-metadata">

**Author:** [@AhmedAlreweny](https://discourse.julialang.org/u/AhmedAlreweny)\
**Replies:** 0\
**Last updated:** [February 7, 2022, 9:31am UTC](https://discourse.julialang.org/t/user-defined-gradient-and-hessian-adnlpmodels-jl/75940 "2022-02-07T09:31:13Z")

</div>

Hello, I am trying to solve a nonlinear optimization problem using NLPModels.jl. As seen from here, the model takes only the objective function and the constraints and compute the gradient and hessian using ForwardDiff.…

---

## [Getindex, to\_indices, and CartesianIndex type inference failure](https://discourse.julialang.org/t/getindex-to-indices-and-cartesianindex-type-inference-failure/75781)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 4\
**Last updated:** [February 7, 2022, 9:24am UTC](https://discourse.julialang.org/t/getindex-to-indices-and-cartesianindex-type-inference-failure/75781 "2022-02-07T09:24:30Z")

</div>

I’m defining a multi-dimensional Hankel array, as follows: struct Hankel{T,N,V\<:AbstractArray{T},D\<:Tuple{Vararg{Int}}} \<: AbstractArray{T,N} v::V d::D function Hankel(v::AbstractArray, d::Tuple{Vararg{Int}}…

---

## [Inferred type of \`pmap\`](https://discourse.julialang.org/t/inferred-type-of-pmap/75930)

<div class="topic-metadata">

**Author:** [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Replies:** 0\
**Last updated:** [February 7, 2022, 3:35am UTC](https://discourse.julialang.org/t/inferred-type-of-pmap/75930 "2022-02-07T03:35:57Z")

</div>

When applying pmap, it seems like type inference breaks down, as shown below: julia\> using Distributed julia\> f(x) = pmap(val -\> val^2, \[x\]) f (generic function with 1 method) julia\> @code\_warntype f(2) Variables #se…

---

## [Automatic differentiation of complex matrix fails](https://discourse.julialang.org/t/automatic-differentiation-of-complex-matrix-fails/75733)

<div class="topic-metadata">

**Author:** [@Eriklw](https://discourse.julialang.org/u/Eriklw)\
**Replies:** 11\
**Last updated:** [February 7, 2022, 1:06am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-matrix-fails/75733 "2022-02-07T01:06:55Z")

</div>

While automatic differentiation with Zygote works fine for matrices with element in Float64 it fails for elements in ComplexF64: ‘’’ using Zygote function svdtest(A) U,S,V = svd(A) a = S\[1\] return a end A = rand(…

---

## [JuliaCall Python library - is it safe for server use](https://discourse.julialang.org/t/juliacall-python-library-is-it-safe-for-server-use/75918)

<div class="topic-metadata">

**Author:** [@AlanAylmer](https://discourse.julialang.org/u/AlanAylmer)\
**Replies:** 0\
**Last updated:** [February 6, 2022, 9:28pm UTC](https://discourse.julialang.org/t/juliacall-python-library-is-it-safe-for-server-use/75918 "2022-02-06T21:28:42Z")

</div>

I am using Flask and Nginx for a simple stats project. The usecase is that my front end invites the user to upload a spreadsheet. The back end uses Julia. I call Julia using Python JuliaCall. Is this way of doing things…

---

## [Is it possible to index an array with a tuple?](https://discourse.julialang.org/t/is-it-possible-to-index-an-array-with-a-tuple/75886)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 10\
**Last updated:** [February 6, 2022, 6:29pm UTC](https://discourse.julialang.org/t/is-it-possible-to-index-an-array-with-a-tuple/75886 "2022-02-06T18:29:54Z")

</div>

Is this the only way? julia\> a 5-element Vector{Float64}: 3.00000e+00 2.00000e+00 5.00000e+00 9.02242e-01 7.68556e-01 julia\> t (3, 2, 5) julia\> a\[\[t...\]\] 3-element Vector{Float64}: 5.00000e+00 2.00000e+00 7.68…

---

## [Problems in calling multiprocess functions on github actions](https://discourse.julialang.org/t/problems-in-calling-multiprocess-functions-on-github-actions/75905)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 0\
**Last updated:** [February 6, 2022, 5:30pm UTC](https://discourse.julialang.org/t/problems-in-calling-multiprocess-functions-on-github-actions/75905 "2022-02-06T17:30:13Z")

</div>

I am writing a Julia course, where the script is compiled to MD and then to HTML using Literate.jl and Documenter.jl on GitHub actions. The problem is in this snippet: using Distributed, BenchmarkTools a = rand(1:35,10…

---

## [TTFX with DataFrames and CSV](https://discourse.julialang.org/t/ttfx-with-dataframes-and-csv/75432)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 40\
**Last updated:** [February 6, 2022, 4:43pm UTC](https://discourse.julialang.org/t/ttfx-with-dataframes-and-csv/75432 "2022-02-06T16:43:11Z")

</div>

I have a very simple little program: @time using CSV, DataFrames input=""" time,ping 1,25.7 2,31.8 """ io = IOBuffer(input) @time df = CSV.read(io, DataFrame) close(io) df Output: julia\> include("bench.jl") 3.0629…

---

## [Macro: escaping, evaluation, scope etc,](https://discourse.julialang.org/t/macro-escaping-evaluation-scope-etc/75875)

<div class="topic-metadata">

**Author:** [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Replies:** 6\
**Last updated:** [February 6, 2022, 3:37pm UTC](https://discourse.julialang.org/t/macro-escaping-evaluation-scope-etc/75875 "2022-02-06T15:37:42Z")

</div>

Playing around with macros. macro gk(x) ks = keys(eval(x)) return ks end p = (a=1, b="b") julia\> @gk p (:a, :b) That’s OK, that’s what I want. Now, if the macro is defined inside a separate module, I couldn’t…

---

## [Overwhelmed by broadcast interface. Help me 🥺](https://discourse.julialang.org/t/overwhelmed-by-broadcast-interface-help-me/75823)

<div class="topic-metadata">

**Author:** [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Replies:** 17\
**Last updated:** [February 6, 2022, 12:47pm UTC](https://discourse.julialang.org/t/overwhelmed-by-broadcast-interface-help-me/75823 "2022-02-06T12:47:21Z")

</div>

I am writing code that would benefit from generic generator arithmetic over a vector type. In general, Vector{PrimeGenerator} suffices, but it introduces duplication of irrelevant data. Thus, I am attempting to subtype A…

---

## [Matrix{Vector} -\> Vector{Matrix}](https://discourse.julialang.org/t/matrix-vector-vector-matrix/75896)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 1\
**Last updated:** [February 6, 2022, 9:34am UTC](https://discourse.julialang.org/t/matrix-vector-vector-matrix/75896 "2022-02-06T09:34:15Z")

</div>

I have a matrix of k-vectors, how can I get a k-vector of matrices? k = 5 julia\> m = reshape(\[rand(k) for \_ in 1:6\], 2,3) 2×3 Matrix{Vector{Float64}}: \[0.428997, 0.769875, 0.441121, 0.467842, 0.596864\] … \[0.722121, …

---

## [Keyring package in Julia](https://discourse.julialang.org/t/keyring-package-in-julia/20057)

<div class="topic-metadata">

**Author:** [@ValdarT](https://discourse.julialang.org/u/ValdarT)\
**Replies:** 2\
**Last updated:** [February 6, 2022, 7:42am UTC](https://discourse.julialang.org/t/keyring-package-in-julia/20057 "2022-02-06T07:42:46Z")

</div>

Is there a Julia package for accessing system keyring (platform independently), akin to the ones in Python and R? I searched and didn’t find one but perhaps I missed something.

---

## [Memset error](https://discourse.julialang.org/t/memset-error/75884)

<div class="topic-metadata">

**Author:** [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Replies:** 0\
**Last updated:** [February 6, 2022, 12:56am UTC](https://discourse.julialang.org/t/memset-error/75884 "2022-02-06T00:56:05Z")

</div>

This error suddenly started popping up in my code, apparently occurring randomly at different places in the code when I run my tests. Some times it doesn’t happen at all and the tests all complete successfully. Please s…

---

## [Speed issue with KahanSummation](https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491)

<div class="topic-metadata">

**Author:** [@HJW019](https://discourse.julialang.org/u/HJW019)\
**Replies:** 12\
**Last updated:** [February 5, 2022, 10:08am UTC](https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491 "2022-02-05T10:08:16Z")

</div>

I am using Julia version 1.7.1. I need to do summations of long series (repeatedly) where accuracy is important. I am looking at KahanSummation’ sum\_kbn (pure Julia), but am puzzled by the very slow speed (with a lot of …

---

## [CUDA example in Julia doesn't use the GPU](https://discourse.julialang.org/t/cuda-example-in-julia-doesnt-use-the-gpu/75838)

<div class="topic-metadata">

**Author:** [@cirobr](https://discourse.julialang.org/u/cirobr)\
**Replies:** 2\
**Last updated:** [February 5, 2022, 3:17am UTC](https://discourse.julialang.org/t/cuda-example-in-julia-doesnt-use-the-gpu/75838 "2022-02-05T03:17:49Z")

</div>

I’m doing my first steps on running Julia 1.6.5 code on GPU. For some reason, it seems the GPU is not being used at all. These are the steps: First of all, my GPU passed on the test recommended at https://cuda.juliagpu.…

---

## [What is the preferred way to iterate through the Cartesian power of an iterable only available at runtime?](https://discourse.julialang.org/t/what-is-the-preferred-way-to-iterate-through-the-cartesian-power-of-an-iterable-only-available-at-runtime/75815)

<div class="topic-metadata">

**Author:** [@gtgt](https://discourse.julialang.org/u/gtgt)\
**Replies:** 6\
**Last updated:** [February 4, 2022, 10:32pm UTC](https://discourse.julialang.org/t/what-is-the-preferred-way-to-iterate-through-the-cartesian-power-of-an-iterable-only-available-at-runtime/75815 "2022-02-04T22:32:24Z")

</div>

Hi, Sometimes in my code I need to iterate through the Cartesian power of a vector. After searching on the web I can come up with two approaches. Using product and repeated from Base.Iterators. The problem is that thi…

---

## [Capture an output function](https://discourse.julialang.org/t/capture-an-output-function/75824)

<div class="topic-metadata">

**Author:** [@wub7quxa](https://discourse.julialang.org/u/wub7quxa)\
**Replies:** 4\
**Last updated:** [February 5, 2022, 12:08am UTC](https://discourse.julialang.org/t/capture-an-output-function/75824 "2022-02-05T00:08:53Z")

</div>

I use the Calculus module in julia to differentiate functions. For example, using Calculus differentiate("-exp(x)+exp(-x/2)\*(2\*cos((sqrt(3)/2)\*x)+sin((sqrt(3)/2)\*x))",:x) Everything works beautifully. Now I want to def…

---

## [Gtk / PackageCompiler / App runtime error](https://discourse.julialang.org/t/gtk-packagecompiler-app-runtime-error/75822)

<div class="topic-metadata">

**Author:** [@nshaviv](https://discourse.julialang.org/u/nshaviv)\
**Replies:** 0\
**Last updated:** [February 4, 2022, 9:42pm UTC](https://discourse.julialang.org/t/gtk-packagecompiler-app-runtime-error/75822 "2022-02-04T21:42:36Z")

</div>

Hi, I’m trying to get a Gtk standalone application using PackageCompiler. I managed to overcome many hurdles, and finally it works, well, almost… When I run the .exe that was built, I get a bunch of errors like (MyApp…

---

## [Generator expression optimization for a known iteration set](https://discourse.julialang.org/t/generator-expression-optimization-for-a-known-iteration-set/75809)

<div class="topic-metadata">

**Author:** [@RGon](https://discourse.julialang.org/u/RGon)\
**Replies:** 0\
**Last updated:** [February 4, 2022, 5:09pm UTC](https://discourse.julialang.org/t/generator-expression-optimization-for-a-known-iteration-set/75809 "2022-02-04T17:09:25Z")

</div>

I tend to run into a lot of situations where I’m iterating over something that is constant based on the input type. One example is a pattern where I want return a modified immutable function function modifyfields(x::T, …

---

## [Sparsity Detection in Jacobian](https://discourse.julialang.org/t/sparsity-detection-in-jacobian/75756)

<div class="topic-metadata">

**Author:** [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Replies:** 1\
**Last updated:** [February 4, 2022, 4:53pm UTC](https://discourse.julialang.org/t/sparsity-detection-in-jacobian/75756 "2022-02-04T16:53:11Z")

</div>

When trying to run https://diffeq.sciml.ai/stable/tutorials/advanced\_ode\_example/#Declaring-a-Sparse-Jacobian-with-Automatic-Sparsity-Detection I obtain MethodError: no method matching jacobian\_sparsity(::var"#7#8", :…

---

## [How to update two NN with different optimisers and common gradient](https://discourse.julialang.org/t/how-to-update-two-nn-with-different-optimisers-and-common-gradient/75657)

<div class="topic-metadata">

**Author:** [@Avec](https://discourse.julialang.org/u/Avec)\
**Replies:** 5\
**Last updated:** [February 4, 2022, 3:32pm UTC](https://discourse.julialang.org/t/how-to-update-two-nn-with-different-optimisers-and-common-gradient/75657 "2022-02-04T15:32:24Z")

</div>

Hi all, I have two neural networks which I optimize at the same time. Right now it looks somethign like this using Flux Gx = Chain(Conv((3,3), 8=\>4; stride=2, pad=1), BatchNorm(4), x-\>leakyrelu…

---

## [Extracting contents of .tgz file](https://discourse.julialang.org/t/extracting-contents-of-tgz-file/75801)

<div class="topic-metadata">

**Author:** [@Rajesh\_Nakka](https://discourse.julialang.org/u/Rajesh_Nakka)\
**Replies:** 1\
**Last updated:** [February 4, 2022, 3:01pm UTC](https://discourse.julialang.org/t/extracting-contents-of-tgz-file/75801 "2022-02-04T15:01:13Z")

</div>

I am trying to extract contents of a file with tgz extension. I have tried Tar.jl, CodecZlib.jl, Tariterators.jl …etc. without success. I think they have the necessary capabilities but I am not sure how to get it. Could…

---

## [Trait dispatch causing allocations](https://discourse.julialang.org/t/trait-dispatch-causing-allocations/75742)

<div class="topic-metadata">

**Author:** [@jg-854](https://discourse.julialang.org/u/jg-854)\
**Replies:** 9\
**Last updated:** [February 4, 2022, 2:06pm UTC](https://discourse.julialang.org/t/trait-dispatch-causing-allocations/75742 "2022-02-04T14:06:51Z")

</div>

I am simulating electronic circuits and I have chosen to adopt a modular model which works on objects of type Component. A Component can be a Resistor, Capacitor, or even a Serial/Parallel combination of Components. Th…

---

## [Save in Quicktime-compatible format (not H264 - MPEG-4 AVC (part 10) )](https://discourse.julialang.org/t/save-in-quicktime-compatible-format-not-h264-mpeg-4-avc-part-10/75700)

<div class="topic-metadata">

**Author:** [@georgematheos](https://discourse.julialang.org/u/georgematheos)\
**Replies:** 4\
**Last updated:** [February 4, 2022, 11:24am UTC](https://discourse.julialang.org/t/save-in-quicktime-compatible-format-not-h264-mpeg-4-avc-part-10/75700 "2022-02-04T11:24:43Z")

</div>

When I run VideoIO.save( "video.mp4", images, framerate=5; encoder\_options=(crf=23, preset="medium") ) it successfully saves an mp4 video, but it saves it with a codec that Quicktime player is unable to open on…

---

## [Filter doesn't work on grouped dataframe](https://discourse.julialang.org/t/filter-doesnt-work-on-grouped-dataframe/27322)

<div class="topic-metadata">

**Author:** [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Replies:** 5\
**Last updated:** [February 4, 2022, 5:32am UTC](https://discourse.julialang.org/t/filter-doesnt-work-on-grouped-dataframe/27322 "2022-02-04T05:32:44Z")

</div>

The problem is simple, I have a grouped data frame and I want to throw out groups. filter however, does not work. This seems like a very common idiom, so I’m thinking I’m missing some very simple way to handle it. p.s.…

---

## [Broadcasting of logical operators in v1.6 vs v1.7](https://discourse.julialang.org/t/broadcasting-of-logical-operators-in-v1-6-vs-v1-7/75772)

<div class="topic-metadata">

**Author:** [@zengfung](https://discourse.julialang.org/u/zengfung)\
**Replies:** 2\
**Last updated:** [February 4, 2022, 4:14am UTC](https://discourse.julialang.org/t/broadcasting-of-logical-operators-in-v1-6-vs-v1-7/75772 "2022-02-04T04:14:54Z")

</div>

I’m trying to use broadcasting on logical operators in Julia. I find that the same broadcasting code works in v1.7 (right) but not v1.6 (left). Can anyone explain why this is the case? What is a workaround for this s…

---

## [Understanding an argument-modifying function](https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760)

<div class="topic-metadata">

**Author:** [@wub7quxa](https://discourse.julialang.org/u/wub7quxa)\
**Replies:** 2\
**Last updated:** [February 3, 2022, 9:10pm UTC](https://discourse.julialang.org/t/understanding-an-argument-modifying-function/75760 "2022-02-03T21:10:39Z")

</div>

I am using NLsolve to solve systems of nonlinear equations. Everything works fine, but I want to understand what this function does: function f!(F, x) F\[1\]=x\[1\]^2+3\*x\[2\]^2-9 F\[2\]=17\*x\[2\]-14\*x\[1\]^2+49 end f! app…

---

## [Dictionary use and assignment](https://discourse.julialang.org/t/dictionary-use-and-assignment/75746)

<div class="topic-metadata">

**Author:** [@Tominapa](https://discourse.julialang.org/u/Tominapa)\
**Replies:** 3\
**Last updated:** [February 3, 2022, 7:54pm UTC](https://discourse.julialang.org/t/dictionary-use-and-assignment/75746 "2022-02-03T19:54:02Z")

</div>

I have a question related to dictionary initialization. The code snippet illustrates the problem: function DictGen(KeyList, InitVal) return Dict(i =\> InitVal for i in collect(Iterators.product(KeyList...))) end # m…

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

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