# Tag Info

17

@Simon Woods points out in a comment that: In fact the delay on the initial run is caused by compiling code to provide the Poisson distribution :-) You can look at ImageColorOperationsDumpiImageEffectPoissonNoise to see how it works internally. Now, although PoissonDistribution can't be compiled, there's nothing stopping the use of my own C++ ...

13

Let's start by taking a look at the compiled form of one of our queries: DatasetCompileQuery[Query @ First @ spans] (* DatasetWithOverrides@*Checked[Slice[205 ;; 313], Identity] *) We can see that the operation is not implemented directly in terms of part. Indeed, there are three components: DatasetWithOverrides, GeneralUtilitiesChecked and ...

11

This seems fast(er): Extract[a, Transpose[{v, Range@Length@v}]] Addendum Mr.Wizard's clean method Diagonal @ a[[v]] has a surprising property for those of us who think that packed arrays rank just below the wheel in the list of inventions for the sake of efficiency. For unpacked arrays a, it uses virtually no extra memory. Example Initialization. ...

8

This is not an answer. It is just a very long comment. Both a simple manually operated drill press and a computer-controlled five-axis omni-mill can drill a hole through a piece of bar stock. And both will do the actual drilling in about the same amount of time. If one hole in one bar is all you want, then you will accomplish the job much faster with the ...

7

Although apparently undocumented Replace and ReplaceAll work with Association and this combination is considerably faster than Map. Further it appears to be somewhat faster than using a Dispatch table as well. Update: it seems Lookup is faster still. See additional timing result. Setup: rules = Thread[Range @ 26 -> CharacterRange["a", "z"]]; asc = ...

7

This is a very common problem for people who work on data analysis. Here as a solution to the problem using LocatorPane and a few other functions and tricks. TooltipListPlot[data_, tipFunction_, listPlotOptions___] := DynamicModule[ {displayQ = False, yRange , xRange, pt, minX, maxX, minY, maxY, tip, threshold, tipPosition, nf, dataPoints, ...

6

You can fix the error by setting max = 0. (Note the .). But this doesn't really Compile completely and you can check that by inspecting the 6th Part of the compiled function: FreeQ[cf1[[6]], _Function, {0, Infinity}] False Whenever your compiled function has a Function definition in Part 6, your function did not compile properly. On the other hand, ...

4

Edit: please see Update below. Although I am self-answering, as stated, I am not satisfied with these approaches. Nevertheless they may be useful and they can serve as a benchmark for any new solutions. This is cleanest method I know, though sadly it is a true memory hog, and not fast either: Diagonal @ a[[v]] {100, 200, 30, 4, 5, 600, 7} More ...

3

It's your inner while loop that is causing the trouble. I refactored your code a bit also. Basically your value of k decreases after the first run. So you only have to do this whole run (over k) once. This is much faster: θ = 0.3; v = 0.05; α = 1; r = 1; k = 1; q = InverseCDF[GammaDistribution[α, 1], 1 - θ]; Lfun[kr_] := Exp[kr q]/(kr + 1)^α CDF[ ...

3

Timing under 20 seconds on my computer now. Ok, your original program took about 60 seconds on my computer meaning that my computer is faster. The dramatical gain of time is due to halfing the MaxRecursion option value. The plot still shows no visible difference. I replaced Pi-Symbol by Pi for increasing readability in forum. I tested some scenarios, and ...

1

Way 1: As Stephen Luttrell said in comment: conv1[t_] := Evaluate@Integrate[twopulse[s]*imp[t - s], {s, 0, t}, Assumptions -> t \[Element] Reals] now conv1 is: then plot it: Plot[conv1[t], {t, 0.09, 0.18}, PlotRange -> All, PlotStyle -> Green, Exclusions -> None] Way 2: conv2[t_] := NIntegrate[twopulse[s]*imp[t - s], {s, 0, t}]; ...

1

You could do it with a sparse array: s = SparseArray[ MapThread[({#1, #2} -> 1) &, { Range[Length[v]], (v - 1)*Length[v] + Range[Length[v]] }], {Length[v], Times @@ Dimensions[a]}]; s.Flatten[a, 1] But sadly, Flatten will take a long time for large a. (If you could keep around Flatten[a] for many "queries", it might be ...

1

This could be fast. a[[v[[#]], #]] & /@ Range[Length@v];

Only top voted, non community-wiki answers of a minimum length are eligible