# General Usage

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

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

**Page:** 263

---

## [Which package to use as a dependency for geometric primitives?](https://discourse.julialang.org/t/which-package-to-use-as-a-dependency-for-geometric-primitives/102268)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 7\
**Last updated:** [July 31, 2023, 9:53pm UTC](https://discourse.julialang.org/t/which-package-to-use-as-a-dependency-for-geometric-primitives/102268 "2023-07-31T21:53:48Z")

</div>

I need to create method dispatch on geometric primitives: hypersphere and hyperrectangle (i want to create samplers that randomly sample points uniformly within these primitives). I don’t want to re-define types for the…

---

## [Loading views from serialized file disconnects memory link](https://discourse.julialang.org/t/loading-views-from-serialized-file-disconnects-memory-link/102335)

<div class="topic-metadata">

**Author:** [@mwhisena](https://discourse.julialang.org/u/mwhisena)\
**Replies:** 0\
**Last updated:** [July 31, 2023, 9:31pm UTC](https://discourse.julialang.org/t/loading-views-from-serialized-file-disconnects-memory-link/102335 "2023-07-31T21:31:10Z")

</div>

I have a large matrix of data that I wish to create hundreds of views from. These views help me with setindexing and actually using my data in the program. This works perfectly for me, especially if I want to deepcopy to…

---

## [Slice, ignoring out of bounds](https://discourse.julialang.org/t/slice-ignoring-out-of-bounds/102286)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 7:43pm UTC](https://discourse.julialang.org/t/slice-ignoring-out-of-bounds/102286 "2023-07-31T19:43:37Z")

</div>

I want to slice an array ignoring any out-of-bounds indices. Is there a preferred way to do this? My solution safeslice(a, ixs) = a\[filter(i -\> checkbounds(Bool, a, i), ixs)\] julia\> safeslice(\[10,20,30\], -4:2) 2-elemen…

---

## [Please help me figure out why package dependencies are failing](https://discourse.julialang.org/t/please-help-me-figure-out-why-package-dependencies-are-failing/102313)

<div class="topic-metadata">

**Author:** [@aaroncbader](https://discourse.julialang.org/u/aaroncbader)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 7:35pm UTC](https://discourse.julialang.org/t/please-help-me-figure-out-why-package-dependencies-are-failing/102313 "2023-07-31T19:35:12Z")

</div>

To make things easier. I have replaced the names with PkgA, PkgB and PkgC, so it’s easier to see how the packages should depend on each other. PkgB depends on PkgA PkgC also depends on PkgA All three packages are dev…

---

## [Using custom structs with KernelAbstractions](https://discourse.julialang.org/t/using-custom-structs-with-kernelabstractions/102278)

<div class="topic-metadata">

**Author:** [@berk.geveci](https://discourse.julialang.org/u/berk.geveci)\
**Replies:** 6\
**Last updated:** [July 31, 2023, 7:33pm UTC](https://discourse.julialang.org/t/using-custom-structs-with-kernelabstractions/102278 "2023-07-31T19:33:23Z")

</div>

Hi folks. I am trying to pass a custom struct to a kernel. I have done this successfully with CUDA.jl and Metal.jl successfully using the Adapt package. I can get the same to work with KernelAbstractions. Here is the re…

---

## [Remove zero from Matrix](https://discourse.julialang.org/t/remove-zero-from-matrix/102322)

<div class="topic-metadata">

**Author:** [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Replies:** 5\
**Last updated:** [July 31, 2023, 6:34pm UTC](https://discourse.julialang.org/t/remove-zero-from-matrix/102322 "2023-07-31T18:34:23Z")

</div>

Hello, I have a matrix of the following form 20×3 Matrix{Float64}: 0.0 0.0 0.0 0.0 0.0 0.0 9.94549e-6 1.0e-5 -6.21704e-6 0.0 0.0 0.0 0.0 0.0 …

---

## [Help me find flaws in this pattern: spawning task from constructor](https://discourse.julialang.org/t/help-me-find-flaws-in-this-pattern-spawning-task-from-constructor/102219)

<div class="topic-metadata">

**Author:** [@algunion](https://discourse.julialang.org/u/algunion)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 5:06pm UTC](https://discourse.julialang.org/t/help-me-find-flaws-in-this-pattern-spawning-task-from-constructor/102219 "2023-07-31T17:06:04Z")

</div>

I hope the MWE is self-explanatory, but I’ll say a few words after the code block anyways: struct Agent id::Int in::Channel out::Channel Agent(id, in, out) = new(id, in, out) function Agent(id, in, o…

---

## [Open-ended range?](https://discourse.julialang.org/t/open-ended-range/102287)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 13\
**Last updated:** [July 31, 2023, 4:52pm UTC](https://discourse.julialang.org/t/open-ended-range/102287 "2023-07-31T16:52:31Z")

</div>

I often need a range that doesn’t include the last point: function func(x1, x2, del) for x in x1:del:x2 # but I want the loop only for x != x2 Depending on the values of x1, x2, and del, the loop sometimes includes x =…

---

## [Replace diagonals in existing spdiagm array](https://discourse.julialang.org/t/replace-diagonals-in-existing-spdiagm-array/102202)

<div class="topic-metadata">

**Author:** [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Replies:** 2\
**Last updated:** [July 31, 2023, 4:41pm UTC](https://discourse.julialang.org/t/replace-diagonals-in-existing-spdiagm-array/102202 "2023-07-31T16:41:50Z")

</div>

Hi, wondering if there is an equivalent to the MATLAB method spdiags(Bin, d, A), where the diagonals in A are replaced by those in d with the columns of Bin. As far as I can tell, spdiagsm does not support a method that…

---

## [Writing and reading from, to Google sheet](https://discourse.julialang.org/t/writing-and-reading-from-to-google-sheet/102306)

<div class="topic-metadata">

**Author:** [@dgagnon](https://discourse.julialang.org/u/dgagnon)\
**Replies:** 2\
**Last updated:** [July 31, 2023, 2:33pm UTC](https://discourse.julialang.org/t/writing-and-reading-from-to-google-sheet/102306 "2023-07-31T14:33:52Z")

</div>

Hello Is there any package making it easy to read and write from/to a Google sheet? I can do this from R and I saw how to do it with Python. But I’d rather use Julia. Thanks for pointing me in the right direction.

---

## [Makie and polar plots, how to plot quarter circle only (sector)](https://discourse.julialang.org/t/makie-and-polar-plots-how-to-plot-quarter-circle-only-sector/102262)

<div class="topic-metadata">

**Author:** [@Aran](https://discourse.julialang.org/u/Aran)\
**Replies:** 1\
**Last updated:** [July 31, 2023, 12:34pm UTC](https://discourse.julialang.org/t/makie-and-polar-plots-how-to-plot-quarter-circle-only-sector/102262 "2023-07-31T12:34:12Z")

</div>

Hi there I have a streamlines plot that I have produced using Makie. I have plotted the streamlines using the following commands fig\_polar = Figure(resolution = (1000, 900)) ax2 = PolarAxis( fig\_polar\[1, 1\], t…

---

## [StructTypes.Mutable() does not call the inner constructor](https://discourse.julialang.org/t/structtypes-mutable-does-not-call-the-inner-constructor/102118)

<div class="topic-metadata">

**Author:** [@BlondDon](https://discourse.julialang.org/u/BlondDon)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 11:01am UTC](https://discourse.julialang.org/t/structtypes-mutable-does-not-call-the-inner-constructor/102118 "2023-07-31T11:01:59Z")

</div>

using JSON3 using StructTypes Base.@kwdef mutable struct MyType2 c::Float64 = 3.0 MyType2(c) = c \< 0.0 ? error("bar") : new(c) end Base.@kwdef mutable struct MyType a::Int = 1 b::MyType2 = MyType2(3.0)…

---

## [How to flag Base functions that are being shadowed?](https://discourse.julialang.org/t/how-to-flag-base-functions-that-are-being-shadowed/102289)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 4\
**Last updated:** [July 31, 2023, 10:40am UTC](https://discourse.julialang.org/t/how-to-flag-base-functions-that-are-being-shadowed/102289 "2023-07-31T10:40:30Z")

</div>

Is there a way to highlight instances of function shadowing such as julia\> struct MyType end julia\> Matrix(::MyType) = ones(2,2) Matrix (generic function with 1 method) where a new Matrix function is created in a modu…

---

## [Optim.jl Implementing box minimization does not work for me](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293)

<div class="topic-metadata">

**Author:** [@ditfurth](https://discourse.julialang.org/u/ditfurth)\
**Replies:** 5\
**Last updated:** [July 31, 2023, 10:19am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293 "2023-07-31T10:19:49Z")

</div>

Hi all, I am trying to implement a box minimization, but am struggling to do so. I am at the moment trying to run the line: results = optimize(x -\> blp\_iteration(dt, z, x, W, random\_coeff, fixed\_coeff,agents), ini…

---

## [@testset expands all macros \*before\* executing the generated code](https://discourse.julialang.org/t/testset-expands-all-macros-before-executing-the-generated-code/102197)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 8:52am UTC](https://discourse.julialang.org/t/testset-expands-all-macros-before-executing-the-generated-code/102197 "2023-07-31T08:52:15Z")

</div>

Hello community. I’ve just spent hours confusingly revolving around the following quirk. Given this code in my package: macro a() println("expand a") :(println("exec a")) end macro b() println("expand b") …

---

## [Error with @views and a function](https://discourse.julialang.org/t/error-with-views-and-a-function/102284)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 6:08am UTC](https://discourse.julialang.org/t/error-with-views-and-a-function/102284 "2023-07-31T06:08:15Z")

</div>

I’m getting this strange error when trying to use views with a function. Here is a MWE: x = Array{Float64}(undef, 3, 3, 3) y = similar(x) @views function fun(x, y, t) y\[:, :, t\], x\[:, :, t\] = rand(3, 3) return …

---

## [Error in the precompiling of QuantumOptics package in Julia 1.9.2](https://discourse.julialang.org/t/error-in-the-precompiling-of-quantumoptics-package-in-julia-1-9-2/102181)

<div class="topic-metadata">

**Author:** [@Anil\_Kumar](https://discourse.julialang.org/u/Anil_Kumar)\
**Replies:** 2\
**Last updated:** [July 31, 2023, 3:26am UTC](https://discourse.julialang.org/t/error-in-the-precompiling-of-quantumoptics-package-in-julia-1-9-2/102181 "2023-07-31T03:26:19Z")

</div>

I recently install Julia and anaconda in an IMac, but using QuantumOpitics package for a programme gives me an error: “\[ Info: Precompiling QuantumOptics \[6e0679c1-51ea-5a7c-ac74-d61b76210b0c\] ERROR: LoadError: UndefVa…

---

## [Creating system images much faster with Julia 1.10.0-beta1](https://discourse.julialang.org/t/creating-system-images-much-faster-with-julia-1-10-0-beta1/102251)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 8\
**Last updated:** [July 30, 2023, 8:49pm UTC](https://discourse.julialang.org/t/creating-system-images-much-faster-with-julia-1-10-0-beta1/102251 "2023-07-30T20:49:49Z")

</div>

Re-creating a system image is much (2.4 times) faster with 1.10-beta1 than with 1.9.2: Julia 1.10.0-beta1 ------------------ \[ Info: PackageCompiler: Done ✔ \[01m:47s\] PackageCompiler: compiling incremental system image…

---

## [Makie doesn't show anything when run as a script](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664)

<div class="topic-metadata">

**Author:** [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Replies:** 8\
**Last updated:** [July 30, 2023, 4:11pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664 "2023-07-30T16:11:15Z")

</div>

I am trying to plot something using Makie in the test.jl file. But it doesn’t show figure when using julia test.jl. Here is my code: using GLMakie xs = cos.(1:0.5:20) ys = sin.(1:0.5:20) zs = LinRange(0, 3, length(x…

---

## [Symbolic (symmetric-toepltiz)matrix-vector multiplication doesn't work for higher dimensions of matrix](https://discourse.julialang.org/t/symbolic-symmetric-toepltiz-matrix-vector-multiplication-doesnt-work-for-higher-dimensions-of-matrix/102270)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 0\
**Last updated:** [July 30, 2023, 2:50pm UTC](https://discourse.julialang.org/t/symbolic-symmetric-toepltiz-matrix-vector-multiplication-doesnt-work-for-higher-dimensions-of-matrix/102270 "2023-07-30T14:50:07Z")

</div>

I am trying following , and this works okay! using Symbolics, ToeplitzMatrices N =250 a = Symbolics.variables(:a, 0:N); b= \[1; (1:N).\*a\[2:end\]\] A = SymmetricToeplitz(a) F\_expr = A\*b; However, the code fails if i i…

---

## [Why do Julia functions handle keyword arguments as \`Base.Pairs\` instead of \`NamedTuple\` or \`Dict\`?](https://discourse.julialang.org/t/why-do-julia-functions-handle-keyword-arguments-as-base-pairs-instead-of-namedtuple-or-dict/102263)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 2\
**Last updated:** [July 30, 2023, 5:25am UTC](https://discourse.julialang.org/t/why-do-julia-functions-handle-keyword-arguments-as-base-pairs-instead-of-namedtuple-or-dict/102263 "2023-07-30T05:25:36Z")

</div>

In Python, where we use \*args and \*\*kwargs to handle an arbitrary number of positional and keyword arguments in a function. In Python, these positional arguments are gathered into a tuple, and keyword arguments are gathe…

---

## [How do I install dependencies from the \`\[extras\]\` block of Project.toml to the project-wide manifest?](https://discourse.julialang.org/t/how-do-i-install-dependencies-from-the-extras-block-of-project-toml-to-the-project-wide-manifest/102238)

<div class="topic-metadata">

**Author:** [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Replies:** 3\
**Last updated:** [July 30, 2023, 4:05am UTC](https://discourse.julialang.org/t/how-do-i-install-dependencies-from-the-extras-block-of-project-toml-to-the-project-wide-manifest/102238 "2023-07-30T04:05:36Z")

</div>

Many projects have a Project.toml that lists test dependencies in the \[extras\] block, following by a \[targets\] test = \[...\] block. This way, you can run julia --project in the base project directory and then \]test will…

---

## [Hard reset of Julia environment](https://discourse.julialang.org/t/hard-reset-of-julia-environment/102260)

<div class="topic-metadata">

**Author:** [@mesonepigreco](https://discourse.julialang.org/u/mesonepigreco)\
**Replies:** 1\
**Last updated:** [July 29, 2023, 11:50pm UTC](https://discourse.julialang.org/t/hard-reset-of-julia-environment/102260 "2023-07-29T23:50:00Z")

</div>

Hello, I need to reset a julia environment from all temporary files, like in a fresh installation after a mess I made that is causing many packages to fail precompiliation and loading. In particular, after I activate t…

---

## [How to check if region made by one IntervalBox() contains a region made by another IntervalBox()?](https://discourse.julialang.org/t/how-to-check-if-region-made-by-one-intervalbox-contains-a-region-made-by-another-intervalbox/102246)

<div class="topic-metadata">

**Author:** [@Ashu](https://discourse.julialang.org/u/Ashu)\
**Replies:** 1\
**Last updated:** [July 29, 2023, 8:48pm UTC](https://discourse.julialang.org/t/how-to-check-if-region-made-by-one-intervalbox-contains-a-region-made-by-another-intervalbox/102246 "2023-07-29T20:48:20Z")

</div>

Hello, I want to check if Z = IntervalBox(-1..1, 4) lies in F = f(X...) where f(a, b, c, d) = \[a, b, c, d\] is a vector function, and X=IntervalBox(-10..10, 4) . Using IntervalArithmetic.jl package, I tried Z \\in F and Z…

---

## [How does one create a GPU array from an Array](https://discourse.julialang.org/t/how-does-one-create-a-gpu-array-from-an-array/102247)

<div class="topic-metadata">

**Author:** [@berk.geveci](https://discourse.julialang.org/u/berk.geveci)\
**Replies:** 1\
**Last updated:** [July 29, 2023, 6:42pm UTC](https://discourse.julialang.org/t/how-does-one-create-a-gpu-array-from-an-array/102247 "2023-07-29T18:42:07Z")

</div>

Hi folks, I apologize for this basic question but I have not been able to resolve this by going through the documentation. How does one create a GPU array from an Array using KernelAbstractions? Similar to CuArray(array…

---

## [Auto cxxwrap generator like autopybind11](https://discourse.julialang.org/t/auto-cxxwrap-generator-like-autopybind11/102225)

<div class="topic-metadata">

**Author:** [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Replies:** 3\
**Last updated:** [July 29, 2023, 6:21pm UTC](https://discourse.julialang.org/t/auto-cxxwrap-generator-like-autopybind11/102225 "2023-07-29T18:21:51Z")

</div>

Is there something like autopybind11 / autopybind11 · GitLab where you define a simple config file and it generates all the code needed for wrapping for you?

---

## [Type stable code with autodiff](https://discourse.julialang.org/t/type-stable-code-with-autodiff/102242)

<div class="topic-metadata">

**Author:** [@mesonepigreco](https://discourse.julialang.org/u/mesonepigreco)\
**Replies:** 2\
**Last updated:** [July 29, 2023, 5:39pm UTC](https://discourse.julialang.org/t/type-stable-code-with-autodiff/102242 "2023-07-29T17:39:31Z")

</div>

Dear Julia users I am writing a quite important julia project where performances are very important, and, to enforce type stability, almost all my functions look like this: function get\_kinetic\_energy(scha::SCHA{T}, en…

---

## [What is regex for the end of string in Julia?](https://discourse.julialang.org/t/what-is-regex-for-the-end-of-string-in-julia/102228)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 7\
**Last updated:** [July 29, 2023, 4:29pm UTC](https://discourse.julialang.org/t/what-is-regex-for-the-end-of-string-in-julia/102228 "2023-07-29T16:29:33Z")

</div>

What is regular expression for the final end of string in Julia?

---

## [Is it possible to interpolate a value in a doctest output?](https://discourse.julialang.org/t/is-it-possible-to-interpolate-a-value-in-a-doctest-output/102244)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 0\
**Last updated:** [July 29, 2023, 3:58pm UTC](https://discourse.julialang.org/t/is-it-possible-to-interpolate-a-value-in-a-doctest-output/102244 "2023-07-29T15:58:09Z")

</div>

Suppose I have a doctest for a package where I define Chebyshev: \`\`\`jldoctest julia\> Chebyshev(0..1) Chebyshev(0..1) \`\`\` Say, my package depends on another package that defines the interval 0..1. Now, if the dependency…

---

## [What is regex for blank line in Julia?](https://discourse.julialang.org/t/what-is-regex-for-blank-line-in-julia/102230)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 3\
**Last updated:** [July 29, 2023, 2:15pm UTC](https://discourse.julialang.org/t/what-is-regex-for-blank-line-in-julia/102230 "2023-07-29T14:15:58Z")

</div>

What is regular expression for Blank Line in Julia?

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

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