mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-09 06:58:12 +08:00
type range
This commit is contained in:
+23
-15
@@ -22,38 +22,46 @@ rangeFill(array, start, step) -> array
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type.
|
function _doFill(
|
||||||
function _doFill(arr, start, step, count) {
|
arr: Array<number>,
|
||||||
|
start: number,
|
||||||
|
step: number,
|
||||||
|
count: number
|
||||||
|
) {
|
||||||
for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
|
for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
|
||||||
arr[idx] = val;
|
arr[idx] = val;
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type.
|
export function rangeFill(
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
arr: Array<number>,
|
||||||
export function rangeFill(arr, start = 0, step = 1) {
|
start = 0,
|
||||||
|
step = 1
|
||||||
|
): Array<number> {
|
||||||
return _doFill(arr, start, step, arr.length);
|
return _doFill(arr, start, step, arr.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type.
|
export function range(
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
start: number,
|
||||||
export function range(start, stop, step) {
|
stop?: number,
|
||||||
|
step?: number
|
||||||
|
): Array<number> {
|
||||||
if (start === undefined) return [];
|
if (start === undefined) return [];
|
||||||
if (stop === undefined) {
|
if (stop === undefined) {
|
||||||
stop = start;
|
stop = start;
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
step = step || 1; // catch undefind and zero
|
step = step || 1; // catch undefined and zero
|
||||||
const len = Math.max(Math.ceil((stop - start) / step), 0);
|
const len = Math.max(Math.ceil((stop - start) / step), 0);
|
||||||
return _doFill(new Array(len), start, step, len);
|
return _doFill(new Array(len), start, step, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type.
|
export function linspace(
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
start: number,
|
||||||
export function linspace(start, stop, nsteps) {
|
stop: number,
|
||||||
// @ts-expect-error ts-migrate(2363) FIXME: The right-hand side of an arithmetic operation mus... Remove this comment to see the full error message
|
nsteps: number
|
||||||
const delta = (stop - start) / (nsteps - 1).toFixed();
|
): Array<number> {
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'i' implicitly has an 'any' type.
|
const delta = (stop - start) / Number((nsteps - 1).toFixed());
|
||||||
return range(0, nsteps, 1).map((i) => start + i * delta);
|
return range(0, nsteps, 1).map((i) => start + i * delta);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user