Skip to content

Commit

Permalink
chore: eliminate use of vite-plugin-binary
Browse files Browse the repository at this point in the history
Instead just load data files using regular Node.js `fs` library.
  • Loading branch information
jbms committed Mar 15, 2024
1 parent b35566a commit 10718c4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 100 deletions.
35 changes: 0 additions & 35 deletions build_tools/vite/vite-plugin-binary.ts

This file was deleted.

24 changes: 17 additions & 7 deletions src/sliceview/compressed_segmentation/encode.benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,31 @@
* limitations under the License.
*/

import fs from "node:fs/promises";
import path from "node:path";
import { describe, bench } from "vitest";
import { encodeChannels as encodeChannelsUint32 } from "#src/sliceview/compressed_segmentation/encode_uint32.js";
import { encodeChannels as encodeChannelsUint64 } from "#src/sliceview/compressed_segmentation/encode_uint64.js";
import { makeRandomUint64Array } from "#src/sliceview/compressed_segmentation/test_util.js";
import { prod4, vec3Key } from "#src/util/geom.js";
import { Uint32ArrayBuilder } from "#src/util/uint32array_builder.js";
import exampleChunkDataUint8Array from "#testdata/64x64x64-raw-uint64-segmentation.dat?binary";

const exampleChunkData64 = new Uint32Array(exampleChunkDataUint8Array.buffer);

const exampleChunkData32 = exampleChunkData64.filter((_element, index) => {
return index % 2 === 0;
});
describe("64x64x64 example", async () => {
const testDataDir = path.resolve(
import.meta.dirname,
"..",
"..",
"..",
"testdata",
);
const exampleChunkDataUint8Array = await fs.readFile(
path.resolve(testDataDir, "64x64x64-raw-uint64-segmentation.dat"),
);
const exampleChunkData64 = new Uint32Array(exampleChunkDataUint8Array.buffer);
const exampleChunkData32 = exampleChunkData64.filter((_element, index) => {
return index % 2 === 0;
});

describe("64x64x64 example", () => {
const blockSize = [8, 8, 8];
const output = new Uint32ArrayBuilder(1000000);
const volumeSize = [64, 64, 64, 1];
Expand Down
73 changes: 27 additions & 46 deletions src/util/npy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,12 @@
* limitations under the License.
*/

import fs from "node:fs/promises";
import path from "node:path";
import { describe, it, expect } from "vitest";
import { DataType } from "#src/util/data_type.js";
import { parseNpy } from "#src/util/npy.js";

import float32be_npy from "#testdata/npy_test.float32-be.npy?binary";
import float32le_npy from "#testdata/npy_test.float32-le.npy?binary";
import float32_example from "#testdata/npy_test.float32.json";
import uint16be_npy from "#testdata/npy_test.uint16-be.npy?binary";
import uint16le_npy from "#testdata/npy_test.uint16-le.npy?binary";
import uint16_example from "#testdata/npy_test.uint16.json";
import uint32be_npy from "#testdata/npy_test.uint32-be.npy?binary";
import uint32le_npy from "#testdata/npy_test.uint32-le.npy?binary";
import uint32_example from "#testdata/npy_test.uint32.json";
import uint64be_npy from "#testdata/npy_test.uint64-be.npy?binary";
import uint64le_npy from "#testdata/npy_test.uint64-le.npy?binary";
import uint64_example from "#testdata/npy_test.uint64.json";
import uint8_example from "#testdata/npy_test.uint8.json";
import uint8_npy from "#testdata/npy_test.uint8.npy?binary";

interface ExampleSpec {
dataType: string;
shape: number[];
Expand All @@ -47,35 +34,29 @@ async function checkNpy(spec: ExampleSpec, encoded: Uint8Array) {
}

describe("parseNpy", () => {
it("uint8", async () => {
await checkNpy(uint8_example, uint8_npy);
});

it("uint16-le", async () => {
checkNpy(uint16_example, uint16le_npy);
});
it("uint16-be", async () => {
checkNpy(uint16_example, uint16be_npy);
});

it("uint32-le", async () => {
checkNpy(uint32_example, uint32le_npy);
});
it("uint32-be", async () => {
checkNpy(uint32_example, uint32be_npy);
});

it("uint64-le", async () => {
checkNpy(uint64_example, uint64le_npy);
});
it("uint64-be", async () => {
checkNpy(uint64_example, uint64be_npy);
});

it("float32-le", async () => {
checkNpy(float32_example, float32le_npy);
});
it("float32-be", async () => {
checkNpy(float32_example, float32be_npy);
});
for (const { json, npys } of [
{ json: "uint8", npys: ["uint8"] },
...["uint16", "uint32", "uint64", "float32"].map((x) => ({
json: x,
npys: [`${x}-le`, `${x}-be`],
})),
]) {
for (const npyName of npys) {
it(npyName, async () => {
const testDataDir = path.resolve(
import.meta.dirname,
"..",
"..",
"testdata",
);
const example = JSON.parse(
await fs.readFile(`${testDataDir}/npy_test.${json}.json`, {
encoding: "utf-8",
}),
) as ExampleSpec;
const npy = await fs.readFile(`${testDataDir}/npy_test.${npyName}.npy`);
checkNpy(example, new Uint8Array(npy));
});
}
}
});
4 changes: 0 additions & 4 deletions typings/binary.d.ts

This file was deleted.

8 changes: 0 additions & 8 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { defineWorkspace } from "vitest/config";
import binaryPlugin from "./build_tools/vite/vite-plugin-binary.ts";

const baseConfig = {
extends: "./vite.config.ts",
plugins: [binaryPlugin({ include: ["**/*.npy", "**/*.dat"] })],
};

export default defineWorkspace([
{
...baseConfig,
test: {
environment: "node",
setupFiles: ["./build_tools/vitest/setup-crypto.ts"],
Expand All @@ -19,7 +12,6 @@ export default defineWorkspace([
},
},
{
...baseConfig,
test: {
include: ["src/**/*.browser_test.ts"],
benchmark: {
Expand Down

0 comments on commit 10718c4

Please sign in to comment.