7.4 Conversion
procedure
(list->matrix m n xs) → (Matrix A)
m : Integer n : Integer xs : (Listof A)
procedure
(matrix->list M) → (Listof A)
M : (Matrix A)
> (list->matrix 2 3 '(1 2 3 4 5 6)) - : (Array Positive-Byte)
(array #[#[1 2 3] #[4 5 6]])
> (matrix->list (matrix [[1 2] [3 4] [5 6]])) - : (Listof Positive-Byte)
'(1 2 3 4 5 6)
procedure
(vector->matrix m n xs) → (Matrix A)
m : Integer n : Integer xs : (Vectorof A)
procedure
(matrix->vector M) → (Vectorof A)
M : (Matrix A)
> (vector->matrix 2 3 #(1 2 3 4 5 6))
- : #(struct:Mutable-Array
(Indexes
Index
(Boxof Boolean)
(-> Void)
(-> Indexes Integer)
(-> Indexes Integer Void)
(Vectorof Integer))
#<syntax:.../array/typed-mutable-array.rkt:14:13 prop:custom-write>)
(mutable-array #[#[1 2 3] #[4 5 6]])
> (matrix->vector (matrix [[1 2] [3 4] [5 6]])) - : (Vectorof Integer)
'#(1 2 3 4 5 6)
procedure
(->row-matrix xs) → (Matrix A)
xs : (U (Listof A) (Vectorof A) (Array A))
procedure
(->col-matrix xs) → (Matrix A)
xs : (U (Listof A) (Vectorof A) (Array A))
> (->row-matrix '(1 2 3)) - : (Array Positive-Byte)
(array #[#[1 2 3]])
> (->row-matrix #(1 2 3)) - : (Array Positive-Byte)
(array #[#[1 2 3]])
> (->row-matrix (col-matrix [1 2 3])) - : (Array Positive-Byte)
(array #[#[1 2 3]])
> (->col-matrix (array #[#[#[1]] #[#[2]] #[#[3]]])) - : (Array Positive-Byte)
(array #[#[1] #[2] #[3]])
> (->col-matrix (matrix [[1 0] [0 1]])) array->col-matrix: contract violation
expected: nonempty Array with exactly one axis of length
>= 1
given: (array #[#[1 0] #[0 1]])
procedure
(list*->matrix xss) → (Matrix A)
xss : (Listof (Listof A))
procedure
(matrix->list* M) → (Listof (Listof A))
M : (Matrix A)
> (list*->matrix '((1 2 3) (4 5 6))) - : (Array Positive-Byte)
(array #[#[1 2 3] #[4 5 6]])
> (matrix->list* (matrix [[1 2 3] [4 5 6]])) - : (Listof (Listof Positive-Byte))
'((1 2 3) (4 5 6))
procedure
(vector*->matrix xss) → (Matrix A)
xss : (Vectorof (Vectorof A))
procedure
(matrix->vector* M) → (Vectorof (Vectorof A))
M : (Matrix A)
> ((inst vector*->matrix Integer) #(#(1 2 3) #(4 5 6)))
- : #(struct:Mutable-Array
(Indexes
Index
(Boxof Boolean)
(-> Void)
(-> Indexes Integer)
(-> Indexes Integer Void)
(Vectorof Integer))
#<syntax:.../array/typed-mutable-array.rkt:14:13 prop:custom-write>)
(mutable-array #[#[1 2 3] #[4 5 6]])
> (matrix->vector* (matrix [[1 2 3] [4 5 6]])) - : (Vectorof (Vectorof Integer))
'#(#(1 2 3) #(4 5 6))