# General Usage

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

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

**Page:** 999

---

## [Why is this simple code slow (how to speed it up)](https://discourse.julialang.org/t/why-is-this-simple-code-slow-how-to-speed-it-up/8854)

<div class="topic-metadata">

**Author:** [@cpraveen](https://discourse.julialang.org/u/cpraveen)\
**Replies:** 7\
**Last updated:** [February 6, 2018, 4:44am UTC](https://discourse.julialang.org/t/why-is-this-simple-code-slow-how-to-speed-it-up/8854 "2018-02-06T04:44:42Z")

</div>

This small code takes about 24 seconds every time on my macbook pro. Is there a way to make it faster ? I run it on commend line as julia test.jl using Plots x = linspace(0.0,2\*pi,100); y = sin.(x); plot(x,y) savefig("…

---

## [Get type of field in a type](https://discourse.julialang.org/t/get-type-of-field-in-a-type/8795)

<div class="topic-metadata">

**Author:** [@Ward9250](https://discourse.julialang.org/u/Ward9250)\
**Replies:** 2\
**Last updated:** [February 5, 2018, 10:55pm UTC](https://discourse.julialang.org/t/get-type-of-field-in-a-type/8795 "2018-02-05T22:55:23Z")

</div>

Hi, Say I have types: abstract type abtype end struct mytype \<: abtype a::UInt8 end struct mytype2 \<: abtype a::UInt64 end ... and so on for several more concrete types of abtype Say I want to get the type …

---

## [How to create a type from Symbol in a macro](https://discourse.julialang.org/t/how-to-create-a-type-from-symbol-in-a-macro/8749)

<div class="topic-metadata">

**Author:** [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Replies:** 7\
**Last updated:** [February 5, 2018, 10:51pm UTC](https://discourse.julialang.org/t/how-to-create-a-type-from-symbol-in-a-macro/8749 "2018-02-05T22:51:14Z")

</div>

module X export MM struct MM end end using X Base.@pure get\_module(::Type{T}) where T = T.name.module macro mod\_check(sym) amod = get\_module(Type(sym)) end @mod\_check MM My problem is to create a type f…

---

## [Why does this pointer code seem to always work?](https://discourse.julialang.org/t/why-does-this-pointer-code-seem-to-always-work/8753)

<div class="topic-metadata">

**Author:** [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Replies:** 5\
**Last updated:** [February 5, 2018, 10:38pm UTC](https://discourse.julialang.org/t/why-does-this-pointer-code-seem-to-always-work/8753 "2018-02-05T22:38:16Z")

</div>

I wrote some code expecting it to break. Here is a MWE struct PointerWrapper{T} ptr::Ptr{T} end struct BufferWrapper{T} pw::PointerWrapper data::Vector{T} end function BufferWrapper(data::Vector{T}) whe…

---

## [Generate in macroexpand time an expression that interpolates variables in runtime](https://discourse.julialang.org/t/generate-in-macroexpand-time-an-expression-that-interpolates-variables-in-runtime/8816)

<div class="topic-metadata">

**Author:** [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Replies:** 4\
**Last updated:** [February 5, 2018, 9:45pm UTC](https://discourse.julialang.org/t/generate-in-macroexpand-time-an-expression-that-interpolates-variables-in-runtime/8816 "2018-02-05T21:45:47Z")

</div>

I have a struct to represent symbolic variable: struct Var name::Symbol value::Any end Now I want to generate a function expression that takes objects of type Var and returns an expression made from their .nam…

---

## [Gitlab instead of github](https://discourse.julialang.org/t/gitlab-instead-of-github/8845)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 6\
**Last updated:** [February 5, 2018, 8:13pm UTC](https://discourse.julialang.org/t/gitlab-instead-of-github/8845 "2018-02-05T20:13:41Z")

</div>

Is there a way to use gitlab instead of github? If so how exactly? Can I get all the perks with the easy CI, test coverage, requirements, etc that exists with github? Thanks!

---

## [Reducing verbosity in array calculations](https://discourse.julialang.org/t/reducing-verbosity-in-array-calculations/8778)

<div class="topic-metadata">

**Author:** [@mvhulten](https://discourse.julialang.org/u/mvhulten)\
**Replies:** 8\
**Last updated:** [February 5, 2018, 7:06pm UTC](https://discourse.julialang.org/t/reducing-verbosity-in-array-calculations/8778 "2018-02-05T19:06:48Z")

</div>

I wrote simple code, but it looks messy because I am removing NaN and I usually want to apply element-by-element. To illustrate, I show my calculation of the Pearson correlation coefficient: function r(obs, mod) om…

---

## [Math errors](https://discourse.julialang.org/t/math-errors/8836)

<div class="topic-metadata">

**Author:** [@Peter\_Green](https://discourse.julialang.org/u/Peter_Green)\
**Replies:** 3\
**Last updated:** [February 5, 2018, 6:16pm UTC](https://discourse.julialang.org/t/math-errors/8836 "2018-02-05T18:16:13Z")

</div>

2^2^2 etc is ok but 6^6^6 gives answer 0 9^8^6 gives negative numbers!!! the use of parenthesis helps a little but its not consistant If i go out of bounds /overflow it should tell me with a suitable error message …

---

## [Julia version of Matlab function interp1](https://discourse.julialang.org/t/julia-version-of-matlab-function-interp1/8540)

<div class="topic-metadata">

**Author:** [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Replies:** 4\
**Last updated:** [February 5, 2018, 5:02pm UTC](https://discourse.julialang.org/t/julia-version-of-matlab-function-interp1/8540 "2018-02-05T17:02:27Z")

</div>

I am try to find the Julia version of Matlab function interp1. In Matlab, vq = interp1(x,v,xq) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the sam…

---

## [Dependency policy - should we avoid dependencies or embrace them?](https://discourse.julialang.org/t/dependency-policy-should-we-avoid-dependencies-or-embrace-them/8793)

<div class="topic-metadata">

**Author:** [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Replies:** 20\
**Last updated:** [February 5, 2018, 4:38pm UTC](https://discourse.julialang.org/t/dependency-policy-should-we-avoid-dependencies-or-embrace-them/8793 "2018-02-05T16:38:48Z")

</div>

Julia’s package ecosystem is really modular, with a big emphasis on functionality in packages. Still, it is very often implicitly assumed in discussions here that dependencies are a bad thing. I understand why: the more …

---

## [typeof(Int32(1)/Int32(2)) == Float64 @\_@](https://discourse.julialang.org/t/typeof-int32-1-int32-2-float64/8811)

<div class="topic-metadata">

**Author:** [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Replies:** 16\
**Last updated:** [February 5, 2018, 3:25pm UTC](https://discourse.julialang.org/t/typeof-int32-1-int32-2-float64/8811 "2018-02-05T15:25:11Z")

</div>

Why isn’t it Float32?

---

## [Why does \`@inbounds\` have no return value?](https://discourse.julialang.org/t/why-does-inbounds-have-no-return-value/8832)

<div class="topic-metadata">

**Author:** [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Replies:** 2\
**Last updated:** [February 5, 2018, 3:16pm UTC](https://discourse.julialang.org/t/why-does-inbounds-have-no-return-value/8832 "2018-02-05T15:16:46Z")

</div>

A = rand(1) nothing == @inbounds A\[1\] The last line returns true. I know that the intention is that a variable assignment should happen within the block passed to @inbounds, but why not have an expression return value …

---

## [Cannot preview Gadfly saved images](https://discourse.julialang.org/t/cannot-preview-gadfly-saved-images/8826)

<div class="topic-metadata">

**Author:** [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Replies:** 5\
**Last updated:** [February 5, 2018, 1:28pm UTC](https://discourse.julialang.org/t/cannot-preview-gadfly-saved-images/8826 "2018-02-05T13:28:51Z")

</div>

I am using VS Code and Solarized Dark theme. When I save a Gadfly image, I could not preview it with my image viewer (the whole image looks dark and I can barely see anything). I thought the image has dark background, ho…

---

## [Documenter.jl: @autodocs for specific source files](https://discourse.julialang.org/t/documenter-jl-autodocs-for-specific-source-files/8784)

<div class="topic-metadata">

**Author:** [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Replies:** 2\
**Last updated:** [February 5, 2018, 12:52pm UTC](https://discourse.julialang.org/t/documenter-jl-autodocs-for-specific-source-files/8784 "2018-02-05T12:52:13Z")

</div>

From Documenter.jl’s documentation of @autodocs: \[…\], a Pages vector may be included in @autodocs to filter docstrings based on the source file in which they are defined: \`\`\`@autodocs Modules = \[Foo\] Pages = \["a.jl…

---

## [How to do \`@parallel for i = 1:n, j = 1:m\` like thing?](https://discourse.julialang.org/t/how-to-do-parallel-for-i-1-n-j-1-m-like-thing/7871)

<div class="topic-metadata">

**Author:** [@paalon](https://discourse.julialang.org/u/paalon)\
**Replies:** 6\
**Last updated:** [February 5, 2018, 10:03am UTC](https://discourse.julialang.org/t/how-to-do-parallel-for-i-1-n-j-1-m-like-thing/7871 "2018-02-05T10:03:43Z")

</div>

I want to use multidimensional SharedArray to calculate in parallel. From the documents (https://docs.julialang.org/en/stable/manual/parallel-computing/), the following code calculates in parallel for 1-dimensional arra…

---

## [Detect if running as script](https://discourse.julialang.org/t/detect-if-running-as-script/8818)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 4\
**Last updated:** [February 5, 2018, 3:19am UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818 "2018-02-05T03:19:50Z")

</div>

Does Julia have an equivalent to Python’s if \_\_name\_\_ == "\_\_main\_\_": ... Specifically, my problem is the following. I’m writing a standalone Julia script run\_simulation.jl that does some computation and will ultima…

---

## [Example for Base.edit and Base.less](https://discourse.julialang.org/t/example-for-base-edit-and-base-less/8797)

<div class="topic-metadata">

**Author:** [@ivo\_welch](https://discourse.julialang.org/u/ivo_welch)\
**Replies:** 2\
**Last updated:** [February 4, 2018, 7:18pm UTC](https://discourse.julialang.org/t/example-for-base-edit-and-base-less/8797 "2018-02-04T19:18:33Z")

</div>

Could someone please post an example of how to use Base.edit? julia\> f() = rand()\*2 f (generic function with 1 method) julia\> f(x) = rand()+x f (generic function with 2 methods) julia\> edit(f) also, how do I see the …

---

## [Initialize a struct without a type-parameterized field and add the field later](https://discourse.julialang.org/t/initialize-a-struct-without-a-type-parameterized-field-and-add-the-field-later/8814)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 3\
**Last updated:** [February 4, 2018, 5:33pm UTC](https://discourse.julialang.org/t/initialize-a-struct-without-a-type-parameterized-field-and-add-the-field-later/8814 "2018-02-04T17:33:19Z")

</div>

I am trying to do something that may, or may not be possible. I want to use ForwardDiff, and create a Jacobian function. This function will be part of a struct. A parameter container is also part of this struct. Now, I w…

---

## [Reduce views for a function that is applied piece-wise over an array](https://discourse.julialang.org/t/reduce-views-for-a-function-that-is-applied-piece-wise-over-an-array/8806)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 6\
**Last updated:** [February 4, 2018, 3:10pm UTC](https://discourse.julialang.org/t/reduce-views-for-a-function-that-is-applied-piece-wise-over-an-array/8806 "2018-02-04T15:10:32Z")

</div>

I have a function f! that operates in-place in a D dimensional Vector, used in DifferentialEquations. For example @inline @inbounds function f!(du, u, p, t) σ = p\[1\]; ρ = p\[2\]; β = p\[3\] du\[1\] = σ\*(u\[2\]-u\[1\]) …

---

## [Ironic observation about \`sort\` and \`sortperm\` speed for "small integers" vs R](https://discourse.julialang.org/t/ironic-observation-about-sort-and-sortperm-speed-for-small-integers-vs-r/8715)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 32\
**Last updated:** [February 4, 2018, 1:48pm UTC](https://discourse.julialang.org/t/ironic-observation-about-sort-and-sortperm-speed-for-small-integers-vs-r/8715 "2018-02-04T13:48:42Z")

</div>

I found something ironic about sort performance in Julia vs R. I am trying to sort a vector with integer values ranging from 1 to 1\_000\_000. Julia uses counting sort which is much faster than R’s radix sort, but the situ…

---

## [HttpParser build error on Ubuntu linux 17.10](https://discourse.julialang.org/t/httpparser-build-error-on-ubuntu-linux-17-10/8809)

<div class="topic-metadata">

**Author:** [@Yongkyu\_Cho](https://discourse.julialang.org/u/Yongkyu_Cho)\
**Replies:** 1\
**Last updated:** [February 4, 2018, 12:35pm UTC](https://discourse.julialang.org/t/httpparser-build-error-on-ubuntu-linux-17-10/8809 "2018-02-04T12:35:22Z")

</div>

I installed Ubuntu linux 17.10. Downloaded Julia 0.6.2 (10.8+ 64-bit Generic Linux Binaries for x86) and extract it to a folder. And then installed Atom following this: Installing Atom After installing the package ub…

---

## [Processing csv's in parallel](https://discourse.julialang.org/t/processing-csvs-in-parallel/8791)

<div class="topic-metadata">

**Author:** [@chasecb](https://discourse.julialang.org/u/chasecb)\
**Replies:** 8\
**Last updated:** [February 4, 2018, 12:12am UTC](https://discourse.julialang.org/t/processing-csvs-in-parallel/8791 "2018-02-04T00:12:26Z")

</div>

I’m basically trying to serialize csvs in parallel. The parallel stuff seems to have changed a bit from Julia’s more sophomoric (to be as polite as I can) versions but I could never get it working back then either. Let’s…

---

## [Documenter.jl: @ref a specific method of a function](https://discourse.julialang.org/t/documenter-jl-ref-a-specific-method-of-a-function/8792)

<div class="topic-metadata">

**Author:** [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Replies:** 4\
**Last updated:** [February 3, 2018, 10:08pm UTC](https://discourse.julialang.org/t/documenter-jl-ref-a-specific-method-of-a-function/8792 "2018-02-03T22:08:02Z")

</div>

Let’s say I have two methods """ f(x::Integer) Integer version of \`f\`. """ f(x::Integer) = println("I'm an integer!") """ f(x::Float64) Float64 version of \`f\`. """ f(x::Float64) = println("I'm floating!") an…

---

## [REPL without truncated output](https://discourse.julialang.org/t/repl-without-truncated-output/8794)

<div class="topic-metadata">

**Author:** [@RandomString123](https://discourse.julialang.org/u/RandomString123)\
**Replies:** 0\
**Last updated:** [February 3, 2018, 2:22pm UTC](https://discourse.julialang.org/t/repl-without-truncated-output/8794 "2018-02-03T14:22:35Z")

</div>

How do I get this to print out in the same format but with all of the values, I.E. no ‘⋮’? Julia\> hcat(1:10, 21:30, 31:40) 10×3 Array{Int64,2}: 1 21 31 2 22 32 3 23 33 ⋮ 8 28 38 9 29 39 10 30 40…

---

## [Help implement Kalman filter](https://discourse.julialang.org/t/help-implement-kalman-filter/8718)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 16\
**Last updated:** [February 3, 2018, 7:12am UTC](https://discourse.julialang.org/t/help-implement-kalman-filter/8718 "2018-02-03T07:12:27Z")

</div>

Hi all! I have a specific problem that I think lends itself to a Kalman filter. Since I’ve never used a Kalman filter before and I’m not sure how exactly I could apply it on my data, I thought I’d reach-out here. My da…

---

## [Pkg.add("Profile") fails with "Unknown package" in 0.6.2, Feb 2018](https://discourse.julialang.org/t/pkg-add-profile-fails-with-unknown-package-in-0-6-2-feb-2018/8787)

<div class="topic-metadata">

**Author:** [@ivo\_welch](https://discourse.julialang.org/u/ivo_welch)\
**Replies:** 3\
**Last updated:** [February 3, 2018, 4:49am UTC](https://discourse.julialang.org/t/pkg-add-profile-fails-with-unknown-package-in-0-6-2-feb-2018/8787 "2018-02-03T04:49:29Z")

</div>

are the docs and/or packages broken? https://docs.julialang.org/en/latest/manual/profile/ suggests julia\> Pkg.add("Profile") ERROR: unknown package Profile macro expansion at ./pkg/entry.jl:53 \[inlined\] (::Base.Pkg.En…

---

## [Mutable struct without fields behaving weirdly](https://discourse.julialang.org/t/mutable-struct-without-fields-behaving-weirdly/8752)

<div class="topic-metadata">

**Author:** [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Replies:** 14\
**Last updated:** [February 2, 2018, 5:38pm UTC](https://discourse.julialang.org/t/mutable-struct-without-fields-behaving-weirdly/8752 "2018-02-02T17:38:36Z")

</div>

struct foo end mutable struct bar end bar()==bar() #true bar()===bar() #true isbits(bar) #false A=Vector{Tuple{bar, Int}}(uninitialized, 1) #1-element Array{Tuple{bar,Int64},1}: #undef A=Vector{Tuple{foo, Int}}(uninitia…

---

## [Macro to convert list of variables to Dict keyed by variable name](https://discourse.julialang.org/t/macro-to-convert-list-of-variables-to-dict-keyed-by-variable-name/8755)

<div class="topic-metadata">

**Author:** [@arghhhh](https://discourse.julialang.org/u/arghhhh)\
**Replies:** 4\
**Last updated:** [February 1, 2018, 11:14pm UTC](https://discourse.julialang.org/t/macro-to-convert-list-of-variables-to-dict-keyed-by-variable-name/8755 "2018-02-01T23:14:16Z")

</div>

For debugging purposes, I’d like to be able to write something like: d = @makedict( a, b, c ) which would expand to d = Dict( :a=\>a, :b=\>b, :c=\>c ) I just can’t seem to work out how to do this…

---

## [New find\* methods and type stability](https://discourse.julialang.org/t/new-find-methods-and-type-stability/8722)

<div class="topic-metadata">

**Author:** [@jmkuhn](https://discourse.julialang.org/u/jmkuhn)\
**Replies:** 6\
**Last updated:** [February 1, 2018, 5:11pm UTC](https://discourse.julialang.org/t/new-find-methods-and-type-stability/8722 "2018-02-01T17:11:27Z")

</div>

In 0.7 find\* methods changed the return value from 0 to nothing for no match. Assuming the following code is in a function: s = "abc" pos = findfirst(equalto('b'), s) println(typeof(pos)) pos = findfirst(equalto('x'), …

---

## [ Help: Problem in updating JuMP from 0.15.1 to 0.18.0](https://discourse.julialang.org/t/help-problem-in-updating-jump-from-0-15-1-to-0-18-0/8746)

<div class="topic-metadata">

**Author:** [@erikfilias](https://discourse.julialang.org/u/erikfilias)\
**Replies:** 0\
**Last updated:** [February 1, 2018, 4:49pm UTC](https://discourse.julialang.org/t/help-problem-in-updating-jump-from-0-15-1-to-0-18-0/8746 "2018-02-01T16:49:49Z")

</div>

Hi, I am a new user of Julia. I have the Julia 0.6.2 and JuMP 0.15.1 However, I would like to update JuMP to version 0.18.0 but I have a problem to do it. I received this\> julia\> Pkg.update(“JuMP”) INFO: Updating M…

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

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