« first day (1974 days earlier)      last day (1239 days later) » 

9:29 AM
@LuisMendo profile switched the JIT off?!? That makes no sense :s
What use is a profiler, if it turns of the one thing that speeds up everything the most
Does it switch off as well when you use timeit()?
Reading the question that prompted this: they don't seem to use profile. It looks like max is correct in saying that the overhead of creating the index arrays for the vectorised case is simply large in comparison to the initial vector length.
 
9:47 AM
I like the suggestions here to explicitly set indices to uint32() (or uint16 or so if it fits) for performance reasons. I'll look into that, as I actually have stuff indexing very often
Nope, doesn't work. Results without uint32(), i.e. as written in the question:
   0.000171000000000
   0.099307000000000
   0.097390000000000
   0.096927000000000
   0.928237000000000
   0.135085000000000
   0.156468000000000
   0.575300000000000
Wrapping every array inside uint32():
   0.000071000000000
   0.100708000000000
   0.920009000000000
   0.947982000000000
   0.904252000000000
   1.663645000000000
   1.661605000000000
   0.551616000000000
 
10:35 AM
What are those "results" and how large are your indices?
 
@AndrasDeak The function in this question
I wrapped all 1:1e8 and 1:numel(x), 1:end etc in uint32() for the second run
Oh, they are timings of each of the runs within that function
 
yeah, that makes sense...
"not works" with two different sets of numbers suggested something else
At least with numpy I know that using non-int64 indices is usually slower. Not sure about uint, when I played with this I checked smaller int types. But numpy itself suggests to use np.intp for indices which is aliased to int64 on my system
 
10:54 AM
In MATLAB, as you now, the default type is double. So I can understand the idea that when explicitly creating indices, using integers would use less RAM and might actually speed things up since the check whether the index is indeed an integer doesn't need to take place. However, doing this experiment suggests, at least for R2020a, that somehow the overhead of creating a UINT32 is heavier than the checks.
Or that the UINT32 is internally converted to a double, then checked for integer-ness, and then used or something.
 
@Adriaan yes. I meant using int64 instead of uint32
 
@Adriaan Yes, it defeats the purpose. Apparently "The JIT can reorder the commands of the code. This would confuse the profiler, which looses the relation between code lines and time measurements. In consequence PROFILE disables the JIT completely."
I guess timeit doesn't have that problem, because it measures total time, without regard of what each lines does
 
11:13 AM
this week I learned that in python timeit is weird... because it disables the garbage collector :(
at least that's something you can reproduce on your code
 
 
3 hours later…
2:04 PM
Anyone have a good idea how to build a polarhistogram, but given that I already have the data? So I have bin edges 0:10:360 and the histcounts for each bin, I just want to plot them as a rose diagram. polarhistogram seems to need raw data, rather than the histogram itself. I can of course make a dummy plot h=polarhistogram() and then change h.Values and h.BinEdges, but that seems overkill
polarplot might work.
Hm, that plots a rather ugly line, instead of a nice stair-like histogram
You cannot set the read-only property 'Values' of Histogram.
Error in MSO_angular_histograms (line 70)
h.Values = angle_total(:,1);
It's unhappy about being forced
bin_centres = deg2rad(cumsum(diff(Angle_bins)).'-angle_bin_size/2);
angle_total = sum(angle_out,3, 'omitnan');
angle_total = angle_total./(sum(angle_total,1));

angle_plot = reshape([Angle_bins;Angle_bins],[],1);
angle_plot = deg2rad(angle_plot(2:end-1));
angle_plot(end+1) = angle_plot(1);
val_plot = reshape([angle_total(:,1).';angle_total(:,1).'],[],1);
val_plot(end+1) = val_plot(1);
figure;
t = tiledlayout(2,2);
nexttile
h=polarplot(angle_plot,val_plot);
Pfrt. Well, it works.
 
 
2 hours later…
3:57 PM
@Adriaan Instead of uint32(1:1e8), try uint32(1):1e8. That should also produce integer indices, but not create a double array first. No idea what the JIT does here, but logically uint32(1:1e8) is a large doubles array that is converted to uint32, whereas uint32(1):1e8 produces a uint32 array right away.
 
@CrisLuengo interesting
 

« first day (1974 days earlier)      last day (1239 days later) »