64,277 reputation
6191283
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 3 years, 2 months
seen 2 hours ago

Ok, an obligatory note: opinions expressed here are mine and not those of my employer.


Feb
5
answered FoldWhile and FoldWhileList
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
@halmir I would rather take the code as a spec and make the description less ambiguous in this respect - presumably the OP looked at the results of his code and was satisfied with it, just not its speed.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
@halmir No, it should not - the first and last columns are always kept and do not participate in the comparison. In a sense, the OP's original rule serves as a very clear spec.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
+1, nice idea, and also seems to be the fastest so far.
Feb
5
revised What are the most common pitfalls awaiting new users?
added 151 characters in body
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
It's good code, +1.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
Help yourself: m = RandomVariate[BinomialDistribution[1, 10^-3], {300, 300}] While[removeZeroVectors[m] == Transpose[Transpose[m //. rule] //. rule] == Nest[rZeroVecs[Transpose@#, 2] &, m, 2], m = RandomVariate[BinomialDistribution[1, 10^-3], {300, 300}]].
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
@Rojo Sorry, I saw it but did not connect to this.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
Actually, your code produce different results from mine or @belisarius's, for some benchmarks - your matrices end up smaller.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
Ok, I see. This is a nice code, +1.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
How is z used?
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
@Rojo Thanks. I tried to keep the solution essentially rule-based, that's why I went down this road.
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
I wasn't going to produce the fastest solution - otherwise I'd just use Compile. I produced the solution which still uses rules and is two orders of magnitude faster than the original.
Feb
5
comment Position of a pattern-matched part of an expression
Right, that would be nice, but I don't have time today to look at it. May be later.
Feb
5
answered Performance: Collapsing repeated contiguous rows & cols from a matrix
Feb
5
comment Position of a pattern-matched part of an expression
Yes, it should work, for example with the following expression: expr = {h[g[f[x, 9, v, h[v], 3[5], v, y]], f[x, 9, v, h[v], 3[5], v, y]], f[x, 9, v, h[v], 3[5], v, y]}, and the pattern: pattern = h : HoldPattern@f[x, _, wally_, __, 3[5], wally_, y].
Feb
5
comment Position of a pattern-matched part of an expression
It seems tht our solutions have similar idea behind them, but yours takes care to not evaluate the code (I didn't care since you didn't list it as a prerequisit), and also takes care of conditional patterns etc. Mine however does not assume that expr matches the pattern, but that expr might have subexpressions matching it, so is a bit more general in that respect. In any case, it looks like it's hard to come up with something much better than some variant of tagging / labeling.
Feb
5
comment How to define a package without adding it to $ContextPath
@JoelKlein Oh yeah :)
Feb
5
comment How to define a package without adding it to $ContextPath
@Rojo Yeah, right. I still remember that post, for some reason, although it was nothing particularly special. I actually remember many of my posts, perhaps too many. But you've made a long way since then. You and rm -rf are among a few here who have made huge leaps in terms of Mathematica skills in an amazingly small period of time. You guys are scaring me.
Feb
5
comment How to define a package without adding it to $ContextPath
@Rojo My guess is that $ContextPath is redefined by BeginPackage, and it is its standard function to remove from it all contexts except System` and add the package's context to it. However, the previous value is stored on some kind of stack. The way it is then restored must be something like $ContextPath = Join[$oldContextPath, publicly-imported-packages]. Using Block, we block this modification. Then likely EndPackage sees $ContextPath as a symbolic quantity, and this prompts it to recover the previous value on the stack. Something like this.