# General Usage

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

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

**Page:** 953

---

## [Hot loop updating array elements with product over other array](https://discourse.julialang.org/t/hot-loop-updating-array-elements-with-product-over-other-array/13609)

<div class="topic-metadata">

**Author:** [@stst](https://discourse.julialang.org/u/stst)\
**Replies:** 15\
**Last updated:** [August 17, 2018, 10:05pm UTC](https://discourse.julialang.org/t/hot-loop-updating-array-elements-with-product-over-other-array/13609 "2018-08-17T22:05:22Z")

</div>

How can one improve performance of the following MWE (using 1.0.0)? function bg\_sim\_mwe(nB=100,nSamples=100) e = 0.9 p = 0.8 nt = 100 t = range(0,stop=5.0,length=nt) V(ph) = 1.0 - p + p\*(cos(ph) +…

---

## [Strange summation timings](https://discourse.julialang.org/t/strange-summation-timings/13638)

<div class="topic-metadata">

**Author:** [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)\
**Replies:** 3\
**Last updated:** [August 17, 2018, 9:50pm UTC](https://discourse.julialang.org/t/strange-summation-timings/13638 "2018-08-17T21:50:32Z")

</div>

I wanted to test different ways of writing a simple summation, here’s the code: # series with slow convergence to pi function pisumloop(n) s = 0.0 for k = 1:n s += 1 / k^2 end return sqrt(6\*s) en…

---

## [error using Optim in julia v0.7.0](https://discourse.julialang.org/t/error-using-optim-in-julia-v0-7-0/13634)

<div class="topic-metadata">

**Author:** [@leaoshark](https://discourse.julialang.org/u/leaoshark)\
**Replies:** 1\
**Last updated:** [August 17, 2018, 8:12pm UTC](https://discourse.julialang.org/t/error-using-optim-in-julia-v0-7-0/13634 "2018-08-17T20:12:29Z")

</div>

In julia v0.6.1 this command opt=optimize(x-\>X2(x), initial\_x, lower, upper,Fminbox{NelderMead}()) works very well, but in julia v0.7.0 give this error MethodError: no method matching Fminbox{NelderMead,T,P} where …

---

## [Help in PyPlot - Julia v1.0 - label and spline ( using ATOM )](https://discourse.julialang.org/t/help-in-pyplot-julia-v1-0-label-and-spline-using-atom/13572)

<div class="topic-metadata">

**Author:** [@leaoshark](https://discourse.julialang.org/u/leaoshark)\
**Replies:** 6\
**Last updated:** [August 17, 2018, 7:03pm UTC](https://discourse.julialang.org/t/help-in-pyplot-julia-v1-0-label-and-spline-using-atom/13572 "2018-08-17T19:03:03Z")

</div>

in this command using PyPlot x = 1:10; y = rand(10,2) plot(x,y, label(“Line 1” “Line 2”) title(“Two Lines”) why the name of the line does not appear ? and how can i spline this lines ? ( just for an example, my p…

---

## [Unexpected result about integer](https://discourse.julialang.org/t/unexpected-result-about-integer/13485)

<div class="topic-metadata">

**Author:** [@yelf](https://discourse.julialang.org/u/yelf)\
**Replies:** 13\
**Last updated:** [August 17, 2018, 4:33pm UTC](https://discourse.julialang.org/t/unexpected-result-about-integer/13485 "2018-08-17T16:33:01Z")

</div>

I’m a python user doing scientific computing. I’m also interested in julia, and tried it after v1.0 released. I haven’t start learning julia yet, only tried it as a simple calculator, and get some unexpected result. E…

---

## [Event finding for scalar differential equation](https://discourse.julialang.org/t/event-finding-for-scalar-differential-equation/13511)

<div class="topic-metadata">

**Author:** [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Replies:** 5\
**Last updated:** [August 17, 2018, 4:00pm UTC](https://discourse.julialang.org/t/event-finding-for-scalar-differential-equation/13511 "2018-08-17T16:00:11Z")

</div>

I am trying to define a callback to modify the scalar state of an ODE but I get an error. Here is a simple code that reproduces this: (v0.7) pkg\> st Status \`~/.julia/environments/v0.7/Project.toml\` \[0c46a032\] Diff…

---

## [Too many allocations when indexing with slices](https://discourse.julialang.org/t/too-many-allocations-when-indexing-with-slices/13532)

<div class="topic-metadata">

**Author:** [@noahstier](https://discourse.julialang.org/u/noahstier)\
**Replies:** 16\
**Last updated:** [August 17, 2018, 11:07am UTC](https://discourse.julialang.org/t/too-many-allocations-when-indexing-with-slices/13532 "2018-08-17T11:07:23Z")

</div>

The following code contains two equivalent implementations of a trivial algorithm. slow\_func uses vectorized indexing and assignment while fast\_func individually indexes and assigns each array element in a loop. Can any…

---

## [Best practice for adding validations to setfield! function?](https://discourse.julialang.org/t/best-practice-for-adding-validations-to-setfield-function/13604)

<div class="topic-metadata">

**Author:** [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Replies:** 2\
**Last updated:** [August 17, 2018, 7:32am UTC](https://discourse.julialang.org/t/best-practice-for-adding-validations-to-setfield-function/13604 "2018-08-17T07:32:25Z")

</div>

I run into this problem with mutable structs where I’d like to validate the input. Is there a best practices way to do this? current psuedocode: import Base: setfield! mutable struct Foo fizz::Number is\_good::Bo…

---

## [Pkg add several packages -- syntax and error message](https://discourse.julialang.org/t/pkg-add-several-packages-syntax-and-error-message/13603)

<div class="topic-metadata">

**Author:** [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Replies:** 1\
**Last updated:** [August 17, 2018, 6:07am UTC](https://discourse.julialang.org/t/pkg-add-several-packages-syntax-and-error-message/13603 "2018-08-17T06:07:47Z")

</div>

This is merely a suggestion for a better error message. It took me quite a while to figure out that I used the wrong syntax while trying to add several packages like below. I thought I had messed up the package installat…

---

## [Serialization compresses very well?](https://discourse.julialang.org/t/serialization-compresses-very-well/13602)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 0\
**Last updated:** [August 17, 2018, 5:51am UTC](https://discourse.julialang.org/t/serialization-compresses-very-well/13602 "2018-08-17T05:51:02Z")

</div>

It’s interesting to observe the size of an array of string data (in Julia 0.7): In memory =\> 22 MB Serialized =\> 8 MB JLD2 =\> 40 MB julia\> x = \[randstring(6) for \_ in 1:1000000\]; julia\> Base.summarysize(x) 22000040 …

---

## [Naive matrix multiplication is super slow in Julia 1.0?](https://discourse.julialang.org/t/naive-matrix-multiplication-is-super-slow-in-julia-1-0/13589)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 12\
**Last updated:** [August 17, 2018, 4:21am UTC](https://discourse.julialang.org/t/naive-matrix-multiplication-is-super-slow-in-julia-1-0/13589 "2018-08-17T04:21:21Z")

</div>

I benchmarked the following naive matrix multiplication algorithm in both Julia 0.6 and 1.0. Surprisingly, Julia 1.0 version runs 4 times slower. Doing @code\_llvm shows very neat output in 0.6 vs. 1.0. Any idea what is g…

---

## [Sharing variables between Jupyter notebooks](https://discourse.julialang.org/t/sharing-variables-between-jupyter-notebooks/13593)

<div class="topic-metadata">

**Author:** [@microlifecc](https://discourse.julialang.org/u/microlifecc)\
**Replies:** 2\
**Last updated:** [August 17, 2018, 2:06am UTC](https://discourse.julialang.org/t/sharing-variables-between-jupyter-notebooks/13593 "2018-08-17T02:06:12Z")

</div>

Hi! I was wondering if there is a way to share variables between Jupyter notebooks in Julia. I tried shareList = \[3^i for i in 1:5\] %store shareList Error: Unrecognized magic %store. Julia does not use the IPython …

---

## [Query.jl + ODBC.jl](https://discourse.julialang.org/t/query-jl-odbc-jl/13590)

<div class="topic-metadata">

**Author:** [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Replies:** 2\
**Last updated:** [August 17, 2018, 2:02am UTC](https://discourse.julialang.org/t/query-jl-odbc-jl/13590 "2018-08-17T02:02:36Z")

</div>

I’m looking for some simple examples of using Query.jl to connect to a database via ODBC. Any pointers? BTW, @davidanthoff, I very much enjoyed your workshop at JuliaCon and getting to talk with you!

---

## [Encoding, CSV.read / write](https://discourse.julialang.org/t/encoding-csv-read-write/13553)

<div class="topic-metadata">

**Author:** [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Replies:** 5\
**Last updated:** [August 17, 2018, 1:57am UTC](https://discourse.julialang.org/t/encoding-csv-read-write/13553 "2018-08-17T01:57:57Z")

</div>

I have a large number of files and the encoding is ISO-8859-1. There are errors when I use CSV.read() to read the file. And the error is as follows. error: CSV.ParsingException(“Unexpected start of quote (34), use "92…

---

## [LinearAlgebra.eigen does not accept adjoint matrices ?](https://discourse.julialang.org/t/linearalgebra-eigen-does-not-accept-adjoint-matrices/13410)

<div class="topic-metadata">

**Author:** [@kragol](https://discourse.julialang.org/u/kragol)\
**Replies:** 9\
**Last updated:** [August 16, 2018, 11:14pm UTC](https://discourse.julialang.org/t/linearalgebra-eigen-does-not-accept-adjoint-matrices/13410 "2018-08-16T23:14:29Z")

</div>

Since julia 0.7, the following code using LinearAlgebra A = randn(10,10) E = eigen(A') returns an error ERROR: MethodError: no method matching eigen(::Adjoint{Float64,Array{Float64,2}}) This looks like a bug to me bu…

---

## [How to send a string to be read by the REPL?](https://discourse.julialang.org/t/how-to-send-a-string-to-be-read-by-the-repl/13588)

<div class="topic-metadata">

**Author:** [@Mason](https://discourse.julialang.org/u/Mason)\
**Replies:** 2\
**Last updated:** [August 16, 2018, 9:53pm UTC](https://discourse.julialang.org/t/how-to-send-a-string-to-be-read-by-the-repl/13588 "2018-08-16T21:53:29Z")

</div>

I’m trying to write tests for some code which creates a REPL mode and having a lot of trouble. to test the code I’d like to have a function that allows me to send a string to Base.active\_repl and then returns the string …

---

## [Default length for abstract array](https://discourse.julialang.org/t/default-length-for-abstract-array/13586)

<div class="topic-metadata">

**Author:** [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Replies:** 1\
**Last updated:** [August 16, 2018, 8:54pm UTC](https://discourse.julialang.org/t/default-length-for-abstract-array/13586 "2018-08-16T20:54:23Z")

</div>

I noticed the default definition for the length of an abstract array is prod(size(A)). Shouldn’t it be something more like prod(length.(axes(x))) to account for non-zero indexing?

---

## [Using Julia in a restricted environment with Docker](https://discourse.julialang.org/t/using-julia-in-a-restricted-environment-with-docker/12179)

<div class="topic-metadata">

**Author:** [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Replies:** 9\
**Last updated:** [August 16, 2018, 8:50pm UTC](https://discourse.julialang.org/t/using-julia-in-a-restricted-environment-with-docker/12179 "2018-08-16T20:50:37Z")

</div>

In my algorithms course, we plan to transition to using Julia this fall, and we are currently trying to make it work with INGInious, a system that automatically runs and tests code or code fragments submitted by students…

---

## [Error Precompiling PyPlot in latest Julia 1.0.0-rc1.1](https://discourse.julialang.org/t/error-precompiling-pyplot-in-latest-julia-1-0-0-rc1-1/13013)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 8\
**Last updated:** [August 16, 2018, 8:05pm UTC](https://discourse.julialang.org/t/error-precompiling-pyplot-in-latest-julia-1-0-0-rc1-1/13013 "2018-08-16T20:05:10Z")

</div>

I just installed the latest Julia 1.0.0-rc1.1 and stumbled upon the following errors when installing PyPlot: julia\> using PyPlot \[ Info: Precompiling PyPlot \[d330b81b-6aea-500a-939a-2ce795aea3ee\] WARNING: could not impo…

---

## [Warn() vs @warn](https://discourse.julialang.org/t/warn-vs-warn/13579)

<div class="topic-metadata">

**Author:** [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Replies:** 1\
**Last updated:** [August 16, 2018, 4:55pm UTC](https://discourse.julialang.org/t/warn-vs-warn/13579 "2018-08-16T16:55:54Z")

</div>

Hello, I’m upgrading a package to 0.7 and I was prompted to use @warn instead of warn. I did but got faced with an error which I suspect is due to a poor understanding of macros and string interpolation. Here’s a simpli…

---

## [A bet: what specific algorithms in Julia can be faster or as fast as C++ implementations?](https://discourse.julialang.org/t/a-bet-what-specific-algorithms-in-julia-can-be-faster-or-as-fast-as-c-implementations/13564)

<div class="topic-metadata">

**Author:** [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Replies:** 12\
**Last updated:** [August 16, 2018, 4:22pm UTC](https://discourse.julialang.org/t/a-bet-what-specific-algorithms-in-julia-can-be-faster-or-as-fast-as-c-implementations/13564 "2018-08-16T16:22:31Z")

</div>

Me and my colleague have made a bet that Julia can be faster than C++ in several test cases. I will write a set of algorithms in Julia, and he will write the same algorithms in C++, then we will measure the performance. …

---

## [Status of \`Pkg.dir\` and writing travis and other configs](https://discourse.julialang.org/t/status-of-pkg-dir-and-writing-travis-and-other-configs/13502)

<div class="topic-metadata">

**Author:** [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Replies:** 3\
**Last updated:** [August 16, 2018, 3:53pm UTC](https://discourse.julialang.org/t/status-of-pkg-dir-and-writing-travis-and-other-configs/13502 "2018-08-16T15:53:23Z")

</div>

I was dreading getting travis to work on both 0.6 and 1.0 as I believed that Pkg.dir would throw an error in 1.0, but mercifully I discovered today that even in 1.0 Pkg.dir still only gives a warning. I was wondering wh…

---

## [Strange behavior in Revise.jl](https://discourse.julialang.org/t/strange-behavior-in-revise-jl/13531)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 1\
**Last updated:** [August 16, 2018, 1:58pm UTC](https://discourse.julialang.org/t/strange-behavior-in-revise-jl/13531 "2018-08-16T13:58:56Z")

</div>

Hi all- I encountered a situation in which Revise.jl seems not to to work as expected. I created two modules: myModule and otherModule. myModule is distributed on four of my processors, whereas otherModule is loaded on…

---

## [Ref vs. Ptr and parametric types](https://discourse.julialang.org/t/ref-vs-ptr-and-parametric-types/13569)

<div class="topic-metadata">

**Author:** [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Replies:** 0\
**Last updated:** [August 16, 2018, 1:53pm UTC](https://discourse.julialang.org/t/ref-vs-ptr-and-parametric-types/13569 "2018-08-16T13:53:04Z")

</div>

I have a C function I’m calling with the signature: SNDFILE\* sf\_open\_virtual (SF\_VIRTUAL\_IO \*sfvirtual, int mode, SF\_INFO \*sfinfo, void \*user\_data) ; (from libsndfile) the user\_data pointer is passed as an argument t…

---

## [Libgl dlopen does not work in modules](https://discourse.julialang.org/t/libgl-dlopen-does-not-work-in-modules/13563)

<div class="topic-metadata">

**Author:** [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Replies:** 0\
**Last updated:** [August 16, 2018, 12:04pm UTC](https://discourse.julialang.org/t/libgl-dlopen-does-not-work-in-modules/13563 "2018-08-16T12:04:19Z")

</div>

Hello, I am on julia 0.7 and I have the following problem. This code runs without any problems: using Libdl dlopen(:libgslcblas, RTLD\_GLOBAL) sf\_gamma\_inc\_Q(a, x) = ccall((:gsl\_sf\_gamma\_inc\_Q, :libgsl), Cdouble, (Cdoub…

---

## [Confusing difference: ^literal vs ^variable](https://discourse.julialang.org/t/confusing-difference-literal-vs-variable/13515)

<div class="topic-metadata">

**Author:** [@laborg](https://discourse.julialang.org/u/laborg)\
**Replies:** 6\
**Last updated:** [August 16, 2018, 9:54am UTC](https://discourse.julialang.org/t/confusing-difference-literal-vs-variable/13515 "2018-08-16T09:54:47Z")

</div>

I’m confused by the difference when ^ is used with a literal vs a variable: julia\> p = -13; julia\> 3 ^ p ERROR: DomainError with -13: Cannot raise an integer x to a negative power -13. Make x a float by adding a zero d…

---

## [\`pkg\> rm Proj\` doesn't delete the project folder](https://discourse.julialang.org/t/pkg-rm-proj-doesnt-delete-the-project-folder/13508)

<div class="topic-metadata">

**Author:** [@CarloLucibello](https://discourse.julialang.org/u/CarloLucibello)\
**Replies:** 6\
**Last updated:** [August 16, 2018, 7:22am UTC](https://discourse.julialang.org/t/pkg-rm-proj-doesnt-delete-the-project-folder/13508 "2018-08-16T07:22:58Z")

</div>

as an example, after pkg\> rm ExtractMacro I was expecting the folder .julia/packages/ExtractMacro/Wcrs/ or .julia/packages/ExtractMacro/ to disappear, but it didn’t. Assuming this is intentional behavior I wonder why? …

---

## [Stdout and C code](https://discourse.julialang.org/t/stdout-and-c-code/13533)

<div class="topic-metadata">

**Author:** [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Replies:** 2\
**Last updated:** [August 16, 2018, 7:15am UTC](https://discourse.julialang.org/t/stdout-and-c-code/13533 "2018-08-16T07:15:22Z")

</div>

It seems that the stdout that most of Julia prints to is not the same as the stdout that C’s printf will print to, for example: $ julia -e 'println("before"); ccall(:printf, Cint, (Ptr{Cchar},), "hello\\n"); println("aft…

---

## [Error in Broadcast in v0.7/v1.0](https://discourse.julialang.org/t/error-in-broadcast-in-v0-7-v1-0/13547)

<div class="topic-metadata">

**Author:** [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Replies:** 1\
**Last updated:** [August 16, 2018, 6:28am UTC](https://discourse.julialang.org/t/error-in-broadcast-in-v0-7-v1-0/13547 "2018-08-16T06:28:04Z")

</div>

Someone from discourse.juliacn.com (the Chinese one) found this, I just translate for him. I think this is a bug? not what I expected. julia\> 1 .+ (1, 2) (2, 3) julia\> 1 .+ 1 .+ (1, 2) ERROR: MethodError: no method ma…

---

## [Package modification, has no effect](https://discourse.julialang.org/t/package-modification-has-no-effect/13494)

<div class="topic-metadata">

**Author:** [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Replies:** 2\
**Last updated:** [August 15, 2018, 11:23pm UTC](https://discourse.julialang.org/t/package-modification-has-no-effect/13494 "2018-08-15T23:23:46Z")

</div>

I developed a package on the local machine and used the package in some scripts to process data. I modified the package but when I run the Julia script nothing has been changed. Only when I changed the name of the funct…

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

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