File: test841.thp

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (127 lines) | stat: -rw-r--r-- 3,791 bytes parent folder | download | duplicates (2)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;; -*-theme-d-*-

;; Copyright (C) 2023 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.

;; Expected results: translation and running OK


(define-proper-program (tests test841)

  (import (standard-library core)
	  (standard-library bvm-matrices)
	  (standard-library basic-math)
	  (standard-library console-io)
	  (tests numerical-test-env)
	  (tests matrix-test-env))

  (define-main-proc (() <none> nonpure)
    (let* ((mx1 (bvm-make-matrix 3 3 2.0))
	   (mx2
	    (bvm-matrix '((1.0 2.0 3.0)
			  (4.0 5.0 6.0)
			  (7.0 8.0 9.0)
			  (10.0 11.0 12.0))))
	   (mx3
	    (bvm-matrix '((-2.0 1.0)
			  (3.5 1.5)
			  (-10.0 10.0))))
	   (mx4
	    (bvm-matrix '((1.0 0.0)
			  (-3.5 1.0)
			  (0.0 1.0))))
	   (mx5 (bvm-copy mx1)))
      (bvm-fill! mx1 1.0)
      (matrix-set! mx5 1 1 100.0)
      (report-matrix-test mx1 (bvm-make-matrix 3 3 1.0))
      (report-test (matrix-ref mx5 1 1) 100.0)
      (report-test (number-of-rows mx3) 3)
      (report-test (number-of-columns mx3) 2)
      (report-matrix-test (+ mx3 mx4)
			  (bvm-matrix '((-1.0 1.0)
					(0.0 2.5)
					(-10.0 11.0))))
      (report-matrix-test (- mx3 mx4)
			  (bvm-matrix '((-3.0 1.0)
					(7.0 0.5)
					(-10.0 9.0))))
      (report-matrix-test (- mx3)
			  (bvm-matrix '((2.0 -1.0)
					(-3.5 -1.5)
					(10.0 -10.0))))
      (report-matrix-test (* mx2 mx3)
			  (bvm-matrix '((-25.0 34.0)
					(-50.5 71.5)
					(-76.0 109.0)
					(-101.5 146.5))))
      (report-matrix-test (->real-matrix mx4) mx4)
      (report-matrix-test
       (->single-matrix mx4)
       (bvm-single-matrix '((1.0 0.0)
			    (-3.5 1.0)
			    (0.0 1.0))))
      (report-matrix-test
       (->complex-matrix mx4)
       (bvm-matrix (list
		    (list (complex 1.0 0.0) (complex 0.0 0.0))
		    (list (complex -3.5 0.0) (complex 1.0 0.0))
		    (list (complex 0.0 0.0) (complex 1.0 0.0)))))
      (report-matrix-test
       (->single-complex-matrix mx4)
       (bvm-single-matrix (list
			   (list (complex 1.0 0.0) (complex 0.0 0.0))
			   (list (complex -3.5 0.0) (complex 1.0 0.0))
			   (list (complex 0.0 0.0) (complex 1.0 0.0)))))
      (report-boolean-test (= mx3 mx3) #t)
      (report-boolean-test (= mx3 mx4) #f)
      (report-matrix-test (* 2.5 mx3)
			  (bvm-matrix '((-5.0 2.5)
					(8.75 3.75)
					(-25.0 25.0))))
      (report-matrix-test (* mx3 2.5)
			  (bvm-matrix '((-5.0 2.5)
					(8.75 3.75)
					(-25.0 25.0))))
      (report-matrix-test (transpose mx4)
			  (bvm-matrix '((1.0 -3.5 0.0)
					(0.0 1.0 1.0))))
      (report-matrix-test (transpose mx1) mx1)
      (report-matrix-test (conj mx4) mx4)
      (report-matrix-test (herm mx4)
			  (bvm-matrix '((1.0 -3.5 0.0)
					(0.0 1.0 1.0))))
      (report-matrix-test (herm mx1) mx1)
      (report-matrix-test (bvm-column-vector '(1.0 2.0 -3.0))
			  (bvm-matrix '((1.0)
					(2.0)
					(-3.0))))
      (report-matrix-test (bvm-row-vector '(1.0 2.0 -3.0))
			  (bvm-matrix '((1.0 2.0 -3.0))))
      (report-matrix-test
       (bvm-generate-matrix
	3
	4
	(lambda (((i1 <integer>) (i2 <integer>)) <real> pure)
	  (if (= i1 i2) 1.0 0.0)))
	(bvm-matrix '((1.0 0.0 0.0 0.0)
		      (0.0 1.0 0.0 0.0)
		      (0.0 0.0 1.0 0.0))))
      (report-matrix-test (matrix-map r-square mx2)
			  (bvm-matrix '((1.0 4.0 9.0)
					(16.0 25.0 36.0)
					(49.0 64.0 81.0)
					(100.0 121.0 144.0))))
      (report-matrix-test
       (matrix-map-w-ind
	(lambda (((i1 <integer>) (i2 <integer>) (r-elem <real>))
		 <real> pure)
	  (if (= i1 i2) r-elem 1.0))
	mx2)
       (bvm-matrix '((1.0 1.0 1.0)
		     (1.0 5.0 1.0)
		     (1.0 1.0 9.0)
		     (1.0 1.0 1.0))))
      (report-exception (+ mx2 mx3) 'bvm+:dim-mismatch)
      (report-exception (- mx2 mx3) 'bvm-:dim-mismatch)
      (report-exception (* mx3 mx4) 'bvm*:dim-mismatch))))