Re: [julia-users] Macros generating Functions

2015-05-31 Thread Josh Langsfeld
I don't think this is correct actually. With Julia's metaprogramming abilities, all macros could be handled by runtime functions. The rule I follow is that macros should be used when some processing needs to be done at compile time / source-processing time. Usually, that's exactly when you wan

Re: [julia-users] Macros generating Functions

2015-06-01 Thread Josh Langsfeld
f any examples of macros in Base which define functions. > > Cheers, > > Tom > > > On Monday, 1 June 2015 02:35:28 UTC+10, Josh Langsfeld wrote: >> >> I don't think this is correct actually. With Julia's metaprogramming >> abilities, all macros could be ha

Re: [julia-users] map() vs list comprehension - any preference?

2015-06-17 Thread Josh Langsfeld
For me, map is 100x slower: julia> function f1(g,a) [Pair(x,g) for x in a] end f1 (generic function with 1 method) julia> function f2(g,a) map(x->Pair(x,g), a) end f2 (generic function with 1 method) julia> @time f1(2,ones(1_000_000)); 25.158 milliseconds (284

Re: [julia-users] map() vs list comprehension - any preference?

2015-06-18 Thread Josh Langsfeld
12:52:34 PM UTC-4, Seth wrote: > > Gah. I'm sorry. I can't reproduce my original results! I don't know why, > but the same tests I ran two days ago are not giving me the same timing. I > need to go back to the drawing board here. > > On Wednesday, June 17, 2015 at

[julia-users] Re: Is there a reason any(p, c) isn't lazy?

2015-06-18 Thread Josh Langsfeld
It seems 'any' calls 'mapreduce' which calls 'mapfoldl' which has a specialization that will stop computing in the case of searching for a single true or false value. However, it seems the call to mapreduce instead goes to a more specific method that doesn't implement this shortcut. If 'any' we

[julia-users] Re: Is there a reason any(p, c) isn't lazy?

2015-06-18 Thread Josh Langsfeld
0 > <https://github.com/JuliaLang/julia/issues/11750>. > > On Thursday, June 18, 2015 at 11:04:29 AM UTC-5, Josh Langsfeld wrote: >> >> It seems 'any' calls 'mapreduce' which calls 'mapfoldl' which has a >> specialization that will stop comput

Re: [julia-users] Performances: vectorised operator, for loop and comprehension

2015-06-19 Thread Josh Langsfeld
My results don't show a significant performance advantage of the comprehension. Averaging over 1000 runs of a million-element array, I got: f1 (vectorized): 10.32 ms f2 (loop): 2.07 ms f3 (comprehension): 2.05 ms f4 (map): 38.09 ms Also, as you can see here (https://github.com/JuliaLang/julia/b

[julia-users] Getting the length of a tuple type

2015-06-24 Thread Josh Langsfeld
What is the correct way to get the number of types inside of a T = Tuple{...} type? Is there anything better than length(T.types), which might be compatible with the 0.3 style ( (T1,T2,T3,...))?

[julia-users] Re: Getting the length of a tuple type

2015-06-24 Thread Josh Langsfeld
; On Wednesday, June 24, 2015 at 1:14:41 PM UTC-4, Josh Langsfeld wrote: >> >> What is the correct way to get the number of types inside of a T = >> Tuple{...} type? Is there anything better than length(T.types), which might >> be compatible with the 0.3 style ( >> (T1,T2,T3,...))? >> >

Re: [julia-users] Re: Getting the length of a tuple type

2015-06-25 Thread Josh Langsfeld
t 2:00 PM, Tony Fong wrote: > I have just put out an update to the Lint.jl master which should have some > examples of what you need. Hopefully this would fix the tuple length issue > for you. > > > On Wednesday, June 24, 2015 at 2:54:03 PM UTC-4, Josh Langsfeld wrote: >> >&g

Re: [julia-users] What's the best way to implement multiple methods with similar arguments?

2015-06-28 Thread Josh Langsfeld
The philosophy I try to follow is to use multiple dispatch when you don't care at the calling site what the types of your arguments are and therefore which method will be called. For example, consider the case when you receive some output from a library function and you either don't know or are

[julia-users] Re: Efficient way to compute X' diag(w) Y

2015-07-08 Thread Josh Langsfeld
Maybe I'm missing something obvious, but couldn't you easily write your own 'cross' function that uses a couple nested for-loops to do the arithmetic without any intermediate allocations at all? On Tuesday, July 7, 2015 at 6:24:34 PM UTC-4, Matthieu wrote: > > Thanks, this is what I currently do

Re: [julia-users] Re: Efficient way to compute X' diag(w) Y

2015-07-08 Thread Josh Langsfeld
reas Noack wrote: > You could, but unless the matrices are small, it would be slower because > it wouldn't use optimized matrix multiplication. > > 2015-07-08 10:36 GMT-04:00 Josh Langsfeld : > >> Maybe I'm missing something obvious, but couldn't you easily

[julia-users] Re: collect(a:b) vs. [a:b;] in v0.4

2015-07-10 Thread Josh Langsfeld
You can see the discussion about changing the deprecation suggestion here: https://github.com/JuliaLang/julia/pull/11369 I think people liked it because it's a bit of an abuse of terminology to call the [a:b;] form 'concatenation' when there is only one object being put into the array. The 'col

Re: [julia-users] Re: Which Packages Should be Registered?

2015-07-14 Thread Josh Langsfeld
Christoph and David, If you want your package to be useful to the world, how should new users in your domain find it? With a Google search? I'm of the same opinion of Jeffrey that anything that could be helpful to others should be registered in some capacity. Besides making it easier to find,

[julia-users] Re: How to best define an EulerAngles type

2015-08-26 Thread Josh Langsfeld
You can always just make the arguments give all the parameters: type EulerAngles{T <: Number, Seq} angles::Vector{T} end EulerAngles{T}(seq, angles::Vector{T}) = EulerAngles{T,seq}(angles) julia> EulerAngles(321, [pi,pi/2,0]) EulerAngles{Float64,321}([3.141592653589793,1.57079632679489

[julia-users] Re: Getting type parameters from a parameterized types?

2015-09-11 Thread Josh Langsfeld
You can access the 'parameters' field of a type instance object. But the standard Julian way to get type parameters is to just define a helper function: typeparams{A,B}(::Type{T{A,B}}) = A,B On Friday, September 11, 2015 at 3:20:17 PM UTC-4, Erik Schnetter wrote: > > Is there a function in Juli

[julia-users] Dispatch on arbitrary wrapper types

2015-09-17 Thread Josh Langsfeld
I recently was stumped when I wanted to write a function that dispatched on 'ASCIIString' versus 'UTF8String' but then had to deal with a 'SubString{ASCIIString}'. It made me think that given Julia's prolific use of wrapper types, it would be very nice to be able to dispatch on a type T and als

[julia-users] Re: Dispatch on arbitrary wrapper types

2015-09-17 Thread Josh Langsfeld
Essentially, it would really cool to be able to do something like 'type SubString{T<: AbstractString} <:T ...' for dispatch purposes. 'SubString{ASCIIString} <: ASCIIString' would still return false in general. On Thursday, September 17, 2015 at 1:47:24 PM UTC-4

Re: [julia-users] Re: Dispatch on arbitrary wrapper types

2015-09-17 Thread Josh Langsfeld
re traits. There's discussion about > making them part of the core language eventually, but in the meantime, > check out https://github.com/mauro3/Traits.jl > > On Thu, Sep 17, 2015 at 2:16 PM, Josh Langsfeld > wrote: > >> Essentially, it would really cool to b

[julia-users] pkg.julialang.org test

2015-01-22 Thread Josh Langsfeld
This is a fairly minor topic, but thought I'd bring it up anyway. I noticed the pkg.julialang.org listings generate pass/fail info for the package tests by running the tests locally rather than hooking into Travis. This is a problem for me as my Travis script involves installing dependencies, an

[julia-users] Re: pkg.julialang.org test

2015-01-22 Thread Josh Langsfeld
e marked this way, for example. Either way, you can raise > an issue at https://github.com/IainNZ/PackageEvaluator.jl/issues to > discuss the specifics for your package. > > Regards > - > Avik > > On Thursday, 22 January 2015 14:51:16 UTC, Josh Langsfeld wrote: >>

Re: [julia-users] Re: pkg.julialang.org test

2015-01-22 Thread Josh Langsfeld
you have a suggestion for where to put a > link, please let me know - I've never been able to figure it out. > > Thanks, > Iain > > > On Thursday, January 22, 2015 at 10:29:54 AM UTC-5, Josh Langsfeld wrote: >> >> Thanks for the info. Unstated in my question

Re: [julia-users] Re: pkg.julialang.org test

2015-01-23 Thread Josh Langsfeld
at sort of thing. Except, I don't want it to be that conspicuous > because 99.99% visiting the package aren't package developers. > > On Thu, Jan 22, 2015 at 4:40 PM, Josh Langsfeld > wrote: > >> By a link, do you mean to the github repo for people to visit if >&

Re: [julia-users] Parametric vs Abstract typed collections, design question

2015-02-02 Thread Josh Langsfeld
As Jutho mentioned, a parametric type without a type parameter is just another abstract type so I don't think there would be any difference in performance. But if Foo and Bar have the same internal structure, are they really different types at all? You could always do a manual "type" dispatch b

[julia-users] Re: Type Annotations and Overloading Question

2015-02-04 Thread Josh Langsfeld
For me, option 1 looks the most Julian. Maybe the clunkiness is arising because the calc object shouldn't be a field of Atoms? Fields are just suppose to store data, not logic or methods. If a certain subtype of AbstractAtoms always uses the same calc object, then dispatching just on the atoms

[julia-users] Re: Type Annotations and Overloading Question

2015-02-04 Thread Josh Langsfeld
Sorry, disregard that last sentence which was supposed to have been edited out. On Wednesday, February 4, 2015 at 11:46:09 AM UTC-5, Josh Langsfeld wrote: > > For me, option 1 looks the most Julian. Maybe the clunkiness is arising > because the calc object shouldn't be a field of

[julia-users] Re: Type Annotations and Overloading Question

2015-02-04 Thread Josh Langsfeld
I'm very much enjoying thinking about this and considering what might be the most Julian approach > I thought one problem with not having "proper" inheritance is that this doesn't really help? Even small variations across AbstractAtoms types require a full implementation? Actually, I don't thi

Re: [julia-users] Re: Type Annotations and Overloading Question

2015-02-04 Thread Josh Langsfeld
On Wed, Feb 4, 2015 at 2:29 PM, Christoph Ortner wrote: If I read this correctly, then what you are saying is that I am allowed to > assume that my concrete abstract subtypes will contain certain fields, and > if they don't then too bad for them, they need to go and re-implement some > of the str

[julia-users] Re: Scanning the optional arguments of a function

2015-02-08 Thread Josh Langsfeld
At least for why is doesn't work, the eval runs in the scope of the current module, not in the local scope of the function: julia> myarg = "a string" "a string" julia> f(myarg::Int) = println(eval(:myarg)) f (generic function with 1 method) julia> f(10) a string I don't know if there is a wa

[julia-users] Re: Scanning the optional arguments of a function

2015-02-08 Thread Josh Langsfeld
> *eval(:myarg)* to *@eval $(myarg)*, the call prints *10*. > > On Sunday, February 8, 2015 at 10:57:43 PM UTC-5, Josh Langsfeld wrote: >> >> At least for why is doesn't work, the eval runs in the scope of the >> current module, not in the local scope of the f

[julia-users] Re: Scanning the optional arguments of a function

2015-02-09 Thread Josh Langsfeld
Here's a macro that just has the effect of combining the code that would check each variable's length into a short form. It refers to the input variables both by name and value. macro lencheck(l,vars...) exprs = Expr[] for v in vars sym = string(v) push!(exprs,:(if length

[julia-users] Re: Scanning the optional arguments of a function

2015-02-10 Thread Josh Langsfeld
he syntax for it is to elusive). > It seemed that iterating over variables using symbols would be the thing to > do, but maybe not. > > Cheers! > > On Monday, February 9, 2015 at 3:27:46 PM UTC-5, Josh Langsfeld wrote: >> >> Here's a macro that just has the effec

[julia-users] Re: Numerical precision of simple mathematical operations

2015-02-12 Thread Josh Langsfeld
I don't see why you are only concerned about the value being negative. The number itself is completely meaningless since your calculation basically does the floating-point equivalent of divide zero by infinity. Anything that comes out can't be remotely trusted. I think you will need to reformu

[julia-users] Re: Numerical precision of simple mathematical operations

2015-02-12 Thread Josh Langsfeld
behavior of dividing s3 by d. On Thursday, February 12, 2015 at 10:13:42 AM UTC-5, Josh Langsfeld wrote: > > I don't see why you are only concerned about the value being negative. The > number itself is completely meaningless since your calculation basically > does the floatin

Re: [julia-users] Array of functions - gets overwritten

2015-02-16 Thread Josh Langsfeld
I'm not entirely sure why, but it works if you assign an anonymous closure to f: f = () -> j This also requires the let block. On Monday, February 16, 2015 at 1:27:56 PM UTC-5, Stepa Solntsev wrote: > > I tried, it still doesn't work. > > function nice() > i=1 > while true > let

[julia-users] Re: Function that takes an abstract type and calls function depending on the concrete type passed.

2015-02-21 Thread Josh Langsfeld
If your initial knn function has logic that depends on the concrete type of tree being input, it's a sign you should refactor that logic into separate methods which are dispatched on by the concrete type. The simplest case of this would be to just pass that argument during setup to every _knn f

[julia-users] Re: splice! function. Instead of removing a single item, remove a collection of items stored in an array.

2015-02-23 Thread Josh Langsfeld
corrected_data = deleteat!(x, errors) should be what you're looking for. Alternately, a more functionally pure way to do it is to compute the good indices and then just do corrected_data = x[good_idx], though this will make a copy of those elements of x. On Sunday, February 22, 2015 at 3:14:11

[julia-users] Re: splice! function. Instead of removing a single item, remove a collection of items stored in an array.

2015-02-23 Thread Josh Langsfeld
st index first and work down > > for x=1:length(errors) > splice!(data,errors[x]) > end > > > > On Monday, February 23, 2015 at 8:17:29 AM UTC, Josh Langsfeld wrote: >> >> corrected_data = deleteat!(x, errors) should be what you're looking for. >>

Re: [julia-users] Re: Whats the deal with concatenation in 0.4!?

2015-02-25 Thread Josh Langsfeld
FYI, transposing currently doesn't work even on built-in arrays because it also calls transpose on each element as well. So it converts them all to Array{T,2} and then can't fit them back into a Array{Array{T,1},1}. On Wednesday, February 25, 2015 at 5:24:29 PM UTC-5, Jeff Bezanson wrote: > > Tr

Re: [julia-users] Re: Whats the deal with concatenation in 0.4!?

2015-02-25 Thread Josh Langsfeld
Assuming transposing works, you could do [[a,a,a]' ; [a,a,a]'] which isn't entirely horrible On Wednesday, February 25, 2015 at 5:50:04 PM UTC-5, Simon Danisch wrote: > > Okay... So how do I realize: > a = vec3(...) > [ a a a ; a a a] > > Well, all I think is, that arrays of arrays get treated li

Re: [julia-users] Re: Whats the deal with concatenation in 0.4!?

2015-02-25 Thread Josh Langsfeld
the shape, which makes it hard to predict, when something concatenates or > just constructs. > In this case, [b ; b] does indeed always have type Array{eltype(b)} and not Array{typeof(b)} (unless typeof(b) == Number). > > 2015-02-26 0:10 GMT+01:00 Josh Langsfeld : > >> Assuming

[julia-users] Re: Is string in Julia extendable?

2015-02-26 Thread Josh Langsfeld
It's equivalent to str = str * "def". I believe that's the case for all +=, *=, etc operators and all types. On Thursday, February 26, 2015 at 9:23:19 AM UTC-5, Jerry Xiong wrote: > > Considering below code: > str="abc" > str*="def" > Is the new string "def" just be appended after the memory spac

[julia-users] Re: Using ModX: Can scope avoid collisions & improve readability?

2015-03-02 Thread Josh Langsfeld
It's discussed in the FAQ so there must be a good reason for it, though no rationale is mentioned. http://docs.julialang.org/en/latest/manual/faq/#can-i-use-using-or-import-inside-a-function On Monday, March 2, 2015 at 3:00:21 PM UTC-5, Patrick O'Leary wrote: > > On Saturday, February 28, 2015 a

[julia-users] Re: General question about composite types

2015-03-03 Thread Josh Langsfeld
I believe if all your type fields are concrete (which they are in the case of Float64), the performance should be the same as using Vector{Float64}. This is really nice since you get to use code that is much more understandable like state.x instead of state[1] for no penalty. And if your state

[julia-users] Re: Using ModX: Can scope avoid collisions & improve readability?

2015-03-03 Thread Josh Langsfeld
; So for now the "simpler is better" approach is to have the user manage > importing at the top level only. > > Cheers > Lex > > On Tuesday, March 3, 2015 at 7:23:33 AM UTC+10, Josh Langsfeld wrote: >> >> It's discussed in the FAQ so there must be a good

[julia-users] PyPlot figures

2015-03-04 Thread Josh Langsfeld
In PyPlot.jl, is there a way to create my figures and render them without a figure window getting created? My window manager is interfering with the size hint in the figure() function so it would be nice if I can go straight to a file. Thanks, Josh

[julia-users] Re: PyPlot figures

2015-03-04 Thread Josh Langsfeld
sions. Any idea how I can fix this? On Wednesday, March 4, 2015 at 11:32:01 AM UTC-5, Josh Langsfeld wrote: > > In PyPlot.jl, is there a way to create my figures and render them without > a figure window getting created? My window manager is interfering with the > size hint in the fig

[julia-users] Re: PyPlot figures

2015-03-04 Thread Josh Langsfeld
Ok, I got it working by doing pygui(:qt) or pygui(:gtk) before the 'using PyPlot' call and mentioned in your docs. I'm not totally clear what 'non-interactive' means for the backend. Working directly in the REPL, is that not a default setting? And is that what I ended up changing with either of

[julia-users] Re: Using ModX: Can scope avoid collisions & improve readability?

2015-03-06 Thread Josh Langsfeld
mport merely "makes visible" the code at a module > level... > And "using" first "imports", then "provides a shortcut" to the exported > variables/functions... > > But as far as I can tell, compilation is done "on demand". I beli

[julia-users] Re: Declaring a function taking a type not yet declared as argument.

2015-03-07 Thread Josh Langsfeld
It should be noted that this is an issue with circular dependencies and isn't specific to Julia at all. Sam's suggestions apply to software engineering in general, and not just this particular scenario. On Friday, March 6, 2015 at 5:30:13 PM UTC-5, Kristoffer Carlsson wrote: > > If I have a func

[julia-users] Re: simultaneous minima of a set of function

2015-04-09 Thread Josh Langsfeld
Do you know apriori that the minima of f and g are at the same value of (x,y)? If so, then you can just minimize h(x,y) = f(x,y) + g(x,y). If the two minimums are located in different points, the problem does not seem sufficiently well-posed. On Thursday, April 9, 2015 at 4:19:31 PM UTC-4, Zahi

[julia-users] Re: Custom println with field name

2015-04-20 Thread Josh Langsfeld
To get custom printing of a user-defined type, you only have to overload the show method: julia> type Pt x::Int y::Int end julia> Pt(1,2) Pt(1,2) julia> Base.show(io::IO, p::Pt) = print(io, "Pt: x=$(p.x), y=$(p.y)") show (generic function with 86 methods) julia> Pt(1,2) Pt

Re: [julia-users] Yet Another String Concatenation Thread (was: Re: Naming convention)

2015-04-28 Thread Josh Langsfeld
I don't know why it hasn't been mentioned (it was hinted at by Tamas) but it seems to me the clear solution is for most of Base to actually be moved into submodules like 'LinAlg'. Then to use those names, people need to call 'using LinAlg' or 'using Sparse', etc... Somebody mentioned how 'cholfa

Re: [julia-users] Yet Another String Concatenation Thread (was: Re: Naming convention)

2015-04-28 Thread Josh Langsfeld
Turning named functions into methods of a generic function is definitely something Julia should take maximum advantage of. It does look like it should work well in the case of 'factorize'. But I think it's a bit unrelated from the naming convention issue. Most, if not the large majority, of the

[julia-users] Re: idiom for range + offset

2015-04-29 Thread Josh Langsfeld
An inferior solution to range() is '(1:N) .+ i'. [without the parens, it's parsed as 1:(N .+ i) ] On Wednesday, April 29, 2015 at 10:22:23 AM UTC-4, Sebastian Good wrote: > > I find myself creating ranges of the form i:i+num-1. That is, the ith > thing, and num more. Whenever I see a +1 or -1 I

Re: [julia-users] Re: how to dispatch on an instance being a datatype

2015-05-01 Thread Josh Langsfeld
I vaguely remember Jeff saying after the tuple update something along the lines of 'typeof(typeof(x)) == DataType for all x now'. So as Tom mentioned, there won't be any cases when the not-a-datatype method will be called. On Friday, May 1, 2015 at 9:24:59 AM UTC-4, Tamas Papp wrote: > > Not re

Re: [julia-users] Re: how to dispatch on an instance being a datatype

2015-05-01 Thread Josh Langsfeld
What's the motivation for wanting to restrict calling repack on non-composite types? 'fieldnames' works fine on them too. If you want to do a different operation on non-composites, wouldn't you have to define specialized methods for different type families anyway since they would all have diff

[julia-users] Re: how to compute the maximum value of an object's attribute

2015-05-07 Thread Josh Langsfeld
Or: maximum([t.tau_max for t in TUnitS]) On Thursday, May 7, 2015 at 12:02:09 PM UTC-4, Darwin Darakananda wrote: > > How about : > > mapreduce(t -> t.tau_max, max, TUnitS) > > > On Thursday, May 7, 2015 at 8:49:49 AM UTC-7, Michela Di Lullo wrote: >> >> Hello everyone, >> >> I have to compute

[julia-users] Re: Construct range with custom type

2015-05-13 Thread Josh Langsfeld
I believe you only need to add a method to Base.colon of the form 'colon(start::JDate, step::Real, stop::JDate)' I just tested it and that was the only thing needed to make the the [J1:s:J2] syntax work. On Wednesday, May 13, 2015 at 11:13:53 AM UTC-4, Chris wrote: > > I have a simple custom ty

[julia-users] Re: Construct range with custom type

2015-05-13 Thread Josh Langsfeld
tingPoint,T<:FloatingPoint) at > range.jl:122. > To fix, define > colon(JDate,JDate,JDate) > before the new definition. > > Then, when I test this, I still get a Array{Float64,1}. > > Thanks, > Chris > > On Wednesday, May 13, 2015 at 12:05:19 PM UTC-4, Josh L

[julia-users] Re: verbs for immutable collections

2015-05-13 Thread Josh Langsfeld
Is your concern that some other package might also export non-mutating setindex and delete, thereby conflicting with yours? Or just that they should exist in Base? On Wednesday, May 13, 2015 at 2:35:44 PM UTC-4, Michael Francis wrote: > > I added methods to NamedTuples.jl to support merge, set a

Re: [julia-users] Re: Construct range with custom type

2015-05-14 Thread Josh Langsfeld
decision now, I think. Thanks for your > help. > > Chris > > > On Wednesday, May 13, 2015 at 2:30:53 PM UTC-4, Josh Langsfeld wrote: >> >> Yeah, I missed that you were subtyping FloatingPoint before. It still >> worked ok for me though once I also defined colon me

Re: [julia-users] Re: Construct range with custom type

2015-05-20 Thread Josh Langsfeld
verflow > in <= at promotion.jl:170 (repeats 8 times) > > Any insight into why this is happening? > > Thanks, > Chris > > On Thursday, May 14, 2015 at 3:48:48 AM UTC-10, Josh Langsfeld wrote: >> >> If you do decide to keep it as a FloatingPoint subtype

[julia-users] Selective dispatching on an Int

2015-05-20 Thread Josh Langsfeld
I want to implement some functionality in multiple methods and have the dispatch controlled by an Int variable "N". The trick is I want one method to be called if N == 0 and another one to be called for all other values of N. Is there a way I can do this with "Val{N}" without making the method

[julia-users] Re: Selective dispatching on an Int

2015-05-20 Thread Josh Langsfeld
Ideally, I would like to write func{N::Int}(::Type{Val{N}) = N and get no-method errors if N is a float, symbol, etc... Has there been previous discussion on this topic? On Wednesday, May 20, 2015 at 5:28:26 PM UTC-4, Josh Langsfeld wrote: > > I want to implement some functionality in mu

[julia-users] Re: Selective dispatching on an Int

2015-05-21 Thread Josh Langsfeld
gt; > Am Mittwoch, 20. Mai 2015 23:28:26 UTC+2 schrieb Josh Langsfeld: >> >> I want to implement some functionality in multiple methods and have the >> dispatch controlled by an Int variable "N". The trick is I want one method >> to be called if N == 0 and anot

Re: [julia-users] Re: Construct range with custom type

2015-05-21 Thread Josh Langsfeld
/package_osx10_9/build/src/task.c:423 > julia_trampoline at > /Users/vagrant/buildbot/slave/package_osx10_9/build/src/init.c:1053 > Segmentation fault: 11 > > I can give you more info about my system if needed. Out of curiosity, > assuming I do not subtype from FloatingPoi

[julia-users] Re: Easy way to copy structs.

2014-12-08 Thread Josh Langsfeld
On Monday, December 8, 2014 12:15:23 PM UTC-5, Utkarsh Upadhyay wrote: > > I have just tried playing with Julia and I find myself often copying > `immutable` objects while changing just one field: > > function setX(pt::Point, x::Float64) > # Only changing the `x` field > return Point(x, pt.y,

[julia-users] Re: Easy way to copy structs.

2014-12-08 Thread Josh Langsfeld
There isn't any special syntax for listing some of the type's fields, but you might be able to pull it off with some metaprogramming. setdiff(names(Point), [:x]) will give you the leftover fields to use as default. You might be able to write a macro you could insert into the constructor call to

[julia-users] Announcing RobotOS.jl

2014-12-12 Thread Josh Langsfeld
m quite eager to continue development on the package with whatever community feedback I can get but hopefully it can already prove useful to anyone out there who has already thought of using the two systems together. Thanks, Josh Langsfeld Graduate Research Assistant Maryland Robotics Center - UMD

[julia-users] Re: Announcing RobotOS.jl

2014-12-14 Thread Josh Langsfeld
d be wrapped directly via ccall? > > -Tony > > > On Friday, December 12, 2014 11:06:37 AM UTC-8, Josh Langsfeld wrote: >> >> After about 6 weeks of initial part-time development, I'm announcing the >> first release of the RobotOS.jl package, which

Re: [julia-users] Re: Announcing RobotOS.jl

2014-12-24 Thread Josh Langsfeld
t possibly in the future wrapping the C++ interface could be a > path towards more deterministic performance, along with the GC work that's > being done on the Julia side. > > > peace, > s > > On Sun, Dec 14, 2014 at 7:07 PM, Josh Langsfeld > wrote: >

[julia-users] Static type fields

2014-12-31 Thread Josh Langsfeld
I currently am trying to solve a problem where I have many composite types and I would like to associate some data with each type, such that every instance has access to it. Obviously, in C++ I would just create a static member variable. Is there a good way to go about this in Julia? Currently

Re: [julia-users] Static type fields

2015-01-01 Thread Josh Langsfeld
ity without needing a specialized feature: > > static_data(::Type{MyObj}) = 1 > static_data(::Type{MyOtherObj}) = 2 > > On Wed Dec 31 2014 at 8:23:40 PM Josh Langsfeld wrote: > >> I currently am trying to solve a problem where I have many composite >> types and I would li

Re: [julia-users] Re: Static type fields

2015-01-02 Thread Josh Langsfeld
On Friday, January 2, 2015 6:13:36 PM UTC-5, Jason Knight wrote: > > Lex, check out Tim's suggestion here > . I > believe this can also be done with a let binding, but I can't seem to find > the reference and my Julia is compi

Re: [julia-users] Re: Static type fields

2015-01-06 Thread Josh Langsfeld
On Friday, January 2, 2015 9:19:10 PM UTC-5, ele...@gmail.com wrote: > > This seems to work, providing the equivalent to C++ class data members, > any better suggestions? > > immutable MyObj_a end > > type MyObj > MyObj() = new() > > a::Int=0 > MyObj(:

Re: [julia-users] Re: Static type fields

2015-01-06 Thread Josh Langsfeld
g like X:val, i.e. colon(::Type{X}, ::Symbol) seems like a good option to me. On Tuesday, January 6, 2015 12:56:28 PM UTC-5, Jason wrote: > > Thanks for sharing Josh, I also did not know that internal constructors > worked like that. And it *does* actually work as written with 0.3. &g

Re: [julia-users] How can I achieve C-like ## in Julia

2015-01-07 Thread Josh Langsfeld
Is there any reason there shouldn't be a *(::Symbol, ::Symbol) method to do this even more concisely, and without string intermediates? On Tuesday, January 6, 2015 9:02:27 PM UTC-5, Mike Innes wrote: > > Cool. $(symbol("gen_$x")) might also be a bit more compact, now I think > about it. > > On 7

Re: [julia-users] How can I achieve C-like ## in Julia

2015-01-07 Thread Josh Langsfeld
I went ahead and tried to implement it just because I was interested in the idea. I got a version working that works directly on the underlying c-string data and it actually seems to be about double the speed, and uses about 25% less memory than the symbol(string()) form. Could you elaborate fu

Re: [julia-users] How can I achieve C-like ## in Julia

2015-01-08 Thread Josh Langsfeld
Thanks, I might do that sometime in the next few days if I can make it look a bit nicer. On Wednesday, January 7, 2015 4:24:32 PM UTC-5, Ivar Nesje wrote: > > The problem is where we should stop adding methods to allow symbols to > work as strings. > > * might be fine though, so please submit y

Re: [julia-users] How can I achieve C-like ## in Julia

2015-01-09 Thread Josh Langsfeld
https://github.com/JuliaLang/julia/pull/9700 On Thursday, January 8, 2015 at 10:29:20 AM UTC-5, Josh Langsfeld wrote: > > Thanks, I might do that sometime in the next few days if I can make it > look a bit nicer. > > On Wednesday, January 7, 2015 4:24:32 PM UTC-5, Ivar Nesje w

Re: [julia-users] MethodError: '+' has no method matching +(::DateTime, ::Int64)

2016-04-04 Thread Josh Langsfeld
Shouldn’t Dates.day(1) be the MethodError here? It calls what appears to be an internal calculation method that happens to have the same name as the exported and documented method. On Monday, April 4, 2016 at 11:21:47 AM UTC-4, Jacob Quinn wrote: Dates.day is the accessor funciton, returning

Re: [julia-users] constructor & function have different promotion rules?

2016-04-05 Thread Josh Langsfeld
This is noted in the docs. See a few paragraphs down, "When a type is applied like a function..." http://docs.julialang.org/en/release-0.4/manual/types/#composite-types On Tuesday, April 5, 2016 at 10:19:05 AM UTC-4, FANG Colin wrote: > > methods(TT) > > call(::Type{TT}, x::Float64, y::Float64)

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Josh Langsfeld
Maybe a better design would be to store the rules as anonymous functions rather than code strings? Something like: ``` rules = [(x -> x[1] && x[2]), (x -> x[3] || x[4])] #parentheses not required result = [rule(boolList) for rule in rules] ``` On Tuesday, April 26, 2016 at 12:09:33 PM UTC-4, Ali

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Josh Langsfeld
that all the anonymous functions return Bools. On Tuesday, April 26, 2016 at 2:24:18 PM UTC-4, Ali Rezaee wrote: > > Reading the rules from a file, how can I convert the strings to such > anonymous functions? > > On Tuesday, April 26, 2016 at 6:48:21 PM UTC+2, Josh Langsfeld w

Re: [julia-users] use of parse and eval to create programmatically anonymous function

2016-04-28 Thread Josh Langsfeld
That's quite a strong statement to say never use parse. Could you explain? I think manipulating strings is typically much easier than Expr objects. On Thursday, April 28, 2016 at 8:38:27 AM UTC-4, Yichao Yu wrote: > > > On Apr 28, 2016 7:15 AM, "Ben Lauwens" > > wrote: > > > > Hi > > > > I like

Re: [julia-users] use of parse and eval to create programmatically anonymous function

2016-04-29 Thread Josh Langsfeld
splice expression objects, it will just work and > do the right thing, even for expressions which have no possible string > representation. > > > On Thu, Apr 28, 2016 at 10:21 PM, Yichao Yu > wrote: > >> On Thu, Apr 28, 2016 at 6:05 PM, Josh Langsfeld > > wrote: >> >

[julia-users] Re: Arrays of user defined types, indexing and copying.

2016-08-12 Thread Josh Langsfeld
For your second question, I would have expected just doing deepcopy(MyType_Vec[[1,3,1]]) would have created a new array with a new object allocated for each element. Instead, it puts the same object (which is a copy) in the first and third positions and you get the same behavior. Maybe this i

[julia-users] Re: Function push! adds objects where it should not

2015-10-14 Thread Josh Langsfeld
There must have been some other subtle change you made when converting to 0.4. I see the same fill! behavior in 0.3. julia> VERSION v"0.3.11" julia> X = Array(Vector{Int},5); fill!(X, Int[]); julia> push!(X[1], 11); @show X; X => [[11],[11],[11],[11],[11]] On Tuesday, October 13, 2015 at 6:05

Re: [julia-users] Method fieldnames not defined

2015-10-14 Thread Josh Langsfeld
Actually Compat doesn't rewrite the code to call 'names' but just defines 'fieldnames' directly. So either import Compat Compat.fieldnames(x) or using Compat fieldnames(x) is sufficient. On Wednesday, October 14, 2015 at 4:47:36 PM UTC-4, Milan Bouchet-Valat wrote: > > Le mercredi 14 octobr

[julia-users] Re: non-modifying push (and unshift, etc.)

2015-10-19 Thread Josh Langsfeld
[a; b] / vcat(...) is type stable. It may produce different output depending on the types of a and b but it won't change behavior depending on their values. On Monday, October 19, 2015 at 10:20:06 AM UTC-4, Andras Niedermayer wrote: > > In light of the recent discussions ( > https://groups.googl

[julia-users] Re: julia style to resize array with initialization?

2015-10-26 Thread Josh Langsfeld
You could do 'append!(vec, zeros(i-n))'. On Monday, October 26, 2015 at 3:32:56 PM UTC-4, Cameron McBride wrote: > > Hi All, > > What's the best julian way to do the following: > > function vecadd!(vec, i, v) > n = length(vec) > if n < i > resize!(vec, i) > vec[n+1:i] = 0

Re: [julia-users] linspace-like range generators and keyword ordering

2015-11-13 Thread Josh Langsfeld
This looks like overengineering of what should be a simple problem. Why do you want turn the keywords into arguments for dispatch? Dispatch is best when you need different behavior for different types but here all your input and output types are fixed. You may have already known, but you can wo

Re: [julia-users] linspace-like range generators and keyword ordering

2015-11-16 Thread Josh Langsfeld
On Saturday, November 14, 2015 at 10:59:26 AM UTC-5, MA Laforge wrote: > > >> - `immutable KD{Symbol} end` does not force the type parameter to be a >> symbol. It does the same thing as the more typical 'T' (which could be >> :tfund, Int, Array{Symbol,2}, or anything else). >> > Hmm... I have

[julia-users] Re: Arbitrary Vector literal nesting

2015-11-18 Thread Josh Langsfeld
Your conclusion is correct. The final switch should happen pretty soon on 0.5 master. Until then, the work-around is to prefix all your brackets with 'Any', including the inner arrays. On Wednesday, November 18, 2015 at 12:20:15 PM UTC-5, vis...@stanford.edu wrote: > > Hi everyone, > > Julia se

[julia-users] Re: Arbitrary Vector literal nesting

2015-11-18 Thread Josh Langsfeld
Should also mention that even when ["1", ["1","2","3"]] returns a two element Vector{Any}, the inner array will still get inferred to be Vector{ASCIIString} unless you add the Any prefix. On Wednesday, November 18, 2015 at 12:30:28 PM UTC-5, Josh Langsfe

Re: [julia-users] Re: `findmin` with arbitrary comparison operator?

2015-12-01 Thread Josh Langsfeld
Doesn't 'min' imply/require the usage of '<' ? A whole lot of methods would need the extra argument added for consistency, including min, minimum, maximum, etc... Could a workable solution be to define a function that maps a tuple to a real number instead of a comparison function and do 'findm

Re: [julia-users] Re: `findmin` with arbitrary comparison operator?

2015-12-02 Thread Josh Langsfeld
ore_func is trivial. However, in the end I want not only the minimum > value, but also the additional tuple elements, which would be stripped off > by the score_func. > > -erik > > On Tue, Dec 1, 2015 at 12:38 PM, Josh Langsfeld > wrote: > >> Doesn't 'min' i

[julia-users] Re: using statement with for loop inside if statement

2015-12-09 Thread Josh Langsfeld
But an if statement does not introduce new scope, correct? Something weird/unexpected does seem to be going on here: julia> VERSION v"0.5.0-dev+1491" julia> if true using Compat println("Using") foreach(println, 1:3) end Using 1 2 3 julia> if true u

  1   2   >