mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 13:00:19 +00:00
Add types for multivariate-normal (#37989)
* Add multivariate-normal * Update metadata * Remove patch version * Improve tests and immutability annotations * Allow readonly array in mutators
This commit is contained in:
committed by
Ron Buckton
parent
b50ab5bb1b
commit
e964385bc1
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// Type definitions for multivariate-normal 0.1
|
||||
// Project: https://github.com/tulip/multivariate-normal-js#readme
|
||||
// Definitions by: Ben Weissmann <https://github.com/benweissmann>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface Distribution {
|
||||
sample(): number[];
|
||||
getMean(): ReadonlyArray<number>;
|
||||
setMean(newMean: ReadonlyArray<number>): Distribution;
|
||||
getCov(): ReadonlyArray<ReadonlyArray<number>>;
|
||||
setCov(newCov: ReadonlyArray<ReadonlyArray<number>>): Distribution;
|
||||
}
|
||||
|
||||
export default function MultivariateNormal(
|
||||
mean: ReadonlyArray<number>,
|
||||
cov: ReadonlyArray<ReadonlyArray<number>>,
|
||||
): Distribution;
|
||||
@@ -0,0 +1,35 @@
|
||||
import MultivariateNormal from 'multivariate-normal';
|
||||
|
||||
// Test constructing using mutable and literal arrays
|
||||
const mutArray: number[] = [1, 2, 3];
|
||||
const dist = MultivariateNormal(mutArray, [[0, 0, 1], [0, 1, 0], [1, 0, 0]]);
|
||||
|
||||
// Test methods for creating a new distribution from an existing one using
|
||||
// mutable and literal arrays
|
||||
const mutArray2: number[] = [4, 5, 6];
|
||||
const newDist = dist.setMean(mutArray2).setCov([[0, 0, 1], [0, 1, 0], [1, 0, 0]]);
|
||||
|
||||
// Test accessors
|
||||
const newMean: ReadonlyArray<number> = newDist.getMean();
|
||||
const newCov: ReadonlyArray<ReadonlyArray<number>> = newDist.getCov();
|
||||
|
||||
// Mean and covariance are immutable
|
||||
|
||||
// $ExpectError
|
||||
newDist.getMean()[0] = 10;
|
||||
|
||||
// $ExpectError
|
||||
newDist.getCov()[0] = [1, 2, 3];
|
||||
|
||||
// $ExpectError
|
||||
newDist.getCov()[0][0] = 10;
|
||||
|
||||
// Samples are mutable
|
||||
const sample: number[] = newDist.sample();
|
||||
sample[0] = 123;
|
||||
|
||||
// Check that we can pass immutable arrays into the constructor or mutators
|
||||
MultivariateNormal(newDist.getMean(), newDist.getCov());
|
||||
|
||||
newDist.setCov(dist.getCov());
|
||||
newDist.setMean(dist.getMean());
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"multivariate-normal-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user