[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
Have you found the right implementation? Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops would be the most efficient and probably the most understandable implementation. Also, would it not be easier to have the first index in the `payoff_matrix` determine which player's payof

[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
1 array just seems so much more neat. Which is why I > was looking for a neat implementation of broadcast_slices to match. > > On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote: >> >> Have you found the right implementation? >> >> Fiddling a bit, I ten

[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
Oops, that `cat` code was supposed to be: cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...) Mew! On Sunday, September 25, 2016 at 11:54:43 AM UTC-4, Dan wrote: > > OK. So, to get the array to have the first dim as the player selector, you > can go: > > cat(1,map(x

[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
best_response_dimension, _, 1:length(_) ) > zip(_...) > map(all, _) > end > > On Sunday, September 25, 2016 at 11:57:47 AM UTC-4, Dan wrote: >> >> Oops, that `cat` code was supposed to be: >> >> cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...)

Re: [julia-users] Return structure-like elements from a function

2016-09-27 Thread Dan
That last line was probably meant to be paths = Vector{Matrix{Float64}}(4) On Tuesday, September 27, 2016 at 7:01:14 PM UTC-4, Yichao Yu wrote: > > On Tue, Sep 27, 2016 at 6:28 PM, Zhilong Liu > wrote: > > Hello All, > > > > I am trying to return values to elements inside a structure-like mat

Re: [julia-users] Please help me to convert a BitArray to a Integer array in Julia

2016-10-17 Thread Dan
If saving characters is a thing, then: julia> a = rand(Bool,3,2) 3×2 Array{Bool,2}: false false true false false true julia> 1a 3×2 Array{Int64,2}: 0 0 1 0 0 1 On Monday, October 17, 2016 at 2:08:44 PM UTC+3, Scott Jones wrote: > > Tim, do you know if there is any difference in p

[julia-users] Re: jump ahead in Mersenne Twister

2016-10-21 Thread Dan
h is not too hard as well. G'day, Dan Getz On Friday, October 21, 2016 at 3:43:05 AM UTC+3, Joaquim Masset Lacombe Dias Garcia wrote: > > Hi, > > Have anybody implemented an arbitrary jump ahead for Mersenne Twister in > julia? > > I saw that the randjump do

Re: [julia-users] Re: How to built an array with some keys of a dictionary ?

2016-11-07 Thread Dan
a = Vector{String} is also a good option. On Monday, November 7, 2016 at 5:27:49 PM UTC+2, Steven G. Johnson wrote: > > > > On Monday, November 7, 2016 at 9:45:37 AM UTC-5, Mauro wrote: >> >> On Mon, 2016-11-07 at 15:27, Fred wrote: >> > Hi Steven, >> > >> > >> > I also tried a = Array{Str

Re: [julia-users] Re: How to built an array with some keys of a dictionary ?

2016-11-07 Thread Dan
I meant, a = Vector{String}() Dan On Tuesday, November 8, 2016 at 9:39:53 AM UTC+2, Dan wrote: > > a = Vector{String} > > > > is also a good option. > > On Monday, November 7, 2016 at 5:27:49 PM UTC+2, Steven G. Johnson wrote: >> >> >> >> On Mon

[julia-users] Re: div() for Floatingpoint number

2015-10-09 Thread Dan
F(a,b) = floor(Int,a/b)*b seems to fit the examples. On Thursday, October 8, 2015 at 6:01:07 PM UTC+3, Sisyphuss wrote: > > Hello everyone, > > I want a function F(), so that > F(0.154, 0.1) = 0.1 > F(0.154, 0.01) = 0.15 > F(0.154, 0.003) = 0.153 > > I tried `div(a,b)*b`. However, I got: > > d

[julia-users] Re: Merge two dict with common keys being summed

2015-10-11 Thread Dan
Since this is a common procedure when counting items in sequences, there is a specialized function (`merge`) and data structure (`Accumulator`) for it in the package `DataStructures`. Try a version of the following: using DataStructures a = Dict(2 => 5, 3 => 7, 5 => 1) b = Dict(2 =

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

2015-10-13 Thread Dan
perhaps, fill!(instance.ol, Tuple{Int64, Array{Float64}}[]) uses the same address to fill every entry in `instance.ol` and the behavior observed follows. maybe, onstance.ol = [Tuple{Int64,Array{Float64}}[] for i=1:length(instance.ol)] would be better. On Tuesday, October 13, 2015 at 7:52

[julia-users] A Julia notebook on Probablity

2015-10-19 Thread Dan
Recently, Peter Norvig published a lovely IPython/Jupyter notebook on probability and related puzzles. Mostly as an exercise, I've done a translation to Julia. It was educational to me, and getting stuff translated into Julia is the best way to make sure Julia doesn't overlook important function

[julia-users] Re: A Julia notebook on Probablity

2015-10-19 Thread Dan
yeah. it wasn't optimized for efficiency but rather for closeness to original python code. the python version used generators and hence Julia tasks. same goes for the coin flipping.

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

2015-10-20 Thread Dan
This might have something to do with matching parameter T correctly. T could actually be an Array type and then Array{T,1} would be an Array of Arrays. This is creates ambiguity. In any case, a solution might be to define: dispatchtest{T}(x0::Array{T,1},x::Vararg{Union{T,Array{T,1}}}) = "success

[julia-users] Re: dynamically describing inner constructors

2015-10-22 Thread Dan
the inner constructor, can separate allocation and initialization of a new object. specifically, first do a: newobj = new() then you can set the fields. with a loop this can look like: fieldvalues = Any[val1,val2,val3] On Thursday, October 22, 2015 at 4:14:51 PM UTC+3, Sloan Lindsey wrote:

[julia-users] Re: dynamically describing inner constructors

2015-10-22 Thread Dan
Oops, random click on post. So: function MyType(..) : : fieldvalues = Any[val1,val2,val3] fnames = fieldnames(MyType) for i=1:length(fnames) setfield!(newobj,fname[i],fieldvalues[i]) end return newobj end On Thursday, October 22, 2015 at 5:52:34 PM UTC+3, Dan wrote: > > the

[julia-users] Re: Finding last modified file in a folder

2015-10-24 Thread Dan
copy-pasted the above and noticed: a) works nicely! b) needs a `using Dates` or `Dates.unix2datetime` to work on my 0.4 release. c) `t -> last(t)` could be just `last` On Saturday, October 24, 2015 at 11:43:28 AM UTC+3, cormu...@mac.com wrote: > > Perhaps > > first(sort(map(f -> (realpath(f),

[julia-users] Re: Help my Row Major brain!

2015-10-27 Thread Dan
putting the transpose inside, might look nicer to some: esol = vcat([exact(t)' for t in linspace(0, 10, 100)]...) On Tuesday, October 27, 2015 at 6:52:21 PM UTC+2, Gabriel Gellner wrote: > > Sadly that wants to make a matrix of two long rows ;) like the hcat(...). > So needs the transpose as

[julia-users] Re: How to get first number from Int64

2015-10-27 Thread Dan
If you do a: precomp = map(log10,2:10) Then a oneliner for the first digit is: searchsortedfirst(precomp, log10(lista[3])%1.0) There are many paths in the garden. But this one is not as long (slow) as it looks. On Tuesday, October 27, 2015 at 10:35:18 AM UTC+2, Alireza Nejati wrote:

[julia-users] Re: Is there a tutorial on how to set up my own Julia cluster?

2015-10-28 Thread Dan
perhaps the [count*] notation means: repeat the line count times i.e.: hd1 hd1 hd2 hd2 : no time to dig or test yet, so this is just another guess. On Wednesday, October 28, 2015 at 9:36:08 PM UTC+2, Ismael VC wrote: > > Hello everyone, > > I have succesfully added all nodes and I can init julia

Re: [julia-users] Arrays as streams / consuming data with take et al

2015-11-09 Thread Dan
XXX in your questions = chain. Or more clearly: julia> stream = chain([1,2,3,4,5]) Iterators.Chain(Any[[1,2,3,4,5]]) julia> collect(take(stream, 3)) 3-element Array{Any,1}: 1 2 3 On Monday, November 9, 2015 at 7:47:51 PM UTC+2, andrew cooke wrote: > > > hmmm. maybe i'm doing it wrong as that

Re: [julia-users] Arrays as streams / consuming data with take et al

2015-11-09 Thread Dan
bered somewhere. On Monday, November 9, 2015 at 10:07:52 PM UTC+2, Dan wrote: > > XXX in your questions = chain. > Or more clearly: > julia> stream = chain([1,2,3,4,5]) > Iterators.Chain(Any[[1,2,3,4,5]]) > > julia> collect(take(stream, 3)) > 3-element Array{Any,1}: >

Re: [julia-users] Arrays as streams / consuming data with take et al

2015-11-09 Thread Dan
/JuliaLang/Iterators.jl i guess. > > it doesn't support read though (which i didn't realise i needed when i > first asked). > > i'll add a warning to StatefulIterators pointing people to this. > > thanks, > andrew > > On Monday, 9 November 2015 17:07:52

Re: [julia-users] Arrays as streams / consuming data with take et al

2015-11-09 Thread Dan
2 3 julia> collect(rest(1:3,start(1:3))) 3-element Array{Any,1}: 1 2 3 Shouldn't the type of both arrays be the same? (the latter defined in non-global context still yield Any Array). On Monday, November 9, 2015 at 10:45:12 PM UTC+2, Dan wrote: > > the example with `pull` befor

[julia-users] Re: Median filter

2015-11-10 Thread Dan
As a quick stopgap, you could use the following: medianfilter1(v,ws) = [median(v[i:(i+ws-1)]) for i=1:(length(v)-ws+1)] medianfilter(v) = medianfilter1(vcat(0,v,0),3) `medianfilter` does a 3 window median filter. It is not the fastest implementation, but it works (hopefully). On Tuesday, Nov

[julia-users] Find

2015-11-14 Thread Dan
`x .> 3` is a bit-array. The function form, which is probably what fits, is `x->x.>3` (the back-ticks are for quotation, not part of the code).

[julia-users] Re: push! performance

2015-11-15 Thread Dan
AFAIK the implementation of `push!` in Julia only occasionally allocates a bigger buffer for the new vector. This results in a very low average time for adding multiple elements (O(1) amortized time in complexity jargon). Notice, `a = [a new_element ]` would in Julia do something else than `pus

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
the columns of A'A when A is sparse are just sparse linear combinations of columns of A. the coefficients being stored in the column-based sparse matrix representation (internally a vector of coefficients with pointers to new-column indices). so simply generating column by column with a for loop

[julia-users] Re: Converting ASCIIString to and from Array{UInt8,1}

2015-11-17 Thread Dan
`convert` is the go-to equivalent in Julia of casting. In this case: uint_array = convert(Vector{UInt8},str) but there are many ways of getting similar results! BTW `convert(ASCIIString,uint_array)` gets back. On Wednesday, November 18, 2015 at 1:49:36 AM UTC+2, James Gilbert wrote: > > Solv

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
Well, its not as simple as that because of everything being sparse (adding columns is not just a loop over sum). Actually, it would be interesting to see a clever solution. On Wednesday, November 18, 2015 at 2:14:39 AM UTC+2, Dan wrote: > > the columns of A'A when A is sparse are

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
On Wednesday, November 18, 2015 at 2:30:14 AM UTC+2, Dan wrote: > > Well, its not as simple as that because of everything being sparse (adding > columns is not just a loop over sum). Actually, it would be interesting to > see a clever solution. > > On Wednesday, November 18, 201

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
) while sp.colptr[col+1]=sp.colptr[col2+1] col2+= 1 end @show col,col2,sp.nzval[i],sp.nzval[j] res[col,col2] += sp.nzval[i]*sp.nzval[j] end end res end On Wednesday, November 18, 2015 at 3:35:30 AM UTC+2, Dan wrote: > > T

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
]*sp.nzval[j] end end res end On Wednesday, November 18, 2015 at 3:54:56 AM UTC+2, Dan wrote: > > Oops... a bug (which showed itself when matrix was sparser than my > previous tests): > [when columns where completely empty, the first `if` should have been a > `while

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
It works, but it is slow (compared to `full(A'*A)`) On Wednesday, November 18, 2015 at 3:56:31 AM UTC+2, Dan wrote: > > And finally, getting rid of debug print. > > function AtrA(sp::SparseMatrixCSC) > res = zeros(eltype(sp),sp.n,sp.n) > col = 1 > @inboun

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
Embarrassingly, there is yet another bug. while sp.colptr[col+1]=sp.colptr[col2+1] col2+= 1 end res[col,col2] += sp.nzval[i]*sp.nzval[j] end end res end On Wednesday, November 18, 2015 at 4:18:37 AM UTC+2, Dan wrote: > > It works, but

[julia-users] Re: Looking for a few good algorithms

2015-11-17 Thread Dan
so get improvement for the original problem. The trick is doing the calculation in the right direction for the sparse storage, and it also uses the fact A multiplied by its own transpose. The exact speedup depends on the density and size. But I got 4x on `sprand(200,400,0.1)` On Wednesday, Novembe

[julia-users] Re: Better alternative to find all permutations?

2015-11-19 Thread Dan
How about this: using StatsBase using Iterators function uniquepermutations(base) zpos = Vector{Vector{Vector{Int}}}() zval = Vector{Int}() left = length(base) for (v,c) in countmap(base) push!(zpos,collect(subsets(collect(1:left),c))) push!(zval,v) left -=

[julia-users] Re: Better alternative to find all permutations?

2015-11-19 Thread Dan
Well, the previous listing worked only for Int vectors. Following is a more properly typed version. Various optimizations are possible: @inbounds, reducing allocations, etc. function uniquepermutations(base) zpos = Vector{Vector{Vector{Int}}}() zval = Vector{eltype(base)}() left = le

[julia-users] Re: Better alternative to find all permutations?

2015-11-19 Thread Dan
Knuth's lexicographic permutations version is best (in terms of speed, memory. perhaps less readable). The function name in the code snippet even has a little permutation by itself ;)

[julia-users] Re: Coveralls/Codecov report certain lines are not covered, but test for the lines do appear to exist in code

2015-11-21 Thread Dan
Regarding the last printing point only print(string(eltype(8)) * ", " * string(eltype(8))) is probably what you meant. AbstractString(Int64), tries to create an AbstractString from an Int64, while string(Int64) asks for a string representation. The latter semantics is more accurate, and works.

[julia-users] Re: What is the best way to get two by two tables in Julia?

2015-11-22 Thread Dan
Hi Arin, It would be helpful to have more details about the input (a dataframe?) and output (a two-by-two table or a table indexed by categories?). Some code to give context to the question would be even more help (possibly in another language, such as R). Having said this, here is a starting p

Re: [julia-users] Re: split a utf-8 string

2015-11-22 Thread Dan
`split` already has hooks for using other splitters. To achieve the UTF8 space splitting functionality, one can leverage the `isspace` function and add some decorations. For example: type FuncSplitter pred::Function end function Base.search(s::AbstractString, splt::FuncSplitter, start::In

Re: [julia-users] Re: Better alternative to find all permutations?

2015-11-22 Thread Dan
If we are already at this, it would be cool to have versions with Gray ordering. Something like: for (i1,i2) in permutations(vector,indices=true,Gray=true) theperm[[i1,i2]] = theperm[[i2,i1]] @show theperm end would go over all permutations. The syntax would be different and t

Re: [julia-users] Concatenation without splatting

2015-11-23 Thread Dan
Using `append!` instead of `push!` and letting efficient dynamic reallocation of vector do the resizing: function vcat_nosplat2a(y) result = Array(eltype(y[1]), 0) for a in y append!(result, a) end result end (@benchmark shows way less allocations and 2-3x time) BTW the s

[julia-users] Re: Precompilation and functions with keyword arguments

2015-11-25 Thread Dan
I've managed to reproduce the timing peculiarities you described, with a different function. In fact, I get the same first run slower behavior even with regular functions with -no- keywords. It is almost as if `precompile` is not doing the entire job. Have you tried, just testing the basic preco

[julia-users] Re: Precompilation and functions with keyword arguments

2015-11-25 Thread Dan
Aha! tested the same sequence in a non-REPL run and the 1st and 2nd runtimes after a `precompile` are the same. On Wednesday, November 25, 2015 at 10:23:04 PM UTC+2, Dan wrote: > > I've managed to reproduce the timing peculiarities you described, with a > different function. In f

[julia-users] Re: Precompilation and functions with keyword arguments

2015-11-25 Thread Dan
rapper) { : : : if (sf->linfo->functionObject != NULL) { // found in the system image: force a recompile Function *llvmf = (Function*)sf->linfo->functionObject; if (llvmf->isDeclaration()) { sf->linfo->specFunctionObject = NULL; sf->li

[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Dan
have you tried running collect within a function? sometimes the Global scope is bad for type inference. On Saturday, November 28, 2015 at 2:45:26 AM UTC+2, ele...@gmail.com wrote: > > Collect only requires that the collection is iterable, for which providing > an eltype() function is optional.

[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Dan
Looking at the collect code, it seems you really should define Base.eltype for your iterator and things will work out. On Saturday, November 28, 2015 at 3:15:18 AM UTC+2, Seth wrote: > > I guess that makes sense, though I struggle to see why one would create an > iterator that produces multiple

[julia-users] Re: Arrays of arrays.

2015-11-29 Thread Dan
Since this situation comes up once in a while, it might be nice to have a copyfill which does a copy on each cell. In code: function copyfill!{T}(a::Array{T}, x) xT = convert(T, x) for i in eachindex(a) @inbounds a[i] = copy(xT) end return a end copyfill(v, dims::Dims)

Re: [julia-users] Re: Arrays of arrays.

2015-11-29 Thread Dan
`. all this is unnecessary, but might help for readability purposes. On Sunday, November 29, 2015 at 3:49:19 PM UTC+2, Milan Bouchet-Valat wrote: > > Le dimanche 29 novembre 2015 à 04:21 -0800, Dan a écrit : > > Since this situation comes up once in a while, it might be nice to > &g

Re: [julia-users] Re: slow wordcount

2015-11-30 Thread Dan
Can you provide the comparable python code? Perhaps even the data used for testing? Since you are evaluating Julia, there are two important points to remember: 1) In Julia because the language is fast enough to implement basic functionality in Julia, then the distinction between Base Julia and

Re: [julia-users] Re: slow wordcount

2015-11-30 Thread Dan
Some points: 1) If you are timing the program by running from shell (i.e. including the whole Julia load time) - it's not a good idea for a bunch of reasons. 2) The printouts are also a little dubious to be used in a test. 3) Too short an input makes the test noisy. On Monday, November 30, 2015

Re: [julia-users] Re: slow wordcount

2015-11-30 Thread Dan
: for t in sort(collect(wc), lt=customlt) println(t.first, "\t", t.second) end end On Monday, November 30, 2015 at 5:08:56 PM UTC+2, Dan wrote: > > Can you provide the comparable python code? Perhaps even the data used for > testing? > > Since you are eval

Re: [julia-users] Re: slow wordcount

2015-11-30 Thread Dan
om/juditacs/wordcount#leaderboard for details) > > Dan: > I can use external packages, it's not a big issue. However, FastAnonymous > didn't give results comparable to python. > The baseline python code I compare to is here: > https://github.com/juditacs/wordcoun

Re: [julia-users] Re: slow wordcount

2015-11-30 Thread Dan
and replacing println("$(t.first)\t$(t.second)") with @printf("%s\t%d\n",t.first,t.second) also halves the print time (which might or might not make a big difference but definitely > 1 second) On Monday, November 30, 2015 at 6:20:54 PM UTC+2, Dan wrote:

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

2015-12-01 Thread Dan
suggestion: call the named argument `lt` to match the argument of `sort`. On Tuesday, December 1, 2015 at 6:23:07 PM UTC+2, Júlio Hoffimann wrote: > > Hi Erik, > > What I meant was a derived type from Julia's Tuple type. Though I agree > with you that this may be too much of an overhead for such

[julia-users] Re: hex to bit notation

2015-12-02 Thread Dan
The shift and AND operators are usually used in these situations (>> and &). With the following definition: getbit(x::UInt64,i) = Int((x >> (64-i))&1) You can get any bit from a 64-bit unsigned integer. For example getbit(0xa7f1d92a82c8d8fe,29). On Wednesday, December 2, 2015 at 11:41:51 AM UT

[julia-users] A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die

2015-12-09 Thread Dan
*A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die * >From a design patterns and DRY perspective it seems `for` loops together with >the `break` statement are serving as a useful `try`/`catch` mechanism for non-error situations. A common

[julia-users] A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die

2015-12-09 Thread Dan
*A non-breaking Julia control-flow change to separate the One language from * *mortal languages, doomed to die * >From a design patterns and DRY perspective it seems `for` loops together with >the `break` statement are serving as a useful `try`/`catch` mechanism for non-error situations. A c

[julia-users] A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die

2015-12-09 Thread Dan
*A non-breaking Julia control-flow change to separate the One language from * *mortal languages, doomed to die * >From a design patterns and DRY perspective it seems `for` loops together with >the `break` statement are serving as a useful `try`/`catch` mechanism for non-error situations. A c

Re: [julia-users] Re: A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die

2015-12-09 Thread Dan
27;m sure the syntax needs cleaning up. > > -erik > > > > On Wed, Dec 9, 2015 at 10:47 AM, Seth > wrote: > >> Seems to me that this is just a more complex repeat...until or do...while >> bottom-conditional loop, which has already been discussed and rejected (

[julia-users] Re: DataFrame melt question

2015-12-16 Thread Dan
the following re-reads the header and generates a dictionary which assigns the original column name to the converted one, in a one-liner-ish: df = readtable("/the/file.csv") h = Dict(zip(keys(df.colindex.lookup),split(open("/tmp/file.csv") do f chomp(readline(f)) ; end,",")[collect(values(df.co

[julia-users] Re: Compute selected eigenvectors with eigvecs

2015-12-16 Thread Dan
Linear algebra tells us Symmetric matrices have real eigenvalues and general matrices have complex eigenvalues in general. `eigvecs` can be called with an upper and lower bound on the eigenvalues of the eigenvectors to be found, but upper and lower bounds are applicable only to Real numbers, wh

[julia-users] Re: Using callable types or FastAnonymous with Sundials

2015-12-18 Thread Dan
The parameter for the `cvode` function is `f` and so is the function you want to use. These get confused, and it tries to use the "function" `J` instead. Changing the parameter name to something other than `{f}` should work On Wednesday, December 16, 2015 at 4:26:41 PM UTC+2, Simon Frost wrote:

[julia-users] Re: python a[range(x), y] equivalent in Julia

2015-12-20 Thread Dan
Is the following red expression a good Julia equivalent: julia> a = [ -1 2; 3 -4 ] ⋮ julia> y = [ 1, 2 ] ⋮ julia> [a[i,y[i]] for i=1:2] 2-element Array{Any,1}: -1 -4 (it's also fast) On Sunday, December 20, 2015 at 2:44:20 AM UTC+2, Lex wrote: > > I am expecting [-1 -4] in the Julia e

[julia-users] Keeping heads and tails

2016-06-09 Thread Dan
Hello All, Given a vector (v) of length n, if I want to truncate it to its first k elements. How does one do this? My code currently uses `deleteat!(v,(k+1):length(v))`. But this is somewhat cumbersome and might be inefficient since `deleteat!` has to take care of all other ranges of elements

[julia-users] Re: Keeping heads and tails

2016-06-09 Thread Dan
Great. This is exactly what I needed. On Thursday, June 9, 2016 at 5:11:05 PM UTC-4, Kristoffer Carlsson wrote: > > Use resize! maybe.

[julia-users] Re: local package, howto?

2016-06-12 Thread Dan
Not sure, but I may have had a similar problem and doing (in the shell): git config --global url."https://".insteadOf git:// solved it. On Sunday, June 12, 2016 at 1:42:13 PM UTC-4, Andreas Lobinger wrote: > > Hello colleagues, > > like with similar problems, i don't know how i ended up ther

Re: [julia-users] Abstract version of rng=1:end ?

2016-06-13 Thread Dan
A reason such 'extended' ranges might be good, is the ability to dispatch on them for efficiency. For example, `deleteat!(vec,5:end)` could be implemented faster than just any `deleteat!` of any range. This would be applicable to other such structures with edge effects. Indeed, we can learn fr

[julia-users] Re: Value written to file different from value printed

2016-06-17 Thread Dan
The print to screen statement is rather unequivocal. By elimination, the -1 in the file is the culprit. My guess is the -1 in the file is the value of a different variable. When writing to the file, add some text to identify which line is which var. Notice all vars are initialized to -1. P.S. I

Re: [julia-users] How to make a Matrix of Matrix's?

2016-06-23 Thread Dan
[[M] [M]] works. And is the same as Matrix{Float64}[[M] [M]] But concur it is unintuitive. On Thursday, June 23, 2016 at 10:28:39 PM UTC-4, Sheehan Olver wrote: > > > [M,M] will do a Vector of Matrices in 0.5. But [M M] still does > concatenation. So the question is how to do Matrice

[julia-users] Re: readdlm() pound sign at beginning of string is not read

2016-06-26 Thread Dan
Yes, this is the intended functionality because # is used a character which starts a comment in the file which is not parsed. The simplest way around this is to disble comments using the named parameter `comments` like this: readdlm(file,'\t',comments=false) You can also change the character

[julia-users] Re: Another nested function scope issue

2016-07-01 Thread Dan
Can you explain why it modified the one from the second block? On Friday, July 1, 2016 at 9:58:26 AM UTC-4, FANG Colin wrote: > > Never mind, I get it. > > On the third run, the `state` variable that `counter` modified is the one > from the second let block. >

[julia-users] Re: changing record separator to read text files

2016-07-09 Thread Dan
`readuntil` is your friend. `readline` uses `readuntil`. In fact, it is defined as: readuntil(s,'\n') On Saturday, July 9, 2016 at 7:40:37 AM UTC-4, Fred wrote: > > Hi ! > > It is often very useful to read a text files by blocks of lines, using > another line separator than '\n'. > > Especial

[julia-users] Re: caching the pivot ordering for a sparse cholesky factorization?

2016-07-09 Thread Dan
Hi Gabe, SuiteSparse which comes together with Julia includes a library KLU which does sparse LU factorization. It has the option to return the fill-in reducing order it manages to find for a given sparsity pattern. With this returned structure it can subsequently factorize many matrices (and s

[julia-users] Re: caching the pivot ordering for a sparse cholesky factorization?

2016-07-11 Thread Dan
different solution it would be interesting to hear about it. On Sunday, July 10, 2016 at 9:38:44 PM UTC-4, Gabriel Goh wrote: > > I'd love more details Dan! > > On Saturday, July 9, 2016 at 8:53:16 PM UTC-7, Dan wrote: >> >> Hi Gabe, >> >> SuiteSparse whi

[julia-users] Re: Want: "Deprecation" badge for Github

2016-07-12 Thread Dan
+1 There was also a suggestion at JuliaCon the badge could count the number of warnings displayed - perhaps, this would give some incentive for progressive cleanup/levelingup of code. On Tuesday, July 12, 2016 at 1:15:24 PM UTC-4, Erik Schnetter wrote: > > Our Julia projects live on Github, and

[julia-users] Re: Linear-Equation-System Solver("\") does not work reliably for the "Rational" Type

2016-07-15 Thread Dan
and as it should be A*x == v is true. Hope this helps. -- Dan On Friday, July 15, 2016 at 2:50:01 PM UTC-4, Kurolong wrote: > > Hey Guys and Gals ^^ > I'm having trouble with Julia. Maybe one of you can help me out > The program i am writing requires the > linear-equation-

[julia-users] Re: Unexpected Performance Behaviour

2016-08-02 Thread Dan
The following standalone version recovers the speed of `test2` using the @fastmath macro. Integer exponents have trade-offs in implementation using repeated squaring and multiplication and intrinsic power instructions. Not really sure how to control the implementation used in every instance. fu

[julia-users] Re: Unexpected slowdown

2016-08-22 Thread Dan
Try keeping the loop over all primes and breaking when `a > maxp` where maxp is calculated once before the loop as `maxp = floor(Int,sqrt(n))`. On Monday, August 22, 2016 at 4:58:30 PM UTC-4, Achu wrote: > > I have a simple piece of code that finds me 10001 prime numbers. > > function a() > pl=[

[julia-users] Julia Zmq Server creates Memory Leaks

2016-09-05 Thread Dan
Hi, I am trying to create a Julia server instance by using ZMQ with the Req/Rep pattern. My Julia code for the Rep-server looks like this: module JServer # import zmq using ZMQ import Base.gc # create context ctx=Context(); # create socket socket=Socket(ctx, REP); # msg msg = 0; # repeate

Re: [julia-users] Julia Zmq Server creates Memory Leaks

2016-09-05 Thread Dan
This did the trick. Thanks!

[julia-users] Re: dependent types in julia?

2016-09-14 Thread Dan
Maybe the following is the form you are looking for: julia> decomplexify{T}(::Type{Complex{T}}) = T decomplexify (generic function with 1 method) julia> type bar{S,T} sum::S sumsqr::T function bar(s,ss) if typeof(ss) != decomplexify(typeof(s))

[julia-users] Re: Optimize sum of elements in an Array according to some conditions

2015-12-30 Thread Dan
Thanks Kristoffer, turns out there is always interesting stuff in the bag of optimization tricks. Regarding the original function, a cheat could make it faster: The `x` vector is sorted, which means: function calcSum4(x::Array{Float64,1}, y::Array{Float64,1}, Ei::Float64, Ef::Float64, N::Int64)

Re: [julia-users] Re: Optimize sum of elements in an Array according to some conditions

2015-12-30 Thread Dan
15 at 11:54:27 PM UTC+2, Charles Santana wrote: > > Thanks, Dan! Indeed my "x" vector is sorted and your suggestion is really > fast! > > Best, > > Charles > > On 30 December 2015 at 12:08, Dan > wrote: > >> Thanks Kristoffer, turns out there is a

Re: [julia-users] Iterating over leafs of a tree: use Cartesian?

2016-01-08 Thread Dan
For the special problem of getting all the betas in the post, they can be calculated with combinatorics: betas(levels,parts) = map(x->([x;levels+parts].-[0;x]-1)/parts, combinations(1:(levels+parts-1 ),(levels-1))) The idea is to choose which parts of (0.0,0.2), (0.2,0.4)... (0.8,1.0) go in

[julia-users] Re: What's the difference between unique(a) and union(a)

2016-01-13 Thread Dan
Essentially, not much. `union` accepts multiple arguments with multiple types, but `unique` accepts a single collection. For example: union(1,2,3,3) == unique([1,2,3,3]) This would probably make `union` slightly slower. On Wednesday, January 13, 2016 at 11:58:18 PM UTC+2, Sheehan Olver wrote: > >

Re: [julia-users] randperm run time is slow

2016-01-23 Thread Dan
Another way to go about it, is to look at R's implementation of a random permutation and recreate it in Julia, hoping for similar performance. Having done so, the resulting Julia code is: function nrandperm(r::AbstractRNG, n::Integer) res = Array(typeof(n),n) if n == 0

Re: [julia-users] randperm run time is slow

2016-01-24 Thread Dan
at 4:43:36 PM UTC+2, Kevin Squire wrote: > > Hi Dan, > > It would also be good if you deleted that post (or edited it and removed > the code), for the same reason Viral mentioned: if someone reads the post > and then creates a pull request for changing the Julia implementati

Re: [julia-users] randperm run time is slow

2016-01-24 Thread Dan
A good description of random permutation generation is given in Wikipedia. It's the Fisher-Yates algorithm and its variants. On Saturday, January 23, 2016 at 4:43:36 PM UTC+2, Kevin Squire wrote: > > Hi Dan, > > It would also be good if you deleted that post (or edited it a

Re: [julia-users] Adding a mtrix to the third dimension of a multi-dimensional array

2016-02-14 Thread Dan
>From the help for `cat`: cat(dims, A...) Concatenate the input arrays along the specified dimensions in the iterable dims And indeed, if size(M1)=(3,3,3) and size(M2)=(3,3) Then, size(cat(3,M1,M2)) = (3,3,4) This method may not be efficient (though in terms of memory layou

Re: [julia-users] Adding element to array and filtering multi-dimensional arrays.

2016-02-22 Thread Dan
On Monday, February 22, 2016 at 12:18:02 PM UTC+2, Tamas Papp wrote: > > > On Mon, Feb 22 2016, Aleksandr Mikheev wrote: > > > Hi everyone. I have two simple questions, answer to which I cannot find > by > > myself. > > > > 1. Is there any way to add an element to array? For example, I have

[julia-users] Re: What wrong in (D'*D)/k.-(mean(D,1)'*mean(D,1)) ?

2016-03-04 Thread Dan
The matrix `D` is based on type `Int8` which overflows and wraps (without error) very quickly. The `cov` function automatically converts to a `Float64` but the manual calculation does not. To make the calculations match, try: D = convert(Matrix{Int},D) On Friday, March 4, 2016 at 10:42:02 AM UTC

[julia-users] Re: what name would you give to the functional 'complement' of trunc()?

2016-03-12 Thread Dan
trunc_to_inf and add an alias trunc_to_zero for regular trunc ?? On Saturday, March 12, 2016 at 1:49:41 PM UTC+2, Jeffrey Sarnoff wrote: > > x = trunc(fp) yields fp rounded towards zero to the closest integer valued > float. > What name would you give to the complementary function, rounding away

Re: [julia-users] Re: Mmap allocation question

2016-03-12 Thread Dan
It's better to have code which actually runs in the post. In any case, the allocations at the `for` lines is suspicious - the for should basically only allocate a counter. Are there any global variables? Is `counter1` or `counter2` or `dims` global? Globals are always a good source of confusion

Re: [julia-users] Re: Mmap allocation question

2016-03-12 Thread Dan
unning the code from the REPL, may that be a problem? (As I read in > the REPL everything is global). In the file nothing is global. > Also, the counters are UInt16s, but that shouldnt matter I guess. > > Thanks for the help so far! > > On Saturday, 12 March 2016 14:22:38 UTC+1, Dan

[julia-users] Re: How do I, as efficiently as possible, iterate over the first and last elements along a given dimension of an array?

2016-03-23 Thread Dan
# something along these lines: topleft(A,d) = tuple(ones(Int,ndims(A))...) bottomleft(A,d) = tuple([i==d ? 1 : e for (i,e) in enumerate(size(A))]...) topright(A,d) = tuple([i==d ? e : 1 for (i,e) in enumerate(size(A))]...) bottomright(A,d) = size(A) mapedges(A,d) = zip( CartesianRange{Cartesian

[julia-users] Re: How do I, as efficiently as possible, iterate over the first and last elements along a given dimension of an array?

2016-03-23 Thread Dan
as a matrix reshape(map(x->A3[x[1]]+A3[x[2]],mapedges(A3,3)),dropdim(A3,3)) On Thursday, March 24, 2016 at 3:21:02 AM UTC+2, Dan wrote: > > # something along these lines: > > topleft(A,d) = tuple(ones(Int,ndims(A))...) > bottomleft(A,d) = tuple([i==d ? 1 : e for (i,e) i

  1   2   >