Tag Info

New answers tagged

0

A quick and dirty use of Parallelize gave me a 2.7x speed improvement on my machine (4-core CPU w/ hyperthreading). But since NIntegrate itself cant be parallelized, I used Map to do the trick ...


2

The code in the Question runs slowly, because it evaluates n^2 integrals. However, all the integrands are of the form Dc Exp[-Ax (x - a1)^2] Exp[-Ay (y - b1)^2] Exp[-Ax (x - a2)^2] Exp[-Ay (y - b2)^2]; This generic term can be integrated symbolically in several seconds Integrate[Laplacian[%, {x, y}], {x, -a, a}, {y, -b, b}] (* Dc (E^((-2*a^2 - a1^2 - ...


1

It appears that among other optimizations ImageApply uses a kind of memoization but that it is inactive in the second example. With a small change to the definition we can see how many times the function is actually applied: qX[x_] := (Sow @ x; Piecewise[{{0., x <= 1/3.}, {.5, x <= 2/3.}, {1., x <= 1.}}, 0]) SetAttributes[qX, Listable] The ...


2

The function q3[#] & is not Listable and because the Interleaving option value is True by default, there is not much optimization that can be figured out automatically. Setting the Listable attribute whenever possible will help. Working with "Bit", "Byte", or "Bit16" data types will be faster, too. In this very case, ImageApply[q3, img] and ...


7

It seems, that a pure function calling a Listable one breaks internal optimization in Mathematica's ImageApply. Compare: t = Abs[Sqrt[#]] &; (* pure function *) q[x_] := Abs[Sqrt[x]]; (* "standard" function, implicitly listable *) SetAttributes[h, Listable]; h[x_] := Abs[Sqrt[x]]; (* explicitly listable function *) First /@ { ...


3

I'm not too sure why one is so much slower than the other, but your second (slower) method can be improved by compilation (inspired by this answer). q3Compile = Compile[{{x, _Real}}, Piecewise[{{0., x <= 1/3.}, {.5, x <= 2/3.}, {1., x <= 1.}}, 0], RuntimeAttributes -> {Listable} ]; img = ExampleData[{"TestImage", "Apples"}] ...


2

You can export just the image to EPS by allowing rasterisation with the "AllowRasterization" option in Export. Export["testdata1.eps",t1,"AllowRasterization"->True] Hope this helps.


0

Thanks to Silvia`s suggestion I found even faster way: << AuthorTools` NotebookFileOutline[EvaluationNotebook[]] ~ Do ~ {100} // AbsoluteTiming {0.564001, Null} (*big notebook, done 100 times!*)


5

Here is your initialization code: (*SeedRandom[30];*) (*initial coordinates of masses*) mass = RandomReal[{0, 3}, {4, 2}]; (*mass 1 is connected to {2,3} and so on*) spring = {{2, 3}, {1, 4}, {1, 4}, {2, 3}}; (*spring constant*) k = 2.; (*spring rest length*) l = 1.; (*step size*) step = 0.02; (*tolerance*) tol = 10^-10.; (*pinned masses*) pinned = {2, ...


3

Updated with cleaner and easier to adapt method: The checking of the patterns gets expensive, more so when conditions are attached. Looking at your generators, it's clear that the fulfillment of the patterns and/or conditions is quite sparse. Better to generate directly the hits, and create the array from those. Using your 'c' generator with just the ...



Top 50 recent answers are included