/** * Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal * @author Alexander Rose */ import { Tensor as Tensors } from '../../mol-math/linear-algebra/tensor.js'; import type { Tokens } from '../../mol-io/reader/common/text/tokenizer.js'; interface Column { readonly schema: Column.Schema; readonly __array: ArrayLike | undefined; readonly isDefined: boolean; readonly rowCount: number; value(row: number): T; valueKind(row: number): Column.ValueKind; toArray(params?: Column.ToArrayParams): ArrayLike; areValuesEqual(rowA: number, rowB: number): boolean; } declare namespace Column { type ArrayCtor = { new (size: number): ArrayLike; }; type Schema = Schema.Str | Schema.Int | Schema.Float | Schema.Coordinate | Schema.Aliased | Schema.Tensor | Schema.List; namespace Schema { type Base = { valueType: T; }; export type Str = { '@type': 'str'; T: string; transform?: 'uppercase' | 'lowercase'; } & Base<'str'>; export type Int = { '@type': 'int'; T: number; } & Base<'int'>; export type Float = { '@type': 'float'; T: number; } & Base<'float'>; export type Coordinate = { '@type': 'coord'; T: number; } & Base<'float'>; export type Tensor = { '@type': 'tensor'; T: Tensors.Data; space: Tensors.Space; baseType: Int | Float; } & Base<'tensor'>; export type Aliased = { '@type': 'aliased'; T: T; transform?: T extends string ? 'uppercase' | 'lowercase' : never; } & Base; export type List = { '@type': 'list'; T: T[]; separator: string; itemParse: (x: string) => T; } & Base<'list'>; export const str: Str; export const ustr: Str; export const lstr: Str; export const int: Int; export const coord: Coordinate; export const float: Float; export function Str(options?: { defaultValue?: string; transform?: 'uppercase' | 'lowercase'; }): Str; export function Int(defaultValue?: number): Int; export function Float(defaultValue?: number): Float; export function Tensor(space: Tensors.Space, baseType?: Int | Float): Tensor; export function Vector(dim: number, baseType?: Int | Float): Tensor; export function Matrix(rows: number, cols: number, baseType?: Int | Float): Tensor; export function Aliased(t: Str | Int): Aliased; export function List(separator: string, itemParse: (x: string) => T, defaultValue?: T[]): List; export {}; } interface ToArrayParams { array?: ArrayCtor; start?: number; /** Last row (exclusive) */ end?: number; } interface LambdaSpec { value: (row: number) => T['T']; rowCount: number; schema: T; valueKind?: (row: number) => ValueKind; areValuesEqual?: (rowA: number, rowB: number) => boolean; } interface ArraySpec { array: ArrayLike; schema: T; valueKind?: (row: number) => ValueKind; } interface MapSpec { f: (v: S['T']) => T['T']; schema: T; valueKind?: (row: number) => ValueKind; } function is(v: any): v is Column; const enum ValueKinds { /** Defined value (= 0) */ Present = 0, /** Expressed in CIF as `.` (= 1) */ NotPresent = 1, /** Expressed in CIF as `?` (= 2) */ Unknown = 2 } const ValueKind: { /** Defined value (= 0) */ readonly Present: ValueKinds.Present; /** Expressed in CIF as `.` (= 1) */ readonly NotPresent: ValueKinds.NotPresent; /** Expressed in CIF as `?` (= 2) */ readonly Unknown: ValueKinds.Unknown; }; type ValueKind = (typeof ValueKind)[keyof typeof ValueKinds]; function Undefined(rowCount: number, schema: T): Column; function ofConst(v: T['T'], rowCount: number, type: T): Column; function ofLambda(spec: LambdaSpec): Column; /** values [min, max] (i.e. include both values) */ function range(min: number, max: number): Column; function ofArray(spec: Column.ArraySpec): Column; function ofIntArray(array: ArrayLike): Column; function ofFloatArray(array: ArrayLike): Column; function ofStringArray(array: ArrayLike): Column; function ofStringAliasArray(array: ArrayLike): Column; function ofStringListArray(array: ArrayLike, separator?: string): Column; function ofIntTokens(tokens: Tokens): Column; function ofFloatTokens(tokens: Tokens): Column; function ofStringTokens(tokens: Tokens): Column; function window(column: Column, start: number, end: number): Column; function view(column: Column, indices: ArrayLike, checkIndentity?: boolean): Column; /** A map of the 1st occurence of each value. */ function createFirstIndexMap(column: Column): Map; function createIndexer(column: Column): ((e: T) => R); function mapToArray(column: Column, f: (v: T) => S, ctor?: ArrayCtor): ArrayLike; function areEqual(a: Column, b: Column): boolean; function indicesOf(c: Column, test: (e: T) => boolean): number[]; /** Makes the column backed by an array. Useful for columns that are accessed often. */ function asArrayColumn(c: Column, array?: ArrayCtor): Column; function copyToArray(c: Column, array: { [k: number]: T; length: number; }, offset?: number): void; function isIdentity(c: Column): boolean; } export { Column };