[julia-users] Re: Julia 0.5 Highlights
Does that mean that an empty array comprehension is always Array{Any}? that array comprehensions are now type-inference-independent. That means > that the type of the resulting array only depends on the actual types of > values produced, not what the compiler can prove about the expression in > advance. >
[julia-users] Re: Representation of a material conditional (implication)
Indeed. implies(p::Bool, q::Bool) = q^p perjantai 7. lokakuuta 2016 10.25.06 UTC+3 Fengyang Wang kirjoitti: > > The ^ operator can be used for implication. Due to Curry-Howard, > implication is isomorphic to function abstraction, which combinatorially > can be counted using the exponentiation function. > > On Thursday, October 6, 2016 at 12:10:51 PM UTC-4, Kevin Liu wrote: >> >> How is an implication represented in Julia? >> >> >> https://en.wikipedia.org/wiki/Material_conditional#Definitions_of_the_material_conditional >> >
[julia-users] Re: eval in current scope
You might be able to wrap your expression so as to create a function instead, and call the function with the values of the variables that the actual expression depends on. In Python, because I haven't learned to construct expressions in Julia yet and don't have the time to learn it now: def f(x): return eval("lambda x: x + 1")(x) tiistai 27. syyskuuta 2016 12.28.40 UTC+3 Marius Millea kirjoitti: > > Hi, is there a way to "eval" something in the current scope? My problem is > the following, I've written a macro that, inside the returned expression, > builds an expression which I need to eval. It looks like this, > > macro foo() > quote > ex = ... > eval_in_current_scope(ex) > end > end > > Now, you might say I'm using macros wrong and I should just be doing, > > macro foo() > ex = ... > end > > > but in this case when I build "ex", it needs to occur at runtime since it > depends on some things only available then. So is there any way to go about > this? Thanks. > >
[julia-users] Re: Array of vectors in type definition
type croc teeth :: Int64 legs :: Int64 sons :: Vector{Matrix{Float64}} croc() = new(0,0, Vector{Matrix{Float64}}()) croc(th, gs) = new(th, gs, Vector{Matrix{Float64}}()) croc(th, gs, ns) = new(th, gs, ns) end reptile = croc() reptile.teeth = 4 reptile.legs = 80 push!(reptile.sons, [[3.0 1.0];[4.0 1.0]]) another = croc(80, 4) sons = Vector{Matrix{Float64}}() push!(sons, rand(3,1)) push!(sons, rand(4,1)) onemore = croc(80, 4, sons) @show reptile @show another @show onemore
[julia-users] Re: Array of vectors in type definition
perjantai 22. heinäkuuta 2016 12.26.58 UTC+3 Jussi Piitulainen kirjoitti: > > I'm not sure how the square brackets would be used if you wanted a matrix > of matrices, but you could at least start with an empty one by writing > Matrix{Matrix{Float64}}(). And for an empty vector of matrices, as said, > Vector{Matrix{Float64}}. And Julia will show these types as Array{T,1} and > Array{T,2} instead of Vector and Matrix. > > Sorry, Vector{Matrix{Float64}}() to make a Vector{Matrix{Float64}}.
[julia-users] Re: Array of vectors in type definition
perjantai 22. heinäkuuta 2016 11.28.58 UTC+3 Ferran Mazzanti kirjoitti: > > Sorry for being so noob once again, but I'm getting close without getting > actually to it. > Could somebody tell me please how should I change the previous definition > of caw() as given by Jussi to make room > for a Vector of Arrays (I can fix them to dimension 2) instead of a Vector > of Vector? I'd like to be able to define it simllarly, > so that instances of caw() are initially empty and I push!() 2-dimensional > arrays into it... > My hobby: empty things. Array type has two parameters: element type and number of dimensions. Vector{Float64} is shorthand for Array{Float64,1}, and Matrix{Float64} is similar shorthand for Array{Float64,2}. A vector can be made by listing the elements in square brackets after the element type: julia> Matrix{Float64}[] 0-element Array{Array{Float64,2},1} Or as Stefan did using the type of the vector: julia> Vector{Matrix{Float64}}() 0-element Array{Array{Float64,2},1} There is no Matrix there but you can push! a Matrix there. Or you can start with a non-empty Vector that contains an empty Matrix: julia> Matrix{Float64}[Matrix{Float64}()] 1-element Array{Array{Float64,2},1}: 0x0 Array{Float64,2} The expression inside the square brackets makes an empty Matrix. I think they are changing this, but in the current release the type name before the square brackets makes a big difference when the element is an Array. I'm not sure how the square brackets would be used if you wanted a matrix of matrices, but you could at least start with an empty one by writing Matrix{Matrix{Float64}}(). And for an empty vector of matrices, as said, Vector{Matrix{Float64}}. And Julia will show these types as Array{T,1} and Array{T,2} instead of Vector and Matrix.
[julia-users] Re: Array of vectors in type definition
keskiviikko 20. heinäkuuta 2016 18.57.13 UTC+3 Ferran Mazzanti kirjoitti: > > Sorry guys again, > > I said it works as I tried it out and seemed to work. Now I'm not even > sure it does work, don't ask me why. I try now this > > type caw >legs :: Int64 >spots :: Vector{Vector{Float64}} >caw() = new() > end > > then I can do things like > z = caw() > which produce > > caw(4587026064,#undef) > > > Now the question is: how do I start adding vectors to z.spots? > > I've tried things like > > > push!(z.spots,[1.0]) > > > but then I get > > > LoadError: UndefRefError: access to undefined reference > while loading In[30], in expression starting on line 1 > > > Thanks for your help, > > > Ferran. > > > and now it does not complain > > On Monday, July 18, 2016 at 5:13:23 PM UTC+2, Ferran Mazzanti wrote: >> >> Guys, >> >> today I've tried to include a vector of vectors as part of atype >> definition, something like >> >> type caw >>legs :: Int64 >>spots :: Array{Float64}[] >> end >> >> but that fails. Shall I understand that it is not possible to define that >> in a type definition? I just wanted to include a structrure that could grow >> by adding more data dynamically... >> >> Any hint about this? >> >> Thanks for your kind help, >> >> Ferran. >> > julia> type caw legs :: Int64 spots :: Vector{Vector{Float64}} caw() = new(4587026064, Vector{Float64}[]) end julia> z = caw() caw(4587026064,Array{Float64,1}[]) julia> push!(z.spots, [1.0]) 1-element Array{Array{Float64,1},1}: [1.0] julia> z caw(4587026064,[[1.0]])
[julia-users] Re: Is empty map result type going to be fixed?
Thanks for the very current information. Seems the fate of empty comprehensions was uncertain a month ago. I'm again not sure how or whether it has been resolved, but otherwise there is a lot there that I really look forward to. The empty map type in your example seems to be what I would like and don't have in 0.4.6: it's been a struggle to get element types working under vcat or union in a function when it has empty arguments or no arguments; the mapping form of sum failed, too. tiistai 5. heinäkuuta 2016 18.11.43 UTC+3 David Gold kirjoitti: > > On this branch https://github.com/JuliaLang/julia/pull/16622 there is > > *julia> **map(length, String[])* > > *0-element Array{Int64,1}* > > > So, perhaps on 0.5 this will be "fixed". > > > > > > On Monday, July 4, 2016 at 2:58:07 PM UTC-4, Jussi Piitulainen wrote: >> >> I browsed through some Github issues where this was discussed, but I'm >> unclear on the outcome. It's complicated. >> >> Is the result of `map` on an empty array going to be typed correctly any >> time soon? Ever? In 0.5, maybe? A comprehension seems to work now (this is >> on 0.4.6, the generic Linux binary), while `map` still inherits the type >> of the empty input array: >> ```julia >> julia> cumsum(map(length, UTF8String[])) >> ERROR: BoundsError: attempt to access 0-element Array{UTF8String,1} >> at index [1] >> in cumsum at arraymath.jl:450 >> >> julia> cumsum([length(s) for s in UTF8String[]]) >> 0-element Array{Int64,1} >> >> ``` >> Some of my input arrays will be empty, so I need at least a temporary >> workaround, but should I give up on `map` altogether, or be patient? >> >
[julia-users] Is empty map result type going to be fixed?
I browsed through some Github issues where this was discussed, but I'm unclear on the outcome. It's complicated. Is the result of `map` on an empty array going to be typed correctly any time soon? Ever? In 0.5, maybe? A comprehension seems to work now (this is on 0.4.6, the generic Linux binary), while `map` still inherits the type of the empty input array: ```julia julia> cumsum(map(length, UTF8String[])) ERROR: BoundsError: attempt to access 0-element Array{UTF8String,1} at index [1] in cumsum at arraymath.jl:450 julia> cumsum([length(s) for s in UTF8String[]]) 0-element Array{Int64,1} ``` Some of my input arrays will be empty, so I need at least a temporary workaround, but should I give up on `map` altogether, or be patient?
[julia-users] Re: indexing over `zip(collection1, collection2)`
module Proof import Base: Zip, Zip2, getindex getindex(o::Zip, k::Int) = (o.a[k], o.z[k]...) getindex(o::Zip2, k::Int) = (o.a[k], o.b[k]) end
[julia-users] Re: indexing over `zip(collection1, collection2)`
> Yes, I meant python 2.x > There are no zip objects in Python 2. You can easily get the exact same effect (pull the full result into memory at once, allow indexing, slicing, sorting in place, everything) in Julia. collect(zip(...)) But in Julia, unlike Python, you should be able to implement getindex for zip objects yourself, at least if you are happy to allocate a new tuple at every call. They seem to have types Base.Zip (with fields a, z containing the data) and Base.Zip2 (with fields a, b containing the data). dump(zip("foo", "bar", "whatever")) That should actually be a nice exercise. I suppose indexing would just fail when the underlying data is not indexable.
[julia-users] Re: indexing over `zip(collection1, collection2)`
torstai 23. kesäkuuta 2016 21.18.22 UTC+3 Davide Lasagna kirjoitti: > > Is there any particular reason why `Zip` objects are iterable but not > indexable? Python allows that. > > Does Python now allow that? I'm still on 3.4 and didn't see anything relevant in the "What's new" for 3.5.
[julia-users] Re: How can I define an anonymous function with keyword arguments
maanantai 13. kesäkuuta 2016 4.53.14 UTC+3 Xiaoqing Rong-Mullins kirjoitti: > > The methods I've tried do not allow me to define an anonymous function > with keyword arguments: > > julia> VERSION > v"0.4.5" > > The following trick seems to work. I think this is called eta-expansion (in lambda calculus). julia> (function () function g1(a1,a2;a3=1) a1+a2+a3*2 end end)()(1,1) 4 julia> (function () function g1(a1,a2;a3=1) a1+a2+a3*2 end end)()(1,1; a3 = 0) 2 julia> (function () function g1(a1,a2;a3=1) a1+a2+a3*2 end end)()(1,1; a3 = 2) 6