On this page:
trace-print
check-dual-equal?
check-ρ-
max-tensor-print-length
raw-tensor-printing?
8.12

21 Utilities🔗

These are utilities to help with debugging and testing functions written using malt or any of its other entry points.

procedure

(trace-print v p)  any

  v : any
  p : port
Prints v using display to the port p. If v is a dual, only (ρ v) is printed. Returns v after it is printed.

syntax

(check-dual-equal? a b)

A rackunit check which checks if a and b are equal within a tolerance of 0.0001 according to the following rules.
  • If a and b are both number?, the check passes if (abs (- a b)) is less than 0.0001.

  • If a is dual?, the check passes if (check-dual-equal? (ρ a) b) passes.

  • If b is dual?, the check passes if (check-dual-equal? a (ρ b)) passes.

  • If a and b are both list? and of the same length, the check passes if (check-dual-equal? ea eb) passes where ea and eb are corresponding members of a and b respectively.

  • If a and b are both tensor? and of the same "tlen", the check passes if (check-dual-equal? ea eb) passes where ea and eb are corresponding elements of a and b respectively.

  • If a and b are equal?, the check passes.

  • Otherwise the check fails.

syntax

(check-ρ-∇ (f arg ...) ans grads)

This check passes if
(check-dual-equal (f arg ...) ans)
would pass and
(check-dual-equal (∇¹ f arg ...) grads)
would pass.

parameter

(max-tensor-print-length)  natural?

(max-tensor-print-length max-length)  void?
  max-length : natural?
 = 5
When tensors are printed out using write, display, print, or in the REPL, max-tensor-print-length determines how many elements are printed after which ... is displayed. If set to 0, the whole tensor is printed.

parameter

(raw-tensor-printing?)  boolean?

(raw-tensor-printing? print-raw?)  void?
  print-raw? : boolean?
 = #f
By default, Malt sets the current-print to pretty-print-handler and customizes the REPL, and ports current-output-port and current-error-port to detect and print tensors and duals in a friendlier way. Setting this parameter to #t turns off this printing behavior and tensors and duals are printed with their raw representation.