Reputation
Next tag badge:
207/100 score
19/20 answers
Badges
6 194 285
Newest
 Nice Answer
Impact
~407k people reached

Feb
16
revised Is it possible to use Compile on a function with optional arguments?
Added auto-compilation
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
@Szabolcs That's what your previous comment prompted me to start doing :)
Feb
15
answered Is it possible to use Compile on a function with optional arguments?
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
@Szabolcs Well, I was hoping that someone would come up with something more clever :-). All right, putting this as an answer...
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
@Xerxes This is a good point. There indeed may be situations where treating the second argument as a constant may significantly speed up the code, although those probably won't represent the majority of use cases.
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
Just compile as you would do for a full list of arguments, such as compJ = Compile[{x, y}, x + y], and then delegate the execution from your main function j to compiled one as j[x_, y_: 1] := compJ[x, y].
Feb
14
comment how to read in a file in the same directory?
@JoelKlein Thanks, I am aware of that.
Feb
13
comment How to clear parts of a memoized function?
Yes, I think this is correct - the option only governs the hashed values, not pattern-based rules. And as long as we don't count on the ordering of DownValues with the Sort->False option setting being some specific ordering (like e.g. the order in which they were entered), I think the results will not depend on the particular ordering. Of course, the main reason to use Sort->False option is for speed, since we then skip the sorting step when extracting the DownValues.
Feb
13
comment How to clear parts of a memoized function?
One comment (+1,of course) - with the Sort->False option, DownValues are not listed in the order they were entered (which is what I used to think for some time in the past), but in whatever order they are internally stored - which is rather arbitrary in general. This is probably known to you, but some of those reading the answer may be unaware of this.
Feb
13
answered How to clear parts of a memoized function?
Feb
13
awarded  Nice Answer
Feb
12
comment Accessing files in different directories
See also this answer for another example of what I mean.
Feb
12
comment Accessing files in different directories
Don't make your project notebook-centric then. Put your project layout into e.g. $UserBaseDirectory/Applications, and you can use $InputFileName to record the absolute location of your main package at load-time (see this answer for details). Locate your other resources by fixed relative paths, relative to the main package. This is how such things are usually done. Then, in notebook, you will simply have to call Needs[your-package].
Feb
11
comment Read and filter a text file without importing
Have a look at this question. There are a number of solutions shown there, which you might be able to adopt to your situation. All of them will however require to write some custom code.
Feb
11
comment Counting the population of integers
@jVincent To summarize - and this is my last comment on this matter: the beef I have with your approach to benchmarking is that you present benchmarks which are accurate only for a very narrow subset of all possible cases where functions in question can be used (namely, functions used on smallish toy lists, but in a large loop). To my mind, such benchmarks are of limited utility. Also, if you present them / argue about efficiency, you have to always state under which conditions your conclusions are correct - which you did not do, as far as I am concerned.
Feb
11
comment Counting the population of integers
@jVincent "If you have a loop that constantly performs operation f[input,100], it doesn't matter if f[x,n] is O(n) and g[x,n] is O(n^2), you might still have f be the faster solution.`" - right, this is the core of why I find your approach problematic. The statement is correct, but why do you think that this is the main use case for this function? Had the OP faced a problem having this in a large loop, he'd say so in the question. This is not what most people imply when ask to optimize a function. If they need to optimize code in a loop, they would say so.
Feb
11
comment Counting the population of integers
@jVincent For a fixed and small number of unique elements, your benchmarks may make some sense (although this is hardly a general case for this problem). But even in this case, instead of simply repeating the code 10000 times, I would increase the lengths of individual sublists, over which you are counting. This is important, because Count is a pattern-based function. For long sub-lists, Tally shows its advantages. Keeping sublists small as you do in your tests, you measure anything but the interesting parts. So, even in your narrowed formulation, your benchmarking is seriously flawed.
Feb
11
comment Counting the population of integers
@jVincent ... code run on a toy list in question. This is not what Mr.Wizard and myself meant by discussing efficiency, and I dare to say this is not what most people mean by efficiency either. It's probably third time for this post that I am trying to explain this to you. I am really starting to think that you have never yet faced a real-world code optimization problems, otherwise you would know what I mean. You don't have to go far: browse the questions in performance-tuning tag here, and see how benchmarking is typically done, and what people mean by efficiency.
Feb
11
comment Counting the population of integers
@jVincent You seem to not be getting it, even after both myself and Mr.Wizard tried our best to explain. Your tests via running the code 10000 times on the small toy lists are meaningless, because at that scale what you measure is determined not by the true complexity of an algorithm, but by things that become irrelevant for real list samples. Have a look at Mr.Wizard's benchmarks, for more or less real benchmarking. So, to reiterate once again: your statement is correct, but is only meaningful if the OP will only ever be interested in speeding up code consisting of 10000 iterations of a ...
Feb
11
comment Counting the population of integers
@Mr.Wizard Have a look at my new version.