Skip to content

Refactor number[] to Float32Array/Float64Array for performance#3

Open
Copilot wants to merge 8 commits into
devfrom
copilot/refactor-number-array-to-typedarray
Open

Refactor number[] to Float32Array/Float64Array for performance#3
Copilot wants to merge 8 commits into
devfrom
copilot/refactor-number-array-to-typedarray

Conversation

Copy link
Copy Markdown

Copilot AI commented May 26, 2026

Replace all number[] vector types with typed arrays (Float32Array / Float64Array) for better memory layout, computation efficiency, and typed array API compatibility.

Changes

  • FilterDataArray union typeFloat32Array | Float64Array, exported for consumer use
  • Generic filter<T>() — return type matches input type via generics
  • createTypedArray helper — dynamically constructs the correct typed array type from the input, used for all internal buffer allocation
  • xPrev / dxPrev — changed from number[] | null to FilterDataArray | null; initialization now copies input via typed array constructor instead of aliasing
  • Type declarations — updated both types/OneEuroFilter.d.ts and types/src/OneEuroFilter.d.ts
  • README — documents accepted input types
  • Example — updated to use new Float32Array([...])

Usage

import { OneEuroFilter } from "@webarkit/oneeurofilter-ts";

const filter = new OneEuroFilter(0.0001, 0.01);

// Float32Array — returns Float32Array
const result32 = filter.filter(Date.now(), new Float32Array([1.0, 2.0, 3.0]));

// Float64Array — returns Float64Array (when higher precision needed)
filter.reset();
const result64 = filter.filter(Date.now(), new Float64Array([1.0, 2.0, 3.0]));

- Refactor xPrev, dxPrev, and filter I/O from number[] to Float32Array
- Update type declarations to reflect new signatures
- Update example and README to document Float32Array usage
- Rebuild dist files
Copilot AI changed the title [WIP] Refactor number[] to Float32Array for performance improvement Refactor number[] to Float32Array for performance improvement May 26, 2026
Copilot AI requested a review from kalwalt May 26, 2026 22:00
@kalwalt kalwalt added the enhancement New feature or request label May 26, 2026
- Introduce FilterDataArray union type (Float32Array | Float64Array)
- Make filter() generic so output type matches input type
- Add createTypedArray helper to dynamically construct matching arrays
- Export FilterDataArray type from index
- Update type declarations, README, and rebuild dist
Copilot AI changed the title Refactor number[] to Float32Array for performance improvement Refactor number[] to Float32Array/Float64Array for performance May 26, 2026
@kalwalt kalwalt changed the base branch from main to dev May 27, 2026 08:02
@kalwalt kalwalt marked this pull request as ready for review May 27, 2026 08:02
@kalwalt kalwalt force-pushed the copilot/refactor-number-array-to-typedarray branch from c8afafd to dd2e563 Compare May 27, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor number[] to Float32Array or TypedArray for performance improvement

2 participants