Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-05-02 Thread Stefan Karpinski
Well, yes, I should have put a rather big asterisk on that: * Unless your code explicitly depends on the element type of that or derived arrays. So, yes, it's not that simple. On Fri, May 2, 2014 at 9:06 AM, Andreas Noack Jensen < andreasnoackjen...@gmail.com> wrote: > Does your code break if

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-05-02 Thread Andreas Noack Jensen
> > Does your code break if it is applied to an array with an abstract element > type? If so, you must be doing something rather strange. Stefan, I think this is stated too strongly. There have been many questions and issues related to arrays with abstract element type. For functions returning ar

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-05-01 Thread Simon Kornblith
It seems to me that the massive difference in performance between homogeneous and heterogeneous arrays is at least in part a characteristic of the implementation and not the language. We currently store heterogeneous arrays as arrays of boxed pointers and perform function calls on values taken

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-05-01 Thread Oliver Woodford
On Thursday, May 1, 2014 9:59:08 AM UTC+1, Oliver Woodford wrote: > > On Wednesday, April 30, 2014 9:13:50 PM UTC+1, Stefan Karpinski wrote: >> >> Back to the original subject, because I think there's some value in >> summarizing it. >> >> 1. Variance. It is somewhat unintuitive to a lot of newcom

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-05-01 Thread Oliver Woodford
On Wednesday, April 30, 2014 9:13:50 PM UTC+1, Stefan Karpinski wrote: > > Back to the original subject, because I think there's some value in > summarizing it. > > 1. Variance. It is somewhat unintuitive to a lot of newcomers that in > Julia Array{Real} is a concrete type and Array{Int} is not a

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Stefan Karpinski
Back to the original subject, because I think there's some value in summarizing it. 1. Variance. It is somewhat unintuitive to a lot of newcomers that in Julia Array{Real} is a concrete type and Array{Int} is not a subtype of it. It might be possible to make parametric types in Julia covariant by

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 6:47:43 PM UTC+1, Jacob Quinn wrote: > > I apologize if you felt it was a personal attack, because it certainly > wasn't intended as such. I've always appreciated the Julia community and > how welcoming and encouraging it is and I wouldn't want to tarnish that > repu

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Jacob Quinn
I apologize if you felt it was a personal attack, because it certainly wasn't intended as such. I've always appreciated the Julia community and how welcoming and encouraging it is and I wouldn't want to tarnish that reputation. I'm far from the best person to comment on the particularities of type

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 4:51:13 PM UTC+1, Jacob Quinn wrote: > > I was just trying to share some of my own experience with Julia from > having used it for the last two years, not be dismissive or condescending. > That this hasn't been a show-stopper for some 300+ packages now, IMO, *is* a >

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 4:44:53 PM UTC+1, Stefan Karpinski wrote: > > I think this suggestion was based on Jacob's personal experience – which > others seem to have also had – that after a bit of time letting the > language wash over you Julia, things that seemed problematic > or disconcert

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Stefan Karpinski
On Wed, Apr 30, 2014 at 11:37 AM, Oliver Woodford wrote: > On Wednesday, April 30, 2014 4:01:22 PM UTC+1, Stefan Karpinski wrote: >> >> I really think the only code that should be too worried about whether >> something is a leaf type or not is the compiler... >> >> > Are you saying: > a) we shoul

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Jacob Quinn
I was just trying to share some of my own experience with Julia from having used it for the last two years, not be dismissive or condescending. That this hasn't been a show-stopper for some 300+ packages now, IMO, *is* a valid point against making a somewhat disruptive change to the type system. B

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Stefan Karpinski
I think this suggestion was based on Jacob's personal experience – which others seem to have also had – that after a bit of time letting the language wash over you Julia, things that seemed problematic or disconcerting early on have a way of not seeming important anymore. That might or might not ha

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Tim Holy
I think Stefan was merely saying that my illustration of how to inline away the type-check was overkill :). --Tim On Wednesday, April 30, 2014 08:37:15 AM Oliver Woodford wrote: > On Wednesday, April 30, 2014 4:01:22 PM UTC+1, Stefan Karpinski wrote: > > I really think the only code that should

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 4:01:22 PM UTC+1, Stefan Karpinski wrote: > > I really think the only code that should be too worried about whether > something is a leaf type or not is the compiler... > > Are you saying: a) we should use another way to distinguish between homogeneous and heterogeneo

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 3:46:54 PM UTC+1, Jacob Quinn wrote: > > function frob(x::Array) > isleaftype(eltype(x)) || error("Homogeneous array required')? > > Though, IMO, this is all a non-issue in my experience. Just specifying > frob{T<:Real}(x::Vector{T}) gets you exactly what you want--the

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Stefan Karpinski
I really think the only code that should be too worried about whether something is a leaf type or not is the compiler... On Wed, Apr 30, 2014 at 10:59 AM, Tim Holy wrote: > What's wrong with parameters? Are you making life harder for yourself than > you > need to? :-) > > If you're worried abou

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Jacob Quinn
function frob(x::Array) isleaftype(eltype(x)) || error("Homogeneous array required')? Though, IMO, this is all a non-issue in my experience. Just specifying frob{T<:Real}(x::Vector{T}) gets you exactly what you want--the ability to have JIT generate fast, efficient code for a range of types that t

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Tim Holy
What's wrong with parameters? Are you making life harder for yourself than you need to? :-) If you're worried about the (very slight) overhead (isleaftype calls out to C, and therefore can't be inlined), then you could use a Union where you specify all the types you allow. Or define the followi

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Patrick O'Leary
This is true. I agree in general that having the tighter container is desirable but hey, if you are only interested in the homogeneity property (which is what I was testing) and not in the storage there ya go. On Wednesday, April 30, 2014 8:53:02 AM UTC-5, Ivar Nesje wrote: > > @Patric. It's not

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Stefan Karpinski
Fundamentally I don't think you should be in the business of forcing people who call your code to use arrays with concrete element types. If they really want to use an array with an abstract element type – and they may have perfectly good reasons to – then that's their business. Does your code brea

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 3:20:23 PM UTC+1, Tim Holy wrote: > > You can add this as the first line of your function: >assert_leaftype(T) > where > assert_leaftype(T) = isleaftype(T) || error("Must be a concrete type") > > To your users, this is at least as useful as > ERROR: no

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Tim Holy
You can add this as the first line of your function: assert_leaftype(T) where assert_leaftype(T) = isleaftype(T) || error("Must be a concrete type") To your users, this is at least as useful as ERROR: no method myfunction(Array{Real,1}) which is what it would be if you relied on method

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 2:31:43 PM UTC+1, Patrick O'Leary wrote: > > > It's a flexible type system, but it doesn't provide the power of ML or > Haskell. If you really, really want this, do a runtime check: > > reduce((==), [typeof(el) for el in a]) > I feel that the difference between homo

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Ivar Nesje
@Patric. It's not just a better implementation. It actually works, because your check only check that the actual types are equal, but not if the type of the container is specific. Number[1,2,34,54] would pass your test, but the array will still be pointers to boxed values. kl. 15:40:33 UTC+2 on

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Patrick O'Leary
And today I learned about isleaftype()! This is a better implementation than what I posted. On Wednesday, April 30, 2014 8:32:45 AM UTC-5, Ivar Nesje wrote: > > You can do something like > function f{T<:Real}(x::Array{T,1}) > @assert isleaftype(T) > # function implementation > end > > > k

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Ivar Nesje
You can do something like function f{T<:Real}(x::Array{T,1}) @assert isleaftype(T) # function implementation end kl. 15:16:40 UTC+2 onsdag 30. april 2014 skrev Oliver Woodford følgende: > > On Wednesday, April 30, 2014 2:09:45 PM UTC+1, Patrick O'Leary wrote: >> >> On Wednesday, April 30,

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Patrick O'Leary
On Wednesday, April 30, 2014 8:16:40 AM UTC-5, Oliver Woodford wrote: > > On Wednesday, April 30, 2014 2:09:45 PM UTC+1, Patrick O'Leary wrote: >> >> On Wednesday, April 30, 2014 7:52:16 AM UTC-5, Oliver Woodford wrote: >>> >>> Is that correct? If not, what really is the correct way to constrain >

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Wednesday, April 30, 2014 2:09:45 PM UTC+1, Patrick O'Leary wrote: > > On Wednesday, April 30, 2014 7:52:16 AM UTC-5, Oliver Woodford wrote: >> >> Is that correct? If not, what really is the correct way to constrain >> input arrays to be homogenous? >> > > The tendency in Julia is to embrace th

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Patrick O'Leary
On Wednesday, April 30, 2014 7:52:16 AM UTC-5, Oliver Woodford wrote: > > Is that correct? If not, what really is the correct way to constrain input > arrays to be homogenous? > The tendency in Julia is to embrace that it's a dynamic language, and not excessively type constrain inputs. While I d

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Tuesday, April 29, 2014 7:43:03 PM UTC+1, Tomas Lycken wrote: > > OK, well, just because I wrote that, I realize there is one problem that I > can't off the top of my head say how I'd solve: type assertions for e.g. > arrays. Say I have a variable x, and I want to make sure that it's an arra

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-30 Thread Oliver Woodford
On Tuesday, April 29, 2014 8:07:08 PM UTC+1, Tim Holy wrote: > > On Tuesday, April 29, 2014 11:43:03 AM Tomas Lycken wrote: > > Say I have a variable x, and I want to make sure that it's an array > > of real numbers that are all of the same type, but I don't care which > one. > > Can I say x::A

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Jacob Quinn
Excellent points Tomas. I think this would be particularly helpful for those coming from Java. Perhaps some of your comments could be worked into the manual or FAQ somewhere. -Jacob On Tue, Apr 29, 2014 at 2:43 PM, Tomas Lycken wrote: > Yet another point of view - incidentally the one that conv

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Tomas Lycken
Yes, when declaring function arguments, which I believe fall under case 2. in this list. Is it possible for a usage of `::` that falls under category 1? // T On Tuesday, April 29, 2014 9:07:08 PM UTC+2, Tim Holy wrote: > > On

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Tim Holy
On Tuesday, April 29, 2014 11:43:03 AM Tomas Lycken wrote: > Say I have a variable x, and I want to make sure that it's an array > of real numbers that are all of the same type, but I don't care which one. > Can I say x::Array{T<:Real} as a type assertion? function f{T<:Real}(x::Array{T}) ...

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Tomas Lycken
Yet another point of view - incidentally the one that convinced me that Julia has got this right, while most others don't - is the fact that in the grand scheme of things, JIT is *cheap *while working with types that might have subtypes is *really painful* if you don't want to compromise with p

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Jason Merrill
On Tuesday, April 29, 2014 9:29:56 AM UTC-7, Oliver Woodford wrote: > > On Tuesday, April 29, 2014 5:14:01 PM UTC+1, Jason Merrill wrote: >> >> Suppose the types that you want existed. Let's call them ConcreteArray, >> and Cell. >> >> ConcreteArray gives the guarantee that all of it's elements are

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Matt Bauman
Perhaps the Julian curly-brace array syntax makes Any[] arrays seem special (especially to Matlab converts), when they're really not all that different. Yes, users need to learn that Array{Real} is not a supertype of Array{Int}. But that's a common theme throughout Julia's type system, and re

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Stefan Karpinski
On Tue, Apr 29, 2014 at 12:13 PM, Oliver Woodford wrote: > Quick question, folks: > > Does f(x::Array{Union(Int8,Int16)}) mean that x must be all Int8 or all > Int16 (homogenous), or each element can be either Int8 or Int16 > (heterogeneous)? > > If the latter, then would I need to > use f(x::Uni

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 5:14:01 PM UTC+1, Jason Merrill wrote: > > Suppose the types that you want existed. Let's call them ConcreteArray, > and Cell. > > ConcreteArray gives the guarantee that all of it's elements are stored > directly with a fixed stride. > > Can you give some examples of fu

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 5:13:08 PM UTC+1, Jacob Quinn wrote: > > In my experience, I can think of a single time when having an array of a > specific abstract type was useful (how multiple Period arithmetic is > handled: > https://github.com/karbarcca/Dates.jl/blob/master/src/periods.jl#L88).

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Jacob Quinn
In my experience, I can think of a single time when having an array of a specific abstract type was useful (how multiple Period arithmetic is handled: https://github.com/karbarcca/Dates.jl/blob/master/src/periods.jl#L88). Almost always, I'm concentrating on making sure Arrays I work with are of a

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
Quick question, folks: Does f(x::Array{Union(Int8,Int16)}) mean that x must be all Int8 or all Int16 (homogenous), or each element can be either Int8 or Int16 (heterogeneous)? If the latter, then would I need to use f(x::Union(Array{Int8},Array{Int16})) to achieve the former? If so, then what

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 4:53:05 PM UTC+1, Matt Bauman wrote: > > I use cell arrays very often in Matlab, too, but I've found that I often > don't really need to even worry about the distinction in julia. Square > brackets will constrain the types as much as possible, and if it's not > poss

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 4:41:52 PM UTC+1, Patrick O'Leary wrote: > > It might be easier to understand if we start by stripping away the > constraints and the function syntax and look just at the array type. > > Array{Real} is a concrete type. It's an array whose elements are all > subtypes of

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Matt Bauman
I use cell arrays very often in Matlab, too, but I've found that I often don't really need to even worry about the distinction in julia. Square brackets will constrain the types as much as possible, and if it's not possible, Any[] == {}. Moreover, most of what I used cell arrays for in Matlab

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 4:38:59 PM UTC+1, John Myles White wrote: > > On Apr 29, 2014, at 8:28 AM, Oliver Woodford > > > wrote: > > > Are you saying that f{T<:Real}(a::Array{T}) covers both homogeneous and > heterogeneous arrays, whereas f(a::Array{Real}) only covers heterogeneous > arrays

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Stefan Karpinski
On Tue, Apr 29, 2014 at 11:38 AM, John Myles White wrote: > Array{Any} is also a single type. Not to nit-pick, but there's a second type parameter, so it's actually still abstract. But Array{Any,1} is a single type with no subtypes, which I think is what you meant.

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Patrick O'Leary
It might be easier to understand if we start by stripping away the constraints and the function syntax and look just at the array type. Array{Real} is a concrete type. It's an array whose elements are all subtypes of the abstract type Real. Array{T} is a family of types. It describes a whole bu

Re: [julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread John Myles White
On Apr 29, 2014, at 8:28 AM, Oliver Woodford wrote: > > Are you saying that f{T<:Real}(a::Array{T}) covers both homogeneous and > heterogeneous arrays, whereas f(a::Array{Real}) only covers heterogeneous > arrays? If that's the case it strikes me as just as confusing. This is indeed how param

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 3:48:52 PM UTC+1, Ivar Nesje wrote: > > Sorry for nitpicking, but point 3 is wrong, and it might cause trouble in > the following discussion. > > f{T<:Real}(a::Array{T}) > Matches any array with a element type that is a subtype of Real (eg. > Integer[1,2,BigInt(44)] an

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Oliver Woodford
On Tuesday, April 29, 2014 4:10:37 PM UTC+1, Jason Merrill wrote: > > Do you find yourself dealing with heterogeneous arrays often? It might be > useful to post some examples where this comes up to the list. In my Matlab code I use cell arrays (heterogenous) a great deal, and of course normal a

[julia-users] Re: Array/Cell - a useful distinction, or not?

2014-04-29 Thread Ivar Nesje
Sorry for nitpicking, but point 3 is wrong, and it might cause trouble in the following discussion. f{T<:Real}(a::Array{T}) Matches any array with a element type that is a subtype of Real (eg. Integer[1,2,BigInt(44)] and Real[1, 3.4]) I have had trouble with this too, but now that I somewhat un