Skip to content

Commit

Permalink
more nits
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Oct 25, 2023
1 parent fd23313 commit eac5886
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions src/webgpu/util/floating_point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,40 +232,47 @@ type Array2D<T> = ROArrayArray<T>;
* of FPIntervals. This maps onto the WGSL concept of matrix. Internally
*/
export type FPMatrix =
| [[FPInterval, FPInterval], [FPInterval, FPInterval]]
| [[FPInterval, FPInterval], [FPInterval, FPInterval], [FPInterval, FPInterval]]
| [
[FPInterval, FPInterval],
[FPInterval, FPInterval],
[FPInterval, FPInterval],
[FPInterval, FPInterval]
| readonly [readonly [FPInterval, FPInterval], readonly [FPInterval, FPInterval]]
| readonly [
readonly [FPInterval, FPInterval],
readonly [FPInterval, FPInterval],
readonly [FPInterval, FPInterval]
]
| [[FPInterval, FPInterval, FPInterval], [FPInterval, FPInterval, FPInterval]]
| [
[FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval]
| readonly [
readonly [FPInterval, FPInterval],
readonly [FPInterval, FPInterval],
readonly [FPInterval, FPInterval],
readonly [FPInterval, FPInterval]
]
| [
[FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval]
| readonly [
readonly [FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval]
]
| [
[FPInterval, FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval, FPInterval]
| readonly [
readonly [FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval]
]
| [
[FPInterval, FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval, FPInterval]
| readonly [
readonly [FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval]
]
| [
[FPInterval, FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval, FPInterval],
[FPInterval, FPInterval, FPInterval, FPInterval]
| readonly [
readonly [FPInterval, FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval, FPInterval]
]
| readonly [
readonly [FPInterval, FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval, FPInterval]
]
| readonly [
readonly [FPInterval, FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval, FPInterval],
readonly [FPInterval, FPInterval, FPInterval, FPInterval]
];

// Utilities
Expand Down Expand Up @@ -752,13 +759,13 @@ export abstract class FPTraits {
if (!m.every(c => c.every(e => e instanceof FPInterval && e.kind === this.kind))) {
return false;
}
// At this point m guaranteed to be a readonly FPInterval[][], but maybe typed as a
// At this point m guaranteed to be a ROArrayArray<FPInterval>, but maybe typed as a
// FPVector[].
// Coercing the type since FPVector[] is functionally equivalent to
// readonly FPInterval[][] for .length and .every, but they are type compatible,
// ROArrayArray<FPInterval> for .length and .every, but they are type compatible,
// since tuples are not equivalent to arrays, so TS considers c in .every to
// be unresolvable below, even though our usage is safe.
m = m as readonly FPInterval[][];
m = m as ROArrayArray<FPInterval>;

if (m.length > 4 || m.length < 2) {
return false;
Expand All @@ -785,7 +792,7 @@ export abstract class FPTraits {

const result = map2DArray(m, this.toInterval.bind(this));

// The return of the map above is a readonly FPInterval[][], which needs to be
// The return of the map above is a ROArrayArray<FPInterval>, which needs to be
// narrowed to FPMatrix, since FPMatrix is defined as fixed length tuples.
if (this.isMatrix(result)) {
return result;
Expand All @@ -809,7 +816,7 @@ export abstract class FPTraits {
`Matrix span is not defined for Matrices of differing dimensions`
);

const result: readonly FPInterval[][] = [...Array(num_cols)].map(_ => [...Array(num_rows)]);
const result: FPInterval[][] = [...Array(num_cols)].map(_ => [...Array(num_rows)]);
for (let i = 0; i < num_cols; i++) {
for (let j = 0; j < num_rows; j++) {
result[i][j] = this.spanIntervals(...ms.map(m => m[i][j]));
Expand Down Expand Up @@ -2498,7 +2505,7 @@ export abstract class FPTraits {
const result_cols = result.length;
const result_rows = result[0].length;

// FPMatrix has to be coerced to readonly FPInterval[][] to use .every. This should
// FPMatrix has to be coerced to ROArrayArray<FPInterval> to use .every. This should
// always be safe, since FPMatrix are defined as fixed length array of
// arrays.
return (result as ROArrayArray<FPInterval>).every(c => c.every(r => r.isFinite()))
Expand Down Expand Up @@ -3823,7 +3830,7 @@ export abstract class FPTraits {
});
});

return result as FPMatrix;
return result as ROArrayArray<FPInterval> as FPMatrix;

Check failure on line 3833 in src/webgpu/util/floating_point.ts

View workflow job for this annotation

GitHub Actions / build

Replace `result·as·ROArrayArray<FPInterval>` with `(result·as·ROArrayArray<FPInterval>)`
}

/** Calculate an acceptance interval of x * y, when x is a matrix and y is a matrix */
Expand Down

0 comments on commit eac5886

Please sign in to comment.