You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m trying to make some highly async code interrupt-friendly with try-catches, and most of the time it works, but every so often I hit this. Is there any way to figure out what it was doing in julia code at the time?
^Cfatal: error thrown and no exception handler available.
InterruptException()
jl_mutex_unlock at /Users/ian/Documents/GitHub/julia/src/./locks.h:139 [inlined]
jl_task_get_next at /Users/ian/Documents/GitHub/julia/src/partr.c:475
poptask at ./task.jl:744
wait at ./task.jl:752 [inlined]
task_done_hook at ./task.jl:478
_jl_invoke at /Users/ian/Documents/GitHub/julia/src/gf.c:0 [inlined]
jl_apply_generic at /Users/ian/Documents/GitHub/julia/src/gf.c:2373
jl_apply at /Users/ian/Documents/GitHub/julia/src/./julia.h:1690 [inlined]
jl_finish_task at /Users/ian/Documents/GitHub/julia/src/task.c:208
start_task at /Users/ian/Documents/GitHub/julia/src/task.c:832
(though it's a rather big `if` about whether that's actually something we want to support)
There's a lot of things where people design `AbstractArray` functions to support arbitrary offsets, but for the most part assume unit spacing. If we wanted better irregularly spaced array support, we'd likely need functions like `first(::AbstractArray, ::Int)`
I don't see how that'd be a concern. Shouldn't it just return the same type as `getindex` on a slice would?
With `Array`s, you can just do `arr[begin:begin+3]`, but it would be nice to have a `first` method like for strings.
No, not really. The reason it exists for `AbstractString` is that indexing them is a bad idea when unicode is involved:
julia> first("∀ϵ≠0: ϵ²>0", 3)
"∀ϵ≠"
julia> "∀ϵ≠0: ϵ²>0"[1:3]
ERROR: StringIndexError("∀ϵ≠0: ϵ²>0", 3)
Stacktrace:
[1] string_index_err(::String, ::Int64) at ./strings/string.jl:12
[2] getindex(::String, ::UnitRange{Int64}) at ./strings/string.jl:250
[3] top-level scope at REPL[3]:1
Is there some fundamental reason why this method doesn't/shouldn't exist?
> first([1,2,3], 3)
ERROR: MethodError: no method matching first(::Array{Int64,1}, ::Int64)
i have a small widget with sliders in pluto.jl, i've been trying to add a "reset" button to make them go back to default values. anyone can help with this?
Is there a known way to "reparametrize" a struct in a generic way? That is given an object of type `A{T}` I would like to be able to return a new object of type `A{S}` (taking care of the conversion from `T` to `S` manually). If I have a single type it's easy enough, I can define
reparametrize(a::A{T}) where T = A{S}( #convert internal params to S here# )
But if I want `A` not to be more generic i.e. `A <: SuperType` I can't get my head around how do it to get a function with the following signature
reparametrize(a::A) where {T, A <: SupertType{T})
Is there any way to limit the stacktrace from ~20 levels of depth to just the top 5 levels or something like that? The stacktrace often takes up my entire screen
Is there any reason why inv([x]) has a missing method (i.e. 1x1 arrays do not have an inverse)? Is it at all ambiguous to just write?
inv(x::Array{Int64,1}) = [1/x[1]]
A beginner’s issue with metaprogramming: Say we want to define a macro that substitutes input expression into code and the resulting expression is afterwards evaluated in the caller’s scope. like this
macro foo(ex)
:(Array{Int64}(undef, $ex))
end
let
a = [1, 2]
@foo length(a)
end
I’d like to substitute the `ex` with `length(a)` and evaluate it within the local scope. However, it doesn’t work: The $ does the expansion and finds out that `a` is missing in the macro scope, while `ex` can’t be used either. Any hint?
How should I deal with n x m matrices where I want to extract the size, but one of n or m is possibly 1, hence Julia returns a single value rather than a tuple?
size([2, 1]) = (2,)
I need to fill in an upper triangular matrix with zeros of sizes that depend on the size of its surrounding blocks.
I am writing tests for a package where a method needs some user input(using readLine()). Is there any way I can get julia to automatically send the input when the readLine() method is supposed to take an input?
Hello community, is it possible to retrieve the type and size of input & output arguments of a function? E.g. input: Float64 vector of length N and output Int array of size KxL? This would be usefull for troubleshooting I guess:
`typeof(J_AD)`
`var"#17#18"`
Or am I missing something? Thanks
I have one super simple question, say we have a dataframe `df` with two columns `share` and `year`, how to create a new column `res_share` which is the residual share in each year? In R that would be: `df %>% group_by(year) %>% 1-sum(share)`. But somehow I can't figure out how to do this in Query (or in plain Julia without writing ugly loops)
Hey folks. I’m trying to use Optim.jl for a small problem but keep running into precompile issues and the errors don’t seem to have any useful information (to my best knowledge). Any ideas what could be causing the issue (error posted in thread)?
Thank you for bearing with me, good old XY problem I suppose – as well as not continuing in an ancient thread elsewhere. Background here: <https://julialang.slack.com/archives/CBF3Z1D7V/p1602646185191500> What I am trying to achieve is patching Pkg to include a few lines to apply necessary patches for binaries to run on NixOS – the lines themselves are ~5 and not scary. However, as Pkg is in base that would mean touching the system image. Ideally, I would like to make this work without rebuilding Julia from source (this is the “easy” way) so that one can rely on the official binaries to the largest extent possible on a wonky OS like NixOS.
Is there a way to dispatch on keys of NamedTuples? Like:
struct Foo end
struct Bar end
tnt = (Foo() => anything1, Bar() => anything2) # not allowed, but similar to NamedTuple
@test getproperty(tnt, Foo()) == anything1
@test getproperty(tnt, Bar()) == anything2
Or are there types like this defined somewhere?
Eyo! what is UP. Just like "mean." can find the mean of multiple lists at once, is there then one function that can find the standard deviation or some kind of spread measure?
Is there any way to dispatch a function for a type alias? Or do I have to make a struct which minimally wraps the alias and reimplement the methods which I wanted to get from the alias? Consider the specific example of creating an alias for `Dict{Symbol, Int}` . This type has a bunch of nice methods, but one might also imagine that I'd like to distinguish between my inhabitants of it and inhabitants of my alias with, for example, `Base.show` .
while trying to update `Franklin.jl` I ran into the error `ERROR: ArgumentError: Unsupported architecture 'aarch64' for macOS`. I tried running `pkg> update`and `pkg> resolve` as suggested here: <https://discourse.julialang.org/t/unsupported-architecture/48786>, but that did not help. I am using julia 1.5.0 and windows 10. Any suggestions what I should do?
How can I log both to console as well as a file (and flush after each log line)? Basically I am trying to combine the following into the same global logger:
logger = ConsoleLogger(io, <http://Logging.Info|Logging.Info>)
global_logger(logger)
logger = ConsoleLogger(stdout, <http://Logging.Info|Logging.Info>)
global_logger(logger)
I was wondering what is the most Julia way to return data. I have a function that can return two different results. This is what I have so far
function bar()
res1 = zeros(Float64, 1000)
res2 = zeros(Float64, 1000)
# algorithm to fill in res1 and res2
return res1, res2
end
but maybe I am thinking of using a `kwarg`
function bar(;result_type)
res1 = zeros(Float64, 1000)
res2 = zeros(Float64, 1000)
# algorithm to fill in res1 and res2
if result_type == :first
return res1
else
return res2
end
end
I like the second option because there is code downstream which assumes `bar()` returns a single array (but that's really not that big of a deal). Third option would be to use a struct?
struct MyResults
res1::Array{Float64, 1}
res2::Array{Float64, 1}
end
function bar()
res1 = zeros(Float64, 1000)
res2 = zeros(Float64, 1000)
# algorithm to fill in res1 and res2
res = MyResults()
res.res1 = res1
res.res2 = res2
return res
end
but I think this is unneccesarily making things complicated
Is it possible to get the index of an array when using `map` I have code like this
res = map(myarray) do x
do stuff with x
do special things if x is the first element
end
but I don't really know how to do the second item there
I have a bewildering situation. I have generated some `Expr` , let's call it `code` . Now if I do
function foo()
$code
end
it works. But if I do
# Print code to file
open(io -> println(io, code), "foo.jl", "w")
# read in code
code2 = Meta.parse(String(open(read, "foo.jl")))
function foo()
$code2
end
then it errors. Should these two behave the same? Edit: Figured it out, see thread.
It happens quite often (from time to time) that I have a set of elements, and want to create a dictionary mapping each unique element in the set to the number of occurrences of it in the set, like this:
count_dict = Dict(map(element -> element => count(element .== my_set), unique(my_set)))
Does there exists a function for this
(like I can manage without, but it seemed like something which might exist, and if it does, I should ask)
Thank you <@USU9FRPEU>, I ended up reading a slightly more general one (<https://julialang.github.io/PackageCompiler.jl/dev/devdocs/sysimages_part_1/>), but now I feel much more comfortable with the process.
Follow-up question: If I want to change definitions in the base system image (rather than add another module), I suppose I would change the code in Base, find a way to unload the module, and then apply the same logic described in the link above?
Sorry if this is “too advanced” for the help desk.
I'm looking for an iterator that generates the same output as
Base.Iterators.product([0:1 for i in 1:n]...)
but where the output is ordered in the total number of 1s. So, the first element should be all zeros, then the next block are all the `(0,...,0,1,0,...0)`, before the elements with two 1s, and so on.
Another option that would work for me would be something akin to `Itertools.subsets` but where the output is ordered in the size of the subsets.
Hello, in matlab language, we can use figure(1) and figure(2) to creat two independent plots. How should I do in Julia language? It shows that in Julia,
x = plot( 1:10, rand(10, 1 ) ) # x-plot
y = plot( 1:10, rand(10, 1 ) ) # y-plot
the screen will show only the second plot, and one has to use display function to show x-plot or y-plot, but not both. Google tells that an option of plot,
"reuse = false", of y-plot will solve this problem in REPL, but it shows that this does not work in script or function environment. I do not want to do subplot either.
Is there any trick to solve this problem?
How do I make sure that channels are closed properly when a producer or consumer fails, without the following to deadlock:
producer(c1, c2) = foreach(x -> (put!(c1, x); put!(c2, x)), 1:3)
consumer1(c) = foreach(x -> println("One: ", x), c)
consumer2(c) = foreach(x -> println("Two: ", x), c)
@sync begin
c1 = Channel()
c2 = Channel()
t = @async producer(c1, c2)
bind(c1, t)
bind(c2, t)
@async consumer1(c1)
@async consumer2(c2)
end
The `bind` only works for errors in `producer`, but not `consumer`.
Hello,
I hope this is not a very dump question. I would like to associate a manifest.toml to a .jl file. Is it possible or do I need to create a package?
I am trying to implement `rref` in a modulo field, but I am having trouble with all-zero rows. I wonder if someone could take a look at my code (in thread) and see where I am going wrong, because I’m at a loss…
How might I go about writing a function that takes in a matrix `G` and a number `m` (which is the modulus of the field), and outputs all unique linear combinations?
I have a feeling I need to use `@nloops`, so I have written this:
@generated function get_codewords(G::AbstractArray, ::Val{n}, m::Integer) where n
quote
Base.Cartesian.@nloops $n i d -> 0:m-1 begin
wᵢ = vec([(Base.Cartesian.@ntuple $n i)...]) .* Base.Cartesian.@nextract 1 x d -> G[d, :]
println(wᵢ)
end
end
end
get_codewords(G::AbstractArray, m::Integer) = get_codewords(G, Val(size(G, 1)), m)
But this is not quite what I want. Any ideas? I am a little new to the Linear Algebra game in Julia, so I am probably _way_ overcomplicating it…
I somehow seem to have failed to wrap my head around the docs. But is there any way to rebuild/build a system image without needing a complete checkout of the Julia source tree?
Would anyone tell me how to interrupt `Optim.optimize`? I tried `cntr+c` but it doesn't work.. It will just continue to optimize unless I kill the whole Julia session
Would anyone with expertise in GTK be willing to help me with this issue here: <https://github.com/JuliaGraphics/Gtk.jl/issues/529>
In short, what I am trying to do is grab a previously created GTK window that is created by a Julia script and "recycle" it in such way as to not have to open and close a new GTK window every single time I run the script. I want to use the same GTK each time I run my script. How do I do this?
Why is `\endash` and `\emdash` listed in the <https://docs.julialang.org/en/v1.5/manual/unicode-input/|unicode support> but when I use it I get `syntax: invalid character "–" near column 1`?…
If I have an identity matrix followed by some other stuff (e.g., `[1 0 0 2 3 0; 0 1 0 1 2 2; 0 0 1 4 3 0]`), is there a way in Julia to return only the part of the matrix that isn’t the identity? E.g., return `[2 3 0; 1 2 2; 4 3 0]`?
Is there a way to plot with a second y axis (say, on the right) on a single plot? I didn't see anything in the Plots.jl examples or tutorial and stackoverflow wasn't much use either... I tried `axis=:right`, but it must be an unknown symbol
I encountered some strange behaviour while testing the speed of sampling 1 out of 3 values with specified sampling weights. One of the values is null so I mistakenly used `Nothing` to represent it (instead of `nothing`, whose type is actually Nothing). The code is something like this:
M = M_trans(params...)
@time for i in 1:1000000
sample([1, 0, Nothing], aweights(M[s0, :]))
end
which returns `0.640328 seconds (5.00 M allocations: 289.917 MiB, 4.92% gc time)`. I decided to fix it by using `nothing` but unexpectedly this results in a >10x decrease in speed: `8.461066 seconds (7.00 M allocations: 350.952 MiB, 0.42% gc time)`.
Ultimately I'll just use an integer to encode the null value which is faster than both but I'm just curious about this behaviour. Should I avoid using `nothing` at all costs?
Has anyone run into an issue with `using Flux` inside of a package lately? As of a couple hours ago, I get a bunch of errors about methods being overwritten and `incremental compilation may be fatally broken for this module`
I made an issue about it, but I'm really not sure what's going on at all: <https://github.com/FluxML/Flux.jl/issues/1370>
The Julia Artifacts string macro `artifact"blabla"` appears to be dispatched on REPL behavior (only then it will look for the `toml` file in `pwd()`): <https://github.com/JuliaLang/Pkg.jl/blob/aaf4e6e8ab784f7435c1bdc56832bc03e014dedb/src/Artifacts.jl#L1046> It fails for me when using it in a `notebook` environment (Basically doesn't find `Artifacts.toml`). Are there simple work-around solutions?
I have a 2d array I create like `a = [rand(4) for i in [0]]` (simplified for clarity) and I want to broadcast `cos()` over it. However `cos.(a)` yields `MethodError: no method matching cos(::Array{Float64,1})` . What am I missing?
The following works fine:
julia> using Dates
julia> Dates.DateTime("2020-10-22T16:52:14.409Z", dateformat"yyyy-mm-dd\THH:MM:<http://SS.sZ|SS.sZ>")
2020-10-22T16:52:14.409
Now if I add to it `using` or even `import` of `TimeZones`, then now the same code fails:
julia> using Dates
julia> import TimeZones
julia> Dates.DateTime("2020-10-22T16:52:14.409Z", dateformat"yyyy-mm-dd\THH:MM:<http://SS.sZ|SS.sZ>")
ERROR: ArgumentError: Unable to parse date time. Expected directive DatePart(Z) at char 22
Stacktrace:
[1] macro expansion at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/parse.jl:104 [inlined]
[2] tryparsenext_core(::String, ::Int64, ::Int64, ::DateFormat{Symbol("yyyy-mm-dd\\THH:MM:<http://SS.sZ|SS.sZ>"),Tuple{Dates.DatePart{'y'},Dates.Delim{Char,1},Dates.DatePart{'m'},Dates.Delim{Char,1},Dates.DatePart{'d'},Dates.Delim{Char,1},Dates.DatePart{'H'},Dates.Delim{Char,1},Dates.DatePart{'M'},Dates.Delim{Char,1},Dates.DatePart{'S'},Dates.Delim{Char,1},Dates.DatePart{'s'},Dates.DatePart{'Z'}}}, ::Bool) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/parse.jl:38
[3] macro expansion at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/parse.jl:150 [inlined]
[4] tryparsenext_internal at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/parse.jl:125 [inlined]
[5] parse(::Type{DateTime}, ::String, ::DateFormat{Symbol("yyyy-mm-dd\\THH:MM:<http://SS.sZ|SS.sZ>"),Tuple{Dates.DatePart{'y'},Dates.Delim{Char,1},Dates.DatePart{'m'},Dates.Delim{Char,1},Dates.DatePart{'d'},Dates.Delim{Char,1},Dates.DatePart{'H'},Dates.Delim{Char,1},Dates.DatePart{'M'},Dates.Delim{Char,1},Dates.DatePart{'S'},Dates.Delim{Char,1},Dates.DatePart{'s'},Dates.DatePart{'Z'}}}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/parse.jl:282
[6] DateTime(::String, ::DateFormat{Symbol("yyyy-mm-dd\\THH:MM:<http://SS.sZ|SS.sZ>"),Tuple{Dates.DatePart{'y'},Dates.Delim{Char,1},Dates.DatePart{'m'},Dates.Delim{Char,1},Dates.DatePart{'d'},Dates.Delim{Char,1},Dates.DatePart{'H'},Dates.Delim{Char,1},Dates.DatePart{'M'},Dates.Delim{Char,1},Dates.DatePart{'S'},Dates.Delim{Char,1},Dates.DatePart{'s'},Dates.DatePart{'Z'}}}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/io.jl:482
[7] top-level scope at REPL[8]:1
Looks like it is a bug and I reported it <https://github.com/JuliaTime/TimeZones.jl/issues/303|here>. But in the meantime, how can I work around this? (given that I do need to use both `Dates` and `TimeZones`)
Hello, for this code
#lower power flow limit
@constraint(wildfire_model,
-ref[:branch][l]["rate_a"] <=
sum(SF[l_index,j]*p[j] for j in 1:length(ref[:bus]))
+ sum(PSDF[l_index,j]*alpha[j] for j in 1:length(ref[:branch])))
#upper power flow limit
@constraint(wildfire_model,
sum(SF[l_index,j]*p[j] for j in 1:length(ref[:bus]))
+ sum(PSDF[l_index,j]*alpha[j] for j in 1:length(ref[:branch])))
<= ref[:branch][l]["rate_a"])
I am getting this error `syntax: "<=" is not a unary operator` . This is in JuMP. I am not sure what I did wrong
I am struggling on a data structure dilemma. I have a time series data set spread out across five different file formats. File 1 contains the time series, File 2 and 3 contains about how the data collection instrument was set up for that particular time series, File 4 contains additional time series information, and File 5 contains further information on the data collection instrument. These files exist for nearly 30 separate data recording sessions and each file could contain differing information that would be important for analysis. In total, this comes to about 3 billion data entries spread across these files.
How best could I structure this data? I have looked at RecursiveArrayTools.jl and thought that waspromising, AxisArrays.jl may also work as it can get me away from dictionaries, and AxisIndices (which looks like it builds on top of AxisArrays and makes it even better). Does anyone have any suggestions on what I should do here? Thanks for the help everyone! :smile:
I am discovering the joys and headaches of Named Tuples. How can I make this work?
`function nameparts(v)`
`t = split(v,':')`
`length(t) < 2 ? (nothing,t[1]) : (t[1],t[2])`
`end`
`struct QName{T<:AbstractString}`
`pfx::Union{T,Nothing}`
`nm::T`
`end`
`QName(nm::AbstractString) = QName(nameparts(nm)...)`
`struct ID{T<:AbstractString}`
`id::T`
`end`
`attr = Dict("base"=>"xs:string")`
`atts = @NamedTuple{base::QName, id::Union{Nothing,ID}}`
`s = string.(fieldnames(atts))`
`vals = get.(Ref(attr), s, nothing) #vals will be strings or nothing`
Now I want to instantiate the types to create a result tuple that looks like
`(QName{SubString{String}}("xs", "string"), nothing)`
…but instantiating the NamedTuple gives an error
`maybe = atts(vals)`
ERROR: MethodError: Cannot `convert` an object of type
String to an object of type
QName
Closest candidates are:
convert(::Type{T}, ::T) where T at essentials.jl:171
QName(::AbstractString) at /Users/doug/dev/XSDJ/src/ex.jl:10
QName(::Union{Nothing, T}, ::T) where T<:AbstractString at /Users/doug/dev/XSDJ/src/ex.jl:7
What am I missing? Do I need to implement new methods for `convert` ?
I have a `t=(;a=f, b=g)` named tuple of functions and I want to transform this in a named tuple of return values, such `ev(t, x)` gives `(;a=f(x), b=g(x))` The tricky part is reading the key names from the argument type of `t` of the function `ev` and use this somehow to create a new named tuple...
Is there a neat way of figuring out if a bitstype has a specific bit layout? For example, right now I do
function iszero(x::NTuple{16, UInt8})
r = Ref(x)
ptr = Ptr{UIn128}(pointer_from_objref(r))
return iszero(unsafe_load(ptr))
end
Any idea what is wrong?
struct StVenant_rakenne
Parametrit::Dict
Johdannaisparametrit::Dict
Joki::SharedArray
end
...
Johdannaisparametrit = Johdannaiset(s.Parametrit)
...
function Johdannaiset(Parametrit::Dict)
dX = Parametrit["Pituus"] / (Parametrit["Laskentapisteet"] - 1)
So = (Parametrit["Pohja_alkukorko"] - Parametrit["Pohja_loppukorko"]) / Parametrit["Pituus"]
x = Dict{String,Float64}("dX" => dX, "So" => So)
return x
end
This gets "ERROR: LoadError: MethodError: no method matching -(::String, ::Int64)
Closest candidates are:
-(::Missing, ::Number) at missing.jl:115
-(::BigInt, ::Union{Int16, Int32, Int64, Int8}) at gmp.jl:532
-(::BigFloat, ::Union{Int16, Int32, Int64, Int8}) at mpfr.jl:425
..."
Is there a way to catch a warning? I want to redefine some constants, but instead of triggering a whole list of warnings, I thought it might be better to catch them and print a single one.
Hi, I was just glancing at <https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/> and in the table I saw that the boolean has 8 bits. Why does it have 8 instead of 1 ...?
What's the best way currently to get `Pkg` to run in a reasonable time on Windows and Julia 1.5.2? Updating the registry currently takes something like 5 minutes for me, part of which is probably my lovely corporate antivir which I can't disable
Could anyone point out why the following is happening? If `t0 ≤ t < t1 == true`, `ExcitatoryConductance` gives `ge = Ne*gbar*(finf+(f0-finf)` and ignores `exp(-t/tau)`. Does this have something to do with my usage of constants?
Sorry if I am cluttering up the channel, but I also can’t figure out how to get a function to act on the innermost element of an abstract array? I want:
julia deepsymbol([[1 2 3], [4 5 6]])
2-element Array{Symbol,1}:
[Symbol(\"1\") Symbol(\"2\") Symbol(\"3\")]
[Symbol(\"4\") Symbol(\"5\") Symbol(\"6\")]
Broadcastring `Symbol` makes the outer-most elements in the array `Symbol`s, and I have tried defining
julia> deepsym(a::Number) = a
deepsym (generic function with 1 method)
julia> deepsym(a) = Symbol.(deepsym.(a))
deepsym (generic function with 2 methods)
But that makes _everything_ symbols. Any ideas? :slightly_smiling_face:
How can I use `where T` with a return type in a one-line function?
julia> function myfunc(x::T)::T where T
return x^2
end
myfunc (generic function with 1 method)
julia> myfunc(x::T)::T where T = x^2
ERROR: UndefVarError: T not defined
julia> myfunc(x::T) where T = x^2
myfunc (generic function with 1 method)
I have a package with Python dependencies that uses `Base.prompt` to ask users if it should try auto-installing the dependnecy using either conda or pip. We need the Python package when precompiling to build docstrings. But it looks like `Base.prompt` never prompts the user during precompilation, so it fails. Any suggestions?