julia

Why does julia not recognize the type of an array that is passed as a function argument, listing it as Any instead?

狂风中的少年 提交于 2020-01-04 06:37:26
问题 I am defining a function in julia that accepts a vector (specifically Vector{Complex128} ). When I look at the output of @code_warntype I see that the variable type is listed as Any . This can potentially have speed implications, as I understand. Here is a simple version of the code, for example: function abc(h::Vector{Complex128}) a=1+2 end The output from @code_warntype is julia> @code_warntype abc(zeros(Complex128,2)) Variables: #self#::#abc h::Any a::Int64 Body: begin SSAValue(0) = (Base

Julia custom type assignment

房东的猫 提交于 2020-01-04 06:13:57
问题 I try to assign multiple elements from a custom type in julia. However I don't know how to do it. Or in other words I would like to overload the assignment operator as to return a tuple of all the elements contained in the type. Here is the desired behavior: type foo a b end (a,b) = foo(1,2) a > 1 and here is the error message: ERROR: LoadError: MethodError: `start` has no method matching start(::foo) My take is that I need to implements some sort of iterator that takes care of the assignment

Julia dataframe where a column is an array of arrays?

牧云@^-^@ 提交于 2020-01-04 06:11:49
问题 I'm trying to create a table where each row has time-series data associated with a particular test-case. julia> df = DataFrame(var1 = Int64[], var2 = Int64[], ts = Array{Array{Int64, 1}, 1}) 0x3 DataFrames.DataFrame I'm able to create the data frame. Each var1 , var2 pair is intended to have an associated time series. I want to generate data in a loop and want to append to this dataframe using push! I've tried julia> push!(df, [1, 2, [3,4,5]]) ERROR: ArgumentError: Length of iterable does not

Julia dataframe where a column is an array of arrays?

不打扰是莪最后的温柔 提交于 2020-01-04 06:11:32
问题 I'm trying to create a table where each row has time-series data associated with a particular test-case. julia> df = DataFrame(var1 = Int64[], var2 = Int64[], ts = Array{Array{Int64, 1}, 1}) 0x3 DataFrames.DataFrame I'm able to create the data frame. Each var1 , var2 pair is intended to have an associated time series. I want to generate data in a loop and want to append to this dataframe using push! I've tried julia> push!(df, [1, 2, [3,4,5]]) ERROR: ArgumentError: Length of iterable does not

Printing to specific (runtime-determined) precision in Julia

≯℡__Kan透↙ 提交于 2020-01-03 19:18:42
问题 Given a value x and an integer n (assigned at runtime), I want to print x to exactly n digits after the decimal (after rounding if needed). print(round(x, n)) works fine for (x,n)=(3.141592, 3) but for (x,n)=(2.5,5) , it prints just 2.5 , not 2.50000 (5 digits after decimal point). If I knew n at runtime, say 5, I could do @printf("%.5f", x) But @printf being a macro needs n to be known at compile time. Is this possible using some show magic or something else? 回答1: Using the fresh new Format

Printing to specific (runtime-determined) precision in Julia

◇◆丶佛笑我妖孽 提交于 2020-01-03 19:18:26
问题 Given a value x and an integer n (assigned at runtime), I want to print x to exactly n digits after the decimal (after rounding if needed). print(round(x, n)) works fine for (x,n)=(3.141592, 3) but for (x,n)=(2.5,5) , it prints just 2.5 , not 2.50000 (5 digits after decimal point). If I knew n at runtime, say 5, I could do @printf("%.5f", x) But @printf being a macro needs n to be known at compile time. Is this possible using some show magic or something else? 回答1: Using the fresh new Format

Overload object comparison when adding to a set in Julia?

瘦欲@ 提交于 2020-01-03 17:11:45
问题 Is there a way to overload how Base.Set does its object comparisons in Julia? I tried overloading isequal and == , but my objects are still marked as different when they should be the same. E.g. type Test x y end function ==(a::Test, b::Test) return a.x == b.x && a.y == b.y end Set([Test(2,3), Test(2,3)]) gives Set([Test(2,3),Test(2,3)]) 回答1: A Set is a kind of Dict with values of type Void : ref type Set{T} <: AbstractSet{T} dict::Dict{T,Void} Set() = new(Dict{T,Void}()) Set(itr) = union!

Julia: Converting Vector of Arrays to Array for Arbitrary Dimensions

丶灬走出姿态 提交于 2020-01-03 13:02:16
问题 Using timing tests, I found that it's much more performant to grow Vector{Array{Float64}} objects using push! than it is to simply use an Array{Float64} object and either hcat or vcat . However, after the computation is completed, I need to change the resulting object to an Array{Float64} for further analysis. Is there a way that works regardless of the dimensions? For example, if I generate the Vector of Array s via u = [1 2 3 4 1 3 3 4 1 5 6 3 5 2 3 1] uFull = Vector{Array{Int}}(0) push!

Julia error using PyPlot - signal (11): Segmentation fault

喜夏-厌秋 提交于 2020-01-03 10:41:49
问题 Learning to use PyPlot with Julia programming language (Version 0.4.5), I've encountered an error while trying to produce a simple plot: julia> using PyPlot julia> x = linspace(0,100,1000) linspace(0.0,100.0,1000) julia> y = x.^2; julia> plot(x,y) signal (11): Segmentation fault unknown function (ip: 0x32736) Segmentation fault (core dumped) Someone knows what's going on here? 回答1: I can't reproduce your error when running on 0.4.6 . My thoughts would be: Update to latest version. Update all

Why is typeof hex or binary number Uint64 while type of decimal number is Int64?

爷,独闯天下 提交于 2020-01-03 09:17:20
问题 julia> typeof(-0b111) Uint64 julia> typeof(-0x7) Uint64 julia> typeof(-7) Int64 I find this result a bit surprising. Why does the numeric base of the number determine signed or unsgined-ness? 回答1: Looks like this is expected behavior: This behavior is based on the observation that when one uses unsigned hex literals for integer values, one typically is using them to represent a fixed numeric byte sequence, rather than just an integer value. http://docs.julialang.org/en/latest/manual/integers