[racket] Advice on using math/array and math/matrix to rewrite MATLAB code

From: Daniel Prager (daniel.a.prager at gmail.com)
Date: Sat May 3 02:43:42 EDT 2014

I'm having a go at converting a pitch detection
algorithm<https://github.com/kylebgorman/swipe/blob/master/swipe.m>from
MATLAB to Typed Racket, and which I'll Open Source if I can get it
working, and am after a few pointers, since I'm new to TR and am finding it
slow going.

Examples of the kind of code I'm writing in my fledlging attempts:

#lang typed/racket

(define: (log2 [x : Real]) : Real
  (define result (/ (log x) (log 2)))
  (if (real? result)
      result
      0.0))

(define: (build-step-vector [min : Real] [step : Real] [max : Real]) :
  (Vectorof Real)
  (for/vector: : (Vectorof Real)
      #:length (ceiling (inexact->exact (/ (- max min) step)))
      ([i (in-naturals)])
    (+ min (* i step))))


Suggestions of better idioms and choices most welcome! E.g. the second one
could be written as a range -> array, multiplied by the step.

Beyond that:

   - Can anyone point me to examples of any code before/after converted
   from MATLAB (or Octave) to TR?
   - What's a good scalar type to work with for floating point to start
   with?
   - Which non-scalar type(s) should I favor: vectors, arrays or matrices?
   - Any general tips to develop facility for this kind of stuff? I feel
   like I need to go "back to basics", but there seems to be a dearth of
   examples and tutorials. on math/... beyond the reference materials.


Many thanks

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140503/e0d838d0/attachment.html>

Posted on the users mailing list.