# General Usage

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

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

**Page:** 779

---

## [Multiple type declarations with if-else](https://discourse.julialang.org/t/multiple-type-declarations-with-if-else/35759)

<div class="topic-metadata">

**Author:** [@ykc](https://discourse.julialang.org/u/ykc)\
**Replies:** 8\
**Last updated:** [March 9, 2020, 8:51pm UTC](https://discourse.julialang.org/t/multiple-type-declarations-with-if-else/35759 "2020-03-09T20:51:12Z")

</div>

I understand the proper practice is to pre-allocate outputs, but why wouldn’t the following work? function f() if 1 == 1 x::Float64 = 1.0 else x::Float64 = 2.0 end return x end This retu…

---

## [Custom Type for lazy kernel operations on AbstractArrays, ho can i improve it?](https://discourse.julialang.org/t/custom-type-for-lazy-kernel-operations-on-abstractarrays-ho-can-i-improve-it/35764)

<div class="topic-metadata">

**Author:** [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)\
**Replies:** 3\
**Last updated:** [March 9, 2020, 8:05pm UTC](https://discourse.julialang.org/t/custom-type-for-lazy-kernel-operations-on-abstractarrays-ho-can-i-improve-it/35764 "2020-03-09T20:05:01Z")

</div>

Hi guys is there any way to make this performant? it looks like a super useful type see Example of usage Type Definition struct KernelOp{T,N,S} \<: AbstractArray{T,N} parent::S op::Function opdims::CartesianI…

---

## [Patching without adding dependencies](https://discourse.julialang.org/t/patching-without-adding-dependencies/35762)

<div class="topic-metadata">

**Author:** [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Replies:** 2\
**Last updated:** [March 9, 2020, 6:32pm UTC](https://discourse.julialang.org/t/patching-without-adding-dependencies/35762 "2020-03-09T18:32:22Z")

</div>

Let’s say I created some package MyPackage that I would like to interact with a package TheirPackage that I did not create. Is there any way to override some of the functions of TheirPackage without having to add TheirPa…

---

## [Creating a type graph from a function body with macros](https://discourse.julialang.org/t/creating-a-type-graph-from-a-function-body-with-macros/35735)

<div class="topic-metadata">

**Author:** [@darsnack](https://discourse.julialang.org/u/darsnack)\
**Replies:** 2\
**Last updated:** [March 9, 2020, 2:23pm UTC](https://discourse.julialang.org/t/creating-a-type-graph-from-a-function-body-with-macros/35735 "2020-03-09T14:23:57Z")

</div>

I have a package I am working on where users will write code that looks like (using the package’s @circuit macro): @circuit Foo begin parameters : \[ a =\> 0.5, b =\> 10 \] circuit : (dut::Foo)(…

---

## ["Import guard" in julia](https://discourse.julialang.org/t/import-guard-in-julia/1505)

<div class="topic-metadata">

**Author:** [@kdmurray91](https://discourse.julialang.org/u/kdmurray91)\
**Replies:** 6\
**Last updated:** [March 9, 2020, 1:11pm UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505 "2020-03-09T13:11:53Z")

</div>

Hi all, Apologies if I’m lacking google skills, but I’m unable to find a Julian equivalent of the following common python pattern: if \_\_name\_\_ == "\_\_main\_\_": run\_my\_main\_func() This construct prevents code being e…

---

## [Changing the shape of the initial value problem in DiffentialEquations.jl and possible performance issues](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739)

<div class="topic-metadata">

**Author:** [@Noobie76](https://discourse.julialang.org/u/Noobie76)\
**Replies:** 3\
**Last updated:** [March 9, 2020, 12:45pm UTC](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739 "2020-03-09T12:45:33Z")

</div>

Dear Community I’m not very familiar with the numerical handling of ODEs in Julia. Maybe I should begin with my goal, what I want to achieve in order to simplify the feedback loop. I try to implement a variational solv…

---

## [Pushing a function to its performance limit](https://discourse.julialang.org/t/pushing-a-function-to-its-performance-limit/35647)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 16\
**Last updated:** [March 9, 2020, 12:20pm UTC](https://discourse.julialang.org/t/pushing-a-function-to-its-performance-limit/35647 "2020-03-09T12:20:40Z")

</div>

Hi! I am trying to push this code to be as efficient as possible. If I could achieve any performance gain it would be great because I am calling this function thousands of time. The problem is essentially a problem of b…

---

## [How convert docx and odt into pure text?](https://discourse.julialang.org/t/how-convert-docx-and-odt-into-pure-text/35734)

<div class="topic-metadata">

**Author:** [@Darione](https://discourse.julialang.org/u/Darione)\
**Replies:** 2\
**Last updated:** [March 8, 2020, 11:05pm UTC](https://discourse.julialang.org/t/how-convert-docx-and-odt-into-pure-text/35734 "2020-03-08T23:05:15Z")

</div>

Hi, how can i convert a .docx (or .odt) file into pure text, in Julia? Many thanks

---

## [Extending Base functions for a tree](https://discourse.julialang.org/t/extending-base-functions-for-a-tree/35722)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 7\
**Last updated:** [March 8, 2020, 6:21pm UTC](https://discourse.julialang.org/t/extending-base-functions-for-a-tree/35722 "2020-03-08T18:21:50Z")

</div>

As I recall, Base.length is used to return types with a single dimension Base.size is used to return types with more than one dimension I have build a tree type and I want to return the total number of nodes in the …

---

## [Cool idea: define a function conditionally. Even more powerful than traits](https://discourse.julialang.org/t/cool-idea-define-a-function-conditionally-even-more-powerful-than-traits/35701)

<div class="topic-metadata">

**Author:** [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Replies:** 30\
**Last updated:** [March 8, 2020, 5:18pm UTC](https://discourse.julialang.org/t/cool-idea-define-a-function-conditionally-even-more-powerful-than-traits/35701 "2020-03-08T17:18:01Z")

</div>

I cooked up a little macro that allows you to define a function conditionally. This condition can be totally arbitrary, the sky’s the limit. The only requirement is that the condition must return True or False. Unless I’…

---

## [Why am i getting an array instead of a number](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711)

<div class="topic-metadata">

**Author:** [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Replies:** 4\
**Last updated:** [March 8, 2020, 1:31pm UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711 "2020-03-08T13:31:59Z")

</div>

I have this function that i want to to get a probability from which means that i should get a number but instead of that i’m getting an array with the identical elements. function prob(na) #na must be a Vecto…

---

## [Keyword versus positional arguments](https://discourse.julialang.org/t/keyword-versus-positional-arguments/35538)

<div class="topic-metadata">

**Author:** [@aerdely](https://discourse.julialang.org/u/aerdely)\
**Replies:** 2\
**Last updated:** [March 7, 2020, 8:13pm UTC](https://discourse.julialang.org/t/keyword-versus-positional-arguments/35538 "2020-03-07T20:13:32Z")

</div>

Reviewing @avik Sengupta’s book «Julia High Performance» 2nd edition, it says that performance of functions with positional arguments is better than those with keyword (named) arguments, giving the following example: us…

---

## [How to take the value after typing one character in redline (Char?) Without ENTER](https://discourse.julialang.org/t/how-to-take-the-value-after-typing-one-character-in-redline-char-without-enter/35691)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 2\
**Last updated:** [March 7, 2020, 7:29pm UTC](https://discourse.julialang.org/t/how-to-take-the-value-after-typing-one-character-in-redline-char-without-enter/35691 "2020-03-07T19:29:53Z")

</div>

Is there a way for the variable var to take the value after typing one character in redline (Char?) without pressing Enter? Something like var = readline (:: Char?) (I am doing a quick one-touch input interface) Paul

---

## [Why would closure break type inference?](https://discourse.julialang.org/t/why-would-closure-break-type-inference/35681)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 12\
**Last updated:** [March 7, 2020, 2:33pm UTC](https://discourse.julialang.org/t/why-would-closure-break-type-inference/35681 "2020-03-07T14:33:58Z")

</div>

function my\_mean(A::AbstractArray) isempty(A) && return sum(A)/0 n = length(A) x1 = first(A) / n \_prom(x::T, y::S) where {T,S} = begin R = promote\_type(T, S) return convert(R, x) end ret…

---

## [I want to bin numerical values into manually set percentile values, how can I do this?](https://discourse.julialang.org/t/i-want-to-bin-numerical-values-into-manually-set-percentile-values-how-can-i-do-this/35651)

<div class="topic-metadata">

**Author:** [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Replies:** 2\
**Last updated:** [March 7, 2020, 1:07pm UTC](https://discourse.julialang.org/t/i-want-to-bin-numerical-values-into-manually-set-percentile-values-how-can-i-do-this/35651 "2020-03-07T13:07:16Z")

</div>

Hi how’s it going? I have a numerical column that I’d like to bin into these percentile bin edges: percentiles = \[.05,.35,.8,.95\] In Python it’s as easy as pd.qcut. I was wondering what the simplest way would be for m…

---

## [Sparse with default value "Inf"](https://discourse.julialang.org/t/sparse-with-default-value-inf/35110)

<div class="topic-metadata">

**Author:** [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)\
**Replies:** 27\
**Last updated:** [February 29, 2020, 2:39pm UTC](https://discourse.julialang.org/t/sparse-with-default-value-inf/35110 "2020-02-29T14:39:44Z")

</div>

Hi guys i’m working on a problem which requires solving many linear assignment problems (LAP) and i wonder if it’s possible to declare a sparse matrix object in Julia which defaults to “Inf” rather than 0, as this would …

---

## [SQLite.jl install error with Julia1.3.1](https://discourse.julialang.org/t/sqlite-jl-install-error-with-julia1-3-1/35007)

<div class="topic-metadata">

**Author:** [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Replies:** 10\
**Last updated:** [March 7, 2020, 2:16am UTC](https://discourse.julialang.org/t/sqlite-jl-install-error-with-julia1-3-1/35007 "2020-03-07T02:16:53Z")

</div>

I got the following errors while installing SQLite.jl on Julia1.3.1. without error for the old version of Julia1.1. The followings are the error message. Resolving package versions... ERROR: Unable to automatically inst…

---

## [MySQL.jl install error](https://discourse.julialang.org/t/mysql-jl-install-error/35277)

<div class="topic-metadata">

**Author:** [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Replies:** 11\
**Last updated:** [March 7, 2020, 2:14am UTC](https://discourse.julialang.org/t/mysql-jl-install-error/35277 "2020-03-07T02:14:20Z")

</div>

I got the following error while installing MySQL.jl on windows 10. (@v1.3) pkg\> add MySQL Updating registry at \`C:\\Users\\zhangly\\.juliapro\\JuliaPro\_v1.3.1-1\\registries\\JuliaPro\` tar: Can't convert a path to a wchar\_t…

---

## [Vararg vs Tuple{Vararg} performance](https://discourse.julialang.org/t/vararg-vs-tuple-vararg-performance/35670)

<div class="topic-metadata">

**Author:** [@SnoopyDoowop](https://discourse.julialang.org/u/SnoopyDoowop)\
**Replies:** 4\
**Last updated:** [March 7, 2020, 12:30am UTC](https://discourse.julialang.org/t/vararg-vs-tuple-vararg-performance/35670 "2020-03-07T00:30:09Z")

</div>

Hello! While trying out some things in the julia REPL to see how a\[i…\] = x is transformed into setindex!(a, x, i…). I came across multiple questions : I am wondering why the prototype of setindex! is setindex!(A::Abstr…

---

## [Working with MulAddMul](https://discourse.julialang.org/t/working-with-muladdmul/35668)

<div class="topic-metadata">

**Author:** [@bjack205](https://discourse.julialang.org/u/bjack205)\
**Replies:** 0\
**Last updated:** [March 6, 2020, 10:34pm UTC](https://discourse.julialang.org/t/working-with-muladdmul/35668 "2020-03-06T22:34:51Z")

</div>

I’m trying to implement the 5-argument mul! made available in Julia v1.3 on StaticArrays, and SizedArrays in particular. I’m trying to make use of LinearAlgebra.MulAddMul that is used throughout the matrix multiplication…

---

## [Parellel arrays](https://discourse.julialang.org/t/parellel-arrays/35645)

<div class="topic-metadata">

**Author:** [@eaubanel](https://discourse.julialang.org/u/eaubanel)\
**Replies:** 4\
**Last updated:** [March 6, 2020, 8:33pm UTC](https://discourse.julialang.org/t/parellel-arrays/35645 "2020-03-06T20:33:43Z")

</div>

I need to have multiple threads write values to a shared array. I’m thinking of having each thread write to a private array, and then have the threads each write their private values into a shared array. In the following…

---

## [\`Serialization.serialize()\` strings are not interned, causing duplication](https://discourse.julialang.org/t/serialization-serialize-strings-are-not-interned-causing-duplication/35626)

<div class="topic-metadata">

**Author:** [@NHDaly](https://discourse.julialang.org/u/NHDaly)\
**Replies:** 0\
**Last updated:** [March 6, 2020, 5:11am UTC](https://discourse.julialang.org/t/serialization-serialize-strings-are-not-interned-causing-duplication/35626 "2020-03-06T05:11:09Z")

</div>

Can anyone help me understand the serialization behavior for many shared references to large strings? I’ve noticed that multiple shared references to strings end up duplicated on disk when serialized via Serialization.se…

---

## [Problems reading compressed HDF5 file created in Python](https://discourse.julialang.org/t/problems-reading-compressed-hdf5-file-created-in-python/35580)

<div class="topic-metadata">

**Author:** [@adriano.vilela](https://discourse.julialang.org/u/adriano.vilela)\
**Replies:** 6\
**Last updated:** [March 6, 2020, 6:04pm UTC](https://discourse.julialang.org/t/problems-reading-compressed-hdf5-file-created-in-python/35580 "2020-03-06T18:04:24Z")

</div>

I’m having problems reading an HDF5 file that was saved in Python with the pytables library (www.pytables.org). The file I’m trying to read is available at: https://www.cefala.org/~adriano/.shared/simple\_mjpeg\_frames\_0\_…

---

## [Create view for an Array of FieldVector](https://discourse.julialang.org/t/create-view-for-an-array-of-fieldvector/35649)

<div class="topic-metadata">

**Author:** [@CFBaptista](https://discourse.julialang.org/u/CFBaptista)\
**Replies:** 4\
**Last updated:** [March 6, 2020, 5:14pm UTC](https://discourse.julialang.org/t/create-view-for-an-array-of-fieldvector/35649 "2020-03-06T17:14:21Z")

</div>

Let’s say I have a struct that represents a point in 3D: using StaticArrays struct Point3D{T} \<: FieldVector{3, T} x::T y::T z::T end Then I generate some points like: points = rand(Point3D{Float64}, 10) I…

---

## [How store this variable into files, and reaload it?](https://discourse.julialang.org/t/how-store-this-variable-into-files-and-reaload-it/35636)

<div class="topic-metadata">

**Author:** [@Darione](https://discourse.julialang.org/u/Darione)\
**Replies:** 7\
**Last updated:** [March 6, 2020, 4:55pm UTC](https://discourse.julialang.org/t/how-store-this-variable-into-files-and-reaload-it/35636 "2020-03-06T16:55:30Z")

</div>

Hello, I have this two kind of variabiles, x and y, to save to file, and after to reload. julia\> x Dict{Any,Any} with 2 entries: "day" =\> \[1, 2, 3\] "beautifull" =\> \[7, 5, 10, 11, 23, 56\] julia\> y = \[\["W…

---

## [Batteries included](https://discourse.julialang.org/t/batteries-included/35565)

<div class="topic-metadata">

**Author:** [@Darione](https://discourse.julialang.org/u/Darione)\
**Replies:** 19\
**Last updated:** [March 6, 2020, 4:13pm UTC](https://discourse.julialang.org/t/batteries-included/35565 "2020-03-06T16:13:35Z")

</div>

While I got stuck importing a package to save arrays to text files, I’m thinking that Julia doesn’t appear too “batteries included”, as are Python and PHP for example. How come this difference in setting? Is it because…

---

## [Register and specialize a function in a different module/package (Julia segfaults)](https://discourse.julialang.org/t/register-and-specialize-a-function-in-a-different-module-package-julia-segfaults/35591)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 12\
**Last updated:** [March 6, 2020, 3:33pm UTC](https://discourse.julialang.org/t/register-and-specialize-a-function-in-a-different-module-package-julia-segfaults/35591 "2020-03-06T15:33:27Z")

</div>

I am working on a DSL for creating web pages. Something like this (Julia like pseudo-code): module Html function table(f::Function; args...) # actual implementation here end function tr(f::Function; args...) # actual …

---

## [Varinfo() slow if variable large](https://discourse.julialang.org/t/varinfo-slow-if-variable-large/35585)

<div class="topic-metadata">

**Author:** [@Usor](https://discourse.julialang.org/u/Usor)\
**Replies:** 4\
**Last updated:** [March 6, 2020, 2:02pm UTC](https://discourse.julialang.org/t/varinfo-slow-if-variable-large/35585 "2020-03-06T14:02:36Z")

</div>

I’ve often had not-so-large DataFrames loaded, and performance with varinfo() was good. When a DataFrame exceeds a certain size, e.g. beyond 100 MB, varinfo() is very slow. (I didn’t check the exact size, but the one lo…

---

## [How to only read (first or last better) element of Set?](https://discourse.julialang.org/t/how-to-only-read-first-or-last-better-element-of-set/35635)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 7\
**Last updated:** [March 6, 2020, 1:49pm UTC](https://discourse.julialang.org/t/how-to-only-read-first-or-last-better-element-of-set/35635 "2020-03-06T13:49:53Z")

</div>

How to only read (first or last better) element of Set ? julia\> X=Set(\["a","b"\]) Set(\["b", "a"\]) julia\> X\[1\] ERROR: MethodError: no method matching getindex(::Set{String}, ::Int64) Stacktrace: \[1\] top-level scope at n…

---

## [Storing evaled function inside a struct](https://discourse.julialang.org/t/storing-evaled-function-inside-a-struct/35454)

<div class="topic-metadata">

**Author:** [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Replies:** 28\
**Last updated:** [March 6, 2020, 1:30pm UTC](https://discourse.julialang.org/t/storing-evaled-function-inside-a-struct/35454 "2020-03-06T13:30:50Z")

</div>

Hi everyone! I’m looking for feedback on the approach of some code I’ve written. Since the code is for work I’ll share a greatly simplified version of what it looks like. I’d like to hear opinions on the “right way” to…

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

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