Re: [julia-users] Multiple dispatch algorithm.

2016-11-04 Thread Matt Bauman
I posted an answer to this a year ago on Stack Overflow: http://stackoverflow.com/a/32148113/176071 The internal implementation of the method caches has since changed, but the concepts should still apply. If I remember right, Stefan's remarks were about the addition of triangular subtyping,

[julia-users] Re: View (a portion of a) vector as a matrix

2016-10-03 Thread Matt Bauman
You can also express this as a two-dimensional index: @view x[[1:3 4:6]] # or @view x[reshape(1:6, 2,3)] In this case, though, the reshaped view should a bit more performant. On Monday, October 3, 2016 at 10:33:34 AM UTC-5, Alexey Cherkaev wrote: > > Ah, of course! reshape the view! Sometimes

[julia-users] Re: equivalent of numpy newaxis?

2016-09-12 Thread Matt Bauman
It's pretty close. In Julia 0.5, we have all the parts that are required to make this a possibility. We have index types that specify both how many indices in the source array should be consumed (CartesianIndex{N} spans N dimensions) and types that determine what the dimensionality of the

[julia-users] Re: Cell array of images like Matlab

2016-09-10 Thread Matt Bauman
I cannot reproduce that error, and I know that the lead author of Images uses stacked image arrays quite frequently. julia> using TestImages, Images src = testimage("mandrill") arr = convert(Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8 }},2}, src) cat(3, arr, arr)

[julia-users] Re: idiom for standard basis vector (eg [0,1,0])

2016-09-09 Thread Matt Bauman
You could implement: Base.getindex(U::UniformScaling, I::AbstractArray, j::Int) = [U[i,j] for i in I] Base.getindex(U::UniformScaling, i::Int, J::AbstractArray) = [U[i,j] for j in J] Base.getindex(U::UniformScaling, I::AbstractArray, J::AbstractArray) = [U[i, j] for i in I, j in J] Then:

Re: [julia-users] Re: How to shuffle the order of matrix by rows

2016-09-08 Thread Matt Bauman
Even simpler: use the built-in `randperm(n)`. You can even use the `end` keyword within the indexing expression as a shorthand for the dimension's length: julia> A = rand(1:100, 5, 3) 5×3 Array{Int64,2}: 15 57 20 74 92 100 17 89 31 82 12 29 93 9 66 julia> A[randperm(end),

[julia-users] Re: Pesky type instability

2016-06-12 Thread Matt Bauman
Constructing expressions with strings for a generated function is definitely much more complicated and harder to read. And it'll almost certainly take more resources and time during compilation. You'll probably also be very interested in Base.Cartesian. See the developer documentation here:

[julia-users] Re: Arrays{T,N} of size = (n, 1, 1, 1, ...)

2016-06-08 Thread Matt Bauman
See http://stackoverflow.com/questions/21152051/difference-between-nx1-array-and-n-element-array-in-julia/ In your example, sometimes returning a matrix and sometimes returning a vector from rand(5, x) would be similarly type-unstable. More than that, though: the logical conclusion of this

Re: [julia-users] Initializing a new array generates unexpected results

2016-06-07 Thread Matt Bauman
Just as a small addendum to Erik's excellent answer: One way to think about zero-dimensional arrays is by analogy with geometry. Matrices are like planes, vectors are like lines, and zero-dimensional arrays are like points. Points don't have any dimensions or lengths, but they still describe

Re: Soukromá zpráva ohledně: [julia-users] Re: getindex vs @getindex

2016-05-26 Thread Matt Bauman
So, if I understand correctly, the problem you're trying to solve is that A[end] lowers to getindex(A, endof(A)), but you want to know that the index is the last one since you can implement a more efficient algorithm in that case. Making getindex a macro won't solve this problem, so lets set

[julia-users] Re: how to check if a string is a legal variable name?

2016-05-23 Thread Matt Bauman
There's Base.isidentifier. Be aware that it's not documented or exported, though. julia> Base.isidentifier("1gh") false julia> Base.isidentifier("a_b1") true On Monday, May 23, 2016 at 3:17:55 PM UTC-4, vav...@uwaterloo.ca wrote: > > A macro I'm writing needs a function to check whether a

[julia-users] Re: vector assignment performance

2016-05-20 Thread Matt Bauman
I believe something just like that is already implemented in Devectorize.jl's @devec macro. Try: `@devec y[:] = y + a .* x[ind]`. https://github.com/lindahua/Devectorize.jl On Friday, May 20, 2016 at 11:04:34 AM UTC-4, vav...@uwaterloo.ca wrote: > > I'm not sure that fixed-size array solves

[julia-users] Re: Possible mistake in the manual?

