# General Usage

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

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

**Page:** 571

---

## [Unable to use add\_agent!() function with keyword argument](https://discourse.julialang.org/t/unable-to-use-add-agent-function-with-keyword-argument/65321)

<div class="topic-metadata">

**Author:** [@imantha](https://discourse.julialang.org/u/imantha)\
**Replies:** 2\
**Last updated:** [July 26, 2021, 5:40pm UTC](https://discourse.julialang.org/t/unable-to-use-add-agent-function-with-keyword-argument/65321 "2021-07-26T17:40:05Z")

</div>

Hi, Just curious to find out if it is possible to use keyword argument with add\_agent!() function. When I tried adding a keyword argument, I got the following error : LoadError: MethodError: No Method matching CasAgent…

---

## [Load package and use exported macro, all within a macro](https://discourse.julialang.org/t/load-package-and-use-exported-macro-all-within-a-macro/65316)

<div class="topic-metadata">

**Author:** [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Replies:** 0\
**Last updated:** [July 26, 2021, 3:46pm UTC](https://discourse.julialang.org/t/load-package-and-use-exported-macro-all-within-a-macro/65316 "2021-07-26T15:46:35Z")

</div>

Can someone please explain why the following errors? macro d(np::Integer) quote using Distributed addprocs($np) @everywhere begin using Pkg Pkg.activate(".") e…

---

## [Multithreaded compute farm](https://discourse.julialang.org/t/multithreaded-compute-farm/65047)

<div class="topic-metadata">

**Author:** [@nabla](https://discourse.julialang.org/u/nabla)\
**Replies:** 26\
**Last updated:** [July 26, 2021, 3:14pm UTC](https://discourse.julialang.org/t/multithreaded-compute-farm/65047 "2021-07-26T15:14:14Z")

</div>

I searched for a function in Julia that creates a “compute farm” based on a channel: workers take tasks from a channel and put back 0 or more tasks to the same channel. (many mathematical problems seem to be approachable…

---

## [Package merged into General but cannot be added to my local machine](https://discourse.julialang.org/t/package-merged-into-general-but-cannot-be-added-to-my-local-machine/55928)

<div class="topic-metadata">

**Author:** [@iHany](https://discourse.julialang.org/u/iHany)\
**Replies:** 6\
**Last updated:** [July 26, 2021, 2:47pm UTC](https://discourse.julialang.org/t/package-merged-into-general-but-cannot-be-added-to-my-local-machine/55928 "2021-07-26T14:47:34Z")

</div>

I’ve registered a package like this but I cannot install it on my machine. (@v1.5) pkg\> add LazyFym ERROR: The following package names could not be resolved: \* LazyFym (not found in project, manifest or registry)

---

## [Speed up column looping in matrix](https://discourse.julialang.org/t/speed-up-column-looping-in-matrix/65295)

<div class="topic-metadata">

**Author:** [@HJW019](https://discourse.julialang.org/u/HJW019)\
**Replies:** 6\
**Last updated:** [July 26, 2021, 1:54pm UTC](https://discourse.julialang.org/t/speed-up-column-looping-in-matrix/65295 "2021-07-26T13:54:23Z")

</div>

I am working on a project where one of the functions is the bottleneck of speed. The problem seems to do with accessing a large matrix. I’d appreciate any advice to improve the code. The problem is represented by the fo…

---

## [Underscore does not appear in VSCode terminal windows (Mint 20.2)](https://discourse.julialang.org/t/underscore-does-not-appear-in-vscode-terminal-windows-mint-20-2/65302)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 1\
**Last updated:** [July 26, 2021, 1:20pm UTC](https://discourse.julialang.org/t/underscore-does-not-appear-in-vscode-terminal-windows-mint-20-2/65302 "2021-07-26T13:20:54Z")

</div>

This is a small annoyance: the underscore character \_ does not appear in the terminal window of VSCode: the expected output is: julia\> Char('\_') '\_': ASCII/Unicode U+005F (category Pc: Punctuation, connector) julia\> …

---

## [Trying to understand method specializations involving CartesianIndices in julia's multidimensional.jl?](https://discourse.julialang.org/t/trying-to-understand-method-specializations-involving-cartesianindices-in-julias-multidimensional-jl/65294)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 2\
**Last updated:** [July 26, 2021, 10:16am UTC](https://discourse.julialang.org/t/trying-to-understand-method-specializations-involving-cartesianindices-in-julias-multidimensional-jl/65294 "2021-07-26T10:16:50Z")

</div>

Julia’s multidimensional.jl defines the methods ndims(::Type{CartesianIndices{N}}) where {N} = N ndims(::Type{CartesianIndices{N,TT}}) where {N,TT} = N I wonder if these may not be written concisely as ndims(::Type{\<:…

---

## [Parsing datetime string](https://discourse.julialang.org/t/parsing-datetime-string/65179)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 7\
**Last updated:** [July 26, 2021, 10:09am UTC](https://discourse.julialang.org/t/parsing-datetime-string/65179 "2021-07-26T10:09:12Z")

</div>

Hi all :slight\_smile: I want to parse the following datetime string but can’t find the right format. julia\> using Dates julia\> format = dateformat"y-m-dTH:M:S.s" dateformat"y-m-dTH:M:S.s" julia\> dt\_str = "2021-05-26T…

---

## [Track memory allocation not working correctly](https://discourse.julialang.org/t/track-memory-allocation-not-working-correctly/57543)

<div class="topic-metadata">

**Author:** [@Wikunia](https://discourse.julialang.org/u/Wikunia)\
**Replies:** 8\
**Last updated:** [July 26, 2021, 9:50am UTC](https://discourse.julialang.org/t/track-memory-allocation-not-working-correctly/57543 "2021-07-26T09:50:47Z")

</div>

I’m currently a bit perplexed by --track\_allocation=user while I’m writing a blog post about BenchmarkTools and profiling. My test code is: function get\_primes(to) possible\_primes = collect(2:to) # iterate over…

---

## [How to improve performance of sum()](https://discourse.julialang.org/t/how-to-improve-performance-of-sum/64928)

<div class="topic-metadata">

**Author:** [@andrewkhardy](https://discourse.julialang.org/u/andrewkhardy)\
**Replies:** 19\
**Last updated:** [July 19, 2021, 8:13pm UTC](https://discourse.julialang.org/t/how-to-improve-performance-of-sum/64928 "2021-07-19T20:13:40Z")

</div>

Hello. I recently tried out Julia because I was hoping for a speed improvement over numpy.sum(). I’m trying to benchmark a sum for a 2D integral and so far my Julia code is much slower. I’m wondering if there’s any perf…

---

## [Outer constructor for Base.@kwdef with constrained parametric type](https://discourse.julialang.org/t/outer-constructor-for-base-kwdef-with-constrained-parametric-type/65286)

<div class="topic-metadata">

**Author:** [@Jae-Mo\_Lihm](https://discourse.julialang.org/u/Jae-Mo_Lihm)\
**Replies:** 2\
**Last updated:** [July 26, 2021, 7:45am UTC](https://discourse.julialang.org/t/outer-constructor-for-base-kwdef-with-constrained-parametric-type/65286 "2021-07-26T07:45:05Z")

</div>

julia\> Base.@kwdef struct A1{T \<: Real} n::Int end julia\> A1{T}() where {T} = A1{T}(n=3) julia\> Base.@kwdef struct A2{T} n::Int end julia\> A2{T}() where {T} = A2{T}(n=3) julia\> A1{…

---

## [Overwrite the subdataframes made with a for loop](https://discourse.julialang.org/t/overwrite-the-subdataframes-made-with-a-for-loop/65176)

<div class="topic-metadata">

**Author:** [@bojusemo](https://discourse.julialang.org/u/bojusemo)\
**Replies:** 10\
**Last updated:** [July 26, 2021, 1:54am UTC](https://discourse.julialang.org/t/overwrite-the-subdataframes-made-with-a-for-loop/65176 "2021-07-26T01:54:42Z")

</div>

Hi Guys, Could someone help me, please? I have a function with two dataframes (df1 and df2) as input that filter df1 based on a column that contains unique identifiers (IDs) and creates a subdataframe, makes a series o…

---

## [Julia API design](https://discourse.julialang.org/t/julia-api-design/65285)

<div class="topic-metadata">

**Author:** [@minetest2048](https://discourse.julialang.org/u/minetest2048)\
**Replies:** 1\
**Last updated:** [July 26, 2021, 12:26am UTC](https://discourse.julialang.org/t/julia-api-design/65285 "2021-07-26T00:26:16Z")

</div>

I want to try to reimplement pyxivapi in Julia, which is client for XIVAPI REST API. But I don’t know how to write the Julia APIs that looks like Julia library. Julia feels very different than other programming languages…

---

## [Generically iterating over arrays of points](https://discourse.julialang.org/t/generically-iterating-over-arrays-of-points/65273)

<div class="topic-metadata">

**Author:** [@dfarmer](https://discourse.julialang.org/u/dfarmer)\
**Replies:** 3\
**Last updated:** [July 25, 2021, 9:42pm UTC](https://discourse.julialang.org/t/generically-iterating-over-arrays-of-points/65273 "2021-07-25T21:42:41Z")

</div>

I’m trying to write some functions that work on arrays of 2d or 3d points, so generally speaking I’m planning to use Vector{SVector{3,T}} but I would like to make the functions generic enough to handle a 3xN matrix form …

---

## [Replacing missings based on values in two DataFrame columns](https://discourse.julialang.org/t/replacing-missings-based-on-values-in-two-dataframe-columns/64764)

<div class="topic-metadata">

**Author:** [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Replies:** 1\
**Last updated:** [July 16, 2021, 6:01pm UTC](https://discourse.julialang.org/t/replacing-missings-based-on-values-in-two-dataframe-columns/64764 "2021-07-16T18:01:27Z")

</div>

Given an input table like this: Row │ x y z │ Int64 Int64 Int64? ─────┼─────────────────────── 1 │ 100 1 missing 2 │ 101 1 missing 3 │ 102 1 missing 4 │ …

---

## [Avoiding memory allocation when repeatedly using small arrays](https://discourse.julialang.org/t/avoiding-memory-allocation-when-repeatedly-using-small-arrays/65261)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 5\
**Last updated:** [July 25, 2021, 5:13pm UTC](https://discourse.julialang.org/t/avoiding-memory-allocation-when-repeatedly-using-small-arrays/65261 "2021-07-25T17:13:11Z")

</div>

I often find myself needing fairly simple, small autodiff vector operations applied repeatedly. I don’t know how to do this without allocation each time. Is it possible? Here is an example where I’m integrating an array…

---

## [Filter and filter! give different results](https://discourse.julialang.org/t/filter-and-filter-give-different-results/65271)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 2\
**Last updated:** [July 25, 2021, 5:11pm UTC](https://discourse.julialang.org/t/filter-and-filter-give-different-results/65271 "2021-07-25T17:11:42Z")

</div>

I am wondering why filter and filter! give different results in the example below. Case 1 with filter! includes an extra element whereas Case 2 with filter works as expected mutable struct M x::Int y::Int end C…

---

## [Selectively unpacking binary data](https://discourse.julialang.org/t/selectively-unpacking-binary-data/64768)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 1\
**Last updated:** [July 25, 2021, 11:08am UTC](https://discourse.julialang.org/t/selectively-unpacking-binary-data/64768 "2021-07-25T11:08:57Z")

</div>

I need to unpack a few values of known types and offsets from a binary file. The difference with earlier discussed cases is, firstly, that the values are not adjacent in the file, so it is necessary to specify offsefs; …

---

## [Different @code\_warntype behavior depending on number of fileds in 'struct'](https://discourse.julialang.org/t/different-code-warntype-behavior-depending-on-number-of-fileds-in-struct/65259)

<div class="topic-metadata">

**Author:** [@sidelkin](https://discourse.julialang.org/u/sidelkin)\
**Replies:** 2\
**Last updated:** [July 25, 2021, 3:54pm UTC](https://discourse.julialang.org/t/different-code-warntype-behavior-depending-on-number-of-fileds-in-struct/65259 "2021-07-25T15:54:34Z")

</div>

Hello. When the number of fields in a struct is less than 15, @code\_warntype diagnoses that the function is ‘type-stable’. But as their number grows, the function becomes ‘type-unstable’ from @code\_warntype’s point of v…

---

## [How apply Subtraction operator to extrema() function](https://discourse.julialang.org/t/how-apply-subtraction-operator-to-extrema-function/65255)

<div class="topic-metadata">

**Author:** [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Replies:** 1\
**Last updated:** [July 25, 2021, 8:29am UTC](https://discourse.julialang.org/t/how-apply-subtraction-operator-to-extrema-function/65255 "2021-07-25T08:29:22Z")

</div>

How apply Subtraction operator to extrema() function julia\> extrema(2:10) (2, 10) julia\> -(2,10) -8 julia\> -extrema(2:10) ERROR: MethodError: no method matching -(::Tuple{Int64, Int64}) Closest candidates are: -(::Un…

---

## [Naive dot product faster in Fortran than in Juila](https://discourse.julialang.org/t/naive-dot-product-faster-in-fortran-than-in-juila/63317)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 12\
**Last updated:** [July 24, 2021, 11:03pm UTC](https://discourse.julialang.org/t/naive-dot-product-faster-in-fortran-than-in-juila/63317 "2021-07-24T23:03:42Z")

</div>

Does anyone knows why this simple dot product is faster in Fortran then in Julia? (LinearAlgebra.dot is faster and with LoopVectorization the Julia code gets also faster. but this is not what I am questioning. I am curi…

---

## [First order ODE with input delay](https://discourse.julialang.org/t/first-order-ode-with-input-delay/65231)

<div class="topic-metadata">

**Author:** [@Fabian](https://discourse.julialang.org/u/Fabian)\
**Replies:** 1\
**Last updated:** [July 24, 2021, 7:18pm UTC](https://discourse.julialang.org/t/first-order-ode-with-input-delay/65231 "2021-07-24T19:18:05Z")

</div>

Hi, I am new to Julia / Turing.jl and wondering if it is possible to estimate the affine parameters a,b of the following model. The model is a stochastic differential equation (SDE) of first order with variable input d…

---

## [How to check \`-O\` optimization flag setting inside script?](https://discourse.julialang.org/t/how-to-check-o-optimization-flag-setting-inside-script/65233)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 2\
**Last updated:** [July 24, 2021, 2:05pm UTC](https://discourse.julialang.org/t/how-to-check-o-optimization-flag-setting-inside-script/65233 "2021-07-24T14:05:01Z")

</div>

I’m writing a script to run a performance benchmark. I’d like to add a check that Julia is running with full optimization (i.e. -O3) to ensure the results are representative. Is there a way to get the -O optimization fla…

---

## [How do I know if an unbuffered (0 sized) channel ready to put! (not blocking)?](https://discourse.julialang.org/t/how-do-i-know-if-an-unbuffered-0-sized-channel-ready-to-put-not-blocking/65228)

<div class="topic-metadata">

**Author:** [@zwtechnb](https://discourse.julialang.org/u/zwtechnb)\
**Replies:** 0\
**Last updated:** [July 24, 2021, 10:43am UTC](https://discourse.julialang.org/t/how-do-i-know-if-an-unbuffered-0-sized-channel-ready-to-put-not-blocking/65228 "2021-07-24T10:43:48Z")

</div>

For a buffered channel(n) with n\>0, I can check it full or not with comparing the Channel field: sz\_max with the undocumented function Base.n\_avail(channel). For channel(0), when a take! on it, a put! can be operated on…

---

## [Why does Julia allocate memory when I already pre-allocated?](https://discourse.julialang.org/t/why-does-julia-allocate-memory-when-i-already-pre-allocated/65223)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 5\
**Last updated:** [July 24, 2021, 9:25am UTC](https://discourse.julialang.org/t/why-does-julia-allocate-memory-when-i-already-pre-allocated/65223 "2021-07-24T09:25:16Z")

</div>

Look at the code here. julia\> results = Vector{Int}(undef, 10^7); julia\> @time for i in 1:10^7 results\[i\] = i end 0.315568 seconds (20.00 M allocations: 305.160 MiB, 5.86% gc time) Why is there mem…

---

## [IJulia Kernel not starting unless IJulia is installed in the global environment, ie (v1.1)](https://discourse.julialang.org/t/ijulia-kernel-not-starting-unless-ijulia-is-installed-in-the-global-environment-ie-v1-1/21172)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 9\
**Last updated:** [July 24, 2021, 3:10am UTC](https://discourse.julialang.org/t/ijulia-kernel-not-starting-unless-ijulia-is-installed-in-the-global-environment-ie-v1-1/21172 "2021-07-24T03:10:47Z")

</div>

I recently updated my mac to latest Mojave (10.14.3) and it looks like IJulia no longer works (Safari 12.0.3). The executed cell just hangs and never returns. I see lots of JS errors. julia\> versioninfo() Julia Versi…

---

## [Julia script.jl arg1 arg2... =\> script.exe arg1, arg2...?](https://discourse.julialang.org/t/julia-script-jl-arg1-arg2-script-exe-arg1-arg2/65193)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 2\
**Last updated:** [July 23, 2021, 7:43pm UTC](https://discourse.julialang.org/t/julia-script-jl-arg1-arg2-script-exe-arg1-arg2/65193 "2021-07-23T19:43:11Z")

</div>

I wonder if the the command-line call julia script.jl arg1 arg2… can be done with a compiled C-code: script.exe arg1 arg2… Would this reduce start-up time/TTFP? Looking at Embedding Julia there is only a small e…

---

## [Finding the module of a callsite in the stacktrace](https://discourse.julialang.org/t/finding-the-module-of-a-callsite-in-the-stacktrace/65191)

<div class="topic-metadata">

**Author:** [@haberdashPI](https://discourse.julialang.org/u/haberdashPI)\
**Replies:** 0\
**Last updated:** [July 23, 2021, 4:42pm UTC](https://discourse.julialang.org/t/finding-the-module-of-a-callsite-in-the-stacktrace/65191 "2021-07-23T16:42:58Z")

</div>

I want to get an item returned from stacktrace() such that it is the first StackFrame for which getmodule(x) == m where m is some known module. This works: getmodule(x) = nothing getmodule(x::Base.StackTraces.StackFrame…

---

## [Is it possible to dump segfault stack trace from REPL-only crash?](https://discourse.julialang.org/t/is-it-possible-to-dump-segfault-stack-trace-from-repl-only-crash/65172)

<div class="topic-metadata">

**Author:** [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Replies:** 3\
**Last updated:** [July 23, 2021, 4:41pm UTC](https://discourse.julialang.org/t/is-it-possible-to-dump-segfault-stack-trace-from-repl-only-crash/65172 "2021-07-23T16:41:11Z")

</div>

I ran into this issue https://github.com/julia-vscode/julia-vscode/issues/2299 that can only be reproduced in the REPL (one that’s connected to VS Code). I am trying to obtain a useful dump from the segfault following R…

---

## [Iterators over observations/data](https://discourse.julialang.org/t/iterators-over-observations-data/65158)

<div class="topic-metadata">

**Author:** [@stephancb](https://discourse.julialang.org/u/stephancb)\
**Replies:** 1\
**Last updated:** [July 23, 2021, 3:39pm UTC](https://discourse.julialang.org/t/iterators-over-observations-data/65158 "2021-07-23T15:39:32Z")

</div>

Is there a reason why in StatsBase fit(Histogram, obs::AbstractArray, bins,...) does not accept an iterator over the observations? Possible sources of observations are streams, csv files, databases etc. To just bin them…

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

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