Re: [racket-users] a matrix question

2018-03-26 Thread Tim Hanson
Many thanks, Jens Axel! That looks very good and includes several techniques 
that will help and inspire me, in particular for*/matrix, which I hadn't used 
yet.

I'll try it out the next chance I get.

-- 
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.


Re: [racket-users] a matrix question

2018-03-25 Thread Jens Axel Søgaard
Hi Tim,

Here is one way to do it:

#lang typed/racket
(require math/matrix math/array)

(: columns->matrix (All (A) ((Listof (Matrix A)) -> (Matrix A
(define (columns->matrix cs)
  (define m (matrix-num-rows (first cs)))
  (define n (length cs))
  (: has-m-rows? : ((Matrix A) -> Boolean))
  (define (has-m-rows? c) (= (matrix-num-rows c) m))
  (unless (andmap has-m-rows? cs)
(error 'columns-matrix "all columns must have the same number of rows"))
  (for*/matrix n m ([c (in-list cs)]
[x (in-vector (matrix->vector c))]) : A
x))

(display (columns->matrix (list (col-matrix [1 2 3]) (col-matrix [4 5 6]

-- 
Jens Axel



2018-03-25 13:12 GMT+02:00 Tim Hanson :

> hi,
>
> I'm trying out matrices (without typed racket, though I read the
> performance caveat -- I'm not worried about performance at the moment) and
> am trying to find the best idioms for a small function I'd like to build.
>
> Q1: is there an elegant away to assemble a matrix column-wise? (my first
> draft solution is to read one col-matrix and write cell by cell into a
> destination (mutable) matrix); my preference would be to use immutable
> items, but that's secondary to elegance at this point.
>
> cheers,
>
> Tim
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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.


[racket-users] a matrix question

2018-03-25 Thread Tim Hanson
hi, 

I'm trying out matrices (without typed racket, though I read the performance 
caveat -- I'm not worried about performance at the moment) and am trying to 
find the best idioms for a small function I'd like to build.

Q1: is there an elegant away to assemble a matrix column-wise? (my first draft 
solution is to read one col-matrix and write cell by cell into a destination 
(mutable) matrix); my preference would be to use immutable items, but that's 
secondary to elegance at this point.

cheers,

Tim

-- 
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.