日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab提速技巧(自matlab帮助文件)

發布時間:2023/12/4 循环神经网络 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab提速技巧(自matlab帮助文件) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

matlab提速技巧(自matlab幫助文件)

1.首先要學會用profiler.
1.1. 打開profiler.
To open the Profiler, select View -> Profiler from the MATLAB desktop, or type profile viewer in the Command Window. The MATLAB Profiler opens.
在我的機器上是: 在matlab desktop下,Desktop->Profiler.
在M文件編輯器下,Tools->Open Profiler.
1.2. 運行profiler
可以把要運行的code拷入Run this code后面的輸入框里。
You can run this example
[t,y] = ode23('lotka',[0 2],[20;20])
也可以輸入要運行的M文件名。
1.3.Click Start Profiling (or press Enter after entering the statement).
1.4. 查看Profile Detail Report
會告知你哪些代碼消耗了多少時間,可以找到哪些函數或那些代碼行消耗了主要的時間,或者是經常被調用。

也可以用stopwatch Timer函數,計算程序消耗時間
Use tic and toc as shown here.
tic
???- run the program section to be timed -
toc


2.?加速1:向量化
MATLAB is a matrix language, which means it is designed for vector and matrix operations. You can often speed up your M-file code by using vectorizing algorithms that take advantage of this design. Vectorization means converting for and while loops to equivalent vector or matrix operations.

i = 0;
for t = 0:.01:1000
????i = i+1;
????y(i) = sin(t);
end

運行時間為30.776秒。
改為向量化代碼:
t = 0:.01:1000;
y = sin(t);
運行時間為0秒。

Functions Used in Vectorizing
Some of the most commonly used functions for vectorizing are:
?all
?diff
?ipermute
?permute
?reshape
?squeeze
?any
?find
?logical
?prod
?shiftdim
?sub2ind
?cumsum
?ind2sub
?ndgrid
?repmat
?sort
?sum
?
?3.?加速2:Preallocating Arrays(預分配空間)
You can often improve code execution time by preallocating the arrays that store output results. Preallocation makes it unnecessary for MATLAB to resize an array each time you enlarge it. Use the appropriate preallocation function for the kind of array you are working with.
Preallocation also helps reduce memory fragmentation if you work with large matrices.

4.加速其他方法:
Coding Loops in a MEX-File for Speed

If there are instances where you must use a for loop, consider coding the loop in a MEX-file. In this way, the loop executes much more quickly since the instructions in the loop do not have to be interpreted each time they execute.

Functions Are Faster Than Scripts

Your code will execute more quickly if it is implemented in a function rather than a script. Every time a script is used in MATLAB, it is loaded into memory and uated one line at a time. Functions, on the other hand, are compiled into pseudo-code and loaded into memory once. Therefore, additional calls to the function are faster.

Load and Save Are Faster Than File I/O Functions

If you have a choice of whether to use load and save instead of the MATLAB file I/O routines, choose the former. The load and save functions are optimized to run faster and reduce memory fragmentation.

Avoid Large Background Processes

Avoid running large processes in the background at the same time you are executing your program in MATLAB. This frees more CPU time for your MATLAB session.

?

?5.?多線程
在matlab desktop里,File->Preferences->General->Multithreading, 看是否選擇了Enable Multithreaded Computation。

如果沒選,check it, 看是否有提速。

總結

以上是生活随笔為你收集整理的matlab提速技巧(自matlab帮助文件)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。