# General Usage

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

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

**Page:** 795

---

## [Design pattern for correctly overwriting abstract methods (interface methods)](https://discourse.julialang.org/t/design-pattern-for-correctly-overwriting-abstract-methods-interface-methods/33778)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 6\
**Last updated:** [January 26, 2020, 8:42am UTC](https://discourse.julialang.org/t/design-pattern-for-correctly-overwriting-abstract-methods-interface-methods/33778 "2020-01-26T08:42:22Z")

</div>

I have something like the following situation: module Cache export cache function cache(data) throw(NotImplementedException()) end end module FileCache import Cache function Cache.cache(data) # do cache stuff …

---

## [Is there a mechanism in Julia to load modules on demand?](https://discourse.julialang.org/t/is-there-a-mechanism-in-julia-to-load-modules-on-demand/33784)

<div class="topic-metadata">

**Author:** [@nxtruong](https://discourse.julialang.org/u/nxtruong)\
**Replies:** 6\
**Last updated:** [January 25, 2020, 6:56pm UTC](https://discourse.julialang.org/t/is-there-a-mechanism-in-julia-to-load-modules-on-demand/33784 "2020-01-25T18:56:21Z")

</div>

As I understand, using and import statements must be at the top level. However, sometimes I just want to import a module on-demand, in a function that uses that module. For example, a large module X contains both functio…

---

## [Catching the signal SIGWINCH in Julia](https://discourse.julialang.org/t/catching-the-signal-sigwinch-in-julia/33782)

<div class="topic-metadata">

**Author:** [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Replies:** 0\
**Last updated:** [January 25, 2020, 2:29pm UTC](https://discourse.julialang.org/t/catching-the-signal-sigwinch-in-julia/33782 "2020-01-25T14:29:59Z")

</div>

Hi! I am trying to develop a package to create text-based user interfaces in Julia: TextUserInterfaces.jl. However, I need a way to check if the terminal has been resized so I can automatically update the interface. I n…

---

## [Blessed Way for model Serialization](https://discourse.julialang.org/t/blessed-way-for-model-serialization/33768)

<div class="topic-metadata">

**Author:** [@anoojpatel](https://discourse.julialang.org/u/anoojpatel)\
**Replies:** 0\
**Last updated:** [January 24, 2020, 10:02pm UTC](https://discourse.julialang.org/t/blessed-way-for-model-serialization/33768 "2020-01-24T22:02:43Z")

</div>

I was wondering/looking for clarification on what the best way to serialize models or model weights w.r.t. to necessary non-differentiated against parameters (Batch Norm). I find that directly serializing model object cr…

---

## [ERROR: LoadError: UndefRefError: access to undefined reference](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 4\
**Last updated:** [January 24, 2020, 5:59pm UTC](https://discourse.julialang.org/t/error-loaderror-undefreferror-access-to-undefined-reference/33683 "2020-01-24T17:59:41Z")

</div>

So I have the following function function regionextract(data::Array{\<:Real},coord::Array) nlon1 = length(coord\[1\]); nlon2 = size(data,1); nlat1 = length(coord\[2\]); nlat2 = size(data,2); nt = size(data)\[3:en…

---

## [Calling Intel MKL as an external library on Mac](https://discourse.julialang.org/t/calling-intel-mkl-as-an-external-library-on-mac/33722)

<div class="topic-metadata">

**Author:** [@razvangheorghe](https://discourse.julialang.org/u/razvangheorghe)\
**Replies:** 2\
**Last updated:** [January 24, 2020, 4:05pm UTC](https://discourse.julialang.org/t/calling-intel-mkl-as-an-external-library-on-mac/33722 "2020-01-24T16:05:33Z")

</div>

Hi, I’d like to use the Fortran subroutine ZGELSS from MKL in Julia and I’m a bit confused. julia\> versioninfo() Julia Version 1.3.0 Commit 46ce4d7933 (2019-11-26 06:09 UTC) Platform Info: OS: macOS (x86\_64-apple-darw…

---

## [Surprising result if type annotations are used](https://discourse.julialang.org/t/surprising-result-if-type-annotations-are-used/33685)

<div class="topic-metadata">

**Author:** [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Replies:** 2\
**Last updated:** [January 24, 2020, 9:17am UTC](https://discourse.julialang.org/t/surprising-result-if-type-annotations-are-used/33685 "2020-01-24T09:17:45Z")

</div>

Consider the following code: julia\> function foo(T) if T == Float64 v::Vector{Float64} = zeros(5) else v = T\[1, 2, 3, 4, 5\] end v end jul…

---

## [Confusion with local packages](https://discourse.julialang.org/t/confusion-with-local-packages/33714)

<div class="topic-metadata">

**Author:** [@jebej](https://discourse.julialang.org/u/jebej)\
**Replies:** 3\
**Last updated:** [January 24, 2020, 9:16am UTC](https://discourse.julialang.org/t/confusion-with-local-packages/33714 "2020-01-24T09:16:44Z")

</div>

Back in the 0.6 days, I used to push! to LOAD\_PATH a directory containing all the packages I worked on. After updating to 1.0, I kept using the same strategy, which meant adding all the packages that my packages depended…

---

## [Type instability in closure after reassigning a variable](https://discourse.julialang.org/t/type-instability-in-closure-after-reassigning-a-variable/33656)

<div class="topic-metadata">

**Author:** [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Replies:** 7\
**Last updated:** [January 23, 2020, 8:35pm UTC](https://discourse.julialang.org/t/type-instability-in-closure-after-reassigning-a-variable/33656 "2020-01-23T20:35:09Z")

</div>

I’ve stumbled recently on this behavior (julia 1.3.1): function test() s = "hello" s = lowercase(s) x() = s x() end and @code\_warntype test() yields Variables #self#::Core.Compiler.Const(test, false)…

---

## [BSON confusing behaviour](https://discourse.julialang.org/t/bson-confusing-behaviour/33700)

<div class="topic-metadata">

**Author:** [@compleat](https://discourse.julialang.org/u/compleat)\
**Replies:** 2\
**Last updated:** [January 23, 2020, 1:29pm UTC](https://discourse.julialang.org/t/bson-confusing-behaviour/33700 "2020-01-23T13:29:58Z")

</div>

Apologies for so many questions in so short a time, but I have decided to do a “push”, so I am tackling the issues in sequence (and there are alot of them). Regarding using BSON to load: Here is an example of trying to…

---

## [Too much time taken to build GR](https://discourse.julialang.org/t/too-much-time-taken-to-build-gr/22798)

<div class="topic-metadata">

**Author:** [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Replies:** 5\
**Last updated:** [January 23, 2020, 6:55pm UTC](https://discourse.julialang.org/t/too-much-time-taken-to-build-gr/22798 "2020-01-23T18:55:53Z")

</div>

I am using julia 1.1.0 on win 10 and it takes long time to build GR. It was taking long time and so I disconnected from internet and it resulted in error. It seems to download couple of file during build process which I …

---

## [Find in in Julai 1.0 .. LinearIndices to long](https://discourse.julialang.org/t/find-in-in-julai-1-0-linearindices-to-long/33674)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 3\
**Last updated:** [January 23, 2020, 3:57pm UTC](https://discourse.julialang.org/t/find-in-in-julai-1-0-linearindices-to-long/33674 "2020-01-23T15:57:49Z")

</div>

in vector los i need to find some ones new code of julai is some comlicated : (LinearIndices(los.==1))\[findall(los.==1)\] Is some more easy to do ? Paul

---

## [Color scale for an ordered variable](https://discourse.julialang.org/t/color-scale-for-an-ordered-variable/33702)

<div class="topic-metadata">

**Author:** [@yanivab](https://discourse.julialang.org/u/yanivab)\
**Replies:** 0\
**Last updated:** [January 23, 2020, 3:22pm UTC](https://discourse.julialang.org/t/color-scale-for-an-ordered-variable/33702 "2020-01-23T15:22:50Z")

</div>

I’m trying to make a scatter plot with marker color denoting the data session collection number. How does one do this? If I set group = :session, I get non sequential colours (even with, say, color\_palette = :blues): @…

---

## [Example C vs Julia vs Python](https://discourse.julialang.org/t/example-c-vs-julia-vs-python/33120)

<div class="topic-metadata">

**Author:** [@jleman](https://discourse.julialang.org/u/jleman)\
**Replies:** 41\
**Last updated:** [January 23, 2020, 6:44am UTC](https://discourse.julialang.org/t/example-c-vs-julia-vs-python/33120 "2020-01-23T06:44:52Z")

</div>

I have been using Julia for about a year. I am an EE, not a programmer. In one of my graduate EE courses I requested to use Julia instead of C for an assignment and got the task of comparing performance of C, Julia, an…

---

## [TensorFlow \`matmul\` equivalent in Julia: matrix multiplication with two given tensor dimensions](https://discourse.julialang.org/t/tensorflow-matmul-equivalent-in-julia-matrix-multiplication-with-two-given-tensor-dimensions/33676)

<div class="topic-metadata">

**Author:** [@tanhevg](https://discourse.julialang.org/u/tanhevg)\
**Replies:** 5\
**Last updated:** [January 22, 2020, 10:14pm UTC](https://discourse.julialang.org/t/tensorflow-matmul-equivalent-in-julia-matrix-multiplication-with-two-given-tensor-dimensions/33676 "2020-01-22T22:14:09Z")

</div>

Does Julia have an equivalent of TensorFlow matmul ? I need matrix multiplication using two given (or pre-defined) dimensions of the tensors, preserving other dimensions. Tensorflow matmul uses the two innermost tensor …

---

## [Threads memory allocations](https://discourse.julialang.org/t/threads-memory-allocations/33675)

<div class="topic-metadata">

**Author:** [@squirrel](https://discourse.julialang.org/u/squirrel)\
**Replies:** 2\
**Last updated:** [January 22, 2020, 9:03pm UTC](https://discourse.julialang.org/t/threads-memory-allocations/33675 "2020-01-22T21:03:43Z")

</div>

Hi. I’m really trying to understand parallel programming in Julia. Can someone please explain to me why using threads requires so many memory allocations? using BenchmarkTools using .Threads function test\_serial(u) …

---

## [Performance bug when creating a sparse matrix via Python](https://discourse.julialang.org/t/performance-bug-when-creating-a-sparse-matrix-via-python/33661)

<div class="topic-metadata">

**Author:** [@TomDeWeer](https://discourse.julialang.org/u/TomDeWeer)\
**Replies:** 3\
**Last updated:** [January 22, 2020, 7:05pm UTC](https://discourse.julialang.org/t/performance-bug-when-creating-a-sparse-matrix-via-python/33661 "2020-01-22T19:05:22Z")

</div>

Hi all, I am trying to solve Ax=B for a sparse A in Julia. I create the A and B matrix in Python and import it into Julia via the PyCall package.The problem is that this import takes ages and consumes all my RAM. I beli…

---

## [Help to create a structure to use ForwardDiff package](https://discourse.julialang.org/t/help-to-create-a-structure-to-use-forwarddiff-package/33657)

<div class="topic-metadata">

**Author:** [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Replies:** 5\
**Last updated:** [January 22, 2020, 5:50pm UTC](https://discourse.julialang.org/t/help-to-create-a-structure-to-use-forwarddiff-package/33657 "2020-01-22T17:50:33Z")

</div>

Hi! I want to use the ForwardDiff package to perform automatic differentiation of a function. However, this function requires an structure in which I am declaring like this: @with\_kw mutable struct MyStruct{T\<:Real} …

---

## [On AD of matrix, from Tracker to Zygote](https://discourse.julialang.org/t/on-ad-of-matrix-from-tracker-to-zygote/33667)

<div class="topic-metadata">

**Author:** [@vavrines](https://discourse.julialang.org/u/vavrines)\
**Replies:** 3\
**Last updated:** [January 22, 2020, 5:01pm UTC](https://discourse.julialang.org/t/on-ad-of-matrix-from-tracker-to-zygote/33667 "2020-01-22T17:01:44Z")

</div>

Since the Flux has moved to Zygote, I tried to modify some previous codes. The motivation is to calculate second-order derivatives of a matrix, but I met the following errors. With the setup x0 = 0.0; x1 = 2.0 y0 = 0.…

---

## [Writing to file removes escape char](https://discourse.julialang.org/t/writing-to-file-removes-escape-char/33637)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 6\
**Last updated:** [January 22, 2020, 2:31pm UTC](https://discourse.julialang.org/t/writing-to-file-removes-escape-char/33637 "2020-01-22T14:31:00Z")

</div>

I have this string s julia\> s = "abc.\\$foo" julia\> s "abc.\\$foo" When I write it to file, this happens: julia\> open("moo.jl", "w") do io write(io, s) end 8 And in moo.jl I have: abc.$foo So I get $fo…

---

## [Julia package not up-to-date](https://discourse.julialang.org/t/julia-package-not-up-to-date/33653)

<div class="topic-metadata">

**Author:** [@nxtruong](https://discourse.julialang.org/u/nxtruong)\
**Replies:** 1\
**Last updated:** [January 22, 2020, 8:07am UTC](https://discourse.julialang.org/t/julia-package-not-up-to-date/33653 "2020-01-22T08:07:47Z")

</div>

I am using Julia version 1.3.1 (2019-12-30) on Mac OS, official binary downloaded from Julia website. I wanted to add the package Parametron, so I used Julia’s Pkg interface to add it. It reported that the version of Pa…

---

## [How to parameterize the name of a struct?](https://discourse.julialang.org/t/how-to-parameterize-the-name-of-a-struct/33623)

<div class="topic-metadata">

**Author:** [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Replies:** 9\
**Last updated:** [January 21, 2020, 11:20pm UTC](https://discourse.julialang.org/t/how-to-parameterize-the-name-of-a-struct/33623 "2020-01-21T23:20:59Z")

</div>

I would like to define in an automatic way a struct like: struct MyStruct some\_field end where the struct name “MyStruct” can be read from a string array. I found https://github.com/cstjean/QuickTypes.jl, but from m…

---

## [Newcomer's guide to Julia package manager](https://discourse.julialang.org/t/newcomers-guide-to-julia-package-manager/33492)

<div class="topic-metadata">

**Author:** [@aaowens](https://discourse.julialang.org/u/aaowens)\
**Replies:** 14\
**Last updated:** [January 21, 2020, 9:12pm UTC](https://discourse.julialang.org/t/newcomers-guide-to-julia-package-manager/33492 "2020-01-21T21:12:27Z")

</div>

I wrote a blog post to help beginners understand package management in Julia. The intended audience is people who have no familiarity with the concept of packages, versions, etc. I’ve seen a lot of people try to run some…

---

## [Plot! function does not plot the right distribution](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635)

<div class="topic-metadata">

**Author:** [@Lixiang\_Wei](https://discourse.julialang.org/u/Lixiang_Wei)\
**Replies:** 3\
**Last updated:** [January 21, 2020, 9:12pm UTC](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635 "2020-01-21T21:12:22Z")

</div>

Hi, I have a problem when using plot!, which should add a curve of Normal(10,2) fitting on my histogram. However, in my plot, I could see the label for plot!, it is overlapping on x-axis. I am using Mac, my friend is us…

---

## [More specific definition for DenseArray](https://discourse.julialang.org/t/more-specific-definition-for-densearray/33591)

<div class="topic-metadata">

**Author:** [@emmt](https://discourse.julialang.org/u/emmt)\
**Replies:** 11\
**Last updated:** [January 21, 2020, 6:39pm UTC](https://discourse.julialang.org/t/more-specific-definition-for-densearray/33591 "2020-01-21T18:39:26Z")

</div>

The documentation of a DenseArray{T,N} says: N-dimensional dense array with elements of type T. The elements of a dense array are stored contiguously in memory. but this is a bit unspecific. For instance, my underst…

---

## [Allocations on threaded prefix algorithm](https://discourse.julialang.org/t/allocations-on-threaded-prefix-algorithm/33631)

<div class="topic-metadata">

**Author:** [@squirrel](https://discourse.julialang.org/u/squirrel)\
**Replies:** 0\
**Last updated:** [January 21, 2020, 6:10pm UTC](https://discourse.julialang.org/t/allocations-on-threaded-prefix-algorithm/33631 "2020-01-21T18:10:43Z")

</div>

I’m going through the Parallel Computing course at juliaacademy.com. They give this example of a prefix code being rewritten in parallel. However, the video does not go through it, and when I run it on my own, I get a lo…

---

## [Parallelizaton on GPU slower than on CPU...?](https://discourse.julialang.org/t/parallelizaton-on-gpu-slower-than-on-cpu/33587)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 10\
**Last updated:** [January 21, 2020, 2:54pm UTC](https://discourse.julialang.org/t/parallelizaton-on-gpu-slower-than-on-cpu/33587 "2020-01-21T14:54:51Z")

</div>

I built a new PC and I’ve been toying around with some code just to see how it performs and I’m trying to understand why the following code (from the CUDA.jl docs) runs slower on my GPU than on my CPU (I have a Ryzen 9 3…

---

## [How can I get this to infer types?](https://discourse.julialang.org/t/how-can-i-get-this-to-infer-types/33617)

<div class="topic-metadata">

**Author:** [@Per](https://discourse.julialang.org/u/Per)\
**Replies:** 1\
**Last updated:** [January 21, 2020, 2:31pm UTC](https://discourse.julialang.org/t/how-can-i-get-this-to-infer-types/33617 "2020-01-21T14:31:36Z")

</div>

I’m having problems getting my code to infer a return type correctly. Here’s a MWE: using Test struct TwoTo{N} end @inline t(g::Base.Generator{\<:TwoTo{N}, F}) where {N,F} = ntuple(i-\>g.f(i+1), Val{N-1}()) f(r) = t(t(i f…

---

## [Voices of experience - abstract types as classes or interfaces?](https://discourse.julialang.org/t/voices-of-experience-abstract-types-as-classes-or-interfaces/33609)

<div class="topic-metadata">

**Author:** [@tro3](https://discourse.julialang.org/u/tro3)\
**Replies:** 4\
**Last updated:** [January 21, 2020, 1:56pm UTC](https://discourse.julialang.org/t/voices-of-experience-abstract-types-as-classes-or-interfaces/33609 "2020-01-21T13:56:25Z")

</div>

Not looking to start a religious war of any sort - just looking for the voices of experience before I dive into this next thing. I am new to Julia, but coming to the conclusion based on the dispatch behavior that I shou…

---

## [How to setup Julia workers to use specific number of cores?](https://discourse.julialang.org/t/how-to-setup-julia-workers-to-use-specific-number-of-cores/33597)

<div class="topic-metadata">

**Author:** [@indycdrom](https://discourse.julialang.org/u/indycdrom)\
**Replies:** 5\
**Last updated:** [January 21, 2020, 11:05am UTC](https://discourse.julialang.org/t/how-to-setup-julia-workers-to-use-specific-number-of-cores/33597 "2020-01-21T11:05:27Z")

</div>

I am a beginner, so I am trying my best to describe my issue as clearly as possible. I installed julia 1.2.0 in a windows 2012 with 2 CPU/socket (22 cores in each CPU) and 512GB RAM. I am wondering whether I can start …

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

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