# General Usage

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

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

**Page:** 1074

---

## [Port C++ union to Julia](https://discourse.julialang.org/t/port-c-union-to-julia/950)

<div class="topic-metadata">

**Author:** [@peter.mancini](https://discourse.julialang.org/u/peter.mancini)\
**Replies:** 4\
**Last updated:** [December 14, 2016, 9:26pm UTC](https://discourse.julialang.org/t/port-c-union-to-julia/950 "2016-12-14T21:26:06Z")

</div>

I am porting some complex C++ code to Julia. The one part that has me really perplexed is how to port the C++ concept of a union. If you aren’t familiar with union, its like a structure, but all of the members share the …

---

## [Promote and infinite recursion](https://discourse.julialang.org/t/promote-and-infinite-recursion/867)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 1\
**Last updated:** [December 14, 2016, 6:04pm UTC](https://discourse.julialang.org/t/promote-and-infinite-recursion/867 "2016-12-14T18:04:25Z")

</div>

When reading the code of IntervalSets.jl I saw a constructor defined like this: checked\_conversion{T}(::Type{T}, a, b) = \_checked\_conversion(T, convert(T, a), convert(T, b)) \_checked\_conversion{T}(::Type{T}, a::T, b::T)…

---

## [Calling code from a library (.so): works on one system, fails on another](https://discourse.julialang.org/t/calling-code-from-a-library-so-works-on-one-system-fails-on-another/904)

<div class="topic-metadata">

**Author:** [@rwgardner](https://discourse.julialang.org/u/rwgardner)\
**Replies:** 3\
**Last updated:** [December 14, 2016, 3:36pm UTC](https://discourse.julialang.org/t/calling-code-from-a-library-so-works-on-one-system-fails-on-another/904 "2016-12-14T15:36:52Z")

</div>

I am trying to call a function from a compiled library (a .so file). As a simplified example: handle = ccall((:foo, "path/to/my\_lib1.so"), Ptr{Void}, (UInt32, Ptr{UInt8}), 100, "path/to/my\_lib2.so") on one system, 64…

---

## [Julia equivalent to 'not in' in R](https://discourse.julialang.org/t/julia-equivalent-to-not-in-in-r/835)

<div class="topic-metadata">

**Author:** [@Patrik\_Waldmann](https://discourse.julialang.org/u/Patrik_Waldmann)\
**Replies:** 9\
**Last updated:** [December 14, 2016, 3:22pm UTC](https://discourse.julialang.org/t/julia-equivalent-to-not-in-in-r/835 "2016-12-14T15:22:03Z")

</div>

What would be Julia code for the following R code: a ← c(1:5) b ← c(1:10) c ← b\[-a\] Thanks, Patrik

---

## [Profiling of Multi-threaded code](https://discourse.julialang.org/t/profiling-of-multi-threaded-code/819)

<div class="topic-metadata">

**Author:** [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Replies:** 5\
**Last updated:** [December 14, 2016, 2:44pm UTC](https://discourse.julialang.org/t/profiling-of-multi-threaded-code/819 "2016-12-14T14:44:13Z")

</div>

Hello all, I would like to ask for any suggestions / recommendations about profiling multi-threaded code in Julia. The single-threaded version works fine, but once I turned on multi-threading, I hardly observe any impro…

---

## [Dictionary of all indices of all unique values in an array](https://discourse.julialang.org/t/dictionary-of-all-indices-of-all-unique-values-in-an-array/939)

<div class="topic-metadata">

**Author:** [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Replies:** 0\
**Last updated:** [December 14, 2016, 12:04pm UTC](https://discourse.julialang.org/t/dictionary-of-all-indices-of-all-unique-values-in-an-array/939 "2016-12-14T12:04:40Z")

</div>

StatsBase.indexmap(a) creates a dictionary of indices of first occurrences of all unique values in a. Is there a standard function that would create a map to all indices of all unique values in a (not only the first one…

---

## [Dependency only for testing](https://discourse.julialang.org/t/dependency-only-for-testing/863)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 6\
**Last updated:** [December 14, 2016, 6:49am UTC](https://discourse.julialang.org/t/dependency-only-for-testing/863 "2016-12-14T06:49:31Z")

</div>

If a packages is only needed for testing (eg loaded by runtests.jl), but not for the package functionality per se, should I include it in REQUIRE?

---

## [Collections of Functions](https://discourse.julialang.org/t/collections-of-functions/896)

<div class="topic-metadata">

**Author:** [@ohsonice](https://discourse.julialang.org/u/ohsonice)\
**Replies:** 11\
**Last updated:** [December 13, 2016, 7:24pm UTC](https://discourse.julialang.org/t/collections-of-functions/896 "2016-12-13T19:24:31Z")

</div>

Hi all, this is my first post. Sorry if there’s a similar topic, I couldn’t find it. I am curious about the use case below. I would like to define a function as such: julia\> function f(funs::Array{Function,1}) …

---

## [\`length.(keys(d))\` does not work?](https://discourse.julialang.org/t/length-keys-d-does-not-work/913)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 7\
**Last updated:** [December 13, 2016, 7:21pm UTC](https://discourse.julialang.org/t/length-keys-d-does-not-work/913 "2016-12-13T19:21:40Z")

</div>

Create a dictionary with vector keys: d = Dict(\[1,2\] =\> 1.1, \[3,2\] =\> 0.1) Then I want to evalute the length of the keys, so I write: length.(keys(d)) But this results in an error: ERROR: MethodError: no method mat…

---

## [Assigning values of different types to unused variable](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912)

<div class="topic-metadata">

**Author:** [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Replies:** 5\
**Last updated:** [December 13, 2016, 4:43pm UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912 "2016-12-13T16:43:25Z")

</div>

Sometimes it is convenient to use \_ as a placehold for return values you do not care about. I wonder if there is any “danger” in something similar to: f() = 1.0, 1, "foo" function g() a, \_, \_ = f() end Here the va…

---

## [How to @parallel a CartesianRange?](https://discourse.julialang.org/t/how-to-parallel-a-cartesianrange/924)

<div class="topic-metadata">

**Author:** [@oatlzzvztd](https://discourse.julialang.org/u/oatlzzvztd)\
**Replies:** 0\
**Last updated:** [December 13, 2016, 4:37pm UTC](https://discourse.julialang.org/t/how-to-parallel-a-cartesianrange/924 "2016-12-13T16:37:53Z")

</div>

In serial, the following for loop is just fine: A = randn(5,5) for inds = CartesianRange(size(A)) i, j = inds.I # Some function of A\[i, j\], i, and j end However, naively adding @sync @parallel to the for loop thro…

---

## [BinDeps - building source with commit ids in dirname](https://discourse.julialang.org/t/bindeps-building-source-with-commit-ids-in-dirname/892)

<div class="topic-metadata">

**Author:** [@merl-dev](https://discourse.julialang.org/u/merl-dev)\
**Replies:** 3\
**Last updated:** [December 13, 2016, 9:26am UTC](https://discourse.julialang.org/t/bindeps-building-source-with-commit-ids-in-dirname/892 "2016-12-13T09:26:06Z")

</div>

I am trying to write a build.jl that relies on a BitBucket repo. The problem is that when unpacked BitBucket repos/tars contain commit id’s (mypackage/deps/src/bitbucket user - packagename - commit id/ ) so users will ke…

---

## [Type inference infinite loop?](https://discourse.julialang.org/t/type-inference-infinite-loop/856)

<div class="topic-metadata">

**Author:** [@sacha](https://discourse.julialang.org/u/sacha)\
**Replies:** 1\
**Last updated:** [December 13, 2016, 1:32am UTC](https://discourse.julialang.org/t/type-inference-infinite-loop/856 "2016-12-13T01:32:07Z")

</div>

Under julia\> versioninfo() Julia Version 0.6.0-dev.1529 Commit 9ae5e06\* (2016-12-08 23:28 UTC) Platform Info: OS: macOS (x86\_64-apple-darwin15.6.0) CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz WORD\_SIZE: 64 BLA…

---

## [\[1,2,3\] |\> f. doesn't work](https://discourse.julialang.org/t/1-2-3-f-doesnt-work/903)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 4\
**Last updated:** [December 12, 2016, 10:57pm UTC](https://discourse.julialang.org/t/1-2-3-f-doesnt-work/903 "2016-12-12T22:57:48Z")

</div>

Try this: f(x) = x^2 \[1,2,3\] |\> f. with the dot, to map f over the array. It doesn’t work. Is this intended?

---

## [Problem with finalizers](https://discourse.julialang.org/t/problem-with-finalizers/897)

<div class="topic-metadata">

**Author:** [@wbhart](https://discourse.julialang.org/u/wbhart)\
**Replies:** 12\
**Last updated:** [December 12, 2016, 11:00pm UTC](https://discourse.julialang.org/t/problem-with-finalizers/897 "2016-12-12T23:00:01Z")

</div>

I’m currently having some trouble with a finalizer cleaning up an object that is needed by another finalizer. I have two objects, both of which contain pointers to some C object, one of which is a “context object” for t…

---

## [FFT plan can't be sent between processes?](https://discourse.julialang.org/t/fft-plan-cant-be-sent-between-processes/877)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 11\
**Last updated:** [December 12, 2016, 10:14pm UTC](https://discourse.julialang.org/t/fft-plan-cant-be-sent-between-processes/877 "2016-12-12T22:14:13Z")

</div>

I’m not fully sure if this is a bug, something where just the error message ought to be nicer, or whether I’ve done something really bad! The problem arises trying to transfer an FFT plan between processes as you see bel…

---

## [IJulia 0.5 kernel dies on macOS / OS X](https://discourse.julialang.org/t/ijulia-0-5-kernel-dies-on-macos-os-x/860)

<div class="topic-metadata">

**Author:** [@idontgetoutmuch](https://discourse.julialang.org/u/idontgetoutmuch)\
**Replies:** 0\
**Last updated:** [December 11, 2016, 9:48am UTC](https://discourse.julialang.org/t/ijulia-0-5-kernel-dies-on-macos-os-x/860 "2016-12-11T09:48:13Z")

</div>

Does anyone have any ideas about this: https://github.com/JuliaLang/IJulia.jl/issues/489?

---

## [From type to ptr and back](https://discourse.julialang.org/t/from-type-to-ptr-and-back/888)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 4\
**Last updated:** [December 12, 2016, 3:15pm UTC](https://discourse.julialang.org/t/from-type-to-ptr-and-back/888 "2016-12-12T15:15:44Z")

</div>

Dear User, I am calling a C library that ask for a void \* data in a struct. Hence, I pass to this struct my julia variable a of Type Data using the void pointer b = pointer\_from\_objref(a). However, later on, I want to …

---

## [Accessing matrix (2x2) at \[3\] throws an error on master](https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889)

<div class="topic-metadata">

**Author:** [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Replies:** 2\
**Last updated:** [December 12, 2016, 2:29pm UTC](https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889 "2016-12-12T14:29:48Z")

</div>

Sooo, more Optim getting ready for v0.6 material. I fixed the macro problems in Optim fails on v0.6 - #6 by pkofod but the tests still do not pass, as I get the following error ERROR: LoadError: LoadError: BoundsError: …

---

## [Getting all possible combination of vector with all possible order](https://discourse.julialang.org/t/getting-all-possible-combination-of-vector-with-all-possible-order/879)

<div class="topic-metadata">

**Author:** [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Replies:** 2\
**Last updated:** [December 12, 2016, 11:35am UTC](https://discourse.julialang.org/t/getting-all-possible-combination-of-vector-with-all-possible-order/879 "2016-12-12T11:35:17Z")

</div>

I know that there is combination function whthin package ‘Combinatorics’ which gives me all possible combination without regarding order of elements x = combinations(\[1,2,3\], 3) # which gives this collect(x) =\> \[1,2,3…

---

## [Optim fails on v0.6](https://discourse.julialang.org/t/optim-fails-on-v0-6/872)

<div class="topic-metadata">

**Author:** [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Replies:** 5\
**Last updated:** [December 12, 2016, 10:21am UTC](https://discourse.julialang.org/t/optim-fails-on-v0-6/872 "2016-12-12T10:21:12Z")

</div>

… and I’m not really sure why. To keep things simple, we’ve simply used two macros to repeat some fields which are in all Optimizers. The approach is the following (with gradient descent as an example): type GradientDe…

---

## [How to find if a method is implemented for an interface?](https://discourse.julialang.org/t/how-to-find-if-a-method-is-implemented-for-an-interface/636)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 9\
**Last updated:** [December 11, 2016, 12:41am UTC](https://discourse.julialang.org/t/how-to-find-if-a-method-is-implemented-for-an-interface/636 "2016-12-11T00:41:06Z")

</div>

Suppose I have a simple interface for which some methods are optional: abstract Foo{T} method1{T}(::Foo{T}, x, y) method2{T}(::Foo{T}, a, b) # optional The user of the interface should implement method1, but the implem…

---

## [Transpiling Julia to C](https://discourse.julialang.org/t/transpiling-julia-to-c/830)

<div class="topic-metadata">

**Author:** [@tomerg](https://discourse.julialang.org/u/tomerg)\
**Replies:** 0\
**Last updated:** [December 9, 2016, 3:51pm UTC](https://discourse.julialang.org/t/transpiling-julia-to-c/830 "2016-12-09T15:51:19Z")

</div>

Hi, I’m new to Julia. I read the blog posts on static compilation and transpiling Julia to C, and I tried to do it by myself. I followed the instructions and I built Julia (0.6.0-dev), I compiled llvm (3.7.1) and llvm-…

---

## [Strange behavior parallel for](https://discourse.julialang.org/t/strange-behavior-parallel-for/824)

<div class="topic-metadata">

**Author:** [@Thuener](https://discourse.julialang.org/u/Thuener)\
**Replies:** 1\
**Last updated:** [December 9, 2016, 1:06pm UTC](https://discourse.julialang.org/t/strange-behavior-parallel-for/824 "2016-12-09T13:06:13Z")

</div>

I’m having a strange behavior when using @parallel for inside other for. c = collect(0:0.1:0.2) λ = \[0.0 0.0\] for λ\[1\] in c @parallel for λ\[2\] in c println("λ $(λ)") end end Running this code with one th…

---

## [Module Naming](https://discourse.julialang.org/t/module-naming/822)

<div class="topic-metadata">

**Author:** [@Jeremy](https://discourse.julialang.org/u/Jeremy)\
**Replies:** 3\
**Last updated:** [December 9, 2016, 10:41am UTC](https://discourse.julialang.org/t/module-naming/822 "2016-12-09T10:41:37Z")

</div>

I’m currently in the process of preparing a few modules I created for publication to Github. They load and parse data from various instruments. So far I’ve named them after the companies that make the instruments or the …

---

## [Julian equivalent to \`python -m SimpleHTTPServer 8000\`](https://discourse.julialang.org/t/julian-equivalent-to-python-m-simplehttpserver-8000/811)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 2\
**Last updated:** [December 8, 2016, 8:06pm UTC](https://discourse.julialang.org/t/julian-equivalent-to-python-m-simplehttpserver-8000/811 "2016-12-08T20:06:14Z")

</div>

I have a website in the making and I need to test it locally. I know I can just python -m SimpleHTTPServer 8000 and then open http://localhost:8000/index.html in my browser, but I’d rather use Julia instead. I tested th…

---

## [Incorrect memory allocation in Julia v0.5](https://discourse.julialang.org/t/incorrect-memory-allocation-in-julia-v0-5/736)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 27\
**Last updated:** [December 8, 2016, 4:45pm UTC](https://discourse.julialang.org/t/incorrect-memory-allocation-in-julia-v0-5/736 "2016-12-08T16:45:48Z")

</div>

Julia v0.5 has some serious issues regarding memory allocation. In an attempt to optimize my package I realized many inconsistencies: - ## Copyright (c) 2015, Júlio Hoffimann Mendes \<juliohm@stanford.edu\> …

---

## [Pycall in production?](https://discourse.julialang.org/t/pycall-in-production/783)

<div class="topic-metadata">

**Author:** [@Tem\_Pl](https://discourse.julialang.org/u/Tem_Pl)\
**Replies:** 1\
**Last updated:** [December 8, 2016, 1:05pm UTC](https://discourse.julialang.org/t/pycall-in-production/783 "2016-12-08T13:05:36Z")

</div>

Does anyone have experience using PyCall in production? Is it reliable for long running applications?

---

## [Type-checked cfunction call from C++](https://discourse.julialang.org/t/type-checked-cfunction-call-from-c/806)

<div class="topic-metadata">

**Author:** [@barche](https://discourse.julialang.org/u/barche)\
**Replies:** 0\
**Last updated:** [December 8, 2016, 10:17am UTC](https://discourse.julialang.org/t/type-checked-cfunction-call-from-c/806 "2016-12-08T10:17:57Z")

</div>

Hi all, I’d like to pick up the discussion at https://groups.google.com/d/topic/julia-users/A9HWFVdN4HI/discussion again. To facilitate calling Julia functions from C++, I added some functionality to CxxWrap.jl to make …

---

## [Why Have 0-Dimensional Arrays?](https://discourse.julialang.org/t/why-have-0-dimensional-arrays/797)

<div class="topic-metadata">

**Author:** [@jecs](https://discourse.julialang.org/u/jecs)\
**Replies:** 6\
**Last updated:** [December 8, 2016, 7:46am UTC](https://discourse.julialang.org/t/why-have-0-dimensional-arrays/797 "2016-12-08T07:46:18Z")

</div>

Hi. I apologize if this has been asked before, but I’m a bit confused by 0-dimensional arrays. You can access the elements of a 1D array via the syntax x\[k\], of a 2D array via x\[k,l\] or x\[k\], and so on. But a 0D array …

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

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