2016-05-04 Thread Matt Bauman
Good catch! Would you be willing to open a pull request to correct it? You can edit it directly on GitHub if you'd prefer: https://github.com/JuliaLang/julia/edit/master/doc/manual/arrays.rst Thanks! On Wednesday, May 4, 2016 at 2:08:58 PM UTC-4, passerby51 wrote: > > Hello, > > In the

[julia-users] Re: sparse function

2016-05-03 Thread Matt Bauman
On Monday, May 2, 2016 at 11:47:49 PM UTC-4, new to Julia wrote: > > when I use sparse function in Julia coding, I have the following error: > > LoadError: MethodError: `sparse` has no method matching > sparse(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, > ::Int64,

Re: [julia-users] Inferring function call in let-block

2016-04-22 Thread Matt Bauman
At its root, isn't this just stemming from the fact that constant bindings aren't implemented in local scopes? If you define `child` as `global`, then it is able to infer concretely and `parent` no longer needs to hold onto the `child` binding. On Friday, April 22, 2016 at 1:27:21 PM UTC-4,

[julia-users] Re: macros design

2016-04-20 Thread Matt Bauman
On Wednesday, April 20, 2016 at 8:58:35 AM UTC-4, Didier Verna wrote: > > > What's the rationale behind this particular way of invoking macros > (the @ character) ? It's nice for both humans (it's obvious that there could be some non-standard evaluation semantics or other such funniness)

[julia-users] Re: Type inference on the length of varargs

2016-04-19 Thread Matt Bauman
That's https://github.com/JuliaLang/julia/pull/11242. Another common workaround is a generated function (but the wrapper function is better if you don't need other generated functionality): @generated function f(x...) N = length(x) :(Array{Int, $N}) end On Tuesday, April 19, 2016 at

Re: [julia-users] X'Y and NullableArrays?

2016-04-18 Thread Matt Bauman
You can take some inspiration from DataArrays: https://github.com/JuliaStats/DataArrays.jl/blob/44192cf6261d6eed476018fb2770c5ca8dc4e9f2/src/operators.jl#L377-L445 There's a link there to a blog post about speeding up R's multiplication — I've not read it too carefully, but I think that may

Re: [julia-users] Square matrices as a parametric type ?

2016-04-18 Thread Matt Bauman
On Monday, April 18, 2016 at 11:03:53 AM UTC-4, Didier Verna wrote: > > What I'm actually interested in is how deep in the language > this needs to be grounded, since I guess this is not based on the > AbstractArray interface. Does it need to access the language's > internals ? How's

[julia-users] Re: logic operations

2016-04-16 Thread Matt Bauman
If I understand correctly, it looks like you're describing `C = setdiff(A, B)`. http://docs.julialang.org/en/release-0.4/stdlib/collections/#Base.setdiff On Saturday, April 16, 2016 at 12:05:39 PM UTC-4, digxx wrote: > > Say I have 2 arrays > A=[1,2,3,4,5,6] > B=[1,6,7] > and the resulting

Re: [julia-users] Re: What do you call an (Associative{Int,T} or AbstractArray{T})

2016-04-14 Thread Matt Bauman
On Thursday, April 14, 2016 at 8:38:33 AM UTC-4, James Fairbanks wrote: > > Is that from this package https://github.com/JuliaSparse/SparseVectors.jl > or somewhere else? > Yes, and it was incorporated into Base in 0.5. It's basically a one-column SparseMatrixCSC. > > They should have

[julia-users] Re: What do you call an (Associative{Int,T} or AbstractArray{T})

2016-04-13 Thread Matt Bauman
On Wednesday, April 13, 2016 at 6:29:21 PM UTC-4, James Fairbanks wrote: > > Or do you make a constructor that validates C <: Associative{NTuple{N, > Int},T} at construction time? > What would be the appropriate error to throw in this case? > Exactly! It's not currently possible to express the

[julia-users] Re: What do you call an (Associative{Int,T} or AbstractArray{T})

2016-04-13 Thread Matt Bauman
If you're able to define a `size` method for the Associative types, then I'd call them all AbstractArrays. I'd use a wrapper type like the last example in http://docs.julialang.org/en/release-0.4/manual/interfaces/#abstract-arrays. You could parameterize the `data` field so any associative

Re: [julia-users] Creating an empty 2D array and append values to it

2016-04-12 Thread Matt Bauman
It'd probably be fastest if you can pre-allocate your array: A = Array(ASCIIString, 3, 2) for i=1:size(A, 1) A[i, 1] = string('w'+i, 1) A[i, 2] = string('w'+i, 2) end If you don't know how many elements you'll have, you can use two column vectors, `c1` and `c2`, and push to them

[julia-users] Re: Dropping or replacing NaNs from array

2016-04-07 Thread Matt Bauman
I'd use logical indexing for this: a[isnan(a)] = 42 clean_a = a[!isnan(a)] On Thursday, April 7, 2016 at 9:20:05 AM UTC-4, Kristoffer Carlsson wrote: > > to replace with 42, maybe: > > map!((i) -> isnan(i)? 42 : i, a) > > to delete: > > deleteat!(a, find(isnan, a)) > > > > > On Thursday, April

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Matt Bauman
Perhaps a simpler solution would be to just assert that `evaluate` always returns a Float64? You may even be able to remove the isa branches in that case, but I'm not sure how it'll compare. On Saturday, April 2, 2016 at 4:34:09 PM UTC-4, Cedric St-Jean wrote: > > Thank you for the detailed

[julia-users] Re: Julia is a great idea, but it disqualifies itself for a big portion of its potential consumers

2016-04-02 Thread Matt Bauman
I don't want to get too deep into the weeds here, but I want to point out some things I like about Julia's closed ranges: * Julia's ranges are just vectors of indices. In exchange for giving up Python's offset style slicing, you get a fully-functional mathematical vector that supports all

[julia-users] Re: Dispatch on Vector{AbstractString} as an optional parameter

2016-03-25 Thread Matt Bauman
There's a few things going on here. First, you only define one method for `g` — your second definition overwrites the first because keyword arguments don't participate in multiple dispatch. There's been a warning added here in 0.5. So the one method you define just takes one argument and one

[julia-users] Re: DataFrame conversion challenge

2016-03-20 Thread Matt Bauman
Yes, the DataArrays package exists to handle `NA` elements as a foundation for DataFrames. You've stumbled upon an open issue in the language, and you're exactly right: vectorization like this is really handy, but it can make reading code a bit harder to understand. In this case, for example,

Re: [julia-users] Re: implicit conversion

2016-03-15 Thread Matt Bauman
To generalize this idiom a bit, I think I'd write it as: Base.convert(::Type{Float64}, a::MyNum) = convert(Float64, a.x) f(a) = f(convert(Float64, a)) f(a::Float64) = 2. # real algorithm Of course, this will also allow things like `f(1)`. On Tuesday, March 15, 2016 at 10:18:30 AM UTC-4, Stefan

Re: [julia-users] Re: Non-uniform interpolation in 1D

2016-02-27 Thread Matt Bauman
Interpolations is very similar, but it currently only supports linear and nearest-neighbor schemes for gridded interpolations: using Interpolations itp = interpolate((P_NOM,), ETA, Gridded(Linear())) # You pass the x-values as a tuple, since this generalizes to multi-dimensional coordinates

Re: [julia-users] Re: Periodic or cyclic arrays possible?

2016-02-07 Thread Matt Bauman
I highly recommend reading the Interfaces chapter[1] for a walk-through on creating your own array type. Another great trick that you can use is `A[mod1(x, end)]`. 1. http://docs.julialang.org/en/release-0.4/manual/interfaces/ On Sunday, February 7, 2016 at 10:52:45 AM UTC-5, Erik Schnetter

Re: [julia-users] Memory management in Julia

2016-02-01 Thread Matt Bauman
Can you reproduce it if you run julia with the --check-bounds=yes command line argument? On Monday, February 1, 2016 at 1:55:25 PM UTC-5, Madeleine Udell wrote: > > This is on a mac; we've got a variety of function calls giving errors, > some with probability ~.5 and some every time we've run

[julia-users] Re: How to combine @generated and @inline?

2016-01-20 Thread Matt Bauman
You need to manually attach the inline annotation within the function body that gets generated. See, e.g., https://github.com/JuliaLang/julia/blob/275c7e8929dd391960ba88e741c6f537ccca6cc9/base/multidimensional.jl#L233-L236 On Wednesday, January 20, 2016 at 2:27:14 PM UTC-5, Erik Schnetter

Re: [julia-users] Re: How to combine @generated and @inline?

2016-01-20 Thread Matt Bauman
be annotated appropriately. > > On Wed, Jan 20, 2016 at 2:35 PM, Matt Bauman <mba...@gmail.com > > wrote: > >> You need to manually attach the inline annotation within the function >> body that gets generated. See, e.g., >> https://github.com/JuliaLang/julia/bl

[julia-users] Re: Immutable type with a function datatype

2016-01-18 Thread Matt Bauman
On Monday, January 18, 2016 at 11:54:49 AM UTC-5, Anonymous wrote: > > As you can see, I have to define a whole other type tree just so my metric > function can distinguish between sphere manifolds depending on what metric > structure I want it to have. It would be both simpler and make more

Re: [julia-users] Why SimpleVector / svec?

2016-01-05 Thread Matt Bauman
On Tuesday, January 5, 2016 at 3:23:14 AM UTC-5, Ismael Venegas Castelló wrote: > Why force `methods` to work with anything? > Because you can call anything: julia> call(x::Char) = x+1 call (generic function with 1038 methods) julia> 'c'() 'd' julia> methods('c') 1-element Array{Any,1}:

[julia-users] Re: Array view without a single element

2015-12-21 Thread Matt Bauman
Oh man, fun puzzle. Even without the allocations, SubArrays that depend upon an indexing vector (that is, not computable range) are really quite slow since there's a lot of indirection at every element access. You can solve the all-but-one problem with a custom view type fairly easily:

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

2015-11-16 Thread Matt Bauman
Instead of keyword argument ordering, you could use an "Exactly" wrapper type. This would allow you to dispatch and potentially error if the exact constraints cannot be satisfied. immutable Exactly{T} val::T end foo(Exactly(1.0), 2.0, Exactly(3.0)) # the second argument might get fudged

Re: [julia-users] General help with concepts: splatting/slurping, inlining, tuple access, function chaining

2015-11-11 Thread Matt Bauman
These are definitely not stupid questions. Tuning performance at this level is very hard. I'll just add a few practical notes on micro-benchmarking and introspection. Inspecting and benchmarking splatted/slurped functions can be very tricky. One thing to remember is that `@code_llvm`

[julia-users] Re: How to correctly create custom representation of an array of a custom type?

2015-11-06 Thread Matt Bauman
Whenever you define an IO method, you need to make sure that all IO methods you call within it also use that argument. Change println("x ...") to println(io, "x …"). On Friday, November 6, 2015 at 8:17:56 AM UTC-5, Gnimuc Key wrote: > > we can define a good representation of a new type by

[julia-users] Re: How to fill a (general) subarray with a single object

2015-11-03 Thread Matt Bauman
The ability to assign a single element into multiple locations like this is called scalar broadcasting. When you have an array of arrays, however, each element isn't a scalar. So it's trying to assign the elements of the right side (Float64s) to the elements of the right side (matrices). You

[julia-users] Re: speed increase of factor 70 for mixed scalar-vector vcat

2015-10-20 Thread Matt Bauman
Here's how I'd tackle this problem: I'd use dispatch with promote_type to perform the type reduction. This is often the best way to express things like this: scalar_or_eltype{T}(::AbstractArray{T}) = T scalar_or_eltype{T}(::T) = T promote_scalar_or_eltype(A, B) =

[julia-users] Re: speed increase of factor 70 for mixed scalar-vector vcat

2015-10-20 Thread Matt Bauman
On Tuesday, October 20, 2015 at 10:09:42 AM UTC-4, Glen O wrote: > > Seems to be something wrong with the dispatch system with Union... > Yes, Unions with TypeVars can behave strangely when the elements aren't mutually exclusive. I think it's just greedily matching the first thing it can. In

[julia-users] Re: speed increase of factor 70 for mixed scalar-vector vcat

2015-10-20 Thread Matt Bauman
r 20, 2015 at 10:45:15 AM UTC-4, Glen O wrote: > > On Wednesday, 21 October 2015 00:15:41 UTC+10, Matt Bauman wrote: >> >> On Tuesday, October 20, 2015 at 10:09:42 AM UTC-4, Glen O wrote: >>> >>> Seems to be something wrong with the dispatch system with Union...

[julia-users] Re: ANN: NullableArrays.jl package

2015-10-18 Thread Matt Bauman
On Sunday, October 18, 2015 at 3:54:13 PM UTC-4, David Gold wrote: > > @Sebastian: If I understand you correctly, then it should at least be > possible. If T is your datatype that behaves as such and x is the value of > type T that designates missingness, then it seems you could >

Re: [julia-users] Re: Everything I wrote in version .3 is now 'depreciated'

2015-10-16 Thread Matt Bauman
On Friday, October 16, 2015 at 11:29:40 PM UTC-4, Forrest Curo wrote: > > Okay, this might be a good time to explain that 'Compat' package. > Evidently I do have it, because I can't Pkg.add it... How does this work? > See the readme here: https://github.com/JuliaLang/Compat.jl The short version

[julia-users] Re: adding new method for $ is not allowed, while adding for + is fine

2015-10-07 Thread Matt Bauman
$ is also used for interpolation, so it must be disambiguated between the two cases. & is similar, if I remember correctly. On Wednesday, October 7, 2015 at 3:09:08 PM UTC-4, cheng wang wrote: > > Thanks. Still, why + and $ are different in this case ? > > On Wednesday, October 7, 2015 at

[julia-users] Re: Zeroing already allocated array

2015-10-05 Thread Matt Bauman
In case anyone is interested in contributing here, this is a simple optimization to make. `A[:] = 0.` is currently using the abstract fallbacks, which is implemented with as a simple loop. There are already some optimizations for `setindex!(::Array, …)` in cases like this where we can take

[julia-users] Re: Why is multiplying an array ok, but dividing is not?

2015-09-30 Thread Matt Bauman
Use ./ and .^ Whereas multiplying a matrix by a scalar is well-defined in linear algebra, dividing by a matrix has a very specific meaning which requires the a square matrix. Same with exponentiation. The dot-prefixed operators explicitly work elementwise. On Wednesday, September 30, 2015

[julia-users] Re: Will Julia likely ever allow negative indexing of arrays

2015-09-27 Thread Matt Bauman
There has been a lot of discussion about this in the past few weeks https://groups.google.com/d/msg/julia-users/ScwXMfQIBGs/wD1HTXeZBQAJ https://groups.google.com/d/msg/julia-users/fNisYpMdZ6o/DvFaQi_ZBAAJ TL;DR, yes, it is possible, but it takes some care since it's violating a fairly

[julia-users] Re: When does colon indexing get evaluated / converted?

2015-09-22 Thread Matt Bauman
A colon by itself is simply a synonym for `Colon()`, both on 0.3 and 0.4: julia> : Colon() You can use colons in normal function calls and dispatch in both 0.3 and 0.4: julia> f(x::Colon) = x f(:) Colon() That's what's happening with that sub definition. `sub` acts like indexing, but

[julia-users] Re: When does colon indexing get evaluated / converted?

2015-09-21 Thread Matt Bauman
Here's a quick rundown on the status quo: * Colon lowering changed in 0.4, as did the AbstractArray's interface. It's *much* easier to make your own arrays in 0.4. I suggest updating to the latest RC. * There is still a very strong assumption in base Julia that the valid indices in an

[julia-users] Re: Boolean operations on arrays?

2015-09-21 Thread Matt Bauman
The bitwise operations (&, |) broadcast over arrays and work just fine for this. Watch out for their precedence, though: you need to wrap them in parentheses if you want to combine them with the result of comparisons `(A == 1) | (A == 2)`. On Monday, September 21, 2015 at 8:41:29 AM UTC-4,

Re: [julia-users] Boolean operations on arrays?

2015-09-21 Thread Matt Bauman
More concretely, && and || are control flow operators. They short circuit. Therefore, they require Boolean arguments and aren't real functions. They're syntax. & and | are bitwise operations and real, extendable functions. They can operate on booleans *and* integers, performing bitwise

[julia-users] Re: Allowed module names

2015-09-17 Thread Matt Bauman
On Thursday, September 17, 2015 at 9:09:45 AM UTC-4, Ján Dolinský wrote: > > Hello, > > Is a module name consisting of minus sign allowed ? > E.g. my-new-module > Module names follow the same rules as all identifiers do. See here for details:

Re: [julia-users] Overloading a function with type not compiled yet

2015-09-17 Thread Matt Bauman
On Thursday, September 17, 2015 at 9:45:11 AM UTC-4, ami...@gmail.com wrote: > > I don't really get why though, what mechanism prevents Julia to use the > first version now? > Does it look at all the available functions called f and see if one is > better suited, is likely to produce an error of

Re: [julia-users] Re: IDE for Julia

2015-09-14 Thread Matt Bauman
On Monday, September 14, 2015 at 9:44:07 AM UTC-4, Andrei Zh wrote: > > To continue Michael's answer, I think it would be nice to collect list of > most important features that existing editors for Julia still lack and > think out what can be improved. So far I've seen following features: > >

Re: [julia-users] Re: Multi-dimensional Arrays

2015-09-11 Thread Matt Bauman
On Friday, September 11, 2015 at 3:11:48 AM UTC-4, Leonardo wrote: > > I like to have a *unique* type that contains only a specified type and > that can handle any dimension, but only during object instancing (not > during subsequent lifecycle of object, also if both phases are at runtime), >

Re: [julia-users] Is x*f(x) undefined if f modifies x?

2015-09-11 Thread Matt Bauman
Further, I'm fairly certain that we always evaluate function arguments from left to right. I think this all comes from the Lisp-y almost-everything-is-an-expression tradition. On Friday, September 11, 2015 at 9:51:28 AM UTC-4, Tomas Lycken wrote: > > In Julia, this is actually more consistent

[julia-users] Re: Multi-dimensional Arrays

2015-09-10 Thread Matt Bauman
The reason you're needing to define more methods than the interface chapter suggests is because you haven't specified the AbstractArray's parameters; this is just as important as the required methods. That is, you need to define your type as type MyArr{T,N} <: AbstractArray{T,N} in order for

[julia-users] Re: Declare user-defined type variable but *not* initialize it

2015-09-04 Thread Matt Bauman
Just define a zero-argument constructor: type Point x::Float64 y::Float64 Point() = new() end p = Point(); # Will return uninitialized memory or #undef references depending on the field type Note that this will override the default constructors; you'll need to explicitly add back the

Re: [julia-users] Re: v0.4 - Pair does not behave like a Tuple

2015-09-03 Thread Matt Bauman
On Thursday, September 3, 2015 at 10:04:22 AM UTC-4, Michael Francis wrote: > > It brings up a question regarding parameterized types, how should (or > should) one access/refer to the parameters of the type rather than an > instance. It seems like a bad (queezy) practice to dig into the

[julia-users] Re: julian style for assignments in a try block?

2015-09-03 Thread Matt Bauman
Here's one option: use the value of the whole try-block. This is particularly nice in cases where you have some substitute for `(t, data)` (or whatever) that you'd like to use when an exception is thrown. This way you can simply have the last statement of the catch block give the substitute.

[julia-users] Re: v0.4 - Pair does not behave like a Tuple

2015-09-03 Thread Matt Bauman
Oh man that's tricky. The trouble is that you're effectively saying `Pair{Symbol,Int}[1]`, which is the syntax for a typed array: Pair{Symbol,Int}[:x=>1, :y=>2]. One way around this is to define: keytype{A,B}(::Type{Pair{A,B}}) = A valuetype{A,B}(::Type{Pair{A,B}}) = B

Re: [julia-users] Help for 'mean' (version 0.4)

2015-09-01 Thread Matt Bauman
You have shadowed Base.mean with a local `mean` that was bound to `0`. Try help for Base.mean and 0. On Tuesday, September 1, 2015 at 1:18:17 PM UTC-4, Miguel Bazdresch wrote: > > The Segmentation Fault strongly suggests a glitch, not an Easter egg, > unfortunately... :) > > On Tue, Sep 1,

