# papl / src / PaplVector.mli

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226``` ```(* Copyright (c) 2012 Anders Lau Olsen. See LICENSE file for terms and conditions. *) (** Vectors *) type rng_t = PaplRandom.rng_t type 'a pair_t = 'a * 'a (** {2 Module types} *) (** Basic vector operations *) module type BASE = sig type t (** Vectors. *) type box_t = t * t (** Vector boxes. *) (** {2 Interpolation} *) val interpolate : t PaplInterpolate.t (** Linear interpolation of vectors. *) (** {2 Vector space operations} *) val ( *: ) : float -> t -> t (** Scalar multiplication. *) val (/:) : t -> float -> t (** Division of a vector by a scalar. *) val (+:) : t -> t -> t (** Vector addition. *) val (-:) : t -> t -> t (** Vector subtraction. *) val neg : t -> t (** Unary negation. *) (** {2 Miscellaneous} *) val map : (float -> float) -> t -> t (** Map a function onto the elements of a vector. *) val map2 : (float -> float -> float) -> t -> t -> t (** Zip the pairs of coordinates of two vectors by a scalar function. *) val sum : t -> float (** The sum of the elements. *) val abs : t -> t (** The absolute values. *) val sqrt : t -> t (** The square roots. All elements must be non-negative. *) val sign : t -> t (** The signs of the values. Let [b = sign a]: for all [i]: if [a.(i) < 0] then [b.(i) = -1]; otherwise [b.(i) = 1]. *) val min : t -> t -> t (** The smallest value for each pair of coordinates. If [c = min a b] then [c.(i) = Pervasives.min a.(i) b.(i)] for all [i]. *) val max : t -> t -> t (** The largest value for each pair of coordinates. If [c = min a b] then [c.(i) = Pervasives.max a.(i) b.(i)] for all [i]. *) val scale : t -> t -> t (** Pairwise product of two vectors. If [c = scale a b] then [ci = a.(i) * b.(i)] for all [i]. *) val divide : float -> t -> t (** Division of a scalar by a vector. If [b = divide s a] then [b.(i) = s /. a.(i)] for all [i]. The elements of [a] must be non-zero. *) val unit : t -> t (** Scale a vector to unit length. The length is measured by [dist2]. If the length of the vector is zero (or very near zero), an exception is thrown. *) val box_center : box_t -> t (** The center of a box. The center of the box [(a, b)] is [0.5 *: (a +: b)]. *) val box_diagonal : box_t -> t (** The diagonal of a box. The diagonal of the box [(a, b)] is [b -: a]. *) end (** Inner products *) module type DOT = sig type t (** Vectors. *) (** {2 Inner products} *) type dot_t = t -> t -> float (** The type of an inner product function. *) val dot : dot_t (** Inner product of two vectors. *) val dot_weighted : t -> dot_t (** Weighted inner product of two vectors. *) (** {2 Projections} *) val proj_by : dot_t -> t -> t -> t (** Projection of a vector onto a vector [proj dot a b] is the projection of [a] onto [b] (i.e. the resulting vector is parallel to [b]), where [dot] is the inner product of the space. The vector [b] must be non-zero. *) val proj : t -> t -> t (** Projection of a vector onto a vector. [proj a b] is equivalent to [proj_by dot a b]. *) val proj_unit_by : dot_t -> t -> t -> t (** Projection of a vector onto a unit-vector. [proj_unit dot a b] projects [a] onto [b]. Unlike [proj_by dot a b], the function assumes that the norm of [b] is [1.0]. *) val proj_unit : t -> t -> t (** Projection of a vector onto a unit-vector. [proj_unit a b] is equivalent to [proj_unit_by dot a b]. *) end (** Sampling of vectors *) module type SAMPLER = sig type t (** Vectors. *) type box_t (** Vector boxes. *) val uniform : ?rng:rng_t -> box_t -> t PaplSampler.t (** Uniform sampling of a configuration space box. *) val get_uniform : ?rng:rng_t -> box_t -> t (** A single configuration sampled uniformly at random from a box. *) end (** Union of all vector operations *) module type ALL = sig include BASE include DOT with type t := t include PaplVectorMetric.S with type t := t and type weight_t = t include SAMPLER with type t := t and type box_t := box_t end (** {2 Vectors in 2D, 3D, and 4D} *) (** 2-tuples as vectors. *) module V2D : sig include ALL with type t = float * float type triangle_t = t * t * t (** The type of a triangle. *) end (** 3-tuples as vectors. *) module V3D : sig include ALL with type t = float * float * float type triangle_t = t * t * t (** The type of a triangle. *) val cross : t -> t -> t (** The cross product of a pair of vectors. *) val uniform_unit : ?rng:rng_t -> unit -> t PaplSampler.t (** Unit vectors sampled uniformly at random from the surface of the unit sphere. *) val get_uniform_unit : ?rng:rng_t -> unit -> t (** A single unit vector sampled uniformly at random from the surface of the unit sphere. *) end (** 4-tuples as vectors. *) module V4D : ALL with type t = float * float * float * float (** {2 Array vectors} *) (** Arrays as vectors. *) module Array : ALL with type t = float BatArray.t ```
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.