File: test_norm.pro

package info (click to toggle)
gnudatalanguage 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,368 kB
  • sloc: cpp: 189,797; ansic: 46,721; sh: 677; python: 474; makefile: 146; xml: 69; f90: 28
file content (90 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;
; under GNU GPL v3
; Alain Coulais, 17 july 2017
;
; we are not ready for LA_SVD :(
;
; -----------------------------------------------------------------
;
pro TEST_NORM_VECTORS, cumul_errors, verbose=verbose, test=test
;
nb_errors=0
;
; to be extend to other types ? (float, complex ?)
;
vector=INDGEN(10)
norms=FINDGEN(6)/2
expected=[9.0, 372.72165, 45.0, 23.103502, 16.881943, 14.141151]
;
results=FLTARR(N_ELEMENTS(norms))
;
for ii=0, N_ELEMENTS(norms)-1 do begin 
   results[ii]=NORM(vector, lnorm=norms[ii])
endfor
;
if TOTAL(ABS(expected-results)) GT 1.e-6 then nb_errors++
;
BANNER_FOR_TESTSUITE, 'TEST_NORM_VECTORS', nb_errors, /short, verb=verbose
;
ERRORS_CUMUL, cumul_errors, nb_errors
;
if KEYWORD_SET(test) then STOP
;
end
; -----------------------------------------------------------------
;
pro TEST_NORM_MATRIX, cumul_errors, verbose=verbose, test=test, type=type
;
nb_errors=0
;
matrix=DIST(4)
if KEYWORD_SET(type) then matrix=FIX(matrix, type=type)
;
norms=[0,1,2]
expected=[9.3005631, 9.3005631, 6.84515559]
;
results=FLTARR(N_ELEMENTS(norms))
;
for ii=0, N_ELEMENTS(norms)-1 do begin 
   results[ii]=NORM(matrix, lnorm=norms[ii])
endfor
;
if TOTAL(ABS(expected-results)) GT 1.e-6 then nb_errors++
;
BANNER_FOR_TESTSUITE, 'TEST_NORM_MATRIX', nb_errors, /short, verb=verbose
;
ERRORS_CUMUL, cumul_errors, nb_errors
;
if KEYWORD_SET(test) then STOP
;
end
;
; -----------------------------------------------------------------
;
pro TEST_NORM, help=help, verbose=verbose, no_exit=no_exit, test=test
;
if KEYWORD_SET(help) then begin
   print, 'pro TEST_NORM, help=help, verbose=verbose, $'
   print, '               no_exit=no_exit, test=test'
   return
endif
;
; do we need to add tests for other types in "vectors" ?
; e.g. : a=dist(4) & print, norm(a^25L, lnorm=1,/dou)
;
TEST_NORM_VECTORS, nb_errors
;
; same question !
TEST_NORM_MATRIX, nb_errors
TEST_NORM_MATRIX, nb_errors, type=5
a=EXECUTE("TEST_NORM_MATRIX, nb_errors, type=6")
;
; ----------------- final message ----------
;
BANNER_FOR_TESTSUITE, 'TEST_NORM', nb_errors
; 
if (nb_errors GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
;
if KEYWORD_SET(test) then STOP
;
end