56,372 reputation
5158249
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 37
visits member for 2 years, 6 months
seen 16 mins ago

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


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 :-).
Jul
24
comment Code Readability and Object-Oriented Code
@Rojo Yeah, may be you're right. I am becoming too pragmatic. I also started by breaking all the rules in M (actually, I wasn't aware of any, since I did not read forums etc, was just experimenting for quite a bit on my own when started with it). But when you program in several languages on a daily basis and solve a number of specific problems, you become more pragmatic. Not sure it is good though.
Jul
24
comment Code Readability and Object-Oriented Code
@Rojo ... use custom data structures in M is more often than not more than the threshold of implementing a problem in a different way. I've seen a number of examples where the use of M-style data structures was very beneficial from the readability viewpoint, but my point is that, because there are so many ways to do it, only quite skilled M users are able to do it well and not abuse them. OTOH, in languages like C or Java, even users with relatively weak skills can handle them reasonably well, since the number of choices is much less and number of associated pitfalls even lesser.
Jul
24
comment Code Readability and Object-Oriented Code
@Rojo I don't object to that, but then don't use mutable elements and / or operations, use immutable data structures with symbolic heads standing for types. Such as circle[{x,y},r], and define selectors and mutators as say circle/:getX[c_circle]:=c[[1,1]], etc. There is another important conceptual point which I did not list: data structures (ADT-s) serve to separate interface from implementation. But M's flexibility does not enforce that, so we often leak implementation details for our structs into the public interfaces they provide. The amount of discipline required to create and ...