On Tuesday, October 18, 2016 at 5:48:07 PM UTC+2, David K. Storrs wrote:
> Hi Pierre,
> 
> Does matrix-map-cols do what you want?  It's the last function on page 
> https://docs.racket-lang.org/math/matrix_poly.html 
> 
> Also, welcome to Racket!
> 
> Dave
> 
> 
> 
> 
> On Mon, Oct 17, 2016 at 7:00 PM, Pierre-Henry Frohring 
> <frohring.p...@gmail.com> wrote:
> Hello,
> 
> 
> 
> First time here, and just a few hours into Racket...
> 
> It is not going to be rocket science ;-).
> 
> 
> 
> 
> 
> Context:
> 
> 
> 
>   I am using Emacs and org-mode to map each heading of an org file to a html 
> file.
> 
>   Result: one org file → one static website.
> 
>     https://github.com/phfrohring/org-to-blog
> 
> 
> 
>   The org file contains data that is exported to a tsv file:
> 
>     https://github.com/phfrohring/org-to-blog/blob/master/test/blog.org#data
> 
> 
> 
>   A code block in the org file is evaluated:
> 
>     
> https://github.com/phfrohring/org-to-blog/blob/master/test/blog.org#processing
> 
> 
> 
>   And produces a stacked-chart from the tsv data:
> 
>     https://github.com/phfrohring/org-to-blog/blob/master/test/blog.org#result
> 
> 
> 
> 
> 
> The tsv data is parsed into a kind of matrix `M` where each cell `M[i][j]` is 
> a
> 
> string.
> 
>   ex: `M[i][0]` is the column "day" i.e. contains dates
> 
>       `M[i][1]` is the column "description" i.e. contains strings
> 
> 
> 
> In order to use operations over "day" column (adding dates, ...) it is needed 
> to
> 
> parse that column with something like: `iso8601->date` but not the 
> "description"
> 
> column.
> 
> 
> 
> So, it is needed to apply a vector of functions `vF = [f_0,f_1,...]` to `M =
> 
> [col_0,col_1,...]` such that: `(matrix-apply vF M) = M'` where:
> 
> 
> 
>                 M' = [f_0(col_0),f_1(col_1),...,f_n(col_n)]
> 
> 
> 
> Well, this function `matrix-apply` does not seem to exist and my attempt at
> 
> implementing it feels clunky to say the least (ex: fs is not a vector):
> 
> 
> 
>     (define (matrix-apply fs m)
> 
>       (cond [(= (length fs) (matrix-num-cols m))
> 
>              (matrix-augment
> 
>               (map (λ (f_col)
> 
>                      (apply
> 
>                       (λ (mat) (matrix-map (car f_col) mat))
> 
>                       (cdr f_col)))
> 
>                    (zip
> 
>                     fs
> 
>                     (matrix-cols m2))))]
> 
>             [#t (error fs)]))
> 
> 
> 
>     (define m2 (matrix [[1 2 3 4]
> 
>                         [1 2 3 4]]))
> 
> 
> 
>     (matrix-apply (list sqr sqr sqr sqr) m2)
> 
> 
> 
>     => (array #[#[1 4 9 16] #[1 4 9 16]])
> 
> 
> 
> 
> 
> Am I missing the elephant in the corridor? Is an implementation floating
> 
> somewhere?
> 
> 
> 
> Thx!
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users...@googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

Thx Dave!

Assuming I understood the doc correctly:

    (matrix-map-cols f M) → (Matrix B)
      f : ((Matrix A) -> (Matrix B))
      M : (Matrix A)

So, `f` expects a matrix as an input.  What I am trying to do is to apply a
vector of functions `[f_i]` such that each `f_i` acts on a vector: the columns
of the matrix M.  Also, the type M[i,j] may differ from one column to the other.

Something that would look like:

    (matrix-map-cols [f] M) → (Matrix [B_1 B_2 … B_n])
      where each f_i in [f] has type: f_i : (List A_i) → (List B_i)
      M : (Matrix [A_1 A_2 … A_n])

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to