# General Usage

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

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

**Page:** 561

---

## [Function inside Macro](https://discourse.julialang.org/t/function-inside-macro/66476)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 0\
**Last updated:** [August 16, 2021, 10:49am UTC](https://discourse.julialang.org/t/function-inside-macro/66476 "2021-08-16T10:49:36Z")

</div>

Hi there, I am struggling to find a way to combine a macro und a function. Lets start with an MWE of what I want to do: using QuickTypes abstract type AbstractModel end param = (a = 1., b = 2.) # Create a new Parametr…

---

## [Build struct from arrays and names](https://discourse.julialang.org/t/build-struct-from-arrays-and-names/66350)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 3\
**Last updated:** [August 16, 2021, 10:35am UTC](https://discourse.julialang.org/t/build-struct-from-arrays-and-names/66350 "2021-08-16T10:35:59Z")

</div>

From a stream, I receive a number of arrays and strings as their field names. How can I dynamically build a structure from it? Of course, trying to define a struct within the code generates ERROR: LoadError: syntax: …

---

## [Issue with Plots](https://discourse.julialang.org/t/issue-with-plots/66460)

<div class="topic-metadata">

**Author:** [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Replies:** 1\
**Last updated:** [August 16, 2021, 9:58am UTC](https://discourse.julialang.org/t/issue-with-plots/66460 "2021-08-16T09:58:43Z")

</div>

Unexpectedly, Plots stopped working. I use gr() and get this message: could not load library “libGR.so” dlopen(libGR.so.dylib, 1): image not found using ENV\[“GRDIR”\]=“” Pkg.build(“GR”) has not helped. When I try w…

---

## [OutOfMemoryError with sparse A'\*A](https://discourse.julialang.org/t/outofmemoryerror-with-sparse-a-a/65911)

<div class="topic-metadata">

**Author:** [@Thomas](https://discourse.julialang.org/u/Thomas)\
**Replies:** 9\
**Last updated:** [August 16, 2021, 9:55am UTC](https://discourse.julialang.org/t/outofmemoryerror-with-sparse-a-a/65911 "2021-08-16T09:55:38Z")

</div>

I have to multiply large sparse matrices in the following orthogonal projection orthProject(A::SparseMatricCSC, v::SparseVector) = A \* ((A' \* A) \\ Vector(A' \* v)) but due I got this error ERROR: OutOfMemoryError() Sta…

---

## [Help! Plots not loading](https://discourse.julialang.org/t/help-plots-not-loading/49941)

<div class="topic-metadata">

**Author:** [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Replies:** 47\
**Last updated:** [August 16, 2021, 9:50am UTC](https://discourse.julialang.org/t/help-plots-not-loading/49941 "2021-08-16T09:50:59Z")

</div>

I’m having trouble with the GR backend for Plots using Plots \[ Info: Precompiling Plots \[91a5bcdd-55d7-5caf-9e0b-520d859cae80\] Your GR installation is incomplete. Rerun build step for GR package. ERROR: LoadError: Load…

---

## [Nbabel nbody integrator speed up](https://discourse.julialang.org/t/nbabel-nbody-integrator-speed-up/51712)

<div class="topic-metadata">

**Author:** [@darleybarreto](https://discourse.julialang.org/u/darleybarreto)\
**Replies:** 64\
**Last updated:** [August 16, 2021, 5:17am UTC](https://discourse.julialang.org/t/nbabel-nbody-integrator-speed-up/51712 "2021-08-16T05:17:29Z")

</div>

Hi folks, I found this implementation of a Nbabel integrator in Julia, which I believe it’s a very simple one. The author report a runtime of 2.57s against 0.48s of Pythran. Would any of you help me improve this? I belie…

---

## [Surface command in Julia](https://discourse.julialang.org/t/surface-command-in-julia/66378)

<div class="topic-metadata">

**Author:** [@Manisha\_07](https://discourse.julialang.org/u/Manisha_07)\
**Replies:** 7\
**Last updated:** [August 16, 2021, 5:55am UTC](https://discourse.julialang.org/t/surface-command-in-julia/66378 "2021-08-16T05:55:05Z")

</div>

MethodError: no method matching optimize\_ticks(::Float64, ::Float64; k\_min=4, k\_max=8, scale=:identity) Closest candidates are: optimize\_ticks(::T, ::T; extend\_ticks, Q, k\_min, k\_max, k\_ideal, granularity\_weight, simpl…

---

## [How to "unshare" an array?](https://discourse.julialang.org/t/how-to-unshare-an-array/66441)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 7\
**Last updated:** [August 15, 2021, 8:49pm UTC](https://discourse.julialang.org/t/how-to-unshare-an-array/66441 "2021-08-15T20:49:35Z")

</div>

I want to efficiently build up a large matrix in a loop. At every iteration I will: Perform some linear algebra operations on the matrix (it’s more complicated than the example below), and Append a new row to the matr…

---

## [Radial basis function](https://discourse.julialang.org/t/radial-basis-function/66446)

<div class="topic-metadata">

**Author:** [@Manisha\_07](https://discourse.julialang.org/u/Manisha_07)\
**Replies:** 0\
**Last updated:** [August 15, 2021, 10:37pm UTC](https://discourse.julialang.org/t/radial-basis-function/66446 "2021-08-15T22:37:09Z")

</div>

Hello Guys Now i have come up with new doubts I need to use 2nd order differencial equation and used radial basis function for approximating the solution Please let me know how to solve 2nd order differencial equation…

---

## [How to convert a multivariable polynomial with integer coefficients to one with Float64 coefficients?](https://discourse.julialang.org/t/how-to-convert-a-multivariable-polynomial-with-integer-coefficients-to-one-with-float64-coefficients/66438)

<div class="topic-metadata">

**Author:** [@geo](https://discourse.julialang.org/u/geo)\
**Replies:** 2\
**Last updated:** [August 15, 2021, 5:42pm UTC](https://discourse.julialang.org/t/how-to-convert-a-multivariable-polynomial-with-integer-coefficients-to-one-with-float64-coefficients/66438 "2021-08-15T17:42:57Z")

</div>

The following code works, but seems ugly. There should be a better way to convert than multiplying by 1.0! using DynamicPolynomials @polyvar x\[1:3\] m = monomials(x, 0:3) mD = differentiate.(m, x\[1\]) \*1.0

---

## [Faster counting of sequences](https://discourse.julialang.org/t/faster-counting-of-sequences/66359)

<div class="topic-metadata">

**Author:** [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Replies:** 10\
**Last updated:** [August 15, 2021, 3:00pm UTC](https://discourse.julialang.org/t/faster-counting-of-sequences/66359 "2021-08-15T15:00:14Z")

</div>

I have a problem in which I am trying to figure out how many items were first selected by user i and later by user j for all users. My idea was to create a sparse matrix M with n-users \\times n-users in which the rows s…

---

## [Conda taking forever to install Jupyter lab](https://discourse.julialang.org/t/conda-taking-forever-to-install-jupyter-lab/66156)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 11\
**Last updated:** [August 15, 2021, 2:22pm UTC](https://discourse.julialang.org/t/conda-taking-forever-to-install-jupyter-lab/66156 "2021-08-15T14:22:04Z")

</div>

to get my kids back into the idea of school, I started doing some simple physics experiments with them. We’ve got some data and I wrote a Jupyter notebook to analyze. Then I went to install Jupyter lab on their computers…

---

## [Is there any way to explicitly prohibit a function from modifying the \`mutable struct\` or \`Vector/Array\` parameters?](https://discourse.julialang.org/t/is-there-any-way-to-explicitly-prohibit-a-function-from-modifying-the-mutable-struct-or-vector-array-parameters/66416)

<div class="topic-metadata">

**Author:** [@Pingzi\_Kang](https://discourse.julialang.org/u/Pingzi_Kang)\
**Replies:** 5\
**Last updated:** [August 15, 2021, 1:56pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-explicitly-prohibit-a-function-from-modifying-the-mutable-struct-or-vector-array-parameters/66416 "2021-08-15T13:56:57Z")

</div>

As we know, Julia’s functions can modify the contents of the passed mutable struct or Array. Sometimes this can cause confusion as to whether the function modifies the members of the mutable struct or not. It might be he…

---

## [Why this code does a segfault?](https://discourse.julialang.org/t/why-this-code-does-a-segfault/66394)

<div class="topic-metadata">

**Author:** [@Lecrapouille](https://discourse.julialang.org/u/Lecrapouille)\
**Replies:** 21\
**Last updated:** [August 15, 2021, 11:46am UTC](https://discourse.julialang.org/t/why-this-code-does-a-segfault/66394 "2021-08-15T11:46:06Z")

</div>

Why this code does a segfault ? foo.c #include \<stdio.h\> struct mystruct { int a; int b; }; typedef struct mystruct mystruct\_t; int recvstruct(mystruct\_t\* st) { printf("C %u, %u\\n", st-\>a, st-\>b); ret…

---

## [Typing functions arguments representing tuples of custom structs](https://discourse.julialang.org/t/typing-functions-arguments-representing-tuples-of-custom-structs/66395)

<div class="topic-metadata">

**Author:** [@claudio20497](https://discourse.julialang.org/u/claudio20497)\
**Replies:** 7\
**Last updated:** [August 15, 2021, 10:40am UTC](https://discourse.julialang.org/t/typing-functions-arguments-representing-tuples-of-custom-structs/66395 "2021-08-15T10:40:35Z")

</div>

Hello, Considering the following struct: struct my\_struct{A \<: Function,B \<: Function} a::A b::B end I would like to write a function func that accepts an OrderedDict which values are Tuples of an unknown amou…

---

## [Julia + Jupyter notebooks in VSCodium?](https://discourse.julialang.org/t/julia-jupyter-notebooks-in-vscodium/66403)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 7\
**Last updated:** [August 14, 2021, 10:14pm UTC](https://discourse.julialang.org/t/julia-jupyter-notebooks-in-vscodium/66403 "2021-08-14T22:14:44Z")

</div>

Hi. I’m not much for telemetry and such, so I’m trying to use VSCodium to work with Jupyter Notebooks running the Julia kernel. The VSCodium I’m using is the current up to date 1.59.0 AppImage download for Linux x64 VSC…

---

## [Can FunctionWrappers.jl express higher order functions?](https://discourse.julialang.org/t/can-functionwrappers-jl-express-higher-order-functions/66404)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 2\
**Last updated:** [August 14, 2021, 9:56pm UTC](https://discourse.julialang.org/t/can-functionwrappers-jl-express-higher-order-functions/66404 "2021-08-14T21:56:10Z")

</div>

I’m looking into FunctionWrappers.jl which provides functionality similar to function pointers in C and std::function in C++. Suppose a function accept two arguments, where the first argument has type Int, and the second…

---

## [Mesh grid in Julia](https://discourse.julialang.org/t/mesh-grid-in-julia/66363)

<div class="topic-metadata">

**Author:** [@Manisha\_07](https://discourse.julialang.org/u/Manisha_07)\
**Replies:** 10\
**Last updated:** [August 14, 2021, 2:08pm UTC](https://discourse.julialang.org/t/mesh-grid-in-julia/66363 "2021-08-14T14:08:38Z")

</div>

Hello People I have been working on heat equation simulation using Julia Software. I was stuck with creating a surface plot (3d plotting) I have values of x,t and T (is a matrix) how to make 3d plot Please help me

---

## [What would be an efficient image type to apply a series of JuliaImages filters?](https://discourse.julialang.org/t/what-would-be-an-efficient-image-type-to-apply-a-series-of-juliaimages-filters/66332)

<div class="topic-metadata">

**Author:** [@erwanlecarpentier](https://discourse.julialang.org/u/erwanlecarpentier)\
**Replies:** 4\
**Last updated:** [August 14, 2021, 8:11am UTC](https://discourse.julialang.org/t/what-would-be-an-efficient-image-type-to-apply-a-series-of-juliaimages-filters/66332 "2021-08-14T08:11:30Z")

</div>

Hey! I am applying a series of filters/operations from JuliaImages to images that are initially of type Array{UInt8,2}. What would be the most efficient image type for this kind of computation? Should I always convert b…

---

## [Missing methods qr(A)' and qr(A') for sparse](https://discourse.julialang.org/t/missing-methods-qr-a-and-qr-a-for-sparse/66370)

<div class="topic-metadata">

**Author:** [@Thomas](https://discourse.julialang.org/u/Thomas)\
**Replies:** 1\
**Last updated:** [August 14, 2021, 1:36am UTC](https://discourse.julialang.org/t/missing-methods-qr-a-and-qr-a-for-sparse/66370 "2021-08-14T01:36:24Z")

</div>

Weird, that Base.runtests("LinearAlgebra/qr") passed, but I got this error (which I thought this has been fixed in https://github.com/JuliaLang/SuiteSparse.jl/issues/22) using LinearAlgebra, SparseArrays A = sprand(10,1…

---

## [Read a single element vs array from stream](https://discourse.julialang.org/t/read-a-single-element-vs-array-from-stream/66328)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 3\
**Last updated:** [August 13, 2021, 9:37pm UTC](https://discourse.julialang.org/t/read-a-single-element-vs-array-from-stream/66328 "2021-08-13T21:37:27Z")

</div>

Since the single case is used often, I use read1T as a convenience function. Novice question: can the two functions be combined without violating type stability? Or, more generally, does Union{T, AbstractArray{T}} as i…

---

## [Improving perfomance for a beginner](https://discourse.julialang.org/t/improving-perfomance-for-a-beginner/66353)

<div class="topic-metadata">

**Author:** [@jpmorr](https://discourse.julialang.org/u/jpmorr)\
**Replies:** 3\
**Last updated:** [August 13, 2021, 8:35pm UTC](https://discourse.julialang.org/t/improving-perfomance-for-a-beginner/66353 "2021-08-13T20:35:09Z")

</div>

I’ve recently started a side project at work to see if I can use julia to replace python for the majority of my data processing due to the possible gains in performance. Over the years the python code has become quite qu…

---

## [Isbits Without Propagation of Parametric Types?](https://discourse.julialang.org/t/isbits-without-propagation-of-parametric-types/66305)

<div class="topic-metadata">

**Author:** [@Ian\_Slagle](https://discourse.julialang.org/u/Ian_Slagle)\
**Replies:** 4\
**Last updated:** [August 13, 2021, 7:56pm UTC](https://discourse.julialang.org/t/isbits-without-propagation-of-parametric-types/66305 "2021-08-13T19:56:01Z")

</div>

Consider this MWE: abstract type A end abstract type B \<: A end abstract type C \<: A end struct D{T \<: A} data::UInt8 end struct E a::D b::D c::D end struct F{T1 \<: D, T2 \<: D, T3 \<: D} a::T1 …

---

## [Supertype of \`Dict\` with \`Vector{\<:Pair}\` as key values](https://discourse.julialang.org/t/supertype-of-dict-with-vector-pair-as-key-values/66345)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 0\
**Last updated:** [August 13, 2021, 3:27pm UTC](https://discourse.julialang.org/t/supertype-of-dict-with-vector-pair-as-key-values/66345 "2021-08-13T15:27:09Z")

</div>

So I was trying to find the type of something like a Dict(1=\>\[:a=\>1\], 2=\>\[:b=\>2\]) for function argument type specification and it’s easy to see that since the key values are Vector{\<:Pair}, the Dict is a Dict{Int64, \<:Ve…

---

## [How to define a function such that its arguments can mutate?](https://discourse.julialang.org/t/how-to-define-a-function-such-that-its-arguments-can-mutate/66320)

<div class="topic-metadata">

**Author:** [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Replies:** 16\
**Last updated:** [August 13, 2021, 1:59pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-such-that-its-arguments-can-mutate/66320 "2021-08-13T13:59:22Z")

</div>

A stupid question, I just want to have a function which is like a subroutine in Fortran. Just a simple example, function gauss(theta::Array{Float64,2}) theta = \[1.0 1.0 ; 2.0 2.0\] return nothing end I just want to inp…

---

## [Code parallelization for Brownian Dynamics simulation of hard spheres](https://discourse.julialang.org/t/code-parallelization-for-brownian-dynamics-simulation-of-hard-spheres/64584)

<div class="topic-metadata">

**Author:** [@Amir\_Abbasi](https://discourse.julialang.org/u/Amir_Abbasi)\
**Replies:** 5\
**Last updated:** [August 13, 2021, 1:47pm UTC](https://discourse.julialang.org/t/code-parallelization-for-brownian-dynamics-simulation-of-hard-spheres/64584 "2021-08-13T13:47:07Z")

</div>

Hi All! I am using Julia to do Brownian dynamics simulation of many hard spheres in 2D and 3D (employing the repulsive LJ interaction). My code is mostly based on SoftSquishymatter.jl package, but the main difference is…

---

## [Create an array using the output of size()](https://discourse.julialang.org/t/create-an-array-using-the-output-of-size/66326)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 4\
**Last updated:** [August 13, 2021, 11:15am UTC](https://discourse.julialang.org/t/create-an-array-using-the-output-of-size/66326 "2021-08-13T11:15:33Z")

</div>

Matlab: a = -1.3077 3.5784 3.0349 -0.4336 2.7694 0.7254 0.3426 -1.3499 -0.0631 \>\> zeros(size(a)) ans = 0 0 0 0 0 0 0 0 0 julia\> a 3×3 Matrix{Float64}…

---

## [Build a package deps/build.jl](https://discourse.julialang.org/t/build-a-package-deps-build-jl/56771)

<div class="topic-metadata">

**Author:** [@Paht\_J](https://discourse.julialang.org/u/Paht_J)\
**Replies:** 2\
**Last updated:** [August 13, 2021, 10:07am UTC](https://discourse.julialang.org/t/build-a-package-deps-build-jl/56771 "2021-08-13T10:07:04Z")

</div>

Does anyone know how to build a package? The documentation is not helpful It says that I should use dep/build.jl but never describes or shows an example of what is in that file. What would be a good reference? Pkg · The…

---

## [Inferable unpacking of Tuple type to tuple of types](https://discourse.julialang.org/t/inferable-unpacking-of-tuple-type-to-tuple-of-types/66329)

<div class="topic-metadata">

**Author:** [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)\
**Replies:** 2\
**Last updated:** [August 13, 2021, 9:45am UTC](https://discourse.julialang.org/t/inferable-unpacking-of-tuple-type-to-tuple-of-types/66329 "2021-08-13T09:45:42Z")

</div>

In one of my packages, I used the following paradigm to unpack a Tuple{T1,T2,...} into a tuple of the types unpack(::Type{Tuple{}}) = () unpack(::Type{T}) where {T\<:Tuple} = (Base.tuple\_type\_head(T), unpack(Base.tupe\_ty…

---

## [How to exactly lock the type of the arguments of a function?](https://discourse.julialang.org/t/how-to-exactly-lock-the-type-of-the-arguments-of-a-function/66325)

<div class="topic-metadata">

**Author:** [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Replies:** 11\
**Last updated:** [August 13, 2021, 9:13am UTC](https://discourse.julialang.org/t/how-to-exactly-lock-the-type-of-the-arguments-of-a-function/66325 "2021-08-13T09:13:00Z")

</div>

Another stupid question, I have a function function gauss(beta::Array{Float64,1}) beta .= \[1.0 2.0; 3.0 3.0\] return nothing end I set beta in the argument as a 1D array, however I set beta in the function as a 2D arra…

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

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