# General Usage

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

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

**Page:** 225

---

## [Avoiding small strings and using IOBuffer](https://discourse.julialang.org/t/avoiding-small-strings-and-using-iobuffer/106980)

<div class="topic-metadata">

**Author:** [@grahamas](https://discourse.julialang.org/u/grahamas)\
**Replies:** 7\
**Last updated:** [December 1, 2023, 7:06pm UTC](https://discourse.julialang.org/t/avoiding-small-strings-and-using-iobuffer/106980 "2023-12-01T19:06:23Z")

</div>

Recently I’ve been using this bit of code to basically conditionally concatenate a bunch of lines in a file: buf = IOBuffer() open("input.txt", "r") do f for line in readlines(f) if line\[1\] != "#" …

---

## [PrettyTables.jl breaks on non-breaking release](https://discourse.julialang.org/t/prettytables-jl-breaks-on-non-breaking-release/106990)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 7\
**Last updated:** [December 1, 2023, 5:50pm UTC](https://discourse.julialang.org/t/prettytables-jl-breaks-on-non-breaking-release/106990 "2023-12-01T17:50:19Z")

</div>

Hello, I use PrettyTables.jl to print the contents of a struct to the REPL. Sometime between 2.0 and 2.3.1 it stopped working. Here is an example showing it works with 2.0: Code using SequentialSamplingModels dist = …

---

## [Performance of streaming \`mean\`](https://discourse.julialang.org/t/performance-of-streaming-mean/106999)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 4\
**Last updated:** [December 1, 2023, 3:49pm UTC](https://discourse.julialang.org/t/performance-of-streaming-mean/106999 "2023-12-01T15:49:25Z")

</div>

Here’s a basic streaming mean function (called avg for convenience): function avg(itr) a = zero(eltype(x)) for (i, x) in enumerate(itr) a += (x - a) / i end return a end Why does it allocate so …

---

## [Make \`find\_zero\` more robust](https://discourse.julialang.org/t/make-find-zero-more-robust/106983)

<div class="topic-metadata">

**Author:** [@rikh](https://discourse.julialang.org/u/rikh)\
**Replies:** 3\
**Last updated:** [December 1, 2023, 2:18pm UTC](https://discourse.julialang.org/t/make-find-zero-more-robust/106983 "2023-12-01T14:18:15Z")

</div>

In my PowerAnalyses.jl package, I’m having trouble in finding a robust way to solve for zero. It works, but it’s not very robust. For example: ArgumentError when effect size is small (\<=0.10) · Issue #21 · rikhuijzer/Pow…

---

## [Fastest algorithm for (xi - xj) \* (yi - yj) for i in 1:n, j in 1:n](https://discourse.julialang.org/t/fastest-algorithm-for-xi-xj-yi-yj-for-i-in-1-n-j-in-1-n/106988)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 13\
**Last updated:** [December 1, 2023, 2:11pm UTC](https://discourse.julialang.org/t/fastest-algorithm-for-xi-xj-yi-yj-for-i-in-1-n-j-in-1-n/106988 "2023-12-01T14:11:33Z")

</div>

Suppose we are given two “big” vectors x and y of real numbers (e.g. Float64), both with the same length n. What is the fastest algorithm to compute \[(x\[i\] - x\[j\]) \* (y\[i\] - y\[j\]) for i in 1:n, j in 1:n\] ? Here is a b…

---

## [Should custom hash functions distinguish types?](https://discourse.julialang.org/t/should-custom-hash-functions-distinguish-types/106984)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 2\
**Last updated:** [December 1, 2023, 11:16am UTC](https://discourse.julialang.org/t/should-custom-hash-functions-distinguish-types/106984 "2023-12-01T11:16:17Z")

</div>

Suppose my package define two struct types A and B, each containing just a single field called data. Then I overload Base.hash as follows: import Base: hash hash(a::A, i) = hash(a.data, i) hash(b::B, i) = hash(b.data,…

---

## [Something like \`grep -q String Filename\` in Julia?](https://discourse.julialang.org/t/something-like-grep-q-string-filename-in-julia/106959)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 6\
**Last updated:** [November 30, 2023, 10:15pm UTC](https://discourse.julialang.org/t/something-like-grep-q-string-filename-in-julia/106959 "2023-11-30T22:15:29Z")

</div>

Is there something similar to grep -q Filename String in Julia? Meaning, a command that just checks if a string is present in a text file and returns true or false? Alternatively (this is actually what I need), is there…

---

## [UndefRefError - Trying access variable inside for](https://discourse.julialang.org/t/undefreferror-trying-access-variable-inside-for/106963)

<div class="topic-metadata">

**Author:** [@th.simoes](https://discourse.julialang.org/u/th.simoes)\
**Replies:** 0\
**Last updated:** [November 30, 2023, 8:30pm UTC](https://discourse.julialang.org/t/undefreferror-trying-access-variable-inside-for/106963 "2023-11-30T20:30:10Z")

</div>

I’m using DBInterface and MySQL to interact with my MySQL database, but my function is stucking into a strange error. This function below works well, but is slow and inefficient: function insertNewDebDataIntoDatabase(d…

---

## [Sum an SVector skipping one element](https://discourse.julialang.org/t/sum-an-svector-skipping-one-element/106943)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 7\
**Last updated:** [November 30, 2023, 6:12pm UTC](https://discourse.julialang.org/t/sum-an-svector-skipping-one-element/106943 "2023-11-30T18:12:04Z")

</div>

I am optimizing a tight loop where one operation is summing an SVector except that it is required that an element is skipped. Its index is not known at compile time, it is obtained from a lookup table. Some attempts: u…

---

## [Batched matrix multiplication in CUDA](https://discourse.julialang.org/t/batched-matrix-multiplication-in-cuda/106918)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 8\
**Last updated:** [November 30, 2023, 4:59pm UTC](https://discourse.julialang.org/t/batched-matrix-multiplication-in-cuda/106918 "2023-11-30T16:59:39Z")

</div>

I am thinking of performing the following batched matrix multiplication using CUDA, but I can’t find an appropriate function for it. using LinearAlgebra N = 50; Nt = 3000; A = rand(Nt,2\*N,2\*N); C = rand(Nt,2\*N,2\*N); B …

---

## [What’s your secret in your uncanny ability to optimize code?](https://discourse.julialang.org/t/what-s-your-secret-in-your-uncanny-ability-to-optimize-code/106942)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 3\
**Last updated:** [November 30, 2023, 2:00pm UTC](https://discourse.julialang.org/t/what-s-your-secret-in-your-uncanny-ability-to-optimize-code/106942 "2023-11-30T14:00:05Z")

</div>

From a faster differential equation solver to faster sorting algorithm, people working with Julia have uncanny ability to optimize things with deceptively simple optimizations that are, indeed, the work of Julian in brin…

---

## [Override DocStringExtension @template](https://discourse.julialang.org/t/override-docstringextension-template/106954)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 0\
**Last updated:** [November 30, 2023, 1:59pm UTC](https://discourse.julialang.org/t/override-docstringextension-template/106954 "2023-11-30T13:59:21Z")

</div>

DocStringExtensions provides the @template macro that allows one to automatically interpolate the function signatures into their docstring without having to write them out or add $SIGNATURES into the docstring. Is there…

---

## [How to test differentiability efficiently](https://discourse.julialang.org/t/how-to-test-differentiability-efficiently/106631)

<div class="topic-metadata">

**Author:** [@Devetak](https://discourse.julialang.org/u/Devetak)\
**Replies:** 6\
**Last updated:** [November 30, 2023, 12:14pm UTC](https://discourse.julialang.org/t/how-to-test-differentiability-efficiently/106631 "2023-11-30T12:14:14Z")

</div>

Hello. As the tile suggest I am interested in testing (using Test) the “AD” capabilities of functions I write. My idea is to simply compare if Zygote.gradient() and finite differences give the same answer. Many times I…

---

## [Continuously tracking callback with boolean condition](https://discourse.julialang.org/t/continuously-tracking-callback-with-boolean-condition/106937)

<div class="topic-metadata">

**Author:** [@flmuk](https://discourse.julialang.org/u/flmuk)\
**Replies:** 1\
**Last updated:** [November 30, 2023, 9:50am UTC](https://discourse.julialang.org/t/continuously-tracking-callback-with-boolean-condition/106937 "2023-11-30T09:50:07Z")

</div>

Hello, I have the following system of equations: using DifferentialEquations using Plots u\_rest = -50. t\_ref = 2. u\_reset = -75. u\_thr = -55. J = 1. last\_spikes = \[1., 1.\] .\* (- t\_ref + eps()) function decay(du, u, p…

---

## [Zero-allocating Instance of Struct](https://discourse.julialang.org/t/zero-allocating-instance-of-struct/106893)

<div class="topic-metadata">

**Author:** [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)\
**Replies:** 11\
**Last updated:** [November 30, 2023, 9:58am UTC](https://discourse.julialang.org/t/zero-allocating-instance-of-struct/106893 "2023-11-30T09:58:52Z")

</div>

I have large structs with a lot of fields (think of multiple 100s) which I need to communicate with a C library. Julia creates the instances of a struct (memory allocation) but C fills in the values. Keeping its memory u…

---

## [Implementing derivative in ChainRules for function with internal fields](https://discourse.julialang.org/t/implementing-derivative-in-chainrules-for-function-with-internal-fields/66844)

<div class="topic-metadata">

**Author:** [@jcallaham](https://discourse.julialang.org/u/jcallaham)\
**Replies:** 5\
**Last updated:** [November 30, 2023, 2:06am UTC](https://discourse.julialang.org/t/implementing-derivative-in-chainrules-for-function-with-internal-fields/66844 "2023-11-30T02:06:25Z")

</div>

I’m trying to define an rrule for a functional, e.g. numerical integration of a given function, and the gradient would be with respect to the parameters of the function. This works no problem with a simple implementatio…

---

## [Vscode language server crashing](https://discourse.julialang.org/t/vscode-language-server-crashing/90185)

<div class="topic-metadata">

**Author:** [@sransome](https://discourse.julialang.org/u/sransome)\
**Replies:** 17\
**Last updated:** [November 30, 2023, 1:32am UTC](https://discourse.julialang.org/t/vscode-language-server-crashing/90185 "2023-11-30T01:32:00Z")

</div>

Hi, for the last month or so, every time my Windows 10 computer gets rebooted the language server will not start when I try to open my Julia project. I have tried reinstalling the Julia extension, Julia itself and V…

---

## [Julia 1.10.0-rc1 hangs on Pkg.status() with high thread count](https://discourse.julialang.org/t/julia-1-10-0-rc1-hangs-on-pkg-status-with-high-thread-count/106905)

<div class="topic-metadata">

**Author:** [@sebastien-lemieux](https://discourse.julialang.org/u/sebastien-lemieux)\
**Replies:** 4\
**Last updated:** [November 29, 2023, 5:20pm UTC](https://discourse.julialang.org/t/julia-1-10-0-rc1-hangs-on-pkg-status-with-high-thread-count/106905 "2023-11-29T17:20:46Z")

</div>

Hello, I’m currently experimenting with 1.10.0-rc1 and I encountered a strange issue. I’m launching julia with JULIA\_NUM\_THREADS=auto on 3 AMD computers in the lab. On two threadripper (32 and 24 cores) everything works…

---

## [Jl\_call - function call latency](https://discourse.julialang.org/t/jl-call-function-call-latency/106791)

<div class="topic-metadata">

**Author:** [@AntoineK](https://discourse.julialang.org/u/AntoineK)\
**Replies:** 5\
**Last updated:** [November 29, 2023, 3:59pm UTC](https://discourse.julialang.org/t/jl-call-function-call-latency/106791 "2023-11-29T15:59:06Z")

</div>

Hello, My first benchmarks show that calling the jl\_call function comes with a latency of 100 nanoseconds (measured by calling an empty Julia function) on a Xeon Gold processor. Is it expected ? In Julia, BenchmarksTo…

---

## [What materials should I read extending the compiler?](https://discourse.julialang.org/t/what-materials-should-i-read-extending-the-compiler/106841)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 14\
**Last updated:** [November 29, 2023, 1:09pm UTC](https://discourse.julialang.org/t/what-materials-should-i-read-extending-the-compiler/106841 "2023-11-29T13:09:21Z")

</div>

I have some knowledge of metaprogramming from my last package. Now, I need to descend into madness, to figure out how the compiler works and how I can access and modify the working of each stage in the pipeline. Impleme…

---

## [Row / column major with PythonCall , OpenCV](https://discourse.julialang.org/t/row-column-major-with-pythoncall-opencv/106620)

<div class="topic-metadata">

**Author:** [@kemu](https://discourse.julialang.org/u/kemu)\
**Replies:** 18\
**Last updated:** [November 29, 2023, 12:15pm UTC](https://discourse.julialang.org/t/row-column-major-with-pythoncall-opencv/106620 "2023-11-29T12:15:27Z")

</div>

row / column major with PythonCall and numpy + OpenCV I am trying to create an image processing program using PythonCall.jl and the Python version of OpenCV. The specification I have in mind now is to create the pixel …

---

## [Revise fails to pre-compile](https://discourse.julialang.org/t/revise-fails-to-pre-compile/106884)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 4\
**Last updated:** [November 29, 2023, 10:51am UTC](https://discourse.julialang.org/t/revise-fails-to-pre-compile/106884 "2023-11-29T10:51:14Z")

</div>

This morning I get the following error: julia\> using Revise Precompiling Revise Info Given Revise was explicitly requested, output will be shown live ERROR: LoadError: UndefVarError: \`is\_GotoIfNot\` not defined …

---

## [Handling Dates](https://discourse.julialang.org/t/handling-dates/106879)

<div class="topic-metadata">

**Author:** [@Sourish](https://discourse.julialang.org/u/Sourish)\
**Replies:** 4\
**Last updated:** [November 29, 2023, 8:44am UTC](https://discourse.julialang.org/t/handling-dates/106879 "2023-11-29T08:44:10Z")

</div>

Hi I am trying to convert a string to date with the following code - but giving me some parsing error using Dates df = DateFormat("d-b-y"); dt = Date("28-Feb-99",df) I am getting the following error: ArgumentError: U…

---

## [How to execute tasks in parallel in a for loop](https://discourse.julialang.org/t/how-to-execute-tasks-in-parallel-in-a-for-loop/106736)

<div class="topic-metadata">

**Author:** [@Chamika\_Kasun](https://discourse.julialang.org/u/Chamika_Kasun)\
**Replies:** 27\
**Last updated:** [November 29, 2023, 3:22am UTC](https://discourse.julialang.org/t/how-to-execute-tasks-in-parallel-in-a-for-loop/106736 "2023-11-29T03:22:42Z")

</div>

I’m quite new to Julia programming, and I’m looking for a better way to parallelize the execution of a for loop. Basically, the logic I have in the following code needs to be executed in parallel. data = \[\] …

---

## [Lazy read string from iostream?](https://discourse.julialang.org/t/lazy-read-string-from-iostream/106782)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 6\
**Last updated:** [November 29, 2023, 3:15am UTC](https://discourse.julialang.org/t/lazy-read-string-from-iostream/106782 "2023-11-29T03:15:13Z")

</div>

It seems that read(iostream, String) reads the entire file into the memory at once. (Please correct me if I’m mistaken.) I’ve just deduced that from this test code: f = open("tmp.txt", "r") s = read(f, String) typeof(…

---

## [Dynamically defining a struct with default values](https://discourse.julialang.org/t/dynamically-defining-a-struct-with-default-values/106855)

<div class="topic-metadata">

**Author:** [@Titas22](https://discourse.julialang.org/u/Titas22)\
**Replies:** 3\
**Last updated:** [November 28, 2023, 8:09pm UTC](https://discourse.julialang.org/t/dynamically-defining-a-struct-with-default-values/106855 "2023-11-28T20:09:07Z")

</div>

Hi, I would like to be able to define a struct with some default values based on an input Dict. The input is something like this: d = Dict("A"=\>1, "B"=\>2, "C"=\>"x", "D"=\>\[1,2\]) And I would like to define a struct lik…

---

## [Accessing the coefficients of a preconditioner](https://discourse.julialang.org/t/accessing-the-coefficients-of-a-preconditioner/106789)

<div class="topic-metadata">

**Author:** [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Replies:** 4\
**Last updated:** [November 28, 2023, 8:04pm UTC](https://discourse.julialang.org/t/accessing-the-coefficients-of-a-preconditioner/106789 "2023-11-28T20:04:25Z")

</div>

Hi all, I would like to access coefficients of a preconditioner constructed using the ILUZero package. ILUZero returns an object of type ::ILU0Precon{Float64, Int64, Float64} which contains a sparse representations of …

---

## [Fortran-Julia interface for program containing non-c-interoperable derived type](https://discourse.julialang.org/t/fortran-julia-interface-for-program-containing-non-c-interoperable-derived-type/106815)

<div class="topic-metadata">

**Author:** [@tmph](https://discourse.julialang.org/u/tmph)\
**Replies:** 6\
**Last updated:** [November 28, 2023, 4:59pm UTC](https://discourse.julialang.org/t/fortran-julia-interface-for-program-containing-non-c-interoperable-derived-type/106815 "2023-11-28T16:59:45Z")

</div>

I’m still new to Julia (and this discourse), but couldn’t find the answer to this question anywhere. I have a large Fortran legacy code base which I’m trying to interface with a high-level language. I got something kind…

---

## [How reliable is \`rank(A)\`?](https://discourse.julialang.org/t/how-reliable-is-rank-a/106834)

<div class="topic-metadata">

**Author:** [@Mikulas\_Vanousek](https://discourse.julialang.org/u/Mikulas_Vanousek)\
**Replies:** 8\
**Last updated:** [November 28, 2023, 1:58pm UTC](https://discourse.julialang.org/t/how-reliable-is-rank-a/106834 "2023-11-28T13:58:44Z")

</div>

The rank(A) function is not reliable. Here is an example, A has in fact rank 2. julia\> A = \[1 0; 10^8 1\] 2×2 Matrix{Int64}: 1 0 100000000 1 julia\> rank(A) 1 I understand this is inevitable for matricies wi…

---

## [Calling .NET Framework from Julia](https://discourse.julialang.org/t/calling-net-framework-from-julia/106808)

<div class="topic-metadata">

**Author:** [@Titas22](https://discourse.julialang.org/u/Titas22)\
**Replies:** 1\
**Last updated:** [November 28, 2023, 12:30pm UTC](https://discourse.julialang.org/t/calling-net-framework-from-julia/106808 "2023-11-28T12:30:46Z")

</div>

Hi, I’m looking for a way to call and use .NET Framework (4.7) dlls from Julia, unfortunately the only options I’ve found for using .NET only cover the non-framework versions of .NET. Unfortunately the libraries I need…

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

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