feat: Implement Vector type #28

Merged
glen merged 12 commits from vector into main 2025-05-07 00:03:50 +00:00
Owner

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 Unknown as 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 component Vector(NumberT) items of such an entity are the rows of the matrix.

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 `Unknown` as 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 component `Vector(NumberT)` items of such an entity are the _rows_ of the matrix.
glen added 12 commits 2025-05-07 00:03:07 +00:00
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
feat: implement invert for vectors and matrices
All checks were successful
/ test (pull_request) Successful in 20s
db86b2ecd0
Here invert returns the pseudoinverse when the input is not invertible.
  To this end, also implements (rudimentary) conversion of Complex to NumberT,
  an identity method that produces identity matrices, determinant, and
  the adjoint operation on matrices (conjugate transpose).
glen merged commit 95d81d0338 into main 2025-05-07 00:03:50 +00:00
glen deleted branch vector 2025-05-07 00:03:50 +00:00
glen referenced this pull request from a commit 2025-05-07 00:03:50 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: StudioInfinity/nanomath#28
No description provided.