Evenly spaced deterministic sample of `k` indices over [0, n).
(n: number, k: number)
| 53 | |
| 54 | /** Evenly spaced deterministic sample of `k` indices over [0, n). */ |
| 55 | function strideSample(n: number, k: number): number[] { |
| 56 | const indices = new Set<number>(); |
| 57 | const count = Math.min(k, n); |
| 58 | for (let i = 0; i < count; i++) |
| 59 | indices.add(Math.round((i * (n - 1)) / (count - 1))); |
| 60 | return [...indices].sort((a, b) => a - b); |
| 61 | } |
| 62 | |
| 63 | function main(): void { |
| 64 | const args = parseArgs(process.argv); |