# Questions tagged [julia]

3516 questions

1

votes

0

answer

51

Views

### Julia traversing the expression tree containing broadcast results in unintended tuples

I am trying to understand Metaprogramming in Julia. I wrote the following
code
function traversal!(x::Expr,mem)
for xx in x.args
if isa(xx,Expr)
push!(mem,xx)
traversal!(xx,mem)
end
end
end
expr=:(sum((x-cos(W2*sin(W1*x+b1)+b2))^2))
mem=[]
a=traversal!(expr,mem)
I expect mem to be
:((x - cos(W2 *...

1

votes

0

answer

165

Views

### What's wrong with my Euclidean Distance Calculation? (Julia)

I'm trying to compute the Perceptually Important Points by using three different methods.
Euclidean Distance;
Perpendicular Distance;
Vertical Distance.
Method 2 and 3 gives me the same Point, but Euclidean distance not. Can't find the mistake I made. Hope someone can help me.
pt = 7.6 #pt
_t = 1...

1

votes

0

answer

98

Views

### How to run an mpi executable from julia

I want to call an MPI exectable from Julia in a Jupyter notebook.
Doing
cmd = Cmd(`mpiexec -np 4 name_of_executable`)
run(cmd)
creates 4 processes, but they all use 25% cpu on one core. Is there a way to have it run 100% on four separate cores?

1

votes

0

answer

90

Views

### Automatic Differentiation in Julia: Hessian from ReverseDiffSparse

How can I evaluate the Hessian of a function in Julia using automatic differentiation (preferably using ReverseDiffSparse)? In the following example, I can compute and evaluate the gradient at a point values through JuMP:
m = Model()
@variable(m, x)
@variable(m, y)
@NLobjective(m, Min, sin(x) + sin(...

1

votes

0

answer

71

Views

### Julia JuMP garbage collection time

I'm new to Julia and is trying to use JuMP to solve a NLP, below is the code
m = JuMP.Model(solver=Ipopt.IpoptSolver(max_iter=50,tol=1e-6))
function lkhf(x1,x2,x3,x4,x5,x6,x7,x8)
x = [x1,x2,x3,x4,x5,x6,x7,x8]
@time ll = loglikelihood(x,pdpoeFacSim,intercept, pdpoeFacMean, pdpoeFacInitial, pdpoeTarge...

1

votes

1

answer

280

Views

### Problems with replacing missing values in a DataFrame with Julia 0.6.2

So, I will preface this by saying that I am new I the Julia language and trying to work through some tutorials on handling data sets. But I seem to be hitting a problem with handling missing values and cannot seem to figure out what is wrong.
Specifically:
I have a 11 x 5 DataFrame containing some t...

1

votes

1

answer

44

Views

### Run function in same module and file in different process

If I have the following Julia code snippet, is there any way I can run the for loop with multiple processes without putting complicated into an extra file and doing something like @everywhere include('complicated.jl')?
Otherwise, the processes don't seem to be able to find the function.
function com...

1

votes

0

answer

204

Views

### PyPlot savefig() error 'TrueType font is missing table' when using ttc font

I am using PyPlot package from Julia language on macOS 10.13. Here is my code that generates the problem:
using PyPlot
PyPlot.svg(true)
function myplot()
my_font=matplotlib[:font_manager][:FontProperties](fname = '/System/Library/Fonts/Helvetica.ttc')
fig, ax = subplots()
ax[:plot](rand(10), rand(10...

1

votes

0

answer

36

Views

### Measuring memory usage of distributed arrays

I've been having trouble measuring the memory usage of distributed arrays and could not find a solution on Julia Discourse. Consider the following example.
addprocs(2)
@everywhere using DistributedArrays
m = [rand(100,100) for i in 1:1000]
d = distribute(m)
How much memory does the array d use? I...

1

votes

1

answer

44

Views

### Can I use a _FillValue when reading a netCDF file in Julia?

I use the package NetCDF.jl.
I have a netCDF file file.nc which contains variable var1. In principle, var1 contains possitive values. A mask value of var1 is defined in the netCDF file, namely _FillValue = -1.e+34. However, if I ncread('file.nc', 'var1'), var1 presents the _FillValue as -1.e+34,...

1

votes

1

answer

86

Views

### Developing reader for onnx models

I am trying to make a reader for onnx models in Julia. Generally, onnx models consist of a model.pb file, which contains metadata about the model. However, I am not able to figure out how can I use protocol buffers or Julia implementation of protocol buffers (ProtoBuf.jl) to generate data structure...

1

votes

0

answer

41

Views

### builing Pardiso 5 on Mac with Julia

I'm trying to build Pardiso 5 on Mac 10.12.6 through Julia but am having issues.
I added the Pardiso package through Julia, then I followed the Pardiso manual (p.33/69) and set LD_LIBRARY_PATH=~/.julia/v0.6/Pardiso/deps/libpardiso500-MACOS-X86-64.dylib from my .bash_profile. Then I run Pkg.build('P...

1

votes

2

answer

202

Views

### Julia function timeout using async and remotecall_fetch fails to find function

I'm trying to kill execution of a function when it times out. Tried to leverage the post here: Julia: Can you set a time limit on eval
It errored on RemoteRef is undefined (I'm using v0.6.0). Replaced RemoteRef with Channel(1). Now the error is
MethodError: no method matching remotecall_fetch
(::I...

1

votes

0

answer

88

Views

### Julia using Slurm invokes only one node

srun --nodes=3 hostname
returns successfully all the 3 node names but
srun --nodes=3 julia test.jl
fails with error below where test.jl is given at the end here
Worker 2 terminated.
ERROR (unhandled task failure): Version read failed. Connection closed by peer.
Stacktrace:
[1] process_hdr(::TCPSocke...

1

votes

2

answer

95

Views

### Unexpected behavior in Julia boolean comparison

I'm testing different parametrization of the CDF of the logistic function and comparing the results and the effect on the curve of the different parameters.
using Distributions
# Vector of x to test the different functions
x = collect(0:20)
Logis = Logistic(10, 1) # PDF of Logistic function in Jul...

1

votes

1

answer

470

Views

### IJulia for Julia v0.7

I tried building the latest (dev) version of Julia (v0.7) and want to use this kernel from Jupyter Notebook. When I tried running
Pkg.add('IJulia') and building the module, the build failed. The errors I get are along the lines of
Error: ------------------------------------------------------------...

1

votes

0

answer

417

Views

### Unable to start Julia in Atom

I get these error messages everytime I try to run a Julia command. I am starting Atom from the command line. I am not sure what else I am doing incorrectly in the setup.
juno-msg-precompilingINFO: Precompiling module Atom.
ERROR: LoadError: could not open file
/Users/John/.julia/v0.6/MbedTLS/sr...

1

votes

0

answer

71

Views

### label boxplot extreme points in julia using Plotly Backend

i'm plotting a boxplot using plotlyJS backend for Plots in Julia 0.6.2
And i'm trying to make it possible to show particular labels (strings) for the points that are extreme. (so we can identify them easily).
check the image for further details
enter image description here
code:
using Plots
plotlyjs...

1

votes

1

answer

106

Views

### How to implement custom serialization/deserialization for a struct in Julia?

The default implementation of Base.serialize and Base.deserialize do the serialization/deserialization for the whole given object.
What is the correct way of excluding a field from being serialized and still be able to deserialize it correctly?
Here is a simplified code sample:
# The target struct
s...

1

votes

0

answer

31

Views

### List of keyword arguments in plot recipe definition

I have originally opened an issue in RecipesBase.jl, but I think this is just me not understanding the machinery of plot recipes. Why the code below fails when I try to pass in a list of keywords with the ... syntax?
using RecipesBase
@userplot FooPlot
@recipe function f(fp::FooPlot; a=1, b=2, kwarg...

1

votes

0

answer

126

Views

### Removing background on a 3d plot Julia

I am having some real trouble trying to plot nice things with Julia.
I first used PyPlot which I was happy with but I had to be able to change the angle on a 3D plots (in that case using surface) so I now use Plots directly with the camera speficication. I would like to remove the background on a 3...

1

votes

0

answer

152

Views

### Julia calling Fortran. signal (11): Segmentation fault error

I am using a very large code in Fortran. It is called sapick6.f90. If I compile this code:
gfortran -O3 -o sapick6 sapick6.f90
and run it:
./sapick6
I have always the same exact result (as expected). It has random number subroutines, but the seed, at the beginning is always the same, as it reads inp...

1

votes

2

answer

158

Views

### Fuzzy C-means clustering in ImageSegmentation.jl

I am trying to cluster different regions of an image using Fuzzy C-means clustering with ImageSegmentation.jl
using ImageSegmentation, Images
fl = load('flower.jpg')
fuzzy_fl = fuzzy_cmeans(fl,3,2)
It gives an error like this:
MethodError: no method matching fuzzy_cmeans(::Base.ReshapedArray{Float64...

1

votes

0

answer

38

Views

### Enable tab completion to find file in Julia outside working directory

How can I enable tab completion in Julia with a function I wrote that loads a file outside of the working directory? Tab completion is super nice, but it only seems to work for files in my working directory. e.g. I store all of my files in a directory foo and I wrote a function to conveniently read...

1

votes

0

answer

128

Views

### How to get intermediate Integer solutions when solving a MIP in Julia (JuMP)?

I am solving a MIP model using CPLEX in Julia. I know CPLEX has a so-called Solution Pool where all the intermediate integer solutions during the solving process are stored. Is there a way of accessing those solutions using Julia (JuMP)?

1

votes

1

answer

64

Views

### non-boolean (UInt16) used in boolean context

I'm getting an error:
TypeError: non-boolean (UInt16) used in boolean context
After some debugging the error is coming from this while loop.
current_value = UInt16(6)
bit = UInt16(8)
while (current_value & bit)
bit >>= 1
end
What's wrong?

1

votes

2

answer

126

Views

### Neural network works with the cross entropy and does not with an other loss function

I'm using tensorflow with julia to create a neural network.
I can create a network with the cross_entropy loss function and it works:
ENV['CUDA_VISIBLE_DEVICES'] = '0' # It is to use the gpu
using TensorFlow
using Distributions
function weight_variable(shape)
initial = map(Float32, rand(Normal(0, .0...

1

votes

0

answer

46

Views

### Cumulative Returns

In R we can do:
cum.ret head(df)
6×5 DataFrames.DataFrame
│ Row │ a │ b │ Close │ Close_Rets │ Cum_Ret │
├─────┼───┼─────────┼──────────┼────────────┼──────────...

1

votes

0

answer

301

Views

### Optimality gap in CBC solver

Is there a way to set the optimality gap in CBC solver, as of now I am able to set the maximum timings on the solver but can not figure out how to set the optimality gap a the stopping criteria.Thanks a lot.
using JuMP , Cbc
m = Model( solver = CbcSolver(Sec=70*60))

1

votes

1

answer

74

Views

### How can I measure the RAM consumption and the time of computing in Julia?

I'm developing different discretization schemes and in order to find out wich is the most effiecient one I would like to determine the maximun RAM comsuption and the time that takes to do an specifyc task, such as solving a system of equations, overwritting a matrix or writting the data to a file....

1

votes

0

answer

275

Views

### OutOfMemoryError() in julia

I'm trying to initialize a grid in Julia but I get an out of memory error when I try to read from stdin(commented out line). If I assign the size manually, it runs fine.
I added the print statement at the bottom to be sure I'm reading in correctly and it gives me the right output. I've searched all...

1

votes

0

answer

210

Views

### LoadError: UndefVarError: plot not defined in Julia

I have the following code in Julia:
#Pkg.add('Plots')
using Plots
plotly()
plot(1:5,1:5)
Julia Pro always returns me the following error:
LoadError: UndefVarError: plot not defined
What is causing this and how can I fix it?

2

votes

0

answer

24

Views

### Julia FixedEffectsModels IV regression doesn't match R IV regression

When I run (what I think is the same regression) in R and in Julia I get very different results. I think this is because the IV regression is using an indicator variable to instrument for another indicator variable but I can't figure out if I am doing something else wrong.
I have tried several diffe...

1

votes

0

answer

53

Views

### if not OffsetArrays.jl then how to store and access array with irregular for loop?

I have the following awkward for loop, and e.g. kreps=(8, 7, 6), a tuple of Int's. I pre-computed a multi-dimensional array kvec_wts that holds a Float depending on kreps. With OffsetArrays.jl, I can call kvec_wts[ka, kb, kc] inside the loop very beautifully!
for kc=-kreps[3]:kreps[3], kb = -kreps[2...

1

votes

1

answer

89

Views

### Error at creating new resource with Julia-Genie

In Genie (http://genieframework.com/),
I try to create a new resource names 'Toto' using the command
./bin/repl --resource:new=Toto
I get the following error :
ERROR: LoadError: UndefVarError: SearchLight not defined
execute(::Genie.Configuration.Settings) at /home/vlaugier/.julia/v0.6/Genie/src/Com...

1

votes

0

answer

88

Views

### Julia Pkg.update() and LibGit2 trouble

I can't do Pkg.update() or Pkg.add('Something') behind my office firewall, though with the following in ~/.gitconfig I can use git to clone from the command line with cntlm running on my local machine
[http]
proxy = 127.0.0.1:3128
sslVerify = false
[url 'https://']
insteadOf = git://
I get the follo...

1

votes

1

answer

360

Views

### frequencies in Julia's real FFT

I'm using Julia's FFT implementation to perform a 2D real FFT on a couple of arrays but I can't be sure of the order of the frequencies in the output. Consider the MWE
N=64
U = rand(Float64, N, N);
FFTW.set_num_threads(2)
prfor = plan_rfft(U, (1,2), flags=FFTW.MEASURE);
size(prfor*U)
The output is a...

1

votes

0

answer

54

Views

### Using sklearn.mixture.GaussianMixture methods on julia

can you help me how i can use all functions of sklearn.mixture.GaussianMixture on Julia ?
using PyPlot
using ScikitLearn
using PyCall
@pyimport sklearn.mixture as mix
data=readcsv('C:/Users/pc/Desktop/data.csv',header=false)
a=mix.GaussianMixture(3)
a.fit(data)
the error is: type PyObject has no fi...

1

votes

1

answer

135

Views

### Plots savefig works at the top level, but not within a function?

I'm trying to write some command line Julia programs to generate and save plots.
This works:
#!/usr/bin/env julia
using Plots
pyplot()
plot(1:100,1:100)
savefig('foo.png')
But this doesn't:
#!/usr/bin/env julia
using Plots
function main(args)
pyplot()
plot(1:100,1:100)
savefig('foo.png')
end
main(AR...

1

votes

1

answer

62

Views

### Shared Array values not updating when using @parallel

I am trying to create a parallel for loop using @parallel, in order to compute a cumulative sum of a SharedArray. A simple test I'm running looks like this:
p = SharedArray{Float64}(10,10);
@parallel for i = 1 : 5
p = p .+ 1
end
p
However, when printing p, I just get a series of zeros, as if the for...