天道酬勤,学无止境

julia

julia: is it possible to play multithreading

I'm working with Julia. There is a networking library: ZeroMQ. What I need is to create a julia project which can receive multi-zeroMQ-sockets. Here is a simple explanation: s1 = Socket(); ZMQ.bind(s1, ip1:port1); s2 = Socket(); ZMQ.bind(s2, ip2:port2); s3 = Socket(); ZMQ.bind(s3, ip3:port3); ZMQ.recv(s1, msg0, 0); // it's blocking ZMQ.recv(s2, msg1, 0); // it's blocking ZMQ.recv(s3, msg2, 0); // it's blocking So here I have three blocking recv, meaning that I should have a new thread for each of them. But I don't know how to play multithreading with Julia.

2022-01-18 18:09:29    分类:问答    multithreading   julia

no method matching in subtraction

I'm using julia 0.5 after run this code : Freqsample = 100; second = 4; step = (Freqsample * second )-1 i get this Error : MethodError: no method matching getindex(::Int64, ::Colon, ::UnitRange{Int64}) in -(::Int64, ::Int64) at main.jl:12 in include_string(::String, ::String) at loading.jl:441 in eval(::Module, ::Any) at boot.jl:234 in (::Atom.##65#68)() at eval.jl:40 in withpath(::Atom.##65#68, ::Void) at utils.jl:30 in withpath(::Function, ::Void) at eval.jl:46 in macro expansion at eval.jl:109 [inlined] in (::Atom.##64#67{Dict{String,Any}})() at task.jl:60 Whats wrong with subtracting ? i'm

2022-01-18 14:27:33    分类:问答    julia

How to start reading a file x bytes from the beginning in Julia?

I need to read records from a file, each being 9 bytes long. I need to know how to start reading at different points in the file

2022-01-18 11:39:25    分类:问答    julia

How to save a file in Julia

At some point, (I think Julia v0.7) you could do @save savepath thingtosave in order to save files using Julia. I tried to run this on v0.7 to see if I got a deprecation warning but even on 0.7 it says that @save is undefined. How can I programmatically save files using Julia?

2022-01-18 09:27:07    分类:问答    julia

numpy.einsum for Julia?

I'm wondering how to get functionality similar to numpy.einsum in Julia. Specifically, I have a 3rd order tensor that I'm looking to multiply by a 2nd tensor (matrix), contracting both of the dimensions to yield a 1st order tensor (vector). Currently, I'm using PyCall so that I can use the numpy.einsum function like so: using PyCall @pyimport numpy as np a = rand(5,4,3) b = rand(5,4) c = np.einsum("ijk,ij", a,b) size(c) == (3,) It feels kind of silly to rely on calling python in order to do tensor math. I also imagine that a julia implementation would have speed advantages. However, I haven't

2022-01-18 06:23:12    分类:问答    linear-algebra   matrix-multiplication   julia

How do you make a view drop dimensions?

This is best illustrated by a simple example on v0.5-rc0: julia> view(zeros(4,2),:,2) 4-element SubArray{Float64,1,Array{Float64,2},Tuple{Colon,Int64},true}: 0.0 0.0 0.0 0.0 julia> zeros(4,2)[:,2] 4-element Array{Float64,1}: 0.0 0.0 0.0 0.0 The first returns a SubArray of Array{Float64,2} with only 1 column, but v0.5 drops dimensions. Is there a way to make the SubArray/View drop the unused dimension?

2022-01-18 04:58:47    分类:问答    matrix   julia

Inline Interactive Plots with Julia in jupyter notebook

when I use %matplotlib notebook import matplotlib.pyplot as plt I get interactive plots, i.e. I can also zoom into the figure. For julia this command does not seem to exist. Any ideas?

2022-01-18 04:24:10    分类:问答    python   julia

Sparse matrices and type constraints in Julia

I am confused about how parametric methods work in Julia. I also hope that parametric is the right word to use here. I've read the docs on methods but it is still not clear why the following error occurs. If I define a function as below function Bazinga{T<:Real}(mat ::Union{Array{T,2},SparseMatrixCSC}) mat^4 end and run Penny = sparse(randn(10,10)) Bazinga(Penny) I get ERROR: MethodError: `Bazinga` has no method matching Bazinga(::SparseMatrixCSC{Float64,Int64}) Closest candidates are: Bazinga{T<:Real}(::Union{Array{T<:Real,2},SparseMatrixCSC{Tv,Ti<:Integer}}) But Int64<:Int is true so what is

2022-01-18 04:14:22    分类:问答    methods   types   julia

MethodError when dispatching on a parametric vector of vectors

I've written a function that dispatches on a vector of vectors of Integers. However, I get a MethodError when I try to use it: julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x)); julia> x = [[1], [2, 3], [4, 5, 6]] 3-element Array{Array{Int64,1},1}: [1] [2, 3] [4, 5, 6] julia> foo(x) ERROR: MethodError: no method matching foo(::Array{Array{Int64,1},1}) Closest candidates are: foo(::Array{Array{#s17,1} where #s17<:Integer,1}) at REPL[1]:1 Why doesn't this work?

2022-01-17 12:42:24    分类:问答    julia

Is there a way to use strings as separators in writetable() - Julia

When using writetable() to write a Data Frame to a file, I would like to be able to have the delimiter be a space then a comma (i.e. " ," as the delimiter). I know writetable() only has the option to have a single char as the separator argument. Is there a possible workaround to be able to have a string as the delimiter? Or, is it possible to simply add a space after every single data point in the data frame and then output it as normal to a .csv file, therefore essentially having the " ," delimiter in the file?

2022-01-17 11:53:21    分类:问答    csv   dataframe   julia   delimiter   separator