# General Usage

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

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

**Page:** 644

---

## [Update on single dispatch benchmark comparison to C++](https://discourse.julialang.org/t/update-on-single-dispatch-benchmark-comparison-to-c/7283)

<div class="topic-metadata">

**Author:** [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Replies:** 19\
**Last updated:** [February 13, 2021, 5:47pm UTC](https://discourse.julialang.org/t/update-on-single-dispatch-benchmark-comparison-to-c/7283 "2021-02-13T17:47:39Z")

</div>

Hi, I’m making an update of the benchmarks I had ran back in 2015, comparing the performance of Julia dispatch on single argument against C++ dispatch: Redirecting to Google Groups The code is in here: https://github.c…

---

## [Unexpected behavior: include() and @\_\_DIR\_\_](https://discourse.julialang.org/t/unexpected-behavior-include-and-dir/55218)

<div class="topic-metadata">

**Author:** [@JuergenD](https://discourse.julialang.org/u/JuergenD)\
**Replies:** 0\
**Last updated:** [February 13, 2021, 5:34pm UTC](https://discourse.julialang.org/t/unexpected-behavior-include-and-dir/55218 "2021-02-13T17:34:38Z")

</div>

I’m regularly using @doc read(joinpath(dirname(@\_\_DIR\_\_), "README.md"), String) MyModule for the (sub)module documentation. Unfortunately @DIR doesn’t behave like documented Base.@\_\_DIR\_\_ — Macro @\_\_DIR\_\_ -\> Abstract…

---

## [Efficient lexicographic ordering of custom types?](https://discourse.julialang.org/t/efficient-lexicographic-ordering-of-custom-types/55209)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 4\
**Last updated:** [February 13, 2021, 4:18pm UTC](https://discourse.julialang.org/t/efficient-lexicographic-ordering-of-custom-types/55209 "2021-02-13T16:18:15Z")

</div>

Suppose I have the Julia type struct Car model::String year::Int32 miles::Int32 end I’d like to overload the isless() function, to enable sorting variables of the type Array{Car, 1}. I would like to sort ac…

---

## [Why is SVector faster than MVector](https://discourse.julialang.org/t/why-is-svector-faster-than-mvector/55174)

<div class="topic-metadata">

**Author:** [@Volker\_Weissmann](https://discourse.julialang.org/u/Volker_Weissmann)\
**Replies:** 13\
**Last updated:** [February 13, 2021, 4:07pm UTC](https://discourse.julialang.org/t/why-is-svector-faster-than-mvector/55174 "2021-02-13T16:07:34Z")

</div>

Why are these nearly identical function not compiled into the same llvm ir? using StaticArrays using BenchmarkTools function funcS() ret = SVector(0,0) ret = ret + SVector(123, 321) return ret end function f…

---

## [Parametric type conversion without eval/repetition?](https://discourse.julialang.org/t/parametric-type-conversion-without-eval-repetition/54308)

<div class="topic-metadata">

**Author:** [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Replies:** 10\
**Last updated:** [February 13, 2021, 2:25pm UTC](https://discourse.julialang.org/t/parametric-type-conversion-without-eval-repetition/54308 "2021-02-13T14:25:18Z")

</div>

Suppose I have several parametric wrapper types, like so (toy example): abstract type AbsWrapper end struct WrapperA{T \<: Real} \<: AbsWrapper x::T end struct WrapperB{T \<: Real} \<: AbsWrapper x::T end I’d like …

---

## [I am probably missing something very obvious. Can someone help me understand this?](https://discourse.julialang.org/t/i-am-probably-missing-something-very-obvious-can-someone-help-me-understand-this/55193)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [February 13, 2021, 9:14am UTC](https://discourse.julialang.org/t/i-am-probably-missing-something-very-obvious-can-someone-help-me-understand-this/55193 "2021-02-13T09:14:39Z")

</div>

I am probably missing something very obvious. Can someone help me understand this? foo\_string = "foo" foo\_dict = Dict("f"=&gt;0, "o"=&gt;0) this: haskey(foo\_dict, "f") returns: true but why does for char in foo\_str…

---

## [What's the recommended way to solve LP problems with \`BigFloat\` constraints and no](https://discourse.julialang.org/t/whats-the-recommended-way-to-solve-lp-problems-with-bigfloat-constraints-and-no/55167)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [February 13, 2021, 6:31am UTC](https://discourse.julialang.org/t/whats-the-recommended-way-to-solve-lp-problems-with-bigfloat-constraints-and-no/55167 "2021-02-13T06:31:03Z")

</div>

What’s the recommended way to solve LP problems with BigFloat constraints and no objective function? Tulip+ JuMP? Cosmo + Convex? Something else? Note that the original poster on Slack cannot see your response here on D…

---

## [Util for debugging channels/threads performance: should I publish a package?](https://discourse.julialang.org/t/util-for-debugging-channels-threads-performance-should-i-publish-a-package/55093)

<div class="topic-metadata">

**Author:** [@pmilovanov](https://discourse.julialang.org/u/pmilovanov)\
**Replies:** 2\
**Last updated:** [February 13, 2021, 5:37am UTC](https://discourse.julialang.org/t/util-for-debugging-channels-threads-performance-should-i-publish-a-package/55093 "2021-02-13T05:37:13Z")

</div>

I wrote some code for myself to better understand what’s going on with threads and channels in my app. It implements TrackingChannel, a wrapper around a channel that measures how long take!, put!, fetch ops took on that …

---

## [Vector local to loop iteration vs. Static Vector](https://discourse.julialang.org/t/vector-local-to-loop-iteration-vs-static-vector/55109)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 6\
**Last updated:** [February 12, 2021, 7:41pm UTC](https://discourse.julialang.org/t/vector-local-to-loop-iteration-vs-static-vector/55109 "2021-02-12T19:41:41Z")

</div>

In simple the example below, I write two functions that compute “the force” between the particles of a set. To compute the forces between each pair of particles one needs to compute the difference in position of the two …

---

## [Tips to cope with scoping rules of top level \`for\` loops etc](https://discourse.julialang.org/t/tips-to-cope-with-scoping-rules-of-top-level-for-loops-etc/24902)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 27\
**Last updated:** [February 12, 2021, 7:28pm UTC](https://discourse.julialang.org/t/tips-to-cope-with-scoping-rules-of-top-level-for-loops-etc/24902 "2021-02-12T19:28:19Z")

</div>

The issue of the scoping rules of top-level for loops (and their kind) revives from time to time, and it seems that this will continue happening for a while; so I thought that it might be useful to share some thoughts an…

---

## [@everything copy absolutely everything in main process](https://discourse.julialang.org/t/everything-copy-absolutely-everything-in-main-process/55159)

<div class="topic-metadata">

**Author:** [@s-baumann](https://discourse.julialang.org/u/s-baumann)\
**Replies:** 4\
**Last updated:** [February 12, 2021, 6:08pm UTC](https://discourse.julialang.org/t/everything-copy-absolutely-everything-in-main-process/55159 "2021-02-12T18:08:52Z")

</div>

I have a long script that has alot of functions defined and packages included. Then there is a big for loop at the end I want to parallelise. For a minimal example: using Distributed Distributed.addprocs(4) @everywhere …

---

## [Do I have some way to find out where that function is coming from at runtime?](https://discourse.julialang.org/t/do-i-have-some-way-to-find-out-where-that-function-is-coming-from-at-runtime/55152)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [February 12, 2021, 4:45pm UTC](https://discourse.julialang.org/t/do-i-have-some-way-to-find-out-where-that-function-is-coming-from-at-runtime/55152 "2021-02-12T16:45:53Z")

</div>

Do I have some way to find out where that function is coming from at runtime? Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack,…

---

## [How to programmatically create and save an image with some text?](https://discourse.julialang.org/t/how-to-programmatically-create-and-save-an-image-with-some-text/55086)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 6\
**Last updated:** [February 12, 2021, 4:34pm UTC](https://discourse.julialang.org/t/how-to-programmatically-create-and-save-an-image-with-some-text/55086 "2021-02-12T16:34:29Z")

</div>

I would like to programmatically “compose” and save as PNG an image with a white background and a digit in the center, of a given font, colour, size. Which approach may I have? I am thinking to plots, but it seems “exag…

---

## [Cannot call \`show(io,MIME...\`](https://discourse.julialang.org/t/cannot-call-show-io-mime/55158)

<div class="topic-metadata">

**Author:** [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Replies:** 2\
**Last updated:** [February 12, 2021, 3:54pm UTC](https://discourse.julialang.org/t/cannot-call-show-io-mime/55158 "2021-02-12T15:54:41Z")

</div>

I am surprised by the following julia\> struct Thing end julia\> x=Thing() Thing() julia\> Base.show(io::IO,::MIME"text/plain",x::Thing)=print(io,"hello") julia\> show(stdout,MIME"text/plain",x) ERROR: MethodError: no me…

---

## [Hi, I am reading through some code and I have something like this happening:\`\`\`](https://discourse.julialang.org/t/hi-i-am-reading-through-some-code-and-i-have-something-like-this-happening/55151)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [February 12, 2021, 3:10pm UTC](https://discourse.julialang.org/t/hi-i-am-reading-through-some-code-and-i-have-something-like-this-happening/55151 "2021-02-12T15:10:25Z")

</div>

Hi, I am reading through some code and I have something like this happening: all(x) = all\_gaus(x, y) Now I cannot seem to find at all where the all\_gaus function is. I see a candidate, but changing that candidate …

---

## [Fixing parameter values to create new simpler function](https://discourse.julialang.org/t/fixing-parameter-values-to-create-new-simpler-function/55134)

<div class="topic-metadata">

**Author:** [@danielward27](https://discourse.julialang.org/u/danielward27)\
**Replies:** 2\
**Last updated:** [February 12, 2021, 11:16am UTC](https://discourse.julialang.org/t/fixing-parameter-values-to-create-new-simpler-function/55134 "2021-02-12T11:16:07Z")

</div>

Very new to Julia, so apologies for the naive question. I was wondering if there was a neat way to fix parameter values in a function, to create a new simpler function. The reason I want to do this is because certain opt…

---

## [What is the fastest way to perform unary operation inplace?](https://discourse.julialang.org/t/what-is-the-fastest-way-to-perform-unary-operation-inplace/55139)

<div class="topic-metadata">

**Author:** [@encendre](https://discourse.julialang.org/u/encendre)\
**Replies:** 1\
**Last updated:** [February 12, 2021, 11:09am UTC](https://discourse.julialang.org/t/what-is-the-fastest-way-to-perform-unary-operation-inplace/55139 "2021-02-12T11:09:16Z")

</div>

What is the fastest way to perform unary operation inplace ? I have tried the followings b = rand(1000000) @time b = -b # 0.011017 seconds (2 allocations: 7.629 MiB) @time b = (-).(b) # 0.012952 seconds (2 allocatio…

---

## [PyError - with ExcelReaders perhaps](https://discourse.julialang.org/t/pyerror-with-excelreaders-perhaps/55092)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 1\
**Last updated:** [February 12, 2021, 7:12am UTC](https://discourse.julialang.org/t/pyerror-with-excelreaders-perhaps/55092 "2021-02-12T07:12:19Z")

</div>

Hello, I am getting an error with PyCall that I am having a hard time interpreting. I think that the error might be caused by using ExcelReaders . The other weird thing is that if I run my code one, it appears. If I run…

---

## [Lightgraph Loses MetaGraphs MetaData](https://discourse.julialang.org/t/lightgraph-loses-metagraphs-metadata/55067)

<div class="topic-metadata">

**Author:** [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Replies:** 0\
**Last updated:** [February 11, 2021, 3:48pm UTC](https://discourse.julialang.org/t/lightgraph-loses-metagraphs-metadata/55067 "2021-02-11T15:48:00Z")

</div>

Hi, I have two graphs independent graphs which have metadata included (via Metagraphs). I want to join both graphs and put an edge in to connect them as 1 graph. I do this with blockdiag() However, that loses my metadat…

---

## [Slurm doesn't like @spawnat :any](https://discourse.julialang.org/t/slurm-doesnt-like-spawnat-any/55112)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 3\
**Last updated:** [February 12, 2021, 6:30am UTC](https://discourse.julialang.org/t/slurm-doesnt-like-spawnat-any/55112 "2021-02-12T06:30:09Z")

</div>

I don’t really have an MWE for this. It never fails on the desktop (10 workers), but when it runs on hpc (single node 40 workers) I get really messy errors. I have plenty of distributed for loops in other sections of t…

---

## [Parallel errors in a Module, using pmap()](https://discourse.julialang.org/t/parallel-errors-in-a-module-using-pmap/54313)

<div class="topic-metadata">

**Author:** [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Replies:** 2\
**Last updated:** [February 12, 2021, 4:37am UTC](https://discourse.julialang.org/t/parallel-errors-in-a-module-using-pmap/54313 "2021-02-12T04:37:00Z")

</div>

I create a package and using pmap for parallel. Encountered many errors, when run Pkg \> test. The package is as follows. file1: /ParalAlg/src/ParalAlg.jl module ParalAlg using Distributed Distributed.addprocs(3) @ever…

---

## [5/5000 Why is the error reported? UndefVarError: fit! not defined](https://discourse.julialang.org/t/5-5000-why-is-the-error-reported-undefvarerror-fit-not-defined/55118)

<div class="topic-metadata">

**Author:** [@Jianqing001](https://discourse.julialang.org/u/Jianqing001)\
**Replies:** 0\
**Last updated:** [February 12, 2021, 4:04am UTC](https://discourse.julialang.org/t/5-5000-why-is-the-error-reported-undefvarerror-fit-not-defined/55118 "2021-02-12T04:04:07Z")

</div>

julia\> using RDatasets: dataset julia\> iris = dataset(“datasets”, “iris”); julia\> first(iris, 5) … julia\> X = convert(Array, iris\[!, \[:SepalLength, :SepalWidth, :PetalLength, :PetalWidth\]\]) … julia\> y = convert(Arr…

---

## [Reducing allocations and run time](https://discourse.julialang.org/t/reducing-allocations-and-run-time/55087)

<div class="topic-metadata">

**Author:** [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Replies:** 8\
**Last updated:** [February 12, 2021, 1:18am UTC](https://discourse.julialang.org/t/reducing-allocations-and-run-time/55087 "2021-02-12T01:18:25Z")

</div>

Hi, I’m running a program and trying to speed it up. I don’t get the logic of views, or any other way to reduce the number of allocations. A simplified example is aa = \[4 3; 4 5\] bb = \[1 2;6 3\] cc = zeros(2,2,2) @time …

---

## [Transform Markdown file from Literate.jl to HTML](https://discourse.julialang.org/t/transform-markdown-file-from-literate-jl-to-html/50515)

<div class="topic-metadata">

**Author:** [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Replies:** 5\
**Last updated:** [February 12, 2021, 12:25am UTC](https://discourse.julialang.org/t/transform-markdown-file-from-literate-jl-to-html/50515 "2021-02-12T00:25:59Z")

</div>

I am experimenting with using Literate.jl for a tutorial and I would like to produce HTML from the Markdown file produced by Literate.markdown, preferably without going through Documenter.jl Can someone suggest a pipeli…

---

## [Distributed Array partition index](https://discourse.julialang.org/t/distributed-array-partition-index/53776)

<div class="topic-metadata">

**Author:** [@matthiasbe](https://discourse.julialang.org/u/matthiasbe)\
**Replies:** 1\
**Last updated:** [February 11, 2021, 11:01pm UTC](https://discourse.julialang.org/t/distributed-array-partition-index/53776 "2021-02-11T23:01:17Z")

</div>

Hi, I’m using DistributedArrays. Is there a way to obtain the local index of a partition in the partition grid ? It would be like the hypothetical local\_partition\_index() method below. using DistributedArrays A = dra…

---

## [Concatenate two csv columns in julia](https://discourse.julialang.org/t/concatenate-two-csv-columns-in-julia/55084)

<div class="topic-metadata">

**Author:** [@yogi1](https://discourse.julialang.org/u/yogi1)\
**Replies:** 4\
**Last updated:** [February 11, 2021, 9:58pm UTC](https://discourse.julialang.org/t/concatenate-two-csv-columns-in-julia/55084 "2021-02-11T21:58:08Z")

</div>

Hi all, I am trying to replicate the excel function concat in julia. I have two columns A and B. I am trying to concatenate the values in these columns and produce a single column with the values in columns A and colum…

---

## [Bug Report](https://discourse.julialang.org/t/bug-report/55081)

<div class="topic-metadata">

**Author:** [@faoh](https://discourse.julialang.org/u/faoh)\
**Replies:** 1\
**Last updated:** [February 11, 2021, 7:32pm UTC](https://discourse.julialang.org/t/bug-report/55081 "2021-02-11T19:32:59Z")

</div>

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks. Exception: EXCEPTION\_ACCESS\_VIOLATION at 0x6b64b09f – jl\_compile\_linfo at /home/Administrato…

---

## [Is using values() the correct way to obtain the namedtuple in keyword arguments?](https://discourse.julialang.org/t/is-using-values-the-correct-way-to-obtain-the-namedtuple-in-keyword-arguments/55074)

<div class="topic-metadata">

**Author:** [@anon60034542](https://discourse.julialang.org/u/anon60034542)\
**Replies:** 1\
**Last updated:** [February 11, 2021, 6:56pm UTC](https://discourse.julialang.org/t/is-using-values-the-correct-way-to-obtain-the-namedtuple-in-keyword-arguments/55074 "2021-02-11T18:56:04Z")

</div>

Suppose I had the following method: function character\_information(name::String, age::Int32; c...) println("Name: $name Age: $age") c\_values = values(c) println(c\_values.Alignment) end # We're not foll…

---

## [Does anyone know why this repo's CompatHelper doesn't start CI?](https://discourse.julialang.org/t/does-anyone-know-why-this-repos-compathelper-doesnt-start-ci/55061)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [February 11, 2021, 4:19pm UTC](https://discourse.julialang.org/t/does-anyone-know-why-this-repos-compathelper-doesnt-start-ci/55061 "2021-02-11T16:19:41Z")

</div>

Does anyone know why this repo’s CompatHelper doesn’t start CI? https://github.com/SciML/DiffEqBayes.jl/pull/200 Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing t…

---

## [Faster conversion to CategoricalArray with many groups](https://discourse.julialang.org/t/faster-conversion-to-categoricalarray-with-many-groups/55057)

<div class="topic-metadata">

**Author:** [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Replies:** 3\
**Last updated:** [February 11, 2021, 4:15pm UTC](https://discourse.julialang.org/t/faster-conversion-to-categoricalarray-with-many-groups/55057 "2021-02-11T16:15:00Z")

</div>

I need to convert columns in a larger (~20M rows) DataFrame to CategoricalArrays to be used with MixedModels and FixedEffectModels (I think the latter does not require Categorical but the former does). If there are many …

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

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