Skip to content

Commit

Permalink
Merge pull request #26 from mrc-ide/mrc-4432
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Aug 15, 2023
2 parents 750cfa5 + 98366e7 commit e3a5e74
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reside-ic/odinjs",
"version": "0.1.1",
"version": "0.1.2",
"description": "odin js/ts support",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -41,6 +41,6 @@
"dependencies": {
"@reside-ic/interpolate": "^0.0.1",
"dfoptim": "^0.0.5",
"dopri": "^0.0.12"
"dopri": "^0.0.13"
}
}
18 changes: 7 additions & 11 deletions src/interpolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export function interpolateCheckY(dimArg: number[], dimTarget: number[],
*/
export function interpolateCheckT(tStart: number, tEnd: number,
times?: InterpolateTimes,
tcrit?: number) {
tcrit?: number[]) {
if (times === undefined) {
return Infinity;
return tcrit;
}
if (tStart < times.min) {
throw Error("Integration times do not span interpolation range;" +
Expand All @@ -88,19 +88,15 @@ export function interpolateCheckT(tStart: number, tEnd: number,
throw Error("Integration times do not span interpolation range;" +
` max: ${times.max}`);
}
if (times.max === Infinity) {
return tcrit;
}

// See odin (R/generate_r_support.R:support_check_interpolate_t)
// It would be better to add an else clause to this containing
//
// tcrit = Math.min(tcrit, times.max);
//
// but this requires updating odin tests and the other
// targets. It's probably the correct behaviour though.
if (tcrit === undefined) {
tcrit = times.max;
tcrit = [];
}

return tcrit;
return [...tcrit, times.max];
}

export function interpolateTimes(start: number[], end: number[]): InterpolateTimes {
Expand Down
2 changes: 1 addition & 1 deletion src/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export function versions() {
return {
dfoptim: "0.0.5",
dopri: "0.0.12",
dopri: "0.0.13",
odinjs: "0.1.1",
};
}
14 changes: 8 additions & 6 deletions test/interpolate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ describe("Can validate interpolation argumements", () => {

describe("Can validate interpolation times", () => {
it("Requires no tcrit with no interpolationTimes", () => {
expect(interpolateCheckT(0, 10)).toBe(Infinity);
expect(interpolateCheckT(0, 10, undefined)).toBe(Infinity);
expect(interpolateCheckT(0, 10)).toBe(undefined);
expect(interpolateCheckT(0, 10, undefined)).toBe(undefined);
expect(interpolateCheckT(0, 10, undefined, [1, 2])).toStrictEqual([1, 2]);
});

it("Requires no tcrit with no max interpolation time", () => {
const t = {min: 0, max: Infinity};
expect(interpolateCheckT(0, 10, t)).toBe(Infinity);
expect(interpolateCheckT(0, 10, t)).toBe(undefined);
expect(interpolateCheckT(0, 10, t, [1, 2])).toStrictEqual([1, 2]);
});

it("Can report back tcrit from interpolation times", () => {
const t = {min: 0, max: 11};
expect(interpolateCheckT(0, 10, t)).toBe(11);
expect(interpolateCheckT(0, 10, t, 10.5)).toBe(10.5);
expect(interpolateCheckT(0, 10, t, 11.5)).toBe(11.5);
expect(interpolateCheckT(0, 10, t)).toStrictEqual([11]);
expect(interpolateCheckT(0, 10, t, [10.5])).toStrictEqual([10.5, 11]);
expect(interpolateCheckT(0, 10, t, [11.5])).toStrictEqual([11.5, 11]);
});

it("Requires that integration times do not extrapolate", () => {
Expand Down

0 comments on commit e3a5e74

Please sign in to comment.