Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion math-lib/math/private/matrix/matrix-basic.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@

(inner A* B*)]
[(or (nan? mxA) (nan? mxB) (= 0 mxA) (= 0 mxB))
(/ (matrix-dot A B) (* mxA mxB))]
(cond
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does an error message look like, when the error condition is triggered?

Maybe raise-arguments-error could be used to give a nicer error message?

[(eqv? mxA 0) (error 'matrix-cos-angle "zero matrix ~a" A)]
[(eqv? mxB 0) (error 'matrix-cos-angle "zero matrix ~a" B)]
[else (/ (matrix-dot A B) (* mxA mxB))])]
[else
(define A* (if (rational? mxA)
(inline-array-map (λ (x) (/ x mxA)) A)
Expand Down
9 changes: 7 additions & 2 deletions math-test/math/tests/matrix-tests.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,11 @@
(for: ([i (in-range 10)])
(define n (+ 1 (random 3)))
(define m (+ 1 (random 4)))
(define A (random-matrix n m))
(define B (random-matrix n m))
(define (non-zero-random-matrix [n : Integer] [m : Integer]) : (Array Integer)
(define A (random-matrix n m))
(if (matrix-zero? A) (non-zero-random-matrix n m) A))
(define A (non-zero-random-matrix n m))
(define B (non-zero-random-matrix n m))
(define ca (matrix-cos-angle A B))
(check-true (or (and (rational? ca) (<= ca 1.))
(matrix-zero? A) (matrix-zero? B))))
Expand All @@ -714,6 +717,8 @@
(matrix [[3 -8+inf.0i]]))
(matrix-cos-angle (matrix [[2 9]])
(matrix [[0. -0+1.0i]])))
(check-exn #px"matrix-cos-angle: zero matrix " (λ () (matrix-cos-angle (matrix [[0 0][0 0]]) (matrix [[3 1][-1 2]]))))
(check-exn #px"matrix-cos-angle: zero matrix " (λ () (matrix-angle (matrix [[1]]) (matrix [[0]]))))

;; TODO: matrix-normalize

Expand Down