« first day (1872 days earlier)      last day (2602 days later) » 

12:31 AM
@Mr.Wizard This seems almost useless for users on our side. MichealE2 has only one gold-badge, belisarius has 2, Szabolcs has none..
(Oh, I haven't seen that there were several tabs of badges. That increases Michaels gold tag badges to two if I'm not mistaken).
Anyway, it seems like a really high burden just to edit the list of duplicates.
 
 
2 hours later…
2:41 AM
@halirutan Forgive me, but I'm actually being selfish here. Previously it was not possible for moderators to mark a duplicate pointing to more than one original. Regular users could, because if different users voted for different originals that was done automatically. Moderators (or gold tag badge users) have a binding vote and therefore the first vote cast closes the question, marking only one original. Now moderators can edit that list as desired.
This also means that if later another duplicate is found it can be added to the list.
 
@Mr.Wizard No harm done as you are doing most of the dirty work anyway.
I just wondered, looking at the votes e.g. on math.SE, how many users really can take advantage of this.
 
@halirutan I think one must admit that Stack Exchange still takes Stack Overflow as the model for all sites, and bases functionality on what works there foremost.
 
 
1 hour later…
3:53 AM
@Mr.Wizard Thanks! :)
 
 
2 hours later…
5:45 AM
@xslittlegrass Excuse me for "much easier to read than the Chinese".So you mean you can understand totally the usage of Unevaluated here?
@xslittlegrass The English presentations always longer than Chinese..Sometimes it is not a good news to me. :)
 
 
5 hours later…
10:50 AM
I think the code under "Honorable Mention
George Varnavides: “Symmetry in Chaos” (128 characters)" is incorrect?:
c=Conjugate[#];func=c& won't define a function same as Conjugate[#]&
 
11:09 AM
Oh no, it's correct… but why? Auto-compilation?
 
11:29 AM
Very interesting……
This is related to a very subtle behavior of CompilationOptions -> {"InlineExternalDefinitions" -> True}
a = #;
Compile[{c}, Nest[a &, c, 10],
  CompilationOptions -> {"InlineExternalDefinitions" -> True}] // CompilePrint
can be compiled.
a = #;
Compile[{c}, a &@c,
  CompilationOptions -> {"InlineExternalDefinitions" -> True}] // CompilePrint
can't be compiled
i.e. the a in a& will be inlined only if a& is the first argument of Nest/NestList
 
12:05 PM
@xzczd precedence baby :)
 
12:26 PM
@halirutan Precedence?
 
@xzczd I think bringing a pure function into this example is more confusing. It seems it doesn't work when the inlined symbol is used as a head of a function. Look at this slightly simpler example:
a = Sqrt;
Compile[{c}, a[c],
  CompilationOptions -> {"InlineExternalDefinitions" ->
     True}] // CompilePrint
Doesn't work, but the equivalent Nest version works.
 
Yeah, I think this should be considered as a not-well-known behavior of "InlineExternalDefinitions" ->True
 
@xzczd What I mean is that one might confuse that the part before the ; is separated and you just define func=(c&)
It leaves c unevaluated, but when you apply something to it, it of course evaluates to the earlier defininition of c=Conjugate[#] making it a correct pure function.
@xzczd Often, I inline things into compile making it a pure function.
 
Hi guys i don't know if this is a correct room for this question here: http://dsp.stackexchange.com/questions/38111/correct-method-for-up-sampling-cross-power-spectrum-for-sub-pixel-motion-estimat

anyone care to have a look?
 
@xzczd In your case, you could use Function but it might look confusing:
a = #;
Function[x,
   Compile[{c}, x &@c,
    CompilationOptions -> {"InlineExternalDefinitions" -> True}]
   ][a] // CompilePrint
 
12:35 PM
@halirutan Well, But c=Conjugate[#];c&@I won't evaluate to -I
I mean, usually, in this case, we need c=Conjugate[#];Evaluate[c]&@I or something similar to make it work as expected
This isn't needed for a auto-compiled Nest/NestList
This is the part I found interesting
 
@xzczd But we don't know how exactly it is inlined. So it is not unusual that it works.
What if they do a verbatim replacement like this:
c = Conjugate[#]; With[{c = c}, func = c &]
internally.
 
They didn't do that, because
a = b;
Compile[{c}, Nest[Function[b, a], c, 10],
  CompilationOptions -> {"InlineExternalDefinitions" -> True}] // CompilePrint
isn't compiled :)
@halirutan This behavior is really new to me. I thought "InlineExternalDefinitions" -> True only works for compilable numbers and pure functions.
 
@xzczd This would be exactly where With cannot be used because it respects scope. Look here, doesn't work either:
With[{a = b}, Function[b, a]]
 
Oh……then
a = #;
Compile[{c}, a &[c],
  CompilationOptions -> {"InlineExternalDefinitions" -> True}] // CompilePrint
How about this?
@halirutan They only do the replacement for Nest/NestList? :D
 
@xzczd No, look at this :)
Use {a &, a &[c]} inside your compile and see that a is really replaced in the first case.
@xzczd So the bottom line is: When you want to apply the body of a pure function to a value inside Compile like in your example, you cannot simply write f[x], you need to call Nest[f,x,1] :)
@xzczd This btw, seems not to catch it all. As far as I can see, OwnValues of symbols are inlined.
expr = Nest[Sqrt, c, 10];
Compile[{c}, expr,
  CompilationOptions -> {"InlineExternalDefinitions" ->
     True}] // CompilePrint
works perfectly.
And it's not a number or a pure function, but a general expression in c.
 
12:56 PM
@halirutan Quite interesting…
Oh seems that Compile is more subtle than I thought…
Maybe I should consider posting a relevant question in the main site.
 
@xzczd Yes, there seem to be some subtleties that one isn't aware of.
Although, I'm not sure one can really answer the questions without internal knowledge.
@Jdane Well, your question is about Matlab, not Mathematica. People tend to be picky about this tiny detail :)
 
@halirutan ah I see, now I really felt helpless, god.
 
@Jdane I mean, the underlying problem is very interesting, but well studied. You could restate your question to make it fit here, but I guess a Mathematica solution wont help you.
 
@halirutan alright I try to shift the context, thanks! :)
 
