1 USING: alien byte-arrays help.markup help.syntax math sequences ;
4 ARTICLE: "math.blas.vectors" "BLAS interface vector operations"
7 "Taking the norm (magnitude) of a vector:"
9 "Summing and taking the maximum of elements:"
11 { $subsection Viamax }
13 "Scalar-vector products:"
20 { $subsection n*V+V! }
24 "Vector inner products:"
26 { $subsection V.conj } ;
28 ABOUT: "math.blas.vectors"
30 HELP: blas-vector-base
31 { $class-description "The base class for all BLAS vector types. Objects of this type should not be created directly; instead, instantiate one of the typed subclasses:"
33 { { $link float-blas-vector } }
34 { { $link double-blas-vector } }
35 { { $link float-complex-blas-vector } }
36 { { $link double-complex-blas-vector } }
38 "All of these subclasses share the same tuple layout:"
40 { { $snippet "underlying" } " contains an alien pointer referencing or byte-array containing a packed array of float, double, float complex, or double complex values;" }
41 { { $snippet "length" } " indicates the length of the vector;" }
42 { "and " { $snippet "inc" } " indicates the distance, in elements, between elements." }
45 HELP: float-blas-vector
46 { $class-description "A vector of single-precision floating-point values. For details on the tuple layout, see " { $link blas-vector-base } "." } ;
47 HELP: double-blas-vector
48 { $class-description "A vector of double-precision floating-point values. For details on the tuple layout, see " { $link blas-vector-base } "." } ;
49 HELP: float-complex-blas-vector
50 { $class-description "A vector 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-vector-base } "." } ;
51 HELP: double-complex-blas-vector
52 { $class-description "A vector 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-vector-base } "." } ;
55 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "y=alpha*x+y" blas-vector-base } }
56 { $description "Calculate the vector sum " { $snippet "αx + y" } " and replace the existing contents of y with the result. Corresponds to the xAXPY routines in BLAS." }
57 { $side-effects "y" } ;
60 { $values { "alpha" number } { "x" blas-vector-base } { "x=alpha*x" blas-vector-base } }
61 { $description "Calculate the scalar-vector product " { $snippet "αx" } " and replace the existing contents of x with the result. Corresponds to the xSCAL routines in BLAS." }
62 { $side-effects "x" } ;
65 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "x.y" number } }
66 { $description "Calculate the inner product " { $snippet "x⋅y" } ". Corresponds to the xDOT and xDOTU routines in BLAS." } ;
69 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "xconj.y" number } }
70 { $description "Calculate the conjugate inner product " { $snippet "x̅⋅y" } ". Corresponds to the xDOTC routines in BLAS." } ;
73 { $values { "x" blas-vector-base } { "norm" number } }
74 { $description "Calculate the norm-2, i.e., the magnitude or absolute value, of " { $snippet "x" } " (" { $snippet "‖x‖₂" } "). Corresponds to the xNRM2 routines in BLAS." } ;
77 { $values { "x" blas-vector-base } { "sum" number } }
78 { $description "Calculate the sum of the norm-1s of the elements of " { $snippet "x" } " (" { $snippet "Σ ‖xᵢ‖₁" } "). Corresponds to the xASUM routines in BLAS." } ;
81 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "x=y" blas-vector-base } { "y=x" blas-vector-base } }
82 { $description "Swap the contents of " { $snippet "x" } " and " { $snippet "y" } " in place. Corresponds to the xSWAP routines in BLAS." }
83 { $side-effects "x" "y" } ;
86 { $values { "x" blas-vector-base } { "max-i" integer } }
87 { $description "Return the index of the element in " { $snippet "x" } " with the largest norm-1. If more than one element has the same norm-1, returns the smallest index. Corresponds to the IxAMAX routines in BLAS." } ;
90 { $values { "x" blas-vector-base } { "max" number } }
91 { $description "Return the value of the element in " { $snippet "x" } " with the largest norm-1. If more than one element has the same norm-1, returns the first element. Corresponds to the IxAMAX routines in BLAS." } ;
93 { Viamax Vamax } related-words
96 { $values { "exemplar" blas-vector-base } { "zero" blas-vector-base } }
97 { $description "Return a vector of zeros with the same length and element type as " { $snippet "v" } ". The vector is constructed with an " { $snippet "inc" } " of zero, so it is not suitable for receiving results from BLAS functions; it is intended to be used as a term in other vector calculations. To construct an empty vector that can be used to receive results, see " { $link <empty-vector> } "." } ;
100 { $values { "alpha" number } { "x" blas-vector-base } { "y" blas-vector-base } { "alpha*x+y" blas-vector-base } }
101 { $description "Calculate the vector sum " { $snippet "αx + y" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result. Corresponds to the xAXPY routines in BLAS." } ;
104 { $values { "alpha" "a number" } { "x" blas-vector-base } { "alpha*x" blas-vector-base } }
105 { $description "Calculate the scalar-vector product " { $snippet "αx" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result. Corresponds to the xSCAL routines in BLAS." } ;
108 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "x+y" blas-vector-base } }
109 { $description "Calculate the vector sum " { $snippet "x + y" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result. Corresponds to the xAXPY routines in BLAS." } ;
112 { $values { "x" blas-vector-base } { "y" blas-vector-base } { "x-y" blas-vector-base } }
113 { $description "Calculate the vector difference " { $snippet "x – y" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result. Corresponds to the xAXPY routines in BLAS." } ;
116 { $values { "x" blas-vector-base } { "-x" blas-vector-base } }
117 { $description "Negate the elements of " { $snippet "x" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result." } ;
120 { $values { "x" blas-vector-base } { "alpha" number } { "x*alpha" blas-vector-base } }
121 { $description "Calculate the scalar-vector product " { $snippet "αx" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result. Corresponds to the xSCAL routines in BLAS." } ;
124 { $values { "x" blas-vector-base } { "alpha" number } { "x/alpha" blas-vector-base } }
125 { $description "Calculate the scalar-vector product " { $snippet "(1/α)x" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result. Corresponds to the xSCAL routines in BLAS." } ;
127 { n*V+V! n*V! n*V+V n*V V+ V- Vneg V*n V/n } related-words
130 { $values { "v" blas-vector-base } { "start" integer } { "length" integer } { "sub" blas-vector-base } }
131 { $description "Slice a subvector out of " { $snippet "v" } " starting at " { $snippet "start" } " with the given " { $snippet "length" } ". The subvector will share storage with the parent vector." } ;