]> gitweb.factorcode.org Git - factor.git/blob - extra/math/blas/matrices/matrices-docs.factor
factor: trim more using lists.
[factor.git] / extra / math / blas / matrices / matrices-docs.factor
1 USING: help.markup help.syntax math math.blas.vectors sequences
2 strings ;
3 IN: math.blas.matrices
4
5 ARTICLE: "math.blas-summary" "Basic Linear Algebra Subroutines (BLAS) interface"
6 "Factor provides an interface to high-performance vector and matrix math routines available in implementations of the BLAS math library. A set of specialized types are provided for handling packed, unboxed vector data:"
7 { $subsections "math.blas-types" }
8 "Scalar-vector and vector-vector operations are available in the " { $vocab-link "math.blas.vectors" } " vocabulary:"
9 { $subsections "math.blas.vectors" }
10 "Vector-matrix and matrix-matrix operations are available in the " { $vocab-link "math.blas.matrices" } " vocabulary:"
11 { $subsections "math.blas.matrices" }
12 "The low-level BLAS Fortran interface can be accessed directly through the " { $vocab-link "math.blas.ffi" } " vocabulary. The BLAS interface can be configured to use different underlying BLAS implementations:"
13 { $subsections "math.blas.config" } ;
14
15 ARTICLE: "math.blas-types" "BLAS interface types"
16 "BLAS vectors come in single- and double-precision, real and complex flavors:"
17 { $subsections
18     float-blas-vector
19     double-blas-vector
20     complex-float-blas-vector
21     complex-double-blas-vector
22 }
23 "These vector types all follow the " { $link sequence } " protocol. In addition, there are corresponding types for matrix data:"
24 { $subsections
25     float-blas-matrix
26     double-blas-matrix
27     complex-float-blas-matrix
28     complex-double-blas-matrix
29 }
30 "There are BOA constructors for all vector and matrix types, which provide the most flexibility in specifying memory layout:"
31 { $subsections
32     <float-blas-vector>
33     <double-blas-vector>
34     <complex-float-blas-vector>
35     <complex-double-blas-vector>
36     <float-blas-matrix>
37     <double-blas-matrix>
38     <complex-float-blas-matrix>
39     <complex-double-blas-matrix>
40 }
41 "For the simple case of creating a dense, zero-filled vector or matrix, simple empty object constructors are provided:"
42 { $subsections
43     <empty-vector>
44     <empty-matrix>
45 }
46 "BLAS vectors and matrices can also be constructed from other Factor sequences:"
47 { $subsections
48     >float-blas-vector
49     >double-blas-vector
50     >complex-float-blas-vector
51     >complex-double-blas-vector
52     >float-blas-matrix
53     >double-blas-matrix
54     >complex-float-blas-matrix
55     >complex-double-blas-matrix
56 } ;
57
58 ARTICLE: "math.blas.matrices" "BLAS interface matrix operations"
59 "Transposing and slicing matrices:"
60 { $subsections
61     Mtranspose
62     Mrows
63     Mcols
64     Msub
65 }
66 "Matrix-vector products:"
67 { $subsections
68     n*M.V+n*V!
69     n*M.V+n*V
70     n*M.V
71     M.V
72 }
73 "Vector outer products:"
74 { $subsections
75     n*V(*)V+M!
76     n*V(*)Vconj+M!
77     n*V(*)V+M
78     n*V(*)Vconj+M
79     n*V(*)V
80     n*V(*)Vconj
81     V(*)
82     V(*)conj
83 }
84 "Matrix products:"
85 { $subsections
86     n*M.M+n*M!
87     n*M.M+n*M
88     n*M.M
89     M.
90 }
91 "Scalar-matrix products:"
92 { $subsections
93     n*M!
94     n*M
95     M*n
96     M/n
97 }
98 "Literal syntax:"
99 { $subsections
100     POSTPONE: smatrix{
101     POSTPONE: dmatrix{
102     POSTPONE: cmatrix{
103     POSTPONE: zmatrix{
104 } ;
105
106
107 ABOUT: "math.blas.matrices"
108
109 HELP: blas-matrix-base
110 { $class-description "The base class for all BLAS matrix types. Objects of this type should not be created directly; instead, instantiate one of the typed subclasses:"
111 { $list
112     { { $link float-blas-matrix } }
113     { { $link double-blas-matrix } }
114     { { $link complex-float-blas-matrix } }
115     { { $link complex-double-blas-matrix } }
116 }
117 "All of these subclasses share the same tuple layout:"
118 { $list
119     { { $snippet "underlying" } " contains an alien pointer referencing or byte-array containing a packed, column-major array of float, double, float complex, or double complex values;" }
120     { { $snippet "ld" } " indicates the distance, in elements, between matrix columns;" }
121     { { $snippet "rows" } " and " { $snippet "cols" } " indicate the number of significant rows and columns in the matrix;" }
122     { "and " { $snippet "transpose" } ", if set to a true value, indicates that the matrix should be treated as transposed relative to its in-memory representation." }
123 } } ;
124
125 { blas-vector-base blas-matrix-base } related-words
126
127 HELP: float-blas-matrix
128 { $class-description "A matrix of single-precision floating-point values. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
129 HELP: double-blas-matrix
130 { $class-description "A matrix of double-precision floating-point values. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
131 HELP: complex-float-blas-matrix
132 { $class-description "A matrix of single-precision floating-point complex values. Complex values are stored in memory as two consecutive float values, real part then imaginary part. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
133 HELP: complex-double-blas-matrix
134 { $class-description "A matrix of double-precision floating-point complex values. Complex values are stored in memory as two consecutive float values, real part then imaginary part. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
135
136 {
137     float-blas-matrix double-blas-matrix complex-float-blas-matrix complex-double-blas-matrix
138     float-blas-vector double-blas-vector complex-float-blas-vector complex-double-blas-vector
139 } related-words
140
141 HELP: Mwidth
142 { $values { "matrix" blas-matrix-base } { "width" integer } }
143 { $description "Returns the number of columns in " { $snippet "matrix" } "." } ;
144
145 HELP: Mheight
146 { $values { "matrix" blas-matrix-base } { "height" integer } }
147 { $description "Returns the number of rows in " { $snippet "matrix" } "." } ;
148
149 { Mwidth Mheight } related-words
150
151 HELP: n*M.V+n*V!
152 { $values { "alpha" number } { "A" blas-matrix-base } { "x" blas-vector-base } { "beta" number } { "y" blas-vector-base } { "y=alpha*A.x+b*y" blas-vector-base } }
153 { $description "Calculate the matrix-vector product " { $snippet "αAx + βy" } ", and overwrite the current contents of " { $snippet "y" } " with the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ", and the height must match the length of " { $snippet "y" } ". Corresponds to the xGEMV routines in BLAS." }
154 { $side-effects "y" } ;
155
156 HELP: n*V(*)V+M!
157 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "A" blas-matrix-base } { "A=alpha*x(*)y+A" blas-matrix-base } }
158 { $description "Calculate the outer product " { $snippet "αx⊗y + A" } " and overwrite the current contents of A with the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". Corresponds to the xGER and xGERU routines in BLAS." }
159 { $side-effects "A" } ;
160
161 HELP: n*V(*)Vconj+M!
162 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "A" blas-matrix-base } { "A=alpha*x(*)yconj+A" blas-matrix-base } }
163 { $description "Calculate the conjugate outer product " { $snippet "αx⊗y̅ + A" } " and overwrite the current contents of A with the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". Corresponds to the xGERC routines in BLAS." }
164 { $side-effects "A" } ;
165
166 HELP: n*M.M+n*M!
167 { $values { "alpha" number } { "A" blas-matrix-base } { "B" blas-matrix-base } { "beta" number } { "C" blas-matrix-base } { "C=alpha*A.B+beta*C" blas-matrix-base } }
168 { $description "Calculate the matrix product " { $snippet "αAB + βC" } " and overwrite the current contents of C with the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match, as must the heights of " { $snippet "A" } " and " { $snippet "C" } ", and the widths of " { $snippet "B" } " and " { $snippet "C" } ". Corresponds to the xGEMM routines in BLAS." }
169 { $side-effects "C" } ;
170
171 HELP: <empty-matrix>
172 { $values { "rows" integer } { "cols" integer } { "exemplar" blas-vector-base blas-matrix-base } { "matrix" blas-matrix-base } }
173 { $description "Create a matrix of all zeros with the given dimensions and the same element type as " { $snippet "exemplar" } "." } ;
174
175 { <zero-vector> <empty-vector> <empty-matrix> } related-words
176
177 HELP: n*M.V+n*V
178 { $values { "alpha" number } { "A" blas-matrix-base } { "x" blas-vector-base } { "beta" number } { "y" blas-vector-base } { "alpha*A.x+b*y" blas-vector-base } }
179 { $description "Calculate the matrix-vector product " { $snippet "αAx + βy" } " and return a freshly allocated vector containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ", and the height must match the length of " { $snippet "y" } ". The returned vector will have the same length as " { $snippet "y" } ". Corresponds to the xGEMV routines in BLAS." } ;
180
181 HELP: n*V(*)V+M
182 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "A" blas-matrix-base } { "alpha*x(*)y+A" blas-matrix-base } }
183 { $description "Calculate the outer product " { $snippet "αx⊗y + A" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". The returned matrix will have the same dimensions as " { $snippet "A" } ". Corresponds to the xGER and xGERU routines in BLAS." } ;
184
185 HELP: n*V(*)Vconj+M
186 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "A" blas-matrix-base } { "alpha*x(*)yconj+A" blas-matrix-base } }
187 { $description "Calculate the conjugate outer product " { $snippet "αx⊗y̅ + A" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". The returned matrix will have the same dimensions as " { $snippet "A" } ". Corresponds to the xGERC routines in BLAS." } ;
188
189 HELP: n*M.M+n*M
190 { $values { "alpha" number } { "A" blas-matrix-base } { "B" blas-matrix-base } { "beta" number } { "C" blas-matrix-base } { "alpha*A.B+beta*C" blas-matrix-base } }
191 { $description "Calculate the matrix product " { $snippet "αAB + βC" } " and overwrite the current contents of C with the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match, as must the heights of " { $snippet "A" } " and " { $snippet "C" } ", and the widths of " { $snippet "B" } " and " { $snippet "C" } ". Corresponds to the xGEMM routines in BLAS." } ;
192
193 HELP: n*M.V
194 { $values { "alpha" number } { "A" blas-matrix-base } { "x" blas-vector-base } { "alpha*A.x" blas-vector-base } }
195 { $description "Calculate the matrix-vector product " { $snippet "αAx" } " and return a freshly allocated vector containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ". The length of the returned vector will match the height of " { $snippet "A" } ". Corresponds to the xGEMV routines in BLAS." } ;
196
197 HELP: M.V
198 { $values { "A" blas-matrix-base } { "x" blas-vector-base } { "A.x" blas-vector-base } }
199 { $description "Calculate the matrix-vector product " { $snippet "Ax" } " and return a freshly allocated vector containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ". The length of the returned vector will match the height of " { $snippet "A" } ". Corresponds to the xGEMV routines in BLAS." } ;
200
201 { n*M.V+n*V! n*M.V+n*V n*M.V M.V } related-words
202
203 HELP: n*V(*)V
204 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "alpha*x(*)y" blas-matrix-base } }
205 { $description "Calculate the outer product " { $snippet "αx⊗y" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGER and xGERU routines in BLAS." } ;
206
207 HELP: n*V(*)Vconj
208 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "alpha*x(*)yconj" blas-matrix-base } }
209 { $description "Calculate the outer product " { $snippet "αx⊗y̅" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGERC routines in BLAS." } ;
210
211 HELP: V(*)
212 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "x(*)y" blas-matrix-base } }
213 { $description "Calculate the outer product " { $snippet "x⊗y" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGER and xGERU routines in BLAS." } ;
214
215 HELP: V(*)conj
216 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "x(*)yconj" blas-matrix-base } }
217 { $description "Calculate the conjugate outer product " { $snippet "x⊗y̅" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGERC routines in BLAS." } ;
218
219 { n*V(*)V+M! n*V(*)Vconj+M! n*V(*)V+M n*V(*)Vconj+M n*V(*)V n*V(*)Vconj V(*) V(*)conj V. V.conj } related-words
220
221 HELP: n*M.M
222 { $values { "alpha" number } { "A" blas-matrix-base } { "B" blas-matrix-base } { "alpha*A.B" blas-matrix-base } }
223 { $description "Calculate the matrix product " { $snippet "αAB" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match. The returned matrix's height will be the same as " { $snippet "A" } "'s, and its width will match " { $snippet "B" } "'s. Corresponds to the xGEMM routines in BLAS." } ;
224
225 HELP: M.
226 { $values { "A" blas-matrix-base } { "B" blas-matrix-base } { "A.B" blas-matrix-base } }
227 { $description "Calculate the matrix product " { $snippet "AB" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match. The returned matrix's height will be the same as " { $snippet "A" } "'s, and its width will match " { $snippet "B" } "'s. Corresponds to the xGEMM routines in BLAS." } ;
228
229 { n*M.M+n*M! n*M.M+n*M n*M.M M. } related-words
230
231 HELP: Msub
232 { $values { "matrix" blas-matrix-base } { "row" integer } { "col" integer } { "height" integer } { "width" integer } { "sub" blas-matrix-base } }
233 { $description "Select a rectangular submatrix of " { $snippet "matrix" } " with the given dimensions. The returned submatrix will share the parent matrix's storage." } ;
234
235 HELP: Mrows
236 { $values { "A" blas-matrix-base } { "rows" sequence } }
237 { $description "Return a sequence of BLAS vectors representing the rows of " { $snippet "matrix" } ". Each vector will share the parent matrix's storage." } ;
238
239 HELP: Mcols
240 { $values { "A" blas-matrix-base } { "cols" sequence } }
241 { $description "Return a sequence of BLAS vectors representing the columns of " { $snippet "matrix" } ". Each vector will share the parent matrix's storage." } ;
242
243 HELP: n*M!
244 { $values { "n" number } { "A" blas-matrix-base } { "A=n*A" blas-matrix-base } }
245 { $description "Calculate the scalar-matrix product " { $snippet "nA" } " and overwrite the current contents of A with the result." }
246 { $side-effects "A" } ;
247
248 HELP: n*M
249 { $values { "n" number } { "A" blas-matrix-base } { "n*A" blas-matrix-base } }
250 { $description "Calculate the scalar-matrix product " { $snippet "nA" } " and return a freshly allocated matrix with the same dimensions as " { $snippet "A" } " containing the result." } ;
251
252 HELP: M*n
253 { $values { "A" blas-matrix-base } { "n" number } { "A*n" blas-matrix-base } }
254 { $description "Calculate the scalar-matrix product " { $snippet "nA" } " and return a freshly allocated matrix with the same dimensions as " { $snippet "A" } " containing the result." } ;
255
256 HELP: M/n
257 { $values { "A" blas-matrix-base } { "n" number } { "A/n" blas-matrix-base } }
258 { $description "Calculate the scalar-matrix product " { $snippet "(1/n)A" } " and return a freshly allocated matrix with the same dimensions as " { $snippet "A" } " containing the result." } ;
259
260 { n*M! n*M M*n M/n } related-words
261
262 HELP: Mtranspose
263 { $values { "matrix" blas-matrix-base } { "matrix^T" blas-matrix-base } }
264 { $description "Returns the transpose of " { $snippet "matrix" } ". The returned matrix shares storage with the original matrix." } ;
265
266 HELP: element-type
267 { $values { "v" blas-vector-base blas-matrix-base } { "type" string } }
268 { $description "Return the C type of the elements in the given BLAS vector or matrix." } ;
269
270 HELP: <empty-vector>
271 { $values { "length" "The length of the new vector" } { "exemplar" blas-vector-base blas-matrix-base } { "vector" blas-vector-base } }
272 { $description "Return a vector of zeros with the given " { $snippet "length" } " and the same element type as " { $snippet "v" } "." } ;
273
274 HELP: smatrix{
275 { $syntax "smatrix{
276     { 1.0 0.0 0.0 1.0 }
277     { 0.0 1.0 0.0 2.0 }
278     { 0.0 0.0 1.0 3.0 }
279     { 0.0 0.0 0.0 1.0 }
280 }" }
281 { $description "Construct a literal " { $link float-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
282
283 HELP: dmatrix{
284 { $syntax "dmatrix{
285     { 1.0 0.0 0.0 1.0 }
286     { 0.0 1.0 0.0 2.0 }
287     { 0.0 0.0 1.0 3.0 }
288     { 0.0 0.0 0.0 1.0 }
289 }" }
290 { $description "Construct a literal " { $link double-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
291
292 HELP: cmatrix{
293 { $syntax "cmatrix{
294     { 1.0 0.0           0.0 1.0           }
295     { 0.0 C{ 0.0 1.0 }  0.0 2.0           }
296     { 0.0 0.0          -1.0 3.0           }
297     { 0.0 0.0           0.0 C{ 0.0 -1.0 } }
298 }" }
299 { $description "Construct a literal " { $link complex-float-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
300
301 HELP: zmatrix{
302 { $syntax "zmatrix{
303     { 1.0 0.0           0.0 1.0           }
304     { 0.0 C{ 0.0 1.0 }  0.0 2.0           }
305     { 0.0 0.0          -1.0 3.0           }
306     { 0.0 0.0           0.0 C{ 0.0 -1.0 } }
307 }" }
308 { $description "Construct a literal " { $link complex-double-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
309
310 {
311     POSTPONE: smatrix{ POSTPONE: dmatrix{
312     POSTPONE: cmatrix{ POSTPONE: zmatrix{
313 } related-words