Re: [julia-users] What does the @inferred macro do?

2015-08-31 Thread Matt Bauman
That's the point of the macro - to ensure that inference infers a concrete result. It can help ensure that code stays type-stable. Throwing for a union is expected.

[julia-users] Re: FW: [julia-dev] 0.4 feature freeze

2015-08-28 Thread Matt Bauman
NEWS.md is a good place to start: https://github.com/JuliaLang/julia/blob/master/NEWS.md#julia-v040-release-notes And Compat.jl can be very helpful in getting things to play nicely on both 0.3 and 0.4: https://github.com/JuliaLang/Compat.jl#supported-syntax On Friday, August 28, 2015 at

Re: [julia-users] Extra '\n' char while creating a string spaning over two lines

2015-08-28 Thread Matt Bauman
The backtick command syntax looks like it ignores newlines. http://docs.julialang.org/en/release-0.3/manual/running-external-programs/ If you're constructing shell commands, that is definitely the way to go: julia cmd = `echo hello world` `echo hello world` julia run(cmd) hello world

[julia-users] Re: Multiple dispatch confusion

2015-08-26 Thread Matt Bauman
Yes, this can be surprising. Look at `methods(u)`: julia methods(u) # 5 methods for generic function u: u(c::Float64) at none:7 u(c::Float64, h::Float64) at none:3 u(c::Float64, h::Float64, b) at none:3 u(c::Float64, h::Float64, b, a) at none:3 u(c::Float64, a) at none:7 When you call `u(2.)`,

