julia

Why does this assignment inside a loop fail in Julia 0.7 and 1.0?

北慕城南 提交于 2020-02-02 10:20:28
问题 (k, a, b, a1, b1) = (BigInt(2), BigInt(4), BigInt(1), BigInt(12), BigInt(4)) while k <= BigInt(4) (p, q, k) = (k*k, BigInt(2)*k+BigInt(1), k+BigInt(1)) end This code compiles and runs in Julia 0.6, but in 1.0 produces ERROR: UndefVarError: k not defined . Did something change between versions? What's wrong with this code in Julia 1.0? 回答1: The answer by shadowtalker is correct. However, there is one important issue with this code that is worth adding some more explanation (and it was too long

Julia: How to profile parallel code

大兔子大兔子 提交于 2020-02-02 10:19:45
问题 Whats an appropriate way to profile parallel code in julia? When I run @profile foo(...) where foo is my function, I get julia> Profile.print() 1234 task.jl; anonymous; line: 23 4 multi.jl; remotecall_fetch; line: 695 2 multi.jl; send_msg_; line: 172 2 serialize.jl; serialize; line: 74 2 serialize.jl; serialize; line: 299 2 serialize.jl; serialize; line: 130 2 serialize.jl; serialize; line: 299 1 dict.jl; serialize; line: 369 1 serialize.jl; serialize_type; line: 278 1 serialize.jl; serialize

How to install a julia package offline in Julia 1.0?

丶灬走出姿态 提交于 2020-02-02 03:17:32
问题 I have my own julia package works well on Julia 0.6. When I try to upgrade to julia 1.0, I found it's more difficult to add my own package in Julia 1.0. I cannot just put it under pkg.dir(). In my situation, the package is just several files on my local disk and don't rely on anything else except julia itself. I could use it with 'generate' and 'activate' in the new package manager, however, after restart the REPL, I have to redo the 'generate' and 'activate'. Is there a way to install the

What is the correct way to save and retrieve dictionaries in Julia?

纵饮孤独 提交于 2020-02-01 03:22:22
问题 I have seen that Julia adecuately interprets "MAT" files which have structures in them which are read as dictionaries without problem. Now I have created a dictionary of my own, which has the following structure (String, String)=> [ Int, Int, Int] on each entry. I can save it with writeddlm and it produces a very orderly tabular text file, separated by tabs ( \t ), but then I cannot retrieve it without doing a LOT of parsing. If I use readdlm I get an array of type Any, with the very

Julia ---- String 字符串类型常用操作

让人想犯罪 __ 提交于 2020-01-31 00:22:16
1、字符类型String的一些特点 Julia Strings 有几个值得注意的高级特征: (1)Julia中用于字符串(和字符串文本)处理的的内置类型是string。它使用UTF-8编码,并支持所有的的Unicode字符。(提供了transcode()函数,用于转换为其他程序的Unicode编码或从其他程序的Unicode编码转换为自己的Unicode编码。) (2)所有字符串类型都是抽象类型abstract string的子类型,其他外部包也会定义额外的抽象字符串子类型(例如,用于其他编码)。如果定义的函数需要字符串参数,则应将参数类型声明为AbstractString,以便接受其他的字符串类型。 (3)像C和Java一样,但是与大多数动态语言不同,Julia有一个表示单个字符的一级类型,称为Char。这只是一种特殊的32位原语类型,其数值表示Unicode编码值。 (4)与Java一样,Julia的字符串是不可变的:AbstractString对象的值不能更改。要使用不同的字符串,可以从其他字符串的部分构造新字符串。 (5)从概念上讲,字符串在存储上类似 字符数组 ,所以它每一位的单个元素都是可以提取的:对于某些索引值,如果不返回字符值,就会引发异常。它允许通过编码表示的字节索引而不是通过由字符索引来高效地对字符串进行索引

Julia - Parallel mathematical optimizers

断了今生、忘了曾经 提交于 2020-01-24 20:01:10
问题 Im using GLPK with through Julia, and I need to optimize the same GLPK.Prob repeatedly. What changes between each optimization is that some combination of variables gets fixed to 0 simply put in pseudocode lp = GLPK.Prob() variables_to_block = [[1,2,3], [2,3], [6,7], [19,100,111]...] for i in variables_to_block block_vars(lp, i) simplex(lp) restore_vars(lp, i) end when I then run this, it looks like CPU1 acts as a scheduler, staying in the 9-11% range, and the load on CPU3 and CPU4 alternates

Julia: How to give multiple workers access to functions that are 'include(…)' into a module?

痞子三分冷 提交于 2020-01-24 18:56:36
问题 I have the following test module (MyMod.jl) to store some functions in Julia. Some of the core functions are written in serial. Other functions call the core functions in parallel. module MyMod export Dummy,distribute_data,recombine_data,regular_test,parallel_test function Dummy(icol,model,data,A,B) nz,nx,nh = size(model) # = size(A) = size(B) for ih = 1:nh for ix = 1:nx for iz = 1:nz data[iz,icol] += A[iz,ix,ih]*B[iz,ix,ih]*model[iz,ix,ih] end end end end function distribute_data(X, obj_name

Pass arguments to @kwdef struct programmatically

与世无争的帅哥 提交于 2020-01-24 18:50:07
问题 Pass arguments to @kwdef struct programmatically The issue I have this struct: Base.@kwdef struct example_struc Latitude::Float64 = 9.9 # Latitude (degree) Longitude::Float64 = -83.7 # Longitude (degree) end @kwdef allows me to instantiate an example_struc() without giving all arguments thanks to the defaults, e.g. : julia> a= example_struc(Longitude= 40.0) julia> a.Latitude 9.93833 julia> a.Longitude 40.0 I would like to instantiate it programmatically (from a tuple read in a file), by

Julia: Can you set a time limit on eval

拟墨画扇 提交于 2020-01-24 17:35:06
问题 I am currently writing a simple IRC bot in Julia to get more familiar with it, and I made my own math thing for calculating users input. The problem is that it can take math problems that take insane amounts of time to run, and thus disconnecting from the IRC server due to ping timeout. How would I run eval() on a expression, without this problem. I was thinking either limiting the time eval() is allowed to use, or some multi threading. 回答1: You could do the following (pseudo code): addprocs

Module aliasing in Julia

筅森魡賤 提交于 2020-01-24 02:23:06
问题 In python you can do something like this to let you use a shortened module name: >>> import tensorflow as tf From then on you can refer to tf , instead of having to type tensorflow everywhere. Is something like this possible in Juila? 回答1: Yep, you can just assign the module to a new name. import JSON const J = JSON J.print(Dict("Hello, " => "World!")) I highly recommend to use the const because otherwise there will be a performance penalty. (With the const , there is no performance penalty.)