# General Usage

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

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

**Page:** 361

---

## [Get CPU usage](https://discourse.julialang.org/t/get-cpu-usage/24468)

<div class="topic-metadata">

**Author:** [@Caesar\_KG](https://discourse.julialang.org/u/Caesar_KG)\
**Replies:** 7\
**Last updated:** [December 3, 2022, 1:06pm UTC](https://discourse.julialang.org/t/get-cpu-usage/24468 "2022-12-03T13:06:04Z")

</div>

Is there any built-in function that I can use to get the CPU usage of PCs? I’m writing a load balancer that orchestrates multiple PCs to perform a computation task based on CPU and memory usage. I know other languages li…

---

## [Does union cause type instability？](https://discourse.julialang.org/t/does-union-cause-type-instability/91173)

<div class="topic-metadata">

**Author:** [@zhangchunyong](https://discourse.julialang.org/u/zhangchunyong)\
**Replies:** 5\
**Last updated:** [December 3, 2022, 12:23pm UTC](https://discourse.julialang.org/t/does-union-cause-type-instability/91173 "2022-12-03T12:23:01Z")

</div>

a=Vector{Union{Missing, Int64}}() push!(a,1) push!(a,missing) push! to the union vector.Can this cause type instability?

---

## [Accessing an N-dimensional array with a vector with N indeces](https://discourse.julialang.org/t/accessing-an-n-dimensional-array-with-a-vector-with-n-indeces/91101)

<div class="topic-metadata">

**Author:** [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Replies:** 5\
**Last updated:** [December 3, 2022, 11:27am UTC](https://discourse.julialang.org/t/accessing-an-n-dimensional-array-with-a-vector-with-n-indeces/91101 "2022-12-03T11:27:04Z")

</div>

I’m currently trying to optimize some code I made that needs to access arrays with a user defined number of dimensions. For example, I could get a 3-dimensional array from a user and need to access an element of this arr…

---

## [ForwardDiff and FunctionWrappers](https://discourse.julialang.org/t/forwarddiff-and-functionwrappers/91130)

<div class="topic-metadata">

**Author:** [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Replies:** 8\
**Last updated:** [December 3, 2022, 11:21am UTC](https://discourse.julialang.org/t/forwarddiff-and-functionwrappers/91130 "2022-12-03T11:21:14Z")

</div>

I have code that makes use of FunctionWrappers in some places. I need to compute gradients for code that involves these wrappers - is this possible? For example, using FunctionWrappers using ForwardDiff f1 = FunctionWra…

---

## [Type-stability with a vector of FunctionWrappers](https://discourse.julialang.org/t/type-stability-with-a-vector-of-functionwrappers/91122)

<div class="topic-metadata">

**Author:** [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Replies:** 7\
**Last updated:** [December 3, 2022, 10:28am UTC](https://discourse.julialang.org/t/type-stability-with-a-vector-of-functionwrappers/91122 "2022-12-03T10:28:51Z")

</div>

I have the following code that I want to use for storing a vector of functions: using FunctionWrappers import FunctionWrappers: FunctionWrapper abstract type AbstractF end struct F{P,T,U} \<: AbstractF p::P f::F…

---

## [Initialize Dict to enable values of different type](https://discourse.julialang.org/t/initialize-dict-to-enable-values-of-different-type/91153)

<div class="topic-metadata">

**Author:** [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Replies:** 3\
**Last updated:** [December 3, 2022, 9:53am UTC](https://discourse.julialang.org/t/initialize-dict-to-enable-values-of-different-type/91153 "2022-12-03T09:53:44Z")

</div>

What is the reason that case 3 fails? And how to avoid this? How can I initialize a Dict to enable values of different type? Here is my snippet: function MyDictFill(\_a::Dict = Dict()) if ~haskey(\_a, "a") …

---

## [How to Plot this Riemann Sum Correctly?](https://discourse.julialang.org/t/how-to-plot-this-riemann-sum-correctly/90944)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 2\
**Last updated:** [December 3, 2022, 8:48am UTC](https://discourse.julialang.org/t/how-to-plot-this-riemann-sum-correctly/90944 "2022-12-03T08:48:14Z")

</div>

Hi all, I have a function : x^{3} - 5x^{2} + 2x + 8 and I have this code: using Plots, LaTeXStrings, ValidatedNumerics gr() f(x) = x^3 - 5x^2 + 2x + 8 #plot(f, 0, 2, aspect\_ratio=:equal, fill=(0, :green), alpha=0.…

---

## [Doubt about "nzval" field in factorization?](https://discourse.julialang.org/t/doubt-about-nzval-field-in-factorization/91151)

<div class="topic-metadata">

**Author:** [@Amro](https://discourse.julialang.org/u/Amro)\
**Replies:** 3\
**Last updated:** [December 3, 2022, 12:22am UTC](https://discourse.julialang.org/t/doubt-about-nzval-field-in-factorization/91151 "2022-12-03T00:22:40Z")

</div>

I have the below MWE. I have two things: 1- The matrices of factor and factor1 are different. However, why the fifth element of factor.nzval=7 not 6. but the matrices of \`\`? using SparseArrays, LinearAlgebra, KLU A\_Mat…

---

## [Pull data from websites in Julia](https://discourse.julialang.org/t/pull-data-from-websites-in-julia/91112)

<div class="topic-metadata">

**Author:** [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Replies:** 10\
**Last updated:** [December 2, 2022, 8:33pm UTC](https://discourse.julialang.org/t/pull-data-from-websites-in-julia/91112 "2022-12-02T20:33:17Z")

</div>

As ski resorts begin to open, they update data on their websites throughout the day, every day. Two factors skiiers care about are: (1) # trails currently open, (2) current Snow base Each resort website posts this info…

---

## [Passing values from an array in ModeliingToolkit framework](https://discourse.julialang.org/t/passing-values-from-an-array-in-modeliingtoolkit-framework/90976)

<div class="topic-metadata">

**Author:** [@Rohan\_Rajagopal](https://discourse.julialang.org/u/Rohan_Rajagopal)\
**Replies:** 3\
**Last updated:** [December 2, 2022, 2:35pm UTC](https://discourse.julialang.org/t/passing-values-from-an-array-in-modeliingtoolkit-framework/90976 "2022-12-02T14:35:46Z")

</div>

I have a previously solved system (dt=1/200, ~adaptive=false, tspan = (0, 50)), stored as an array say 'A.' I want to use these values in another modelingtoolkit setup. A is essentially like a sinusoidal signal. eqs =…

---

## [Some questions about function of function](https://discourse.julialang.org/t/some-questions-about-function-of-function/91144)

<div class="topic-metadata">

**Author:** [@Xuekui\_wang](https://discourse.julialang.org/u/Xuekui_wang)\
**Replies:** 2\
**Last updated:** [December 2, 2022, 2:03pm UTC](https://discourse.julialang.org/t/some-questions-about-function-of-function/91144 "2022-12-02T14:03:49Z")

</div>

I am not so familiar to Julia. I have a program as follows, it means function t2 is a parameter of t5. My question is that why it needs (args...; kwargs...) -\> begin in beginning of t5 , and why here is ;, if it is (a…

---

## [Optimize code by parallelization/GPU](https://discourse.julialang.org/t/optimize-code-by-parallelization-gpu/88578)

<div class="topic-metadata">

**Author:** [@Adegasel](https://discourse.julialang.org/u/Adegasel)\
**Replies:** 8\
**Last updated:** [October 12, 2022, 8:46pm UTC](https://discourse.julialang.org/t/optimize-code-by-parallelization-gpu/88578 "2022-10-12T20:46:14Z")

</div>

I have developed this transform method in order to assign vectors to previously computed centroids. It is currently taking ~20s on my machine, for 1M vectors and 256 clusters. Since I want to apply it to 1B vectors, this…

---

## [How to use a previous version of the Statistics or Linear Algebra Package from the Standard Library](https://discourse.julialang.org/t/how-to-use-a-previous-version-of-the-statistics-or-linear-algebra-package-from-the-standard-library/91126)

<div class="topic-metadata">

**Author:** [@vikram-s-narayan](https://discourse.julialang.org/u/vikram-s-narayan)\
**Replies:** 1\
**Last updated:** [December 2, 2022, 7:59am UTC](https://discourse.julialang.org/t/how-to-use-a-previous-version-of-the-statistics-or-linear-algebra-package-from-the-standard-library/91126 "2022-12-02T07:59:09Z")

</div>

I added a model called GEKPLS.jl to the Surrogates package a few months ago. GEKPLS uses the Linear Algebra and Statistics packages from the standard library. A few weeks ago, a few tests started failing without any cha…

---

## [Can't precompile Makie](https://discourse.julialang.org/t/cant-precompile-makie/91125)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 4\
**Last updated:** [December 2, 2022, 7:42am UTC](https://discourse.julialang.org/t/cant-precompile-makie/91125 "2022-12-02T07:42:26Z")

</div>

What is this? How can I solve it? julia\> using Makie # 0.18.3 \[ Info: Precompiling Makie \[ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a\] ERROR: LoadError: TypeError: in \<:, expected Type, got Vararg Stacktrace: \[1\] #s10#5 …

---

## [How to create a zero-based array?](https://discourse.julialang.org/t/how-to-create-a-zero-based-array/91127)

<div class="topic-metadata">

**Author:** [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)\
**Replies:** 1\
**Last updated:** [December 2, 2022, 6:32am UTC](https://discourse.julialang.org/t/how-to-create-a-zero-based-array/91127 "2022-12-02T06:32:52Z")

</div>

I’d like to create a multidimensional array whose indexes start at 0 instead of 1. I know that this is possible, but I can’t seem to find a simple example of how. This page of the official documentation starts out promi…

---

## [Plot Sin (x) for - π or negative x-axis](https://discourse.julialang.org/t/plot-sin-x-for-or-negative-x-axis/90224)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 14\
**Last updated:** [December 2, 2022, 4:12am UTC](https://discourse.julialang.org/t/plot-sin-x-for-or-negative-x-axis/90224 "2022-12-02T04:12:08Z")

</div>

Hi all, I wonder why the sin(x) function can’t be plot for the domain of -π or the negative x-axis. This is my code: using Plots, LaTeXStrings gr() function pitick(start, stop, denom; mode=:text) a = Int(cld(star…

---

## [Generating a sparse matrix from a piecewise function](https://discourse.julialang.org/t/generating-a-sparse-matrix-from-a-piecewise-function/91119)

<div class="topic-metadata">

**Author:** [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Replies:** 2\
**Last updated:** [December 2, 2022, 12:36am UTC](https://discourse.julialang.org/t/generating-a-sparse-matrix-from-a-piecewise-function/91119 "2022-12-02T00:36:46Z")

</div>

I’m trying to generate a random sparse matrix R where each element in R can take on the following values: r\_{ij}= \\left\\{ \\begin{array}{ll} 1 & \\text{with probability } \\frac{1}{6}\\\\ 0 & \\text{with probab…

---

## [How to make warning into error?](https://discourse.julialang.org/t/how-to-make-warning-into-error/5251)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 4\
**Last updated:** [December 1, 2022, 11:56pm UTC](https://discourse.julialang.org/t/how-to-make-warning-into-error/5251 "2022-12-01T23:56:32Z")

</div>

In C++, we can be pedantic and convert all warnings into errors during compilation: shell\> g++ -Werror Is there a similar feature in Julia? This switch could be very useful in Travis CI builds for mature packages. I am…

---

## [Warning stack trace](https://discourse.julialang.org/t/warning-stack-trace/67516)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 1\
**Last updated:** [December 1, 2022, 11:58pm UTC](https://discourse.julialang.org/t/warning-stack-trace/67516 "2022-12-01T23:58:58Z")

</div>

Is it possible to retrieve a warning’s stack trace, similar to errors? The reason I’m asking is that I want to trace the source of the warning, as now it shows the line where it’s being thrown, but not the actual code th…

---

## [Matrix{Float64}\<:Matrix{Number} is false?](https://discourse.julialang.org/t/matrix-float64-matrix-number-is-false/91077)

<div class="topic-metadata">

**Author:** [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Replies:** 8\
**Last updated:** [December 1, 2022, 8:26pm UTC](https://discourse.julialang.org/t/matrix-float64-matrix-number-is-false/91077 "2022-12-01T20:26:35Z")

</div>

Why is Matrix{Float64}\<:Matrix{Number} false?

---

## [BigInt to bytes](https://discourse.julialang.org/t/bigint-to-bytes/91107)

<div class="topic-metadata">

**Author:** [@iskyd](https://discourse.julialang.org/u/iskyd)\
**Replies:** 6\
**Last updated:** [December 1, 2022, 8:22pm UTC](https://discourse.julialang.org/t/bigint-to-bytes/91107 "2022-12-01T20:22:38Z")

</div>

I’m looking for a way to convert a BigInt number to bytes representation (in python this is done via (int).to\_bytes()). The only solution I came up with is doing BigInt → Hex → Bytes. For example: number::BigInt = par…

---

## [Broadcast over a multiple output function and receive a Tuple of Arrays](https://discourse.julialang.org/t/broadcast-over-a-multiple-output-function-and-receive-a-tuple-of-arrays/91111)

<div class="topic-metadata">

**Author:** [@bensetterholm](https://discourse.julialang.org/u/bensetterholm)\
**Replies:** 3\
**Last updated:** [December 1, 2022, 8:06pm UTC](https://discourse.julialang.org/t/broadcast-over-a-multiple-output-function-and-receive-a-tuple-of-arrays/91111 "2022-12-01T20:06:03Z")

</div>

Is there a convenient way to broadcast over a function that produces multiple outputs and receive a tuple of arrays instead of an array of tuples? For example, with the sincos function, I get the following output upon b…

---

## [In julia import Pkg failed to precompiling. Why and how to solve this problem?](https://discourse.julialang.org/t/in-julia-import-pkg-failed-to-precompiling-why-and-how-to-solve-this-problem/91108)

<div class="topic-metadata">

**Author:** [@connect2robiul](https://discourse.julialang.org/u/connect2robiul)\
**Replies:** 1\
**Last updated:** [December 1, 2022, 5:31pm UTC](https://discourse.julialang.org/t/in-julia-import-pkg-failed-to-precompiling-why-and-how-to-solve-this-problem/91108 "2022-12-01T17:31:21Z")

</div>

---

## [Reading binary file into a Vector of custom struct](https://discourse.julialang.org/t/reading-binary-file-into-a-vector-of-custom-struct/91097)

<div class="topic-metadata">

**Author:** [@bensetterholm](https://discourse.julialang.org/u/bensetterholm)\
**Replies:** 9\
**Last updated:** [December 1, 2022, 5:20pm UTC](https://discourse.julialang.org/t/reading-binary-file-into-a-vector-of-custom-struct/91097 "2022-12-01T17:20:12Z")

</div>

I am trying to find the best way to read a binary file directly into a vector of struct. The binary file has a format so that it could be read in as a vector of objects with format like so (where the file may have any n…

---

## [Some questions about function (size(i::Int))](https://discourse.julialang.org/t/some-questions-about-function-size-i-int/91093)

<div class="topic-metadata">

**Author:** [@Xuekui\_wang](https://discourse.julialang.org/u/Xuekui_wang)\
**Replies:** 6\
**Last updated:** [December 1, 2022, 2:32pm UTC](https://discourse.julialang.org/t/some-questions-about-function-size-i-int/91093 "2022-12-01T14:32:01Z")

</div>

I saw a function as follows. Can you tell me what’s the mean of size(i::Int)=i ==0 ? 3 : 4\*i ? function t3(input) vect=\[\] size(i::Int)=i ==0 ? 3 : 4\*i for i in 1: (input) append!(vect, size(i)) e…

---

## [Serialization of a SubArray forgets position in parent array](https://discourse.julialang.org/t/serialization-of-a-subarray-forgets-position-in-parent-array/90951)

<div class="topic-metadata">

**Author:** [@iagoleal](https://discourse.julialang.org/u/iagoleal)\
**Replies:** 3\
**Last updated:** [December 1, 2022, 1:07pm UTC](https://discourse.julialang.org/t/serialization-of-a-subarray-forgets-position-in-parent-array/90951 "2022-12-01T13:07:56Z")

</div>

Hello! I am working in a codebase where we use Vectors divided in multiple “viewing windows” (SubArrays) representing some data. Recently I had to serialize those views and noticed that the information about the parent…

---

## [How do I add a function/method to an already defined module](https://discourse.julialang.org/t/how-do-i-add-a-function-method-to-an-already-defined-module/22699)

<div class="topic-metadata">

**Author:** [@iPostHuman](https://discourse.julialang.org/u/iPostHuman)\
**Replies:** 11\
**Last updated:** [December 1, 2022, 12:37pm UTC](https://discourse.julialang.org/t/how-do-i-add-a-function-method-to-an-already-defined-module/22699 "2022-12-01T12:37:03Z")

</div>

This is a follow up question relating to my question on sub modules: Discourse question on submodules Okay. My issues seems to be around circular dependencies. I have an engine that wants to call methods that some “oth…

---

## [Bessel function of second with complex order](https://discourse.julialang.org/t/bessel-function-of-second-with-complex-order/20443)

<div class="topic-metadata">

**Author:** [@Tanjona\_Radonirina\_R](https://discourse.julialang.org/u/Tanjona_Radonirina_R)\
**Replies:** 4\
**Last updated:** [February 7, 2019, 9:01am UTC](https://discourse.julialang.org/t/bessel-function-of-second-with-complex-order/20443 "2019-02-07T09:01:37Z")

</div>

Is there a math library in Julia which can compute a modified Bessel function of the second kind with complex order and argument? I am only aware of SpecialFunctions.jl which contains a method to compute a modified Besse…

---

## [Resetting Counter in a While loop](https://discourse.julialang.org/t/resetting-counter-in-a-while-loop/91043)

<div class="topic-metadata">

**Author:** [@phantom](https://discourse.julialang.org/u/phantom)\
**Replies:** 6\
**Last updated:** [December 1, 2022, 12:10pm UTC](https://discourse.julialang.org/t/resetting-counter-in-a-while-loop/91043 "2022-12-01T12:10:04Z")

</div>

Suppose I want a function to continuously iterate through a set until it is directed to stop. Currently I am using a while loop with an if else statement to reset the counter. So it looks something like. a=\["a","b"\] f…

---

## [Usage of \`@.\`](https://discourse.julialang.org/t/usage-of/91086)

<div class="topic-metadata">

**Author:** [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Replies:** 3\
**Last updated:** [December 1, 2022, 11:20am UTC](https://discourse.julialang.org/t/usage-of/91086 "2022-12-01T11:20:04Z")

</div>

Hi, I am trying to generate random vector with {-1, +1} on length n. The following code works y = 2 .\* (rand(n) .\> 0.50) .- 1 When I try to use @., it throws error y = @. 2 \* (rand(n) \> 0.50) - 1 ERROR: MethodError…

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

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