57,072 reputation
5160253
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 37
visits member for 2 years, 7 months
seen 5 hours ago

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


Aug
8
awarded  Good Answer
Aug
8
comment How to perform a depth-first preorder traversal of an expression?
Related topic: I have implemented a special version of Cases which performs the depth-first preorder traversal (perhaps not optimally). In that case, this was important to avoid unpacking during the traversal performed by Cases.
Aug
1
comment Using block or module to free cache
You may find this question relevant, and possibly also this one.
Aug
1
comment Specifying string patterns in DeleteCases
I would say that the reason is dead simple and not directly related to the added functionality being just big. Cases and DeleteCases work on parsed expressions, while string functions work on strings. These are just so different that mixing them togeher would be a very wrong design decision IMO.
Aug
1
comment How to get complete Documentation Center graph of guide pages?
Thanks, @Vitaliy, glad I could help.
Aug
1
awarded  Enlightened
Jul
31
revised position of sequence of elements in list
added 153 characters in body
Jul
31
revised position of sequence of elements in list
Changed to use Internal`Bag; added 7 characters in body
Jul
31
answered position of sequence of elements in list
Jul
31
comment position of sequence of elements in list
The fastest solution I know is the seqposC function from this answer. There was also the same question asked on StackOverflow before, with several nice answers posted there.
Jul
31
comment Converting other C++ classes to MTensor in LibraryLink
A simple self-contained example with a toy matrix class would make it easier to answer. I am not aware of a bulk constructor of MTensor which would take an array and dimensionality and construct MTensor by passing a reference to an array. So, it seems that you will have to construct MTensor instance from your class's data at least once. You may choose to share memory with the kernel though, which may help you avoid making extra copies.
Jul
31
comment Converting other C++ classes to MTensor in LibraryLink
Unless you can get a hold on the pointer to the (multi-dimensional) array which is used by that class to store the data (which is hardly recommended since most likely a different memory management scheme (new-delete) was used there, and in addition this will in any case require the knowledge of implementation details of that class, relying on which is also hardly recommended), I don't see a way for you to avoid the reallocation. Presumably you should be able to subclass the class in question and add a method that would convert its data to a proper MTensor form.
Jul
27
comment Find subexpression to minimize leafcount after replacment with temporary variable
Hi @belisarius! You will have to modify code for csub a bit, and tweak the limitCount parameter. In the code for csub, I put a restriction Depth[Unevaluated[x]] > 2. Change this to Depth[Unevaluated[x]] > 1, and set limitCount to 2 (say): csub[Hold[Evaluate[expr]], {}, 2]. I get then: Hold[Let[{$25 := x + y + z}, Hold[(Sin[$25]/$25)^$25]]]. I should probably make a minimal depth as a parameter. I could also add a LeafCount minimizer which would automatically try different values for parameters and optimize minimal depth and limitCount.
Jul
27
revised Find subexpression to minimize leafcount after replacment with temporary variable
Added a leafcount
Jul
27
answered Find subexpression to minimize leafcount after replacment with temporary variable
Jul
27
comment Efficient Langevin Equation Solver
+1. B.t.w., you don't need extra With[{f=fn},...] at the start, since the semantics of parameter-passing for functions defined with patterns is the same as with rule substitutions, and that will guarantee that your f would be injected into the body of Compile.
Jul
26
comment Efficient Langevin Equation Solver
You can use JIT-compilation, but my tests show that this only improves speed by about 10-15 percents. The running time seems to be dominated by the random number generation, which, for your example, is done in chunks large enough so that compilation does not bring much speed improvement. So, your function is pretty efficient, both because you generate random numbers in large enough chunks, and because NestList auto-compiles. It may make more sense to compile it if, for example, you would use it with small m argument in a loop.
Jul
25
awarded  Nice Answer
Jul
25
comment Where can I find examples of good Mathematica programming practice?
Now this is really useful, big +1. The better we categorize all these resources, the more effective this page will be.
Jul
24
comment Code Readability and Object-Oriented Code
@Rojo Ok. I will edit mine too, perhaps tomorrow (got to get some sleep). It was not supposed to be an exact opposite of yours, I just wanted to encourage clear Occam's razor - style thinking about data structures, particularly mutable ones. This was a useful comment exchange, thanks :-).