# General Usage

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

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

**Page:** 195

---

## [Scalar function for reals and arrays: single function definition](https://discourse.julialang.org/t/scalar-function-for-reals-and-arrays-single-function-definition/110886)

<div class="topic-metadata">

**Author:** [@abehersan](https://discourse.julialang.org/u/abehersan)\
**Replies:** 6\
**Last updated:** [February 28, 2024, 12:13pm UTC](https://discourse.julialang.org/t/scalar-function-for-reals-and-arrays-single-function-definition/110886 "2024-02-28T12:13:33Z")

</div>

I often find myself writing two methods for a simple scalar function. E.g. function gauss(x::Real; a=1.0, c=0.0, s=0.7) return a/s/(sqrt(2pi))\*exp(-((x-c)^2/(2\*s^2))) end function gauss(x::AbstractArray{\<:Real}; a=…

---

## [Parallel assembly of a finite element sparse matrix](https://discourse.julialang.org/t/parallel-assembly-of-a-finite-element-sparse-matrix/95947)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 34\
**Last updated:** [February 28, 2024, 5:04am UTC](https://discourse.julialang.org/t/parallel-assembly-of-a-finite-element-sparse-matrix/95947 "2024-02-28T05:04:02Z")

</div>

There was a thread recently (Behavior of threads) concerning a problem of interest to me: how to teach a serial finite element code to perform the assembly of a global sparse matrix in parallel (on shared memory computer…

---

## [Help me understand the \`unique\` semantic for a vector of mutable struct](https://discourse.julialang.org/t/help-me-understand-the-unique-semantic-for-a-vector-of-mutable-struct/110887)

<div class="topic-metadata">

**Author:** [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Replies:** 6\
**Last updated:** [February 28, 2024, 12:01pm UTC](https://discourse.julialang.org/t/help-me-understand-the-unique-semantic-for-a-vector-of-mutable-struct/110887 "2024-02-28T12:01:51Z")

</div>

The unique documentation mentions that it is based on the isequal function. Hence I cannot understand the result of the following MWE: Base.@kwdef mutable struct AStruct toto::String = "toto" tuti::Int …

---

## [Trying to understand inferred effects](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [February 28, 2024, 10:02am UTC](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854 "2024-02-28T10:02:05Z")

</div>

julia\> Base.infer\_effects(getindex, (UnitRange{Int}, Int)) (+c,+e,!n,+t,+s,+m,+u) julia\> Base.infer\_effects(getindex, (Base.OneTo{Int}, Int)) (!c,+e,!n,+t,+s,+m,+u) julia\> VERSION v"1.12.0-DEV.88" Firstly, why is the …

---

## [Status of Julia wrappers of SYCL](https://discourse.julialang.org/t/status-of-julia-wrappers-of-sycl/110870)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 2\
**Last updated:** [February 28, 2024, 7:08am UTC](https://discourse.julialang.org/t/status-of-julia-wrappers-of-sycl/110870 "2024-02-28T07:08:10Z")

</div>

What do you know? Any bit of info will help. Ta!

---

## [\`Union\` constraints in abstract type declarations seem to break subtype relations](https://discourse.julialang.org/t/union-constraints-in-abstract-type-declarations-seem-to-break-subtype-relations/110322)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 5\
**Last updated:** [February 28, 2024, 5:01am UTC](https://discourse.julialang.org/t/union-constraints-in-abstract-type-declarations-seem-to-break-subtype-relations/110322 "2024-02-28T05:01:04Z")

</div>

I’m currently writing a package, CliffordNumbers.jl, that makes the following abstract type declaration: const BaseNumber = Union{Real,Complex} abstract type AbstractCliffordNumber{Q\<:QuadraticForm,T\<:BaseNumber} \<: Nu…

---

## [Assistance with optimization](https://discourse.julialang.org/t/assistance-with-optimization/110862)

<div class="topic-metadata">

**Author:** [@narnold0](https://discourse.julialang.org/u/narnold0)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:48pm UTC](https://discourse.julialang.org/t/assistance-with-optimization/110862 "2024-02-27T21:48:28Z")

</div>

Hi friends, I made a post about the problem of generating pairs of objects while also filtering them, and it seemed that parallel computing was the main suggestion, so I’m trying to learn CUDA for that, but I’ve run int…

---

## [Why can't it find that method?](https://discourse.julialang.org/t/why-cant-it-find-that-method/110860)

<div class="topic-metadata">

**Author:** [@Mark\_Nahabedian](https://discourse.julialang.org/u/Mark_Nahabedian)\
**Replies:** 2\
**Last updated:** [February 28, 2024, 2:47am UTC](https://discourse.julialang.org/t/why-cant-it-find-that-method/110860 "2024-02-28T02:47:08Z")

</div>

I normally post to Slack, but seems too long winded for that venue. I’m having some trouble that might be related to a macro I’ve defined, but as near as I can tell the macro expands as I expect. I’m hoping you can hel…

---

## [Using an \`Int\` as a \`Num\`](https://discourse.julialang.org/t/using-an-int-as-a-num/110866)

<div class="topic-metadata">

**Author:** [@brombo](https://discourse.julialang.org/u/brombo)\
**Replies:** 4\
**Last updated:** [February 28, 2024, 1:32am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866 "2024-02-28T01:32:32Z")

</div>

I am using Symbolics.jl. I have a function function f(a::Num,b::Num)::Num, but in using it I want to use, sometimes - @variables x, z y = f(1,x) as well as @variables x, z y = f(z,x) but I get an error because 1 is …

---

## [Singular.jl: polynomial ring over a polynomial ring](https://discourse.julialang.org/t/singular-jl-polynomial-ring-over-a-polynomial-ring/110839)

<div class="topic-metadata">

**Author:** [@Andreas\_Poulsen](https://discourse.julialang.org/u/Andreas_Poulsen)\
**Replies:** 2\
**Last updated:** [February 27, 2024, 11:50pm UTC](https://discourse.julialang.org/t/singular-jl-polynomial-ring-over-a-polynomial-ring/110839 "2024-02-27T23:50:43Z")

</div>

Hi I’m attempting to use a library in Julia (grobcov.lib), which expects an ideal of polynomials over a polynomial ring, for example QQ\["a", "b"\]\["x", "y"\]. My problem is how to construct such a ring in Singular. I’ve t…

---

## [Extend package methods / write add-ons](https://discourse.julialang.org/t/extend-package-methods-write-add-ons/77531)

<div class="topic-metadata">

**Author:** [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Replies:** 3\
**Last updated:** [February 27, 2024, 9:06pm UTC](https://discourse.julialang.org/t/extend-package-methods-write-add-ons/77531 "2024-02-27T21:06:06Z")

</div>

Hi, I am trying to write an add-on for a package, but I am struggling with a – likely minor – issue. Suppose that some package has a function function foo(S1::Any) .... bar(S1) .... and bar(S1) is defined …

---

## [How to declare N nested Vectors?](https://discourse.julialang.org/t/how-to-declare-n-nested-vectors/110813)

<div class="topic-metadata">

**Author:** [@chaojin](https://discourse.julialang.org/u/chaojin)\
**Replies:** 15\
**Last updated:** [February 27, 2024, 8:14pm UTC](https://discourse.julialang.org/t/how-to-declare-n-nested-vectors/110813 "2024-02-27T20:14:47Z")

</div>

HI, I want to declare N nested Vectors in Julia. e.g. Vector{Int} Vector{Vector{Int}} ... Vector{Vector{....Vector{Int}...} # N dimensional nested Vector In C++, it can be implemented by using recursive specializatio…

---

## [What does \`MLJ.evaluate!(mach, ...)\` to \`mach\` parameters](https://discourse.julialang.org/t/what-does-mlj-evaluate-mach-to-mach-parameters/110857)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 1\
**Last updated:** [February 27, 2024, 6:59pm UTC](https://discourse.julialang.org/t/what-does-mlj-evaluate-mach-to-mach-parameters/110857 "2024-02-27T18:59:45Z")

</div>

The documentation does not say anything about this unfortunately. I am wondering how the parameters of the given machine mach are actually changed? Is it like a respective TunedModel? Can I use the mach further for pre…

---

## [Create directories, read files and create file](https://discourse.julialang.org/t/create-directories-read-files-and-create-file/110855)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 1\
**Last updated:** [February 27, 2024, 5:19pm UTC](https://discourse.julialang.org/t/create-directories-read-files-and-create-file/110855 "2024-02-27T17:19:26Z")

</div>

I have this program in C++ (but even Python) which opens or creates a directory called file\_path, scrolls each text file which goes along the Data\_xyzw.txt format, finds the bigger xyzw and creates a name which is Data\_a…

---

## [Getting the min value of two dataframes with identical cols](https://discourse.julialang.org/t/getting-the-min-value-of-two-dataframes-with-identical-cols/110778)

<div class="topic-metadata">

**Author:** [@Marc\_Sevaux](https://discourse.julialang.org/u/Marc_Sevaux)\
**Replies:** 5\
**Last updated:** [February 27, 2024, 5:14pm UTC](https://discourse.julialang.org/t/getting-the-min-value-of-two-dataframes-with-identical-cols/110778 "2024-02-27T17:14:04Z")

</div>

I have two almost identical df julia\> df1 = DataFrame(ID = \[1, 2, 3, 4,6\], Value = \[10, 20, 30, 40,10\]) 5×2 DataFrame Row │ ID Value │ Int64 Int64 ─────┼────────────── 1 │ 1 …

---

## [Allocating OnlineStats on the stack](https://discourse.julialang.org/t/allocating-onlinestats-on-the-stack/110856)

<div class="topic-metadata">

**Author:** [@mattwigway](https://discourse.julialang.org/u/mattwigway)\
**Replies:** 2\
**Last updated:** [February 27, 2024, 4:26pm UTC](https://discourse.julialang.org/t/allocating-onlinestats-on-the-stack/110856 "2024-02-27T16:26:22Z")

</div>

I’m using OnlineStats to calculate a likelihood function, so I’m creating and destroying a LogSumExp for each row. LogSumExps, like all online stats, are mutable structs, so heap-allocated in general, but I thought that …

---

## [Communication between structures](https://discourse.julialang.org/t/communication-between-structures/110848)

<div class="topic-metadata">

**Author:** [@brombo](https://discourse.julialang.org/u/brombo)\
**Replies:** 2\
**Last updated:** [February 27, 2024, 4:11pm UTC](https://discourse.julialang.org/t/communication-between-structures/110848 "2024-02-27T16:11:22Z")

</div>

Suppose I have two structures A and B. When I instantiate A it creates a bunch of arrays say a, b, and c that every instance of B needs to performe it’s calculations. Let x and y be instances of B. Then to calculate x…

---

## [BenchmarkTools.jl and VScode](https://discourse.julialang.org/t/benchmarktools-jl-and-vscode/110791)

<div class="topic-metadata">

**Author:** [@Heng\_Zhang](https://discourse.julialang.org/u/Heng_Zhang)\
**Replies:** 6\
**Last updated:** [February 27, 2024, 3:57pm UTC](https://discourse.julialang.org/t/benchmarktools-jl-and-vscode/110791 "2024-02-27T15:57:59Z")

</div>

‘’‘julia using BenchmarkTools @benchmark sort(data) setup=(data=rand(10)) ‘’’ When I ran these code in Vs-code, errors as below: BenchmarkTools.Trial: 10000 samples with 1000 evaluations. ERROR: MethodError: no met…

---

## [How to reuse a local python environment when starting Julia Jupyter notebook?](https://discourse.julialang.org/t/how-to-reuse-a-local-python-environment-when-starting-julia-jupyter-notebook/110847)

<div class="topic-metadata">

**Author:** [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 2:23pm UTC](https://discourse.julialang.org/t/how-to-reuse-a-local-python-environment-when-starting-julia-jupyter-notebook/110847 "2024-02-27T14:23:10Z")

</div>

I have configured a micromamba environment plot manually with all dependencies satisfied. And I want PythonCall.jl (or CondaPkg.jl) to use this environment. In terminal and Julia REPL, I can make it as follows: PS C:\\Us…

---

## [Why do we need locks when a thread is waiting for an event from another thread?](https://discourse.julialang.org/t/why-do-we-need-locks-when-a-thread-is-waiting-for-an-event-from-another-thread/110846)

<div class="topic-metadata">

**Author:** [@Dandan](https://discourse.julialang.org/u/Dandan)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 1:16pm UTC](https://discourse.julialang.org/t/why-do-we-need-locks-when-a-thread-is-waiting-for-an-event-from-another-thread/110846 "2024-02-27T13:16:18Z")

</div>

This is rather a general question about low level internals of parallel computing, I guess. Suppose I have two threads and one is waiting for another to finish some job. In Julia I can program it with Threads.Condition,…

---

## [Is there a generic function for appending an element to an immutable collection?](https://discourse.julialang.org/t/is-there-a-generic-function-for-appending-an-element-to-an-immutable-collection/109883)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 9\
**Last updated:** [February 27, 2024, 11:34am UTC](https://discourse.julialang.org/t/is-there-a-generic-function-for-appending-an-element-to-an-immutable-collection/109883 "2024-02-27T11:34:06Z")

</div>

Suppose v::T supports getindex and length, but it is not necessarily an \<:AbstractVector and may not be mutable. Is there a generic function (possibly defined in a package, not Base) for appending one element, creating …

---

## [What is the actual difference between AvancedMH.jl's Static and RandomWalk Prposals](https://discourse.julialang.org/t/what-is-the-actual-difference-between-avancedmh-jls-static-and-randomwalk-prposals/110838)

<div class="topic-metadata">

**Author:** [@caesoma](https://discourse.julialang.org/u/caesoma)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:59am UTC](https://discourse.julialang.org/t/what-is-the-actual-difference-between-avancedmh-jls-static-and-randomwalk-prposals/110838 "2024-02-27T09:59:05Z")

</div>

I am trying to modify the proposal distributions in the Metropolis-Hastings sampler in the AdvancedMH.jl package. It is not clear to me what the Static and RandomWalk proposals do. As I understand it, the former draws a…

---

## [Adaptive proposals in AdvancedMH.jl (or other Metropolis-capable) package](https://discourse.julialang.org/t/adaptive-proposals-in-advancedmh-jl-or-other-metropolis-capable-package/110837)

<div class="topic-metadata">

**Author:** [@caesoma](https://discourse.julialang.org/u/caesoma)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:42am UTC](https://discourse.julialang.org/t/adaptive-proposals-in-advancedmh-jl-or-other-metropolis-capable-package/110837 "2024-02-27T09:42:03Z")

</div>

I am trying to run an MCMC chain with a Metropolis-Hastings sampler, but a fixed proposal distribution normally yields poor results. Apparently the AdvancedMH.jl package doesn’t have the feature for tuning the variance o…

---

## [Best method for having a single number that is mutable](https://discourse.julialang.org/t/best-method-for-having-a-single-number-that-is-mutable/110820)

<div class="topic-metadata">

**Author:** [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Replies:** 6\
**Last updated:** [February 27, 2024, 9:25am UTC](https://discourse.julialang.org/t/best-method-for-having-a-single-number-that-is-mutable/110820 "2024-02-27T09:25:06Z")

</div>

I often find myself doing the following: struct MyType x::Float64 some\_other\_fields end where I want to sometimes change the value of x. What’s the best way to deal with this? It seems a bit silly to rebuild a M…

---

## [What is the difference between NeuralPDE and Nvidia Modulus sym in python?](https://discourse.julialang.org/t/what-is-the-difference-between-neuralpde-and-nvidia-modulus-sym-in-python/110826)

<div class="topic-metadata">

**Author:** [@Maysam\_Gholampour](https://discourse.julialang.org/u/Maysam_Gholampour)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 6:54am UTC](https://discourse.julialang.org/t/what-is-the-difference-between-neuralpde-and-nvidia-modulus-sym-in-python/110826 "2024-02-27T06:54:48Z")

</div>

Hi, I want to know what is the difference between the default nn architecture in Julia and Nvidia Modulus Sym. I mean here we have Lux and create network for each variable. what I mean about defuault in julia is somethi…

---

## [NeuralPDE tutorial not running](https://discourse.julialang.org/t/neuralpde-tutorial-not-running/110188)

<div class="topic-metadata">

**Author:** [@Y\_Sungtaek\_JU](https://discourse.julialang.org/u/Y_Sungtaek_JU)\
**Replies:** 7\
**Last updated:** [February 27, 2024, 6:43am UTC](https://discourse.julialang.org/t/neuralpde-tutorial-not-running/110188 "2024-02-27T06:43:16Z")

</div>

I am new to NeuralPDE.jl. I tried the second tutorial for PDE PINN (defining systems of PDEs for PINNs) https://docs.sciml.ai/NeuralPDE/stable/tutorials/systems/#systems But I got the error message below for the line: …

---

## [Formatting or Format?](https://discourse.julialang.org/t/formatting-or-format/9477)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 19\
**Last updated:** [February 26, 2024, 11:29pm UTC](https://discourse.julialang.org/t/formatting-or-format/9477 "2024-02-26T23:29:23Z")

</div>

Formatting.jl is nice but it doesn’t seem to be maintained…? Format.jl is a fork that looks more active. What’s the story here? Are we going to consolidate these?

---

## [Efficient way for executing multiple models](https://discourse.julialang.org/t/efficient-way-for-executing-multiple-models/110804)

<div class="topic-metadata">

**Author:** [@cirobr](https://discourse.julialang.org/u/cirobr)\
**Replies:** 0\
**Last updated:** [February 26, 2024, 7:51pm UTC](https://discourse.julialang.org/t/efficient-way-for-executing-multiple-models/110804 "2024-02-26T19:51:11Z")

</div>

Cheers, Let chain be a Flux.Chain of FCNs. I want to execute each of the chained models independently with the same input array, then concatenate all outputs as the model result. I did the following: using Flux: Chain…

---

## [Unsure about properties](https://discourse.julialang.org/t/unsure-about-properties/110756)

<div class="topic-metadata">

**Author:** [@sadish-d](https://discourse.julialang.org/u/sadish-d)\
**Replies:** 11\
**Last updated:** [February 26, 2024, 3:34pm UTC](https://discourse.julialang.org/t/unsure-about-properties/110756 "2024-02-26T15:34:10Z")

</div>

I like the syntax of properties, like that they’re not the same as fields, and that I don’t have to export them. I’m considering switching from using accessor functions to properties in a large chunk of code, but I’m not…

---

## [Unit-testing best practices for CUDA.jl?](https://discourse.julialang.org/t/unit-testing-best-practices-for-cuda-jl/110746)

<div class="topic-metadata">

**Author:** [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Replies:** 11\
**Last updated:** [February 26, 2024, 5:08pm UTC](https://discourse.julialang.org/t/unit-testing-best-practices-for-cuda-jl/110746 "2024-02-26T17:08:59Z")

</div>

I’m writing a CUDA kernel for DynamicExpressions here and was wondering what the best practices are for unit-testing it on CPU-only machines? My current idea is to modify the GPU kernel so that I can manually specify th…

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

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