Re: [julia-users] Slicing DataFrames resets indexes

2015-08-24 Thread Matt Bauman
If the row index is intrinsically connected to and meaningful in relationship to the other columns, you should add it as a separate column. All arrays in Julia start indexing at 1, and data frames displays its row indices consistent with how it would index. Indexing arrays with Real numbers

Re: [julia-users] Constructor or convert(), Upper case or lower case

2015-08-18 Thread Matt Bauman
On Tuesday, August 18, 2015 at 11:29:00 AM UTC-4, Sisyphuss wrote: My point is these inconsistent rules are very confusing. The experience gained in one type cannot be extrapolated to another. I think most people here will agree with you. The discussion on how to spell conversion and/or

Re: [julia-users] Re: Array Index Limits

2015-08-17 Thread Matt Bauman
. I had the same indexing issue with MatLab. Sometimes I miss the brute straightforwardness of Fortran. Larry On Mon, Aug 17, 2015 at 1:16 PM, Matt Bauman mba...@gmail.com javascript: wrote: On Monday, August 17, 2015 at 1:03:17 PM UTC-4, Sisyphuss wrote: I read the interfaces http

[julia-users] Re: Array Index Limits

2015-08-17 Thread Matt Bauman
See the previous discussion here: https://groups.google.com/forum/#!topic/julia-dev/NOF6MA6tb9Y … which looks like it culminated in the OffsetArrays.jl package: https://github.com/alsam/OffsetArrays.jl But you'll need to be very careful about how you use them since they break a core

