feat: Implement Vector type #28
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "vector"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The Vector type is simply a generic type for built-in JavaScript Arrays. The parameter type is the type of all of the entries of the Array. The Vector type also supports inhomogeneous arrays by using the special type
Unknownas the argument type, but note that when computing with inhomogeneous arrays, method dispatch must be performed separately for every entry in a calculation, making all operations considerably slower than on homogeneous Vector instances.Note also that arithmetic operations on nested Vectors, e.g.
Vector(Vector(NumberT))are defined so as to interpret such entities as ordinary matrices, represented in row-major format (i.e., the componentVector(NumberT)items of such an entity are the rows of the matrix.Toward its goal, this commit also: * Adds a new section of logical functions, and defines `not`, `and`, `or` for all current types. * Extends `OneOf` choice/union type to allow argument types that are themselves `OneOf` types. * Adds a readable .toString() method for TypePatterns. * Defines negate (as a no-op) and isnan (as always true) for the Undefined type * Extends comparisons to the Undefined type (to handle comparing vectors of different lengths)So far, abs, add, norm, normsq, and sum are supported. To get them to work, also implements the following: * refactor: Use ReturnType function rather than just accessing .returns * feat: distinguish marking a function as a behavior from its return type * refactor: Rename `NotAType` to `Unknown` because it must be made closer to a bona fide type for the sake of inhomogeneous vectors * feat: make resolving a TypeDispatcher method on a type vector including `Unknown` into a no-op; that simplifies a number of generic behaviors * feat: add `haszero` method parallel to `hasnan` * feat: track the Vector nesting depth of Vector specializations