DNorm2

버전 1.1.0.0 (10.4 KB) 작성자: Jan
Euclidian norm along a specified dim of an array - fast C-Mex
다운로드 수: 1K
업데이트 날짜: 2010/10/15

라이선스 보기

Fast euclidian norm over N.th dimension of a DOUBLE array

Y = DNorm2(X, N)
INPUT:
X: Real DOUBLE array.
N: Dimension to operate on.
OUTPUT:
Y: Euclidian norm over N.th dimension: Y = sqrt(sum(X .* X, N)).
Length of N.th dimension of Y is 1.
NaN's are considered.

Matlab's built-in function NORM is fast for vectors, but for matrices the matrix norm is replied. Other efficient methods for vectors(!):
Y = sqrt(sum(X .* X));
Y = sqrt(X * X'); % row vectors, faster than DNorm2!
And James Tursa's MTIMESX is very fast for vectors also and can operate on the 1st dimension of arrays also:
X = rand(100, 100); X = reshape(X, 100, 1, 100);
Y = sqrt(mtimesx(X, 't', X));
But for arrays DNorm2 is faster, and I do not see a way to apply MTIMESX for trailing dimensions without time-consuming transpositions.

COMPILATION:
This function must be compiled before using:
mex -O DNorm2.c
See DNorm2.c for detailed instructions.

TEST: Run uTest_DNorm2 to test validity and speed.

NOTES: See DNorm2.c for strategies to optimize processing speed depending on the size of X.
Unfortunately this function is not multi-threaded. Assistence to include OMP would be very welcome.

Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32bit
Compiler: LCC2.4/3.8, BCC5.5, OWC1.8, MSVC2008
Assumed Compatibility: higher Matlab versions, Mac, Linux, 64bit

인용 양식

Jan (2024). DNorm2 (https://www.mathworks.com/matlabcentral/fileexchange/29035-dnorm2), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2009a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.0

Bugfix: Error check failed for DNorm2(X, 0) on 64 bit systems. Thanks Bruno!

1.0.0.0