# General Usage

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

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

**Page:** 931

---

## [Trig functions very slow](https://discourse.julialang.org/t/trig-functions-very-slow/15335)

<div class="topic-metadata">

**Author:** [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Replies:** 67\
**Last updated:** [October 10, 2018, 9:11am UTC](https://discourse.julialang.org/t/trig-functions-very-slow/15335 "2018-10-10T09:11:25Z")

</div>

I found that some simple mathematical functions, at least trigonometric, are much slower in Julia than e.g. in Python (with numba). Here is a minimalistic example: function f() r = 0. for i in 0:100\_000\_000 - 1 …

---

## [Add ffmpeg either as a build or to CI](https://discourse.julialang.org/t/add-ffmpeg-either-as-a-build-or-to-ci/16079)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 4\
**Last updated:** [October 9, 2018, 8:27pm UTC](https://discourse.julialang.org/t/add-ffmpeg-either-as-a-build-or-to-ci/16079 "2018-10-09T20:27:32Z")

</div>

tl;dr: Anyone know how to add ffmpeg to the CI tests or, better yet, as a build for a package? I’m writing a package that relies on video IO. Since the VideoIO.jl package is not completely v1 ready (but in the process a…

---

## [NamedTuples build fails (SOLVED)](https://discourse.julialang.org/t/namedtuples-build-fails-solved/16103)

<div class="topic-metadata">

**Author:** [@RogerP](https://discourse.julialang.org/u/RogerP)\
**Replies:** 3\
**Last updated:** [October 10, 2018, 8:06am UTC](https://discourse.julialang.org/t/namedtuples-build-fails-solved/16103 "2018-10-10T08:06:33Z")

</div>

Any idea why this is happening? I assumed NamedTuples was OK under 1.0.1

---

## [How to run a Julia script in "release-mode"?](https://discourse.julialang.org/t/how-to-run-a-julia-script-in-release-mode/16091)

<div class="topic-metadata">

**Author:** [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Replies:** 2\
**Last updated:** [October 10, 2018, 12:31am UTC](https://discourse.julialang.org/t/how-to-run-a-julia-script-in-release-mode/16091 "2018-10-10T00:31:41Z")

</div>

e.g I have several Julia functions with a custom check function foo(x) check\_greater\_than(0, x) # do something end What is the canonical way to remove the check globally? I know one way to do it, is to define the…

---

## [sort(A, dims=1) mixing rows](https://discourse.julialang.org/t/sort-a-dims-1-mixing-rows/16086)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 11\
**Last updated:** [October 9, 2018, 7:23pm UTC](https://discourse.julialang.org/t/sort-a-dims-1-mixing-rows/16086 "2018-10-09T19:23:57Z")

</div>

julia\> slow 4811392×2 Array{Any,2}: "Ag" "Aga" ... "zzg" "z" when sort(slow,dims=1) rows are mixed :confused: very denger ! Intuitively sort refers to the table and not each column separately. Is somthi…

---

## [Pkg.add() through proxy fails on Julia 0.5, Windows](https://discourse.julialang.org/t/pkg-add-through-proxy-fails-on-julia-0-5-windows/687)

<div class="topic-metadata">

**Author:** [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Replies:** 24\
**Last updated:** [October 9, 2018, 5:26pm UTC](https://discourse.julialang.org/t/pkg-add-through-proxy-fails-on-julia-0-5-windows/687 "2018-10-09T17:26:13Z")

</div>

I have been successfully using Julia 0.4 from behind corporate proxy. Just trying to upgrade to Julia 0.5 but Pkg() commands fail: julia\> Pkg.init() INFO: Initializing package repository C:\\Users\\plowman\\.julia\\v0.5 IN…

---

## [Automatic differentation of \`f(x::Real) = f(float(x))\` leads to stackoverflow](https://discourse.julialang.org/t/automatic-differentation-of-f-x-real-f-float-x-leads-to-stackoverflow/16076)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 7\
**Last updated:** [October 9, 2018, 4:48pm UTC](https://discourse.julialang.org/t/automatic-differentation-of-f-x-real-f-float-x-leads-to-stackoverflow/16076 "2018-10-09T16:48:16Z")

</div>

Many definitions follow this pattern: f(x::AbstractFloat) = 2x # any computation here f(x::Real) = f(float(x)) But then: julia\> ForwardDiff.derivative(f, 1.) ERROR: StackOverflowError: Stacktrace: \[1\] f(::ForwardDiff…

---

## [Allocations in function timing](https://discourse.julialang.org/t/allocations-in-function-timing/16081)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 2\
**Last updated:** [October 9, 2018, 4:43pm UTC](https://discourse.julialang.org/t/allocations-in-function-timing/16081 "2018-10-09T16:43:49Z")

</div>

Sorry for hijacking the topic, but as I was playing with the algorithms, I noticed that given this function: julia\> function main(n) r = 0 for i = 1:n i -= 1 r += 1 end …

---

## [Weird behavior with Pkg generate on Windows](https://discourse.julialang.org/t/weird-behavior-with-pkg-generate-on-windows/16080)

<div class="topic-metadata">

**Author:** [@lkapelevich](https://discourse.julialang.org/u/lkapelevich)\
**Replies:** 0\
**Last updated:** [October 9, 2018, 4:29pm UTC](https://discourse.julialang.org/t/weird-behavior-with-pkg-generate-on-windows/16080 "2018-10-09T16:29:01Z")

</div>

I am using Julia 0.7.0 on Windows. When I try to activate a new project I get the following (v0.7) pkg\> generate Example Generating project Example: Example\\Project.toml Example/src/Example.jl shell\> cd Example…

---

## [Logger doesn't respect bash output redirection](https://discourse.julialang.org/t/logger-doesnt-respect-bash-output-redirection/15741)

<div class="topic-metadata">

**Author:** [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Replies:** 6\
**Last updated:** [October 9, 2018, 3:39pm UTC](https://discourse.julialang.org/t/logger-doesnt-respect-bash-output-redirection/15741 "2018-10-09T15:39:31Z")

</div>

I have some code where most of the output is in @info statements using the Julia stdlib logger. I now have some big jobs which I want to run in the background and dump their logs somewhere. Normally I would do this wit…

---

## [Index dataframe in RCall's R macro](https://discourse.julialang.org/t/index-dataframe-in-rcalls-r-macro/16073)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 1\
**Last updated:** [October 9, 2018, 3:09pm UTC](https://discourse.julialang.org/t/index-dataframe-in-rcalls-r-macro/16073 "2018-10-09T15:09:59Z")

</div>

Hi- I am wondering if there is a way to index an R dataframe with RCall. I have the following scenario: R"“” #some code solve(df$colname) “”" The problem is that $ is reserved in RCall for denoting a variable. Tha…

---

## [Getting the type of \`f(x)\` at compile time (without evaluating \`f(x)\`), for type-stable functions](https://discourse.julialang.org/t/getting-the-type-of-f-x-at-compile-time-without-evaluating-f-x-for-type-stable-functions/16069)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 9\
**Last updated:** [October 9, 2018, 2:45pm UTC](https://discourse.julialang.org/t/getting-the-type-of-f-x-at-compile-time-without-evaluating-f-x-for-type-stable-functions/16069 "2018-10-09T14:45:51Z")

</div>

I have a type-stable function f(x) that is expensive to evaluate. Given an argument x, how do I obtain the type of the result f(x), but without actually evaluating f(x)? Ideally this should be elided during compilation …

---

## [\`Plots\` fails to draw in julia-1.0](https://discourse.julialang.org/t/plots-fails-to-draw-in-julia-1-0/16055)

<div class="topic-metadata">

**Author:** [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Replies:** 13\
**Last updated:** [October 9, 2018, 2:31pm UTC](https://discourse.julialang.org/t/plots-fails-to-draw-in-julia-1-0/16055 "2018-10-09T14:31:06Z")

</div>

Trying Plots the very first time in julia-1.0 on my Ubuntu machine and seeing the following error: (v1.0) pkg\> st Status \`~/.julia/environments/v1.0/Project.toml\` \[c52e3926\] Atom v0.7.8 \[28b8d3ca\] GR v0.34.1 \[…

---

## [Priority in dispatch](https://discourse.julialang.org/t/priority-in-dispatch/16065)

<div class="topic-metadata">

**Author:** [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Replies:** 2\
**Last updated:** [October 9, 2018, 2:28pm UTC](https://discourse.julialang.org/t/priority-in-dispatch/16065 "2018-10-09T14:28:06Z")

</div>

I have a famility of functions b(t, x::T) = called in a loop for i in 1:n t = t + dt x = x + dt\*f(t, x) end It turns out that sometimes I’d need the index i as well and I’d like to define f((i,s)::Tuple, x) …

---

## [Why superfluous function call is not eliminated?](https://discourse.julialang.org/t/why-superfluous-function-call-is-not-eliminated/16071)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 7\
**Last updated:** [October 9, 2018, 2:00pm UTC](https://discourse.julialang.org/t/why-superfluous-function-call-is-not-eliminated/16071 "2018-10-09T14:00:58Z")

</div>

function f(x) T = typeof(sin(x)) convert(T, x) end It seems that the call sin(x) can be ellided most of the time, because sin is type-stable. However, @code\_llvm f(1.) define double @julia\_f\_35182(double)…

---

## [Help with circular type/inner constructor](https://discourse.julialang.org/t/help-with-circular-type-inner-constructor/16020)

<div class="topic-metadata">

**Author:** [@randyzwitch](https://discourse.julialang.org/u/randyzwitch)\
**Replies:** 15\
**Last updated:** [October 9, 2018, 1:03pm UTC](https://discourse.julialang.org/t/help-with-circular-type-inner-constructor/16020 "2018-10-09T13:03:28Z")

</div>

(continued from Slack) As part of creating types that are originally created in a C++ project, I get the following: mutable struct TDatumVal \<: Thrift.TMsg int\_val::Int64 real\_val::Float64 str\_val::String arr\_v…

---

## [Package "LinearAlgebra"](https://discourse.julialang.org/t/package-linearalgebra/16064)

<div class="topic-metadata">

**Author:** [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Replies:** 4\
**Last updated:** [October 9, 2018, 12:33pm UTC](https://discourse.julialang.org/t/package-linearalgebra/16064 "2018-10-09T12:33:01Z")

</div>

Since I have to use debugger, I’m going back to JuliaPro with Julia-v0.6.4.1. While testing a package, I was bounced and told that I need package “LinearAlgebra”. But failed installing it. Is that because the package no …

---

## [Compressing arbitrary Vector{UInt8} in memory](https://discourse.julialang.org/t/compressing-arbitrary-vector-uint8-in-memory/16058)

<div class="topic-metadata">

**Author:** [@janfrancu](https://discourse.julialang.org/u/janfrancu)\
**Replies:** 5\
**Last updated:** [October 9, 2018, 8:51am UTC](https://discourse.julialang.org/t/compressing-arbitrary-vector-uint8-in-memory/16058 "2018-10-09T08:51:44Z")

</div>

I am creating a lot of FlatBuffers, which I would like to store in S3 storage. Right now I use something akin to the following code to serialize the structure and put it to S3 bucket. fbStruct = ... fbBytes = FlatBuffe…

---

## [ERROR: MethodError: no method matching iterate(::Nothing)](https://discourse.julialang.org/t/error-methoderror-no-method-matching-iterate-nothing/16034)

<div class="topic-metadata">

**Author:** [@scelles](https://discourse.julialang.org/u/scelles)\
**Replies:** 1\
**Last updated:** [October 9, 2018, 7:32am UTC](https://discourse.julialang.org/t/error-methoderror-no-method-matching-iterate-nothing/16034 "2018-10-09T07:32:00Z")

</div>

Hello, I’m trying Introducing Julia/Working with text files - Wikibooks, open books for an open world with Julia 0.7 totaltime, totallines = open("sherlock-holmes.txt") do f linecounter = 0 timetaken = @elapsed…

---

## [Redefining Identical Struct](https://discourse.julialang.org/t/redefining-identical-struct/16047)

<div class="topic-metadata">

**Author:** [@JaredCrean2](https://discourse.julialang.org/u/JaredCrean2)\
**Replies:** 3\
**Last updated:** [October 9, 2018, 1:15am UTC](https://discourse.julialang.org/t/redefining-identical-struct/16047 "2018-10-09T01:15:47Z")

</div>

Redefining a struct with an identical definition does not lead to an ERROR: LoadError: invalid redefinition of constant error: mutable struct LFKernel A0::Array{Float64, 2} end mutable struct LFKernel A0::Array{Flo…

---

## [Performance increased after adding a if?](https://discourse.julialang.org/t/performance-increased-after-adding-a-if/15359)

<div class="topic-metadata">

**Author:** [@Zhiye\_Xia](https://discourse.julialang.org/u/Zhiye_Xia)\
**Replies:** 4\
**Last updated:** [October 8, 2018, 8:17pm UTC](https://discourse.julialang.org/t/performance-increased-after-adding-a-if/15359 "2018-10-08T20:17:33Z")

</div>

Hi everyone, I was playing with a simple case of option pricing when I discovered this strange behavior. After adding an extra conditional statement, the performance of the function actually become faster. This is som…

---

## [Automatically parameterizing a type](https://discourse.julialang.org/t/automatically-parameterizing-a-type/15945)

<div class="topic-metadata">

**Author:** [@fabgrei](https://discourse.julialang.org/u/fabgrei)\
**Replies:** 9\
**Last updated:** [October 8, 2018, 8:15pm UTC](https://discourse.julialang.org/t/automatically-parameterizing-a-type/15945 "2018-10-08T20:15:41Z")

</div>

In order to achieve good performance one is supposed to use parametric types. Is there a way to do this automatically? I want this @parameterize struct Foo field1::Real field2::AbstractVector field3::Number en…

---

## [New replace(s, pat =\> f) in functiion How to use?](https://discourse.julialang.org/t/new-replace-s-pat-f-in-functiion-how-to-use/16042)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 1\
**Last updated:** [October 8, 2018, 7:31pm UTC](https://discourse.julialang.org/t/new-replace-s-pat-f-in-functiion-how-to-use/16042 "2018-10-08T19:31:15Z")

</div>

No idea ho to cheng old function to new , some help ? ‘’’ for i =1:k … only=map(e-\>replace(string(e), i, “”), only) … end ┌ Warning: replace(s::AbstractString, pat, f) is deprecated, use replace(s, pat =\> f) …

---

## [Why Val{...}?](https://discourse.julialang.org/t/why-val/16035)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 5\
**Last updated:** [October 8, 2018, 7:15pm UTC](https://discourse.julialang.org/t/why-val/16035 "2018-10-08T19:15:10Z")

</div>

Why is Val{..} needed? Shouldn’t constant propagation make Val obsolete (https://github.com/JuliaLang/julia/pull/24362)?

---

## [Copy of packages onto offline machine](https://discourse.julialang.org/t/copy-of-packages-onto-offline-machine/16037)

<div class="topic-metadata">

**Author:** [@natemcintosh](https://discourse.julialang.org/u/natemcintosh)\
**Replies:** 0\
**Last updated:** [October 8, 2018, 6:33pm UTC](https://discourse.julialang.org/t/copy-of-packages-onto-offline-machine/16037 "2018-10-08T18:33:13Z")

</div>

I’m trying to get Julia into larger usage at my company. However, one key part of this is getting it set up on our completely offline network. I would like to be able to put basically everything offered in the Julia Pack…

---

## [JuliaCIBot on Modia fails for Julia 1.0, but Travis is successful](https://discourse.julialang.org/t/juliacibot-on-modia-fails-for-julia-1-0-but-travis-is-successful/15993)

<div class="topic-metadata">

**Author:** [@MartinOtter](https://discourse.julialang.org/u/MartinOtter)\
**Replies:** 8\
**Last updated:** [October 8, 2018, 5:14pm UTC](https://discourse.julialang.org/t/juliacibot-on-modia-fails-for-julia-1-0-but-travis-is-successful/15993 "2018-10-08T17:14:48Z")

</div>

A pull request was made at METADATA to register the new Modia 0.2.1 release which is the first version of Modia supporting Julia 0.7 and 1.0. Travis CL on this release was successful for Julia 0.6, 0.7, 1.0. The JuilaC…

---

## [Is there way to replace n occurrences starting from the end of a string?](https://discourse.julialang.org/t/is-there-way-to-replace-n-occurrences-starting-from-the-end-of-a-string/15999)

<div class="topic-metadata">

**Author:** [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Replies:** 6\
**Last updated:** [October 8, 2018, 3:49pm UTC](https://discourse.julialang.org/t/is-there-way-to-replace-n-occurrences-starting-from-the-end-of-a-string/15999 "2018-10-08T15:49:24Z")

</div>

Let’s say you have: foo = "fizz\_buzz\_fizz\_buzz\_fizz\_buzz\_fizz\_buzz\_fizz\_buzz" and you want to change the last two buzzes to bars: nu\_foo = "fizz\_buzz\_fizz\_buzz\_fizz\_buzz\_fizz\_bar\_fizz\_bar" What is the easiest way to …

---

## [REPL, copy/paste and auto indent in julia 0.7](https://discourse.julialang.org/t/repl-copy-paste-and-auto-indent-in-julia-0-7/10230)

<div class="topic-metadata">

**Author:** [@oheil](https://discourse.julialang.org/u/oheil)\
**Replies:** 26\
**Last updated:** [October 8, 2018, 3:35pm UTC](https://discourse.julialang.org/t/repl-copy-paste-and-auto-indent-in-julia-0-7/10230 "2018-10-08T15:35:16Z")

</div>

I am referring here to this issue: https://github.com/JuliaLang/julia/issues/25186 It is not only a cosmetic annoyance as it may seem from the screenshots in the issue above. If you have a large code block, a few hund…

---

## [How to best reshape this array](https://discourse.julialang.org/t/how-to-best-reshape-this-array/15919)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 2\
**Last updated:** [October 8, 2018, 2:59pm UTC](https://discourse.julialang.org/t/how-to-best-reshape-this-array/15919 "2018-10-08T14:59:11Z")

</div>

I have a vector of matrices: julia\> n = 4 4 julia\> sz = (5,6) (5, 6) julia\> imgs = \[i\*ones(Int, sz...) for i in 1:n\] 4-element Array{Array{Int64,2},1}: \[1 1 … 1 1; 1 1 … 1 1; … ; 1 1 … 1 1; 1 1 … 1 1\] \[2 2 … 2 2; 2 …

---

## [Random number in (0,1\]](https://discourse.julialang.org/t/random-number-in-0-1/16009)

<div class="topic-metadata">

**Author:** [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Replies:** 16\
**Last updated:** [October 8, 2018, 11:27am UTC](https://discourse.julialang.org/t/random-number-in-0-1/16009 "2018-10-08T11:27:02Z")

</div>

I want a random Float64 in the interval (0,1\]. I understand rand() returns a number in \[0,1). Should I just use 1-rand() ?

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

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