# General Usage

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

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

**Page:** 793

---

## [Inner constructor, correct type for \`new\`](https://discourse.julialang.org/t/inner-constructor-correct-type-for-new/34013)

<div class="topic-metadata">

**Author:** [@timueh](https://discourse.julialang.org/u/timueh)\
**Replies:** 9\
**Last updated:** [January 31, 2020, 2:43pm UTC](https://discourse.julialang.org/t/inner-constructor-correct-type-for-new/34013 "2020-01-31T14:43:06Z")

</div>

I have a question about what to write in the curly braces of the new{...}() function for inner constructors. Consider this piece of code struct MyType{T} \<: MyAbstractType{T} x::T y::T function MyType(x, y)…

---

## [How to annotate function to return 1D array of the same type as the input 2D array?](https://discourse.julialang.org/t/how-to-annotate-function-to-return-1d-array-of-the-same-type-as-the-input-2d-array/34018)

<div class="topic-metadata">

**Author:** [@Azamat](https://discourse.julialang.org/u/Azamat)\
**Replies:** 1\
**Last updated:** [January 31, 2020, 1:03pm UTC](https://discourse.julialang.org/t/how-to-annotate-function-to-return-1d-array-of-the-same-type-as-the-input-2d-array/34018 "2020-01-31T13:03:00Z")

</div>

How do I express something like this: julia\> function f(mat₁::T{2}, mat₂::T{2})::T{1} where {T \<: DenseArray{\<:Real,N} where N} return eachcol(mat₁) .⋅ eachcol(mat₂) end ERROR: TypeError: in Type{...} e…

---

## [How do I turn array data into an image?](https://discourse.julialang.org/t/how-do-i-turn-array-data-into-an-image/33974)

<div class="topic-metadata">

**Author:** [@samantp](https://discourse.julialang.org/u/samantp)\
**Replies:** 10\
**Last updated:** [January 31, 2020, 10:15am UTC](https://discourse.julialang.org/t/how-do-i-turn-array-data-into-an-image/33974 "2020-01-31T10:15:32Z")

</div>

I’m just trying julia from MATLAB, in which it was quite intuitive to download arrays and display them as images (imshow worked without issue mostly and there was the imagesc function when an array needed to be scaled). …

---

## [How to work with array of reals in HMC](https://discourse.julialang.org/t/how-to-work-with-array-of-reals-in-hmc/33953)

<div class="topic-metadata">

**Author:** [@johnheyer](https://discourse.julialang.org/u/johnheyer)\
**Replies:** 7\
**Last updated:** [January 31, 2020, 10:01am UTC](https://discourse.julialang.org/t/how-to-work-with-array-of-reals-in-hmc/33953 "2020-01-31T10:01:11Z")

</div>

Hi @Tamas\_Papp, I’m sorry if this is a simple question. I am trying to use your DynamicHMC package and sample from R^n . I have set up my code similarly to: https://github.com/tpapp/DynamicHMCExamples.jl/blob/master/src…

---

## [Julia on ipad pro](https://discourse.julialang.org/t/julia-on-ipad-pro/10628)

<div class="topic-metadata">

**Author:** [@Ferran\_Mazzanti](https://discourse.julialang.org/u/Ferran_Mazzanti)\
**Replies:** 7\
**Last updated:** [January 31, 2020, 7:10am UTC](https://discourse.julialang.org/t/julia-on-ipad-pro/10628 "2020-01-31T07:10:51Z")

</div>

Dear all, I was wondering if it is possible to have julia on the ipad… The new ipad pro seems to be pretty powerful compared to some laptops, so I was wondering if there is any sort of repl and/or jupyter coding system …

---

## [How can write a function to find unique elements in array without any allocation?](https://discourse.julialang.org/t/how-can-write-a-function-to-find-unique-elements-in-array-without-any-allocation/34005)

<div class="topic-metadata">

**Author:** [@Manu\_Francis](https://discourse.julialang.org/u/Manu_Francis)\
**Replies:** 4\
**Last updated:** [January 31, 2020, 6:07am UTC](https://discourse.julialang.org/t/how-can-write-a-function-to-find-unique-elements-in-array-without-any-allocation/34005 "2020-01-31T06:07:32Z")

</div>

Hi, I am using unique function to find unique elements in an array. But the memory allocation to use this function is increasing with array size. In my case array size is nearly 10000, and it causes 36 allocation. a =…

---

## [I'm new to Julia and I can't get this constraint to work](https://discourse.julialang.org/t/im-new-to-julia-and-i-cant-get-this-constraint-to-work/34004)

<div class="topic-metadata">

**Author:** [@T\_S](https://discourse.julialang.org/u/T_S)\
**Replies:** 0\
**Last updated:** [January 31, 2020, 1:33am UTC](https://discourse.julialang.org/t/im-new-to-julia-and-i-cant-get-this-constraint-to-work/34004 "2020-01-31T01:33:06Z")

</div>

I am using JuMP. here is the line: @constraint(m, \[i=1:size(sets)\[2\]\], sum(sets\[j,i\]\*apples\_set\[j\] for j in 1:num\_apples) + sum(sets\[num\_apples+j,i\]\*pears\_set\[j\] for j in 1:num\_pears) \<= num\_overlap) Can someone atleas…

---

## [Animation with threads in Plots.jl?](https://discourse.julialang.org/t/animation-with-threads-in-plots-jl/33958)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 8\
**Last updated:** [January 30, 2020, 11:04pm UTC](https://discourse.julialang.org/t/animation-with-threads-in-plots-jl/33958 "2020-01-30T23:04:29Z")

</div>

Since the canonical way of making animation involes: anim = @animate for i in some\_range plotting(blah...., i) end gif(anim, path\_var) is would be natural to parallelize this process since @animate IO a bun…

---

## [Using Plots.jl within a package \_iteratively\_](https://discourse.julialang.org/t/using-plots-jl-within-a-package-iteratively/33852)

<div class="topic-metadata">

**Author:** [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Replies:** 10\
**Last updated:** [January 30, 2020, 7:50pm UTC](https://discourse.julialang.org/t/using-plots-jl-within-a-package-iteratively/33852 "2020-01-30T19:50:24Z")

</div>

Hi, I am doing some optimization iteratively. I produce plots iteratively, updating the plot after each variable-update. I am trying to figure out how to avoid depending on Plots.jl in my package for cases when the plo…

---

## [How do I load a vector of Strings into a BallTree in NearestNeighbors.jl?](https://discourse.julialang.org/t/how-do-i-load-a-vector-of-strings-into-a-balltree-in-nearestneighbors-jl/33950)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 1\
**Last updated:** [January 30, 2020, 6:54pm UTC](https://discourse.julialang.org/t/how-do-i-load-a-vector-of-strings-into-a-balltree-in-nearestneighbors-jl/33950 "2020-01-30T18:54:26Z")

</div>

I’m trying to figure out how to load a vector of strings into a BallTree from NearestNeighbors.jl and I could really use some guidance. From what I understand, I can create my own Metric and use it with a BallTree so her…

---

## [JuMP for Gurobi 9.0](https://discourse.julialang.org/t/jump-for-gurobi-9-0/33983)

<div class="topic-metadata">

**Author:** [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Replies:** 4\
**Last updated:** [January 30, 2020, 4:55pm UTC](https://discourse.julialang.org/t/jump-for-gurobi-9-0/33983 "2020-01-30T16:55:41Z")

</div>

I want to use the latest version of Gurobi Solver (Gurobi 9.0) since it uses to solve convex and non convex problems unlike the previous versions. On the other hand, JuMP is working for versions up to Gurobi 8.1. Any sug…

---

## [Gurobi.GurobiError(10020, “Q matrix is not positive semi-definite (PSD)](https://discourse.julialang.org/t/gurobi-gurobierror-10020-q-matrix-is-not-positive-semi-definite-psd/33995)

<div class="topic-metadata">

**Author:** [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Replies:** 0\
**Last updated:** [January 30, 2020, 6:35pm UTC](https://discourse.julialang.org/t/gurobi-gurobierror-10020-q-matrix-is-not-positive-semi-definite-psd/33995 "2020-01-30T18:35:11Z")

</div>

I have read some solutions for this problem I have using Gurobi. Most answered that Gurobi did not support non convex problems. However, the new version does and that doest work. I wonder if anyone can figure out where m…

---

## [PackageCompilerX on Windows](https://discourse.julialang.org/t/packagecompilerx-on-windows/33935)

<div class="topic-metadata">

**Author:** [@PGS62](https://discourse.julialang.org/u/PGS62)\
**Replies:** 6\
**Last updated:** [January 30, 2020, 5:46pm UTC](https://discourse.julialang.org/t/packagecompilerx-on-windows/33935 "2020-01-30T17:46:26Z")

</div>

I’ve been keeping an eye on @kristoffer.carlsson’s PackageCompilerX and wondering when to try creating a stand-alone executable for some Julia code I have (after previous failures with PackageCompiler). The documentatio…

---

## [Element-wise additions behaviour](https://discourse.julialang.org/t/element-wise-additions-behaviour/33984)

<div class="topic-metadata">

**Author:** [@rpetit](https://discourse.julialang.org/u/rpetit)\
**Replies:** 9\
**Last updated:** [January 30, 2020, 5:04pm UTC](https://discourse.julialang.org/t/element-wise-additions-behaviour/33984 "2020-01-30T17:04:17Z")

</div>

Hi ! I was wondering if someone could explain me the huge gap I noticed in time and memory cost between these two functions. function fwddiff1(γ::Array{T, 2}) where T\<:Real res = zero(γ) for i=1:size(γ)\[1\]-1 …

---

## [Big Integers](https://discourse.julialang.org/t/big-integers/33989)

<div class="topic-metadata">

**Author:** [@ferasawad](https://discourse.julialang.org/u/ferasawad)\
**Replies:** 2\
**Last updated:** [January 30, 2020, 5:22pm UTC](https://discourse.julialang.org/t/big-integers/33989 "2020-01-30T17:22:25Z")

</div>

Hi I am new to Julia. My question is: How can I do arithmetic operations on very big numbers? something like 2^4110 - 3^35 + …

---

## [Design of outer constructors](https://discourse.julialang.org/t/design-of-outer-constructors/33937)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 1\
**Last updated:** [January 30, 2020, 4:59pm UTC](https://discourse.julialang.org/t/design-of-outer-constructors/33937 "2020-01-30T16:59:21Z")

</div>

in StaticArrays @generated function (::Type{SArray{S, T, N}})(x::Tuple) where {S \<: Tuple, T, N} return quote @\_inline\_meta SArray{S, T, N, $(tuple\_prod(S))}(x) end end I see the use of generate…

---

## [Optim.jl: running instructions after each step](https://discourse.julialang.org/t/optim-jl-running-instructions-after-each-step/33969)

<div class="topic-metadata">

**Author:** [@rpetit](https://discourse.julialang.org/u/rpetit)\
**Replies:** 2\
**Last updated:** [January 30, 2020, 3:12pm UTC](https://discourse.julialang.org/t/optim-jl-running-instructions-after-each-step/33969 "2020-01-30T15:12:28Z")

</div>

Hi ! I would like to use Optim.jl to perform a gradient descent, and for some reason would like after each step to be able to run some instruction, possibly modifying the current iterate. Does anyone know if this is po…

---

## [Undocumented "fields"?](https://discourse.julialang.org/t/undocumented-fields/33933)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 4\
**Last updated:** [January 30, 2020, 1:32pm UTC](https://discourse.julialang.org/t/undocumented-fields/33933 "2020-01-30T13:32:53Z")

</div>

in docs, I see the following: eltype\_wrong(::Type{A}) where {A\<:AbstractArray} = A.parameters\[1\] the .parameters, though I can guess what it is, it’s an undocumented “field” of type parameters. I wonder if there’s any o…

---

## [Why parse(UInt8 and parse(Int8 get diffrent type?](https://discourse.julialang.org/t/why-parse-uint8-and-parse-int8-get-diffrent-type/33966)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 6\
**Last updated:** [January 30, 2020, 8:11am UTC](https://discourse.julialang.org/t/why-parse-uint8-and-parse-int8-get-diffrent-type/33966 "2020-01-30T08:11:30Z")

</div>

Julia 0.7 Why parse(UInt8 and parse(Int8 get diffrent type ? julia\> parse(UInt8,"255") 0xff julia\> parse(Int8,"127") 127 Paul

---

## [Help wanted with an EXCEPTION\_ACCESS\_VIOLATION](https://discourse.julialang.org/t/help-wanted-with-an-exception-access-violation/33967)

<div class="topic-metadata">

**Author:** [@seq](https://discourse.julialang.org/u/seq)\
**Replies:** 0\
**Last updated:** [January 30, 2020, 7:55am UTC](https://discourse.julialang.org/t/help-wanted-with-an-exception-access-violation/33967 "2020-01-30T07:55:57Z")

</div>

I have been struggling for many months with a bug whose error message starts like this: Exception: EXCEPTION\_ACCESS\_VIOLATION at 0x2b33f08d -- fmpz\_set at /workspace/srcdir/flint2/fmpz\\set.c:23 I have reported the bug…

---

## [Mayavi mlab usage trouble](https://discourse.julialang.org/t/mayavi-mlab-usage-trouble/33954)

<div class="topic-metadata">

**Author:** [@sparrowhawk](https://discourse.julialang.org/u/sparrowhawk)\
**Replies:** 0\
**Last updated:** [January 30, 2020, 12:18am UTC](https://discourse.julialang.org/t/mayavi-mlab-usage-trouble/33954 "2020-01-30T00:18:22Z")

</div>

I’m having trouble using mayavi.mlab even though I have been able to install mayavi using Conda. I can do the following mv = pyimport("mayavi") #works but cannot do either of the following mlab = pyimport("mayavi.mla…

---

## [Faster way of calculate two-argument ForwardDiff gradient?](https://discourse.julialang.org/t/faster-way-of-calculate-two-argument-forwarddiff-gradient/33948)

<div class="topic-metadata">

**Author:** [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Replies:** 1\
**Last updated:** [January 29, 2020, 8:57pm UTC](https://discourse.julialang.org/t/faster-way-of-calculate-two-argument-forwarddiff-gradient/33948 "2020-01-29T20:57:00Z")

</div>

i have a function f(x1,x2) . sometimes i need dfdx1 , sometimes i need dfdx2, those cases are easy with the existing ForwardDiff API. the problem is when i need the two properties at once. gradient is one way, calling ea…

---

## [References in Julia](https://discourse.julialang.org/t/references-in-julia/33946)

<div class="topic-metadata">

**Author:** [@rvignolo](https://discourse.julialang.org/u/rvignolo)\
**Replies:** 3\
**Last updated:** [January 29, 2020, 8:31pm UTC](https://discourse.julialang.org/t/references-in-julia/33946 "2020-01-29T20:31:39Z")

</div>

Is it possible to change the contents of a vector by means of a pointer? Of course I am aware of the following: julia\> v = zeros(6); julia\> p = v 6-element Array{Float64,1}: 0.0 0.0 0.0 0.0 0.0 0.0 julia\> p\[1\] =…

---

## [Problems using FFTW- SOLVED](https://discourse.julialang.org/t/problems-using-fftw-solved/33930)

<div class="topic-metadata">

**Author:** [@IgnacioSuarez](https://discourse.julialang.org/u/IgnacioSuarez)\
**Replies:** 10\
**Last updated:** [January 29, 2020, 8:08pm UTC](https://discourse.julialang.org/t/problems-using-fftw-solved/33930 "2020-01-29T20:08:18Z")

</div>

Hi! I am using FFTW in Julia 1.1. I am trying to do the Fourier transform of exp(-0.5\*x^2), whose analytical solution is exactly itself but I obtain a complex array. Does anyone know what I am doing wrong? You can fin…

---

## [Question - for loop - variable assignments](https://discourse.julialang.org/t/question-for-loop-variable-assignments/33934)

<div class="topic-metadata">

**Author:** [@o2candoo](https://discourse.julialang.org/u/o2candoo)\
**Replies:** 5\
**Last updated:** [January 29, 2020, 6:01pm UTC](https://discourse.julialang.org/t/question-for-loop-variable-assignments/33934 "2020-01-29T18:01:18Z")

</div>

Hi Community I’m new to Julia (startet today), so if this question does not fit here, let me know. My first idea was to compare Julias speed for simple calculus with other languages i know (its in this particular area …

---

## [Calling Distributions functions with keywords](https://discourse.julialang.org/t/calling-distributions-functions-with-keywords/33779)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 4\
**Last updated:** [January 29, 2020, 12:15pm UTC](https://discourse.julialang.org/t/calling-distributions-functions-with-keywords/33779 "2020-01-29T12:15:49Z")

</div>

Hi guys, I want to create a (mutable) struct that lets me call functions from the Distributions module in a very generic way, an example container for this looks like this: using Distributions, Parameters import DataSt…

---

## [Does defining the type of variables give more speed?](https://discourse.julialang.org/t/does-defining-the-type-of-variables-give-more-speed/33917)

<div class="topic-metadata">

**Author:** [@Darione](https://discourse.julialang.org/u/Darione)\
**Replies:** 2\
**Last updated:** [January 29, 2020, 9:55am UTC](https://discourse.julialang.org/t/does-defining-the-type-of-variables-give-more-speed/33917 "2020-01-29T09:55:44Z")

</div>

Does defining the type of variables give more speed? If I have a generic Dict () and replace it with a Dict with string keys and array elements as values, should I expect a performance improvement? or, when Julia compil…

---

## [Reading structs from binary stream](https://discourse.julialang.org/t/reading-structs-from-binary-stream/33854)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 1\
**Last updated:** [January 28, 2020, 10:01pm UTC](https://discourse.julialang.org/t/reading-structs-from-binary-stream/33854 "2020-01-28T22:01:07Z")

</div>

What is the up-to-date, idiomatic method of deserializing a stream of un-padded binary values from an external source into Julia struct? StrPack.jl carries a big warning that it is not actively maintained.

---

## [Cumsum behaviour on sparse arrays](https://discourse.julialang.org/t/cumsum-behaviour-on-sparse-arrays/33886)

<div class="topic-metadata">

**Author:** [@mlanghinrichs](https://discourse.julialang.org/u/mlanghinrichs)\
**Replies:** 3\
**Last updated:** [January 28, 2020, 8:15pm UTC](https://discourse.julialang.org/t/cumsum-behaviour-on-sparse-arrays/33886 "2020-01-28T20:15:11Z")

</div>

Hi there, I’m rather new to Julia (and already enjoying it a lot), so please don’t be too hard on me if my topic doesn’t make that much sense. However I think I noticed a somewhat surprising behaviour when cumsum (cumul…

---

## [PDF Manual](https://discourse.julialang.org/t/pdf-manual/32961)

<div class="topic-metadata">

**Author:** [@Usor](https://discourse.julialang.org/u/Usor)\
**Replies:** 2\
**Last updated:** [January 28, 2020, 7:59pm UTC](https://discourse.julialang.org/t/pdf-manual/32961 "2020-01-28T19:59:27Z")

</div>

It looks as though the Julia PDF manual hasn’t been available for a while (since v. 1.3), or is it something on my end? The file doesn’t load at all online, and when downloaded, is too small in file size.

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

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