# General Usage

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

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

**Page:** 524

---

## [Splatting a vector into hypot](https://discourse.julialang.org/t/splatting-a-vector-into-hypot/71049)

<div class="topic-metadata">

**Author:** [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Replies:** 4\
**Last updated:** [November 6, 2021, 5:00pm UTC](https://discourse.julialang.org/t/splatting-a-vector-into-hypot/71049 "2021-11-06T17:00:30Z")

</div>

The following code takes an extremely long time to compile on my computer: x = randn(10000); hypot(x...) # 220.104289 seconds (66.32 M allocations: 5.422 GiB, 0.88% gc time, 100.00% compilation time) hypot(x...) # 0.001…

---

## [Interpolation to any string](https://discourse.julialang.org/t/interpolation-to-any-string/71020)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 6\
**Last updated:** [November 6, 2021, 7:05pm UTC](https://discourse.julialang.org/t/interpolation-to-any-string/71020 "2021-11-06T19:05:11Z")

</div>

Hi, is it possible to create a universal function to interpolation to any string? maybe there is a function to pass values to the template one at time? teplate = "\\$str1 \\$str2" function get\_text\_by\_template(teplate; …

---

## [Function closure with large arrays/matrices scaling horribly](https://discourse.julialang.org/t/function-closure-with-large-arrays-matrices-scaling-horribly/71027)

<div class="topic-metadata">

**Author:** [@vivian-rogers](https://discourse.julialang.org/u/vivian-rogers)\
**Replies:** 6\
**Last updated:** [November 6, 2021, 3:19pm UTC](https://discourse.julialang.org/t/function-closure-with-large-arrays-matrices-scaling-horribly/71027 "2021-11-06T15:19:33Z")

</div>

Hi! So I am trying to set up a useful function f to pass around the rest of my code as follows: function f\_prepostproc(params) # do stuff f = f\_generator(params) # evaluate f at certain x values, save to file…

---

## [Why is sorting matrices allocating and why is it sometimes slower than the naive approach?](https://discourse.julialang.org/t/why-is-sorting-matrices-allocating-and-why-is-it-sometimes-slower-than-the-naive-approach/71015)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 11\
**Last updated:** [November 6, 2021, 2:53pm UTC](https://discourse.julialang.org/t/why-is-sorting-matrices-allocating-and-why-is-it-sometimes-slower-than-the-naive-approach/71015 "2021-11-06T14:53:30Z")

</div>

I noticed that sort! is allocating here: x = rand(10, 10); @time sort!(x, dims=1); # 0.000016 seconds (20 allocations: 960 bytes) And I’m not sure why. Here is the investigation I’ve done: using BenchmarkTools funct…

---

## [Simplify signature of printed arrays](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 5\
**Last updated:** [November 5, 2021, 11:30pm UTC](https://discourse.julialang.org/t/simplify-signature-of-printed-arrays/71025 "2021-11-05T23:30:56Z")

</div>

When one prints a simple array of floats, one gets: julia\> println(ones(3)) \[1.0, 1.0, 1.0\] However, if I print an arrays of unitful quantities, I get: julia\> println(ones(3)u"nm") Quantity{Float64, 𝐋, Unitful.FreeUn…

---

## [Unable to connect to postgress with libPQ](https://discourse.julialang.org/t/unable-to-connect-to-postgress-with-libpq/70906)

<div class="topic-metadata">

**Author:** [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Replies:** 7\
**Last updated:** [November 6, 2021, 12:44am UTC](https://discourse.julialang.org/t/unable-to-connect-to-postgress-with-libpq/70906 "2021-11-06T00:44:26Z")

</div>

conn2 = LibPQ.Connection("dbname=postgres") tells me that I can’t find Unix domain socket "/tmp/.s.PGSQL.5432"? I’m using Ubuntu 20.04.3 LTS on an x86 Xeon machine. I’ve had the same issue with Crystal. Postgress i…

---

## [I guess \`@threads\` dosen't work in windows11](https://discourse.julialang.org/t/i-guess-threads-dosent-work-in-windows11/71016)

<div class="topic-metadata">

**Author:** [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)\
**Replies:** 4\
**Last updated:** [November 6, 2021, 12:23am UTC](https://discourse.julialang.org/t/i-guess-threads-dosent-work-in-windows11/71016 "2021-11-06T00:23:55Z")

</div>

Any error or warning dosen’t occur, silence, just like number of thread is 1. I tested three different enviroment: :white\_check\_mark: Windows10 Intel(R) Xeon(R) CPU E3-1270 v5 @ 3.60GHz(8 threads) :x: Windows11 Intel(…

---

## [Initialize multiple variables in one line](https://discourse.julialang.org/t/initialize-multiple-variables-in-one-line/28916)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 20\
**Last updated:** [November 5, 2021, 8:04pm UTC](https://discourse.julialang.org/t/initialize-multiple-variables-in-one-line/28916 "2021-11-05T20:04:53Z")

</div>

Hello, I would like to initialize multiple variables in one line. The following code does not work: a = b = c = Set{Symbol}() If I do: push!(a, :test) all three variables get the same value. I just want to initial…

---

## [Use of \`Perm\` to find sorted subset of indices?](https://discourse.julialang.org/t/use-of-perm-to-find-sorted-subset-of-indices/70912)

<div class="topic-metadata">

**Author:** [@mehdi](https://discourse.julialang.org/u/mehdi)\
**Replies:** 7\
**Last updated:** [November 5, 2021, 7:07pm UTC](https://discourse.julialang.org/t/use-of-perm-to-find-sorted-subset-of-indices/70912 "2021-11-05T19:07:00Z")

</div>

I want to use sortperm on only a subset of indices of an array a, I couldn’t find how to do it with the sortperm function, I can simply use sort on the subset of indices s\_subs this way: sort(s\_subs, by = x -\> a\[x\]) It…

---

## [Gradient rise was obtained by optim.jl package optimization](https://discourse.julialang.org/t/gradient-rise-was-obtained-by-optim-jl-package-optimization/69548)

<div class="topic-metadata">

**Author:** [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Replies:** 10\
**Last updated:** [November 5, 2021, 5:10pm UTC](https://discourse.julialang.org/t/gradient-rise-was-obtained-by-optim-jl-package-optimization/69548 "2021-11-05T17:10:30Z")

</div>

When I was doing optimization calculations with the Optim package\[Optim.jl\], , I found that the objective function sometimes unexpectedly tended to go up. I don’t know why this happens, hope someone can answer for me, th…

---

## [Why does "filter" use an uncommon position for the input dataframe?](https://discourse.julialang.org/t/why-does-filter-use-an-uncommon-position-for-the-input-dataframe/71004)

<div class="topic-metadata">

**Author:** [@Juan](https://discourse.julialang.org/u/Juan)\
**Replies:** 9\
**Last updated:** [November 5, 2021, 4:58pm UTC](https://discourse.julialang.org/t/why-does-filter-use-an-uncommon-position-for-the-input-dataframe/71004 "2021-11-05T16:58:04Z")

</div>

df = DataFrame(x = \[1.0,2.0,3.1, 44\], y = 4.0:7.0, z = \[1,1,2,2\]) filter(:y =\> \>=(3), df) # df must be written at the end. While other functions use the first position. subset(df, :y =\> x → x .\>= 5) select(df, \[:x,…

---

## [Collecting all solutions in a recursive branching algorithm](https://discourse.julialang.org/t/collecting-all-solutions-in-a-recursive-branching-algorithm/70936)

<div class="topic-metadata">

**Author:** [@Eugeleo](https://discourse.julialang.org/u/Eugeleo)\
**Replies:** 13\
**Last updated:** [November 5, 2021, 3:09pm UTC](https://discourse.julialang.org/t/collecting-all-solutions-in-a-recursive-branching-algorithm/70936 "2021-11-05T15:09:32Z")

</div>

Moved this from the New to Julia to a more fitting section I’m trying to translate a divide and conquer algorithm for a modified subset sum problem from Python. A simplified version might look like this: You are given a…

---

## [How to reduce memory allocations in the Sieve of Eratosthenes?](https://discourse.julialang.org/t/how-to-reduce-memory-allocations-in-the-sieve-of-eratosthenes/70679)

<div class="topic-metadata">

**Author:** [@vini-fda](https://discourse.julialang.org/u/vini-fda)\
**Replies:** 8\
**Last updated:** [November 5, 2021, 2:57pm UTC](https://discourse.julialang.org/t/how-to-reduce-memory-allocations-in-the-sieve-of-eratosthenes/70679 "2021-11-05T14:57:17Z")

</div>

Hello there! So I was trying to implement a cache-friendly version of the famous Sieve of Erathostenes in julia, and came up with this: function sieve\_cache\_optim(limit::UInt32; block\_size = 2^15) max\_primes = isqr…

---

## [Is there an in-place alternative to +=, \*=, etc.?](https://discourse.julialang.org/t/is-there-an-in-place-alternative-to-etc/70520)

<div class="topic-metadata">

**Author:** [@failedentertainment](https://discourse.julialang.org/u/failedentertainment)\
**Replies:** 1\
**Last updated:** [November 5, 2021, 3:47pm UTC](https://discourse.julialang.org/t/is-there-an-in-place-alternative-to-etc/70520 "2021-11-05T15:47:09Z")

</div>

Using += with arbitrary precision integers seems to end up using much more memory (and takes much longer) than the equivalent in-place operator (for my test, I used addeq! from Nemo and add! from Base.GMP.MPZ). Result: …

---

## [Combine two color channels in a plot / heatmap / image?](https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008)

<div class="topic-metadata">

**Author:** [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Replies:** 2\
**Last updated:** [November 5, 2021, 3:27pm UTC](https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008 "2021-11-05T15:27:48Z")

</div>

I have an image with two grayscale color channels I would like to visualize in the same plot. How can I combine them? I think I would need to add an alpha or something that scales with the gray value … Or instead of c…

---

## [Improving performance of a number of functions for large scale gradient based optimization](https://discourse.julialang.org/t/improving-performance-of-a-number-of-functions-for-large-scale-gradient-based-optimization/70980)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 11\
**Last updated:** [November 5, 2021, 2:59pm UTC](https://discourse.julialang.org/t/improving-performance-of-a-number-of-functions-for-large-scale-gradient-based-optimization/70980 "2021-11-05T14:59:30Z")

</div>

Hello, I am trying to conduct a large-scale Maximum Likelihood Estimation. Luckily, I have analytical gradients and Hessians and therefore I can speed up my optimization routine by using derivative based methods. Howev…

---

## [Automatic separating variables when printing](https://discourse.julialang.org/t/automatic-separating-variables-when-printing/70993)

<div class="topic-metadata">

**Author:** [@vmuser](https://discourse.julialang.org/u/vmuser)\
**Replies:** 9\
**Last updated:** [November 5, 2021, 2:45pm UTC](https://discourse.julialang.org/t/automatic-separating-variables-when-printing/70993 "2021-11-05T14:45:45Z")

</div>

One (very minor) thing that bothers me in Julia is that print and println do not put spaces between the arguments. So for example print(1,2,3) prints 123. I wrote my own (probably not ideal) function that does it: func…

---

## [Read labeled image with Images.jl](https://discourse.julialang.org/t/read-labeled-image-with-images-jl/70934)

<div class="topic-metadata">

**Author:** [@tsobako](https://discourse.julialang.org/u/tsobako)\
**Replies:** 7\
**Last updated:** [November 5, 2021, 2:11pm UTC](https://discourse.julialang.org/t/read-labeled-image-with-images-jl/70934 "2021-11-05T14:11:13Z")

</div>

Hi. I have made segmentation labeling of images with the following tool (Labelme repo). It allows to export labels as a PNG image with every pixel as a single byte and it could be possible to load it properly with Pytho…

---

## [Threads.@threads over an iterator does not work - is there an reason?](https://discourse.julialang.org/t/threads-threads-over-an-iterator-does-not-work-is-there-an-reason/71003)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 1\
**Last updated:** [November 5, 2021, 1:02pm UTC](https://discourse.julialang.org/t/threads-threads-over-an-iterator-does-not-work-is-there-an-reason/71003 "2021-11-05T13:02:36Z")

</div>

julia\> Threads.@threads for (index, value) in enumerate(\[1,2\]) end ERROR: TaskFailedException Stacktrace: \[1\] wait @ .\\task.jl:322 \[inlined\] \[2\] threading\_run(func::Function) @ Base.Threads .\\threadingcons…

---

## [Initialize AbstractArray?](https://discourse.julialang.org/t/initialize-abstractarray/70988)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 15\
**Last updated:** [November 5, 2021, 12:26pm UTC](https://discourse.julialang.org/t/initialize-abstractarray/70988 "2021-11-05T12:26:19Z")

</div>

Is there a way to initialize an array that is a subtype of AbstractArray? For example, x = \[\] initializes Vectors, but how can I initialize an object that can be any arbitrary subtype of AbstractArray? is it possible?

---

## [POSIXct format in Julia](https://discourse.julialang.org/t/posixct-format-in-julia/70998)

<div class="topic-metadata">

**Author:** [@jnewbie](https://discourse.julialang.org/u/jnewbie)\
**Replies:** 1\
**Last updated:** [November 5, 2021, 10:41am UTC](https://discourse.julialang.org/t/posixct-format-in-julia/70998 "2021-11-05T10:41:38Z")

</div>

Hello everyone I am translating an R program into Julia. I have a problem because I assign the type POSIXct (POSIXct class stores date/time values as the number of seconds since January 1, 1970) to one of the columns o…

---

## [Can't see anything in HDF5 file I create from Julia](https://discourse.julialang.org/t/cant-see-anything-in-hdf5-file-i-create-from-julia/70992)

<div class="topic-metadata">

**Author:** [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Replies:** 4\
**Last updated:** [November 5, 2021, 10:28am UTC](https://discourse.julialang.org/t/cant-see-anything-in-hdf5-file-i-create-from-julia/70992 "2021-11-05T10:28:50Z")

</div>

Hi all, I have a question about HDF5 files created from Julia with HDF5.jl package. I create files with the following commands: # Open the HDF5 file for writing fid =…

---

## [How to convert a matrix to an RGB image using Images.jl?](https://discourse.julialang.org/t/how-to-convert-a-matrix-to-an-rgb-image-using-images-jl/7265)

<div class="topic-metadata">

**Author:** [@robblackwell](https://discourse.julialang.org/u/robblackwell)\
**Replies:** 16\
**Last updated:** [November 5, 2021, 9:31am UTC](https://discourse.julialang.org/t/how-to-convert-a-matrix-to-an-rgb-image-using-images-jl/7265 "2021-11-05T09:31:33Z")

</div>

Let’s say that I have a matrix x x = \[0 0.5 1; 0.6 0.7 08.; 1 0.1 0.2\] I can display it as a grayscale image using Gray.(x) How can I convert it to an RGB image using a specified color gradient? Plots.jl allows me t…

---

## [Where is the extra memory allocation?](https://discourse.julialang.org/t/where-is-the-extra-memory-allocation/70866)

<div class="topic-metadata">

**Author:** [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Replies:** 11\
**Last updated:** [November 5, 2021, 1:49am UTC](https://discourse.julialang.org/t/where-is-the-extra-memory-allocation/70866 "2021-11-05T01:49:23Z")

</div>

I wrote a program several days ago, and the memory allocation is acceptable (2.79k allocations: 124.820MiB). Today, I add some new functions in it to implenment another feature. Then the memory allocation becomes much bi…

---

## [Finite element method interpolation performance](https://discourse.julialang.org/t/finite-element-method-interpolation-performance/70944)

<div class="topic-metadata">

**Author:** [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Replies:** 3\
**Last updated:** [November 5, 2021, 12:52am UTC](https://discourse.julialang.org/t/finite-element-method-interpolation-performance/70944 "2021-11-05T00:52:26Z")

</div>

I have a question about the performance in interpolation in finite element method. In the Official Document, it is suggested to do small size array operations with StaticArrays.jl. In my finite element program, the glo…

---

## [Problem passing gradients into Optim](https://discourse.julialang.org/t/problem-passing-gradients-into-optim/70885)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 4\
**Last updated:** [November 4, 2021, 11:14pm UTC](https://discourse.julialang.org/t/problem-passing-gradients-into-optim/70885 "2021-11-04T23:14:21Z")

</div>

Hi! I am trying to minimize a likelihood function for a large number of parameters. Since, the problem is quite large it would be very useful to pass the analytical gradients and the Hessian into the optimization problem…

---

## [Fitting a polynomial of degree 10 to data](https://discourse.julialang.org/t/fitting-a-polynomial-of-degree-10-to-data/70924)

<div class="topic-metadata">

**Author:** [@valperez](https://discourse.julialang.org/u/valperez)\
**Replies:** 9\
**Last updated:** [November 4, 2021, 6:27pm UTC](https://discourse.julialang.org/t/fitting-a-polynomial-of-degree-10-to-data/70924 "2021-11-04T18:27:35Z")

</div>

Hi there :slight\_smile: I’m trying to test Julia’s accuracy so I’m trying to fit a polynomial of degree 10 to my data. The data can be found in the following link: https://www.itl.nist.gov/div898/strd/lls/data/LINKS/DAT…

---

## [How to improve the speed of "inpolygon"?](https://discourse.julialang.org/t/how-to-improve-the-speed-of-inpolygon/70969)

<div class="topic-metadata">

**Author:** [@leon](https://discourse.julialang.org/u/leon)\
**Replies:** 5\
**Last updated:** [November 4, 2021, 6:03pm UTC](https://discourse.julialang.org/t/how-to-improve-the-speed-of-inpolygon/70969 "2021-11-04T18:03:55Z")

</div>

I have about 30,000 pairs of longitude and latitude data (lon1 and lon2). My goal is to check if they will fall into a polygon defined by (lonW and latW). In Matlab, I can do this as below. It is blazing fast. It litera…

---

## [Use function argument inside optional (default) arguments type specification](https://discourse.julialang.org/t/use-function-argument-inside-optional-default-arguments-type-specification/70963)

<div class="topic-metadata">

**Author:** [@claudio20497](https://discourse.julialang.org/u/claudio20497)\
**Replies:** 2\
**Last updated:** [November 4, 2021, 5:16pm UTC](https://discourse.julialang.org/t/use-function-argument-inside-optional-default-arguments-type-specification/70963 "2021-11-04T17:16:05Z")

</div>

Hi, I encountered the following behaviour. I can use a function’s arguments to set the default values for optional (default) arguments: julia\> f(a::Int64; b::Int64 = a-1 ) = b f (generic function with 1 method) But I …

---

## [Shared memory computation inside of each task of parallel map](https://discourse.julialang.org/t/shared-memory-computation-inside-of-each-task-of-parallel-map/70927)

<div class="topic-metadata">

**Author:** [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Replies:** 5\
**Last updated:** [November 4, 2021, 5:01pm UTC](https://discourse.julialang.org/t/shared-memory-computation-inside-of-each-task-of-parallel-map/70927 "2021-11-04T17:01:10Z")

</div>

Hi! I have a pretty simple problem: I have about 50 tasks I would like to do simultaneously, and I would like to do exploit shared memory parallelism on each task. I have control of about 50 nodes with about 40 CPUs eac…

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

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