Skip to content

Commit

Permalink
fix ts errors (#150)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Fix TypeScript errors, add `true-unit-tests.spec.js`, and update `test:node` script in `package.json`.
> 
>   - **Tests**:
>     - Add `true-unit-tests.spec.js` to test `dictionaryFromArrays` function with curried and uncurried inputs.
>   - **Scripts**:
>     - Update `test:node` script in `package.json` to include `true-unit-tests.spec.js`.
>   - **Imports**:
>     - Remove unused imports in `selection.ts`.
>     - Add `DataProps` import in `utilityFunctions.ts`.
>   - **Code Cleanup**:
>     - Remove unused variable `start` in `regl_rendering.ts`.
>     - Comment out unused `ffs` function in `utilityFunctions.ts`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=nomic-ai/deepscatter#150)<sup> for da4b62d. It will automatically update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
bmschmidt authored Sep 20, 2024
1 parent 8f67942 commit 861e950
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"prepublishOnly": "vite build && tsc && typedoc --skipErrorChecking src/*",
"test": "vite build && npm run test:node",
"test:playwright": "playwright test",
"test:node": "node tests/dataset.spec.js",
"test:node": "node tests/dataset.spec.js; node tests/true-unit-tests.spec.js",
"lint": "eslint src",
"docs": "typedoc --out docs src/deepscatter.ts"
},
Expand Down
2 changes: 0 additions & 2 deletions src/regl_rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ export class ReglRenderer extends Renderer {
);
}

const start = Date.now();

try {
this.render_all(props);
} catch (error) {
Expand Down
9 changes: 1 addition & 8 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import { Scatterplot } from './scatterplot';
import { Tile } from './tile';
import { getTileFromRow } from './tixrixqid';
import type * as DS from './types';
import {
Bool,
Struct,
StructRowProxy,
Utf8,
Vector,
makeData,
} from 'apache-arrow';
import { Bool, StructRowProxy, Utf8, Vector, makeData } from 'apache-arrow';
import { bisectLeft, bisectRight, range } from 'd3-array';
interface SelectParams {
name: string;
Expand Down
27 changes: 18 additions & 9 deletions src/utilityFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Vector,
makeVector,
} from 'apache-arrow';
import { DataProps } from 'apache-arrow/data';

type ArrayToArrayMap = {
Int8Array: Int8;
Expand Down Expand Up @@ -70,15 +71,23 @@ function createDictionaryWithVector<T extends keyof ArrayToArrayMap>(
'values must be an array of signed integers, 32 bit or smaller.',
);
}
const type = new Dictionary(labelsArrow.type, t, currentDictNumber++, false);
const returnval = makeVector({
type,
const type: Dictionary<Utf8, ArrayToArrayMap[T]> = new Dictionary(
labelsArrow.type,
t,
currentDictNumber++,
false,
);

// @ts-expect-error These are correct and unit tested, but
// the typing fails for reasons I don't understand.
const props: DataProps<Dictionary<Utf8, ArrayToArrayMap[T]>> = {
type: type,
length: indices.length,
nullCount: 0,
data: indices,
dictionary: labelsArrow,
});

};
const returnval = makeVector(props);
return returnval;
}

Expand Down Expand Up @@ -148,7 +157,7 @@ export class TupleMap<K = Object, V = Object> {
}
}

// finds the first set bit.
function ffs(n: number): number {
return Math.log2(n & -n);
}
// // finds the first set bit.
// function ffs(n: number): number {
// return Math.log2(n & -n);
// }
29 changes: 29 additions & 0 deletions tests/true-unit-tests.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { dictionaryFromArrays } from 'deepscatter';

import { test } from 'uvu';
import * as assert from 'uvu/assert';

test('Dictionary from arrays uncurried', async () => {
const vec = dictionaryFromArrays(
['a', 'b', 'c'],
new Int16Array([0, 0, 0, 1]),
);
assert.is(vec.length, 4);
assert.is(vec.get(0), 'a');
assert.is(vec.get(3), 'b');
});

test('Dictionary from arrays curried', async () => {
const dictionator = dictionaryFromArrays(['a', 'b', 'c']);
const vec = dictionator(new Int16Array([0, 0, 0, 1]));

const unCurriedVec = dictionaryFromArrays(
['a', 'b', 'c'],
new Int16Array([0, 0, 0, 1]),
);
for (let i = 0; i < 4; i++) {
assert.is(vec.get(i), unCurriedVec.get(i));
}
});

test.run();

0 comments on commit 861e950

Please sign in to comment.