@Jdane Maybe two comments: Always include sample images and make your code executable with them.
People don't know what you are dealing with and image registration can be hard.
2. Why do you upscale the data to get subpixel accuracy? Isn't it better to interpolate the data and search for the maximum?
 
1:12 PM
@halirutan Scaled it up so that I could get sub-pixel accuracy, because the motion is within sub-pixel scale. From the up-sampled data, I'll interpolate again to get the approximation
 
@Jdane Look, how is upscaling done? Right, the data is interpolated to calculate the new pixels.
You can just interpolate the data and work with the interpolating functions and you have infinite upscaling..
 
@halirutan by adding zeros around the actual data. Hers's an example: stackoverflow.com/questions/13501502/matlab-padarray-function
 
@Jdane Oh, you're upscaling in the frequency domain. Haven't seen that.
 
@halirutan Yep, up-scaling in frequency domain is much more efficient than in spatial domain
@halirutan I followed this step from a paper, but I not quite sure I followed it correctly. Is it possible for you to have a look at the paper? It's all mathematical.
 
@Jdane Uhh, it's Saturday. I guess I have to refuse for now. Why don't you include the sample images and the link to the paper in the question?
 
1:30 PM
@halirutan Haha I guess I'll hope for the best. Here's the link to the paper: mega.nz/#!zsdCDZAJ!a-5iu3fBHCdzOLGOahWWX4ydGaNa1UVlKFXbTiH3x88
@halirutan start from section 3 will be fine :)
Thanksssss!!!!
sorry here's the link in case your changed your mind mega.nz/#!PoklnaJR!hj_Bejha6owN1TyyxodM-F-OGvjdZYlyJImNapALXLA
;)
 
2:13 PM
I have a large binary image (~ 3000x4000). I want to partition it into small blocks (e.g., 2x2, 3x3 blocks), and replace each block by a single pixel. It should be black if there was at least one black pixel in the block, and white otherwise. What is a fast way of doing it?
Compile helps a lot. My mistake was to try to work with images directly instead of extracting the data. cf = Compile[{{arr, _Integer, 2}, {n, _Integer, 0}}, Map[Min, Partition[arr, {n, n}], {2}]]. Just make sure that the array dimensions are divisible by n.
 
 
1 hour later…
3:35 PM
 
3:48 PM
@Szabolcs A beautiful landscape painting in the last frame..The code will be spread?
 
Sure, why not?
I want to improve it a bit first.
 
@Szabolcs Same to your code but concise..
 
@yode For large arrays BlockMap is slower, but for smaller ones it is considerably faster than my compiled function. I wonder why. Thanks for the tip!
 
 
2 hours later…
5:33 PM
@Szabolcs But this test show the compile seem to take a little effect?
I have to say the compile is a big hole in Mathemtica..
 
MMM
5:53 PM
eqn = {x''[t] + w^2*x[t] == 0, y[t] == x'[t]}; w = 1;
sol = DSolve[eqn, {x[t], y[t]}, t];
xt[t_] = Flatten[x[t] /. sol /. {C[1] -> 1, C[2] -> 1}][[1]];
yt[t_] = Flatten[y[t] /. sol /. {C[1] -> 1, C[2] -> 1}][[1]];
yx[x_] = yt[InverseFunction[Function[{a}, xt[a]]][x]];
Plot[yx[x], {x, -0.5, 0.5}, AspectRatio -> Automatic,
PlotRange -> All]
Show[ParametricPlot[
Evaluate[{x[t], y[t]} /. First[sol] /. {C[1] -> 1, C[2] -> 1}], {t,
0, 10}],
Plot[yx[x], {x, -0.5, 0.5}, AspectRatio -> Automatic,
PlotStyle -> Red]]
 
6:03 PM
@Szabolcs Consider the following approach:
cf1d = Compile[{{line, _Integer, 1}},
   Map[Min, Partition[line, 2]],
   CompilationTarget -> "C", RuntimeAttributes -> {Listable},
   Parallelization -> True
   ];
step[data_] := Transpose[cf1d[Transpose[cf1d[data]]]]
If your operator is separable, you can run it on each line and with the help of compiles parallilization, calculate each line in parallel. Then, you just transpose the result and do it again.
With n=2 fixed for this example, I get the following
link = "https://static.pexels.com/photos/94616/pexels-photo-94616.jpeg";
img = ImageResize[Binarize[ColorConvert[Import[link], "Grayscale"]], 2^12 {1, 1}];
data = ImageData[img, "Bit"];
Your version:
cf = Compile[{{arr, _Integer, 2}, {n, _Integer, 0}},
   Map[Min, Partition[arr, {n, n}], {2}]];
Nest[cf[#, 2] &, data, 5]; // AbsoluteTiming
Has a runtime of 0.928225 seconds
Nest[step, data, 5]; // AbsoluteTiming
has a runtime of 0.320285 seconds.
I expect a simple nested loop in C, parallelized with OpenMP will be even faster.
 

« first day (1872 days earlier)      last day (2602 days later) »