Skip to content

Commit

Permalink
Fix unit tests to account for change in matrix freeze format introduc…
Browse files Browse the repository at this point in the history
…ed in #134.
  • Loading branch information
littleredcomputer committed May 11, 2023
1 parent e3d7a4e commit 0544390
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 206 deletions.
8 changes: 4 additions & 4 deletions test/emmy/abstract/function_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@

(testing "moved-from-matrix"
(is (= '(matrix-by-rows
(up (f x) (g x))
(up (h x) (k x)))
[(f x) (g x)]
[(h x) (k x)])
(v/freeze
(g/simplify
((m/by-rows (map af/literal-function '[f g])
(map af/literal-function '[h k])) 'x)))))

(let [R2f #(af/literal-function % [0 1] 0)]
(is (= '(matrix-by-rows
(up (f x y) (g x y))
(up (h x y) (k x y)))
[(f x y) (g x y)]
[(h x y) (k x y)])
(v/freeze
(g/simplify
((m/by-rows [(R2f 'f) (R2f 'g)]
Expand Down
168 changes: 84 additions & 84 deletions test/emmy/calculus/derivative_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,11 @@
(-> (simplify expr)
(x/substitute (v/freeze S) 'p)))]
(is (= '(matrix-by-rows
(up (((partial 0) H) p)
(((partial 1 0) H) p)
(((partial 1 1) H) p)
(((partial 2 0) H) p)
(((partial 2 1) H) p)))
[(((partial 0) H) p)
(((partial 1 0) H) p)
(((partial 1 1) H) p)
(((partial 2 0) H) p)
(((partial 2 1) H) p)])
(present
((d/D-as-matrix (af/literal-function 'H (h/Hamiltonian 2)))
S)))))
Expand All @@ -577,39 +577,39 @@
present (fn [expr]
(-> (simplify expr)
(x/substitute (v/freeze S) 'p)))]
(is (= '(matrix-by-rows (up (((partial 0) C↑0) p)
(((partial 1 0) C↑0) p)
(((partial 1 1) C↑0) p)
(((partial 2 0) C↑0) p)
(((partial 2 1) C↑0) p))
(up (((partial 0) C↑10) p)
(((partial 1 0) C↑10) p)
(((partial 1 1) C↑10) p)
(((partial 2 0) C↑10) p)
(((partial 2 1) C↑10) p))
(up (((partial 0) C↑11) p)
(((partial 1 0) C↑11) p)
(((partial 1 1) C↑11) p)
(((partial 2 0) C↑11) p)
(((partial 2 1) C↑11) p))
(up (((partial 0) C↑2_0) p)
(((partial 1 0) C↑2_0) p)
(((partial 1 1) C↑2_0) p)
(((partial 2 0) C↑2_0) p)
(((partial 2 1) C↑2_0) p))
(up (((partial 0) C↑2_1) p)
(((partial 1 0) C↑2_1) p)
(((partial 1 1) C↑2_1) p)
(((partial 2 0) C↑2_1) p)
(((partial 2 1) C↑2_1) p)))
(is (= '(matrix-by-rows [(((partial 0) C↑0) p)
(((partial 1 0) C↑0) p)
(((partial 1 1) C↑0) p)
(((partial 2 0) C↑0) p)
(((partial 2 1) C↑0) p)]
[(((partial 0) C↑10) p)
(((partial 1 0) C↑10) p)
(((partial 1 1) C↑10) p)
(((partial 2 0) C↑10) p)
(((partial 2 1) C↑10) p)]
[(((partial 0) C↑11) p)
(((partial 1 0) C↑11) p)
(((partial 1 1) C↑11) p)
(((partial 2 0) C↑11) p)
(((partial 2 1) C↑11) p)]
[(((partial 0) C↑2_0) p)
(((partial 1 0) C↑2_0) p)
(((partial 1 1) C↑2_0) p)
(((partial 2 0) C↑2_0) p)
(((partial 2 1) C↑2_0) p)]
[(((partial 0) C↑2_1) p)
(((partial 1 0) C↑2_1) p)
(((partial 1 1) C↑2_1) p)
(((partial 2 0) C↑2_1) p)
(((partial 2 1) C↑2_1) p)])
(present
((matrix/as-matrix (D C-general)) S))))

(is (= '(matrix-by-rows (up 0 0 0 0 0)
(up 0 0 0 0 0)
(up 0 0 0 0 0)
(up 0 0 0 0 0)
(up 0 0 0 0 0))
(is (= '(matrix-by-rows [0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0])
(simplify
((- (d/D-as-matrix C-general)
(matrix/as-matrix (D C-general)))
Expand All @@ -630,10 +630,10 @@

(testing "identical test in matrix form"
(is (= '(matrix-by-rows
(up m1 0 0 0)
(up 0 m1 0 0)
(up 0 0 m2 0)
(up 0 0 0 m2))
[m1 0 0 0]
[0 m1 0 0]
[0 0 m2 0]
[0 0 0 m2])
(simplify
(matrix/s->m vs (((g/expt D 2) L1) vs) vs)))))))

Expand All @@ -652,31 +652,31 @@
(DOWN Real Real))))
s (s/up 't (s/up 'x 'y) (s/down 'px 'py))]
(is (= '(matrix-by-rows
(up (((partial 0) C↑0) (up t (up x y) (down px py)))
(((partial 1 0) C↑0) (up t (up x y) (down px py)))
(((partial 1 1) C↑0) (up t (up x y) (down px py)))
(((partial 2 0) C↑0) (up t (up x y) (down px py)))
(((partial 2 1) C↑0) (up t (up x y) (down px py))))
(up (((partial 0) C↑10) (up t (up x y) (down px py)))
(((partial 1 0) C↑10) (up t (up x y) (down px py)))
(((partial 1 1) C↑10) (up t (up x y) (down px py)))
(((partial 2 0) C↑10) (up t (up x y) (down px py)))
(((partial 2 1) C↑10) (up t (up x y) (down px py))))
(up (((partial 0) C↑11) (up t (up x y) (down px py)))
(((partial 1 0) C↑11) (up t (up x y) (down px py)))
(((partial 1 1) C↑11) (up t (up x y) (down px py)))
(((partial 2 0) C↑11) (up t (up x y) (down px py)))
(((partial 2 1) C↑11) (up t (up x y) (down px py))))
(up (((partial 0) C↑2_0) (up t (up x y) (down px py)))
(((partial 1 0) C↑2_0) (up t (up x y) (down px py)))
(((partial 1 1) C↑2_0) (up t (up x y) (down px py)))
(((partial 2 0) C↑2_0) (up t (up x y) (down px py)))
(((partial 2 1) C↑2_0) (up t (up x y) (down px py))))
(up (((partial 0) C↑2_1) (up t (up x y) (down px py)))
(((partial 1 0) C↑2_1) (up t (up x y) (down px py)))
(((partial 1 1) C↑2_1) (up t (up x y) (down px py)))
(((partial 2 0) C↑2_1) (up t (up x y) (down px py)))
(((partial 2 1) C↑2_1) (up t (up x y) (down px py)))))
[(((partial 0) C↑0) (up t (up x y) (down px py)))
(((partial 1 0) C↑0) (up t (up x y) (down px py)))
(((partial 1 1) C↑0) (up t (up x y) (down px py)))
(((partial 2 0) C↑0) (up t (up x y) (down px py)))
(((partial 2 1) C↑0) (up t (up x y) (down px py)))]
[(((partial 0) C↑10) (up t (up x y) (down px py)))
(((partial 1 0) C↑10) (up t (up x y) (down px py)))
(((partial 1 1) C↑10) (up t (up x y) (down px py)))
(((partial 2 0) C↑10) (up t (up x y) (down px py)))
(((partial 2 1) C↑10) (up t (up x y) (down px py)))]
[(((partial 0) C↑11) (up t (up x y) (down px py)))
(((partial 1 0) C↑11) (up t (up x y) (down px py)))
(((partial 1 1) C↑11) (up t (up x y) (down px py)))
(((partial 2 0) C↑11) (up t (up x y) (down px py)))
(((partial 2 1) C↑11) (up t (up x y) (down px py)))]
[(((partial 0) C↑2_0) (up t (up x y) (down px py)))
(((partial 1 0) C↑2_0) (up t (up x y) (down px py)))
(((partial 1 1) C↑2_0) (up t (up x y) (down px py)))
(((partial 2 0) C↑2_0) (up t (up x y) (down px py)))
(((partial 2 1) C↑2_0) (up t (up x y) (down px py)))]
[(((partial 0) C↑2_1) (up t (up x y) (down px py)))
(((partial 1 0) C↑2_1) (up t (up x y) (down px py)))
(((partial 1 1) C↑2_1) (up t (up x y) (down px py)))
(((partial 2 0) C↑2_1) (up t (up x y) (down px py)))
(((partial 2 1) C↑2_1) (up t (up x y) (down px py)))])
(simplify
((as-matrix (D C-general)) s)))))))

Expand Down Expand Up @@ -720,36 +720,36 @@
(let [M (matrix/by-rows [(af/literal-function 'f) (af/literal-function 'g)]
[(af/literal-function 'h) (af/literal-function 'k)])]
(is (= '(matrix-by-rows
(up (f t) (g t))
(up (h t) (k t)))
[(f t) (g t)]
[(h t) (k t)])
(simplify (M 't))))

(is (= '(matrix-by-rows
(up ((D f) t) ((D g) t))
(up ((D h) t) ((D k) t)))
[((D f) t) ((D g) t)]
[((D h) t) ((D k) t)])
(simplify ((D M) 't))))

(is (= '(matrix-by-rows
(up (+ (expt (f t) 2) (expt (h t) 2))
(+ (* (f t) (g t)) (* (h t) (k t))))
(up (+ (* (f t) (g t)) (* (h t) (k t)))
(+ (expt (g t) 2) (expt (k t) 2))))
[(+ (expt (f t) 2) (expt (h t) 2))
(+ (* (f t) (g t)) (* (h t) (k t)))]
[(+ (* (f t) (g t)) (* (h t) (k t)))
(+ (expt (g t) 2) (expt (k t) 2))])
(simplify
((* (g/transpose M) M) 't))))

(is (= '(matrix-by-rows
(up (+ (* 2 (f t) ((D f) t))
(* 2 (h t) ((D h) t)))
(+ (* (f t) ((D g) t))
(* (g t) ((D f) t))
(* (h t) ((D k) t))
(* (k t) ((D h) t))))
(up (+ (* (f t) ((D g) t))
(* (g t) ((D f) t))
(* (h t) ((D k) t))
(* (k t) ((D h) t)))
(+ (* 2 (g t) ((D g) t))
(* 2 (k t) ((D k) t)))))
[(+ (* 2 (f t) ((D f) t))
(* 2 (h t) ((D h) t)))
(+ (* (f t) ((D g) t))
(* (g t) ((D f) t))
(* (h t) ((D k) t))
(* (k t) ((D h) t)))]
[(+ (* (f t) ((D g) t))
(* (g t) ((D f) t))
(* (h t) ((D k) t))
(* (k t) ((D h) t)))
(+ (* 2 (g t) ((D g) t))
(* 2 (k t) ((D k) t)))])
(simplify
((D (* (g/transpose M) M)) 't))))))

Expand Down
2 changes: 1 addition & 1 deletion test/emmy/calculus/metric_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
dual-basis [dx dy]
m ((m/point R2-rect) (up 'x0 'y0))]
(is (= '(matrix-by-rows
(up 1 0) (up 0 1))
[1 0] [0 1])
(simplify
(matrix/generate
2 2
Expand Down
27 changes: 11 additions & 16 deletions test/emmy/fdg/ch4_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@
;; equations" alluded to on p.48 of FDG. By equating corresponding
;; entries, we may verify the solution of a, b, c given there.
(is (= '(matrix-by-rows
(up
(+ (* a (sin phi) (sin psi) (sin theta))
[(+ (* a (sin phi) (sin psi) (sin theta))
(* -1 b (sin psi) (cos phi) (cos theta))
(* -1 c (sin phi) (cos theta) (cos psi))
(* -1 b (sin phi) (cos psi))
Expand All @@ -190,9 +189,8 @@
(* c (sin phi) (sin psi) (cos theta))
(* b (sin phi) (sin psi))
(* -1 c (cos phi) (cos psi)))
(+ (* a (sin phi) (cos theta)) (* b (sin theta) (cos phi))))
(up
(+ (* -1 a (sin psi) (sin theta) (cos phi))
(+ (* a (sin phi) (cos theta)) (* b (sin theta) (cos phi)))]
[(+ (* -1 a (sin psi) (sin theta) (cos phi))
(* -1 b (sin phi) (sin psi) (cos theta))
(* c (cos phi) (cos theta) (cos psi))
(* b (cos phi) (cos psi))
Expand All @@ -202,23 +200,20 @@
(* -1 c (sin psi) (cos phi) (cos theta))
(* -1 b (sin psi) (cos phi))
(* -1 c (sin phi) (cos psi)))
(+ (* -1 a (cos phi) (cos theta)) (* b (sin phi) (sin theta))))
(up
(+ (* a (sin psi) (cos theta)) (* c (sin theta) (cos psi)))
(+ (* -1 a (cos phi) (cos theta)) (* b (sin phi) (sin theta)))]
[(+ (* a (sin psi) (cos theta)) (* c (sin theta) (cos psi)))
(+ (* a (cos theta) (cos psi)) (* -1 c (sin psi) (sin theta)))
(* -1 a (sin theta))))
(* -1 a (sin theta))])
(simplify ((D g) 0))))

(is (= '(matrix-by-rows
(up 0 0 0)
(up
(* -1 (sin psi) (sin theta))
[0 0 0]
[(* -1 (sin psi) (sin theta))
(* -1 (sin theta) (cos psi))
(* -1 (cos theta)))
(up
(+ (* (sin psi) (cos phi) (cos theta)) (* (sin phi) (cos psi)))
(* -1 (cos theta))]
[(+ (* (sin psi) (cos phi) (cos theta)) (* (sin phi) (cos psi)))
(+ (* (cos phi) (cos theta) (cos psi)) (* -1 (sin phi) (sin psi)))
(* -1 (sin theta) (cos phi))))
(* -1 (sin theta) (cos phi))])
(simplify ((D h) 0))))))))

(deftest section-4-3
Expand Down
4 changes: 2 additions & 2 deletions test/emmy/matrix_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@
v (m/column 7 8 9)]
(is (= ::m/matrix (v/kind M)))
(is (= '(matrix-by-rows
(up 1 2 3)
(up 4 5 6))
[1 2 3]
[4 5 6])
(v/freeze M)))
(is (= (m/by-rows [1 4] [2 5] [3 6]) (g/transpose M)))
(is (= (m/by-rows [0 0 0] [0 0 0]) (v/zero-like M)))
Expand Down
Loading

0 comments on commit 0544390

Please sign in to comment.