[julia-users] Re: Array Index Limits

2015-08-17 Thread Matt Bauman
On Monday, August 17, 2015 at 1:03:17 PM UTC-4, Sisyphuss wrote: I read the interfaces http://docs.julialang.org/en/latest/manual/interfaces/ chapter of the documentation today. I learned that, if you define an iterable as a subtype of AbstractArray, with only defining three methods

[julia-users] Re: [doc] SparseArray uses Int instead of generic type as index

2015-08-17 Thread Matt Bauman
On Monday, August 17, 2015 at 2:17:06 PM UTC-4, Matt Bauman wrote: That's a bug. I'll fix it shortly. Shortly was an overestimate. Apparently I already fixed this 11 days ago. :) If you update Julia, you'll see that the builtin fallbacks implement the conversion to `Int` for you.

Re: [julia-users] big matrices in Julia

2015-08-14 Thread Matt Bauman
You could create a phony 2-dimensional array that computes the distances on the fly… but you won't be able to pass this matrix to, e.g., BLAS. immutable DistanceMatrix : AbstractArray{Float64, 2} locs::Array{Float64, 2} # a 2xN or 3xN matrix containing the location coordinates end

Re: [julia-users] Inconsistent behavior of `try`

2015-08-12 Thread Matt Bauman
The basic try/catch/finally behaviors have been discussed before. I think this is a good summary: https://groups.google.com/d/msg/julia-users/Kqn6gNIwD5o/aKE17Nclh3kJ On Wednesday, August 12, 2015 at 9:25:32 AM UTC-4, Yichao Yu wrote: On Wed, Aug 12, 2015 at 9:20 AM, Sisyphuss

[julia-users] Re: `collect` makes array, `...` makes tuple?

2015-08-11 Thread Matt Bauman
I think it's best to think of `...` as expanding into an argument list. So `[A...]` makes an array, `Dict(X...)` forms a dictionary, and `tuple(A...)` makes a tuple. On 0.4 you can even say `(A...,)` to splice the arguments directly into the tuple syntax.

[julia-users] Re: FloatRange limited usability

2015-07-31 Thread Matt Bauman
I'd recommend not using FloatRange for this task. Instead, I'd create a new Interval type that doesn't have discrete steps and instead represents all real numbers between (and including) its endpoints. You can even use an unused operator (..) to allow easy construction of intervals. Naively,

Re: [julia-users] ANN: StructsOfArrays.jl

2015-07-30 Thread Matt Bauman
I absolutely love that it's only 43 lines of code! On Thursday, July 30, 2015 at 2:14:50 PM UTC-4, Stefan Karpinski wrote: The ease with which you were able to put that together is pretty amazing. On Thu, Jul 30, 2015 at 1:38 PM, Simon Kornblith si...@simonster.com javascript: wrote:

[julia-users] Re: setindex! for matrix of vectors

2015-07-29 Thread Matt Bauman
Is your custom object `: AbstractArray`? Are you on 0.3 or a recent 0.4-dev? Are you implementing custom `setindex!` methods? I don't think that your workaround should be necessary, but you haven't posted enough context for me to fully appreciate the issue. As far as support for

[julia-users] Re: setindex! for matrix of vectors

2015-07-28 Thread Matt Bauman
Yes, this is one of the ever-tricky cases of did you mean the container or the elements of that container? Setindex always assumes that, if the RHS of the assignment is an array of some sort, it's the elements that should be assigned. David, `A[:] = Vector[[1,2,3]]` works as you'd expect

Re: [julia-users] Indexing Array with empty vector in v.0.4.

2015-07-19 Thread Matt Bauman
I think we should probably support indexing with Array{Any}, just so long as all the contained elements are Ints. It's not performant or recommended, but it can still work just fine.

Re: [julia-users] The unique function and iterables of custom composite types

2015-07-17 Thread Matt Bauman
significant octets match (above)? On Thursday, July 16, 2015 at 12:25:01 PM UTC-4, Matt Bauman wrote: On Thursday, July 16, 2015 at 12:19:25 PM UTC-4, milktrader wrote: Also, back to the OP question, is the correct solution to simply define Base.hash(f::Foo) = f.x No, I'd define

[julia-users] Re: PSA: JLD split from HDF5---must add package

2015-07-17 Thread Matt Bauman
How should packages that depend upon JLD update their REQUIRE files? Should they just tag a new version that requires JLD instead (or in addition to, if they also use HDF5's capabilities)? On Friday, July 17, 2015 at 10:14:27 AM UTC-4, Tim Holy wrote: Hi folks, If you use HDF5/JLD, the

Re: [julia-users] The unique function and iterables of custom composite types

2015-07-16 Thread Matt Bauman
(foos[1]) and hash(foos[2]) have the same last hex digit? On Thu, Jul 16, 2015 at 11:30 AM, Matt Bauman mba...@gmail.com wrote: Bizarre. I happen to have last updated on *exactly* the same commit SHA, but I'm seeing the original (expected) behavior: $ julia -q julia versioninfo() Julia

Re: [julia-users] The unique function and iterables of custom composite types

2015-07-16 Thread Matt Bauman
Bizarre. I happen to have last updated on *exactly* the same commit SHA, but I'm seeing the original (expected) behavior: $ julia -q julia versioninfo() Julia Version 0.4.0-dev+5860 Commit 7fa43ed (2015-07-08 20:57 UTC) Platform Info: System: Darwin (x86_64-apple-darwin14.3.0) CPU: Intel(R)

Re: [julia-users] The unique function and iterables of custom composite types

2015-07-16 Thread Matt Bauman
On Thursday, July 16, 2015 at 12:25:01 PM UTC-4, Matt Bauman wrote: On Thursday, July 16, 2015 at 12:19:25 PM UTC-4, milktrader wrote: Also, back to the OP question, is the correct solution to simply define Base.hash(f::Foo) = f.x No, I'd define Base.hash(f::Foo) = hash(f.x

Re: [julia-users] The unique function and iterables of custom composite types

2015-07-16 Thread Matt Bauman
of the contents with each other (and with `h`). And that's exactly how most base functions do it. On Thursday, July 16, 2015 at 12:35:25 PM UTC-4, Seth wrote: On Thursday, July 16, 2015 at 9:25:01 AM UTC-7, Matt Bauman wrote: On Thursday, July 16, 2015 at 12:19:25 PM UTC-4, milktrader wrote: Also

Re: [julia-users] The unique function and iterables of custom composite types

2015-07-16 Thread Matt Bauman
On Thursday, July 16, 2015 at 12:19:25 PM UTC-4, milktrader wrote: Also, back to the OP question, is the correct solution to simply define Base.hash(f::Foo) = f.x No, I'd define Base.hash(f::Foo) = hash(f.x, 0x64c74221932dea5b), where I chose the constant by rand(UInt). This way it won't

[julia-users] Re: Too many packages?

2015-07-11 Thread Matt Bauman
One of the most powerful features of Julia is that packages (and user code in general) aren't at a major disadvantage to code included in Julia itself. 0.4 promises to make this even better with precompilation and documentation. Many of the folks who have spearheaded the big packages are also

Re: [julia-users] Re: Convert Array{Tuple} to Matrix

2015-07-07 Thread Matt Bauman
Are you using 0.3 or 0.4? You could try making `SpatialData` a subtype of `AbstractArray`. It's possible to do on either version, but it's substantially easier to do on 0.4. Then you could use any of the methods in base that are defined for `AbstractArray` (including `maximum`) directly.

Re: [julia-users] Re: Convert Array{Tuple} to Matrix

2015-07-07 Thread Matt Bauman
Are the 'unset' indices defined to have some value in your application? If not, trying to shoehorn this into an `AbstractArray` probably won't work very well. Also note that, while correct, using the methods in base will be slow if you have very large and very sparse matrices. In defining

Re: [julia-users] array concatenation without copying?

2015-07-06 Thread Matt Bauman
I played with this a little while ago. It's simplest if you can manage to always concatenate along a *new* dimension. Otherwise I think you'll have to do a lot of bookkeeping to track when to index into which array. Here's a very minimal starting point (requires 0.4) that requires all arrays

Re: [julia-users] Re: Current Performance w Trunk Compared to 0.3

2015-06-30 Thread Matt Bauman
That's great to hear! Thanks for reporting back. On Tuesday, June 30, 2015 at 2:48:01 PM UTC-4, David Anthoff wrote: I had reported slow performance for a medium size code base a couple weeks ago on 0.4 relative to 0.3. I just tested again with the latest nightly, now 0.4 is faster. Thanks

[julia-users] Re: is it possible to call a shadowed function?

2015-06-30 Thread Matt Bauman
Note the warning message you get upon trying to define Base.rand(): Warning: Method definition rand() in module Random at random.jl:195 overwritten in module Main at none:1 You're not shadowing rand; you're totally overwriting one of its main methods. I agree with Tom that you should

[julia-users] Re: make iterators default in for-loops

2015-06-25 Thread Matt Bauman
Zip and enumerate are also iterators in Julia. The little performance improvement that the @itr macro provides isn't because they aren't iterators… it's simply from a little quirk in Julia 0.3. In the latest development versions (0.4-), however, there is no longer a performance difference

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

2015-06-24 Thread Matt Bauman
Right now there's not an official way to do this. You could take a look at my Tuples package[1], which is an attempt at hashing out the API before trying to get this functionality into base. Your feedback would be very welcome! 1: https://github.com/mbauman/Tuples.jl On Wednesday, June 24,

Re: [julia-users] Tests failing on latest Julia

2015-06-22 Thread Matt Bauman
Should be fixed now! Thanks so much for reporting the problem, Julio. https://github.com/JuliaLang/julia/pull/11810 On Monday, June 22, 2015 at 9:11:20 AM UTC-4, Matt Bauman wrote: Yup, I would have seen this quicker if it were an posted as issue. I don't follow the mailing list all

  1   2   >