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,CAAC,CAAG,OAAO,cAAO,CAAC;QACpC,KAAK,YAAY,CAAC,CAAG,OAAO,cAAO,CAAC;QACpC,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;KACxB;AACL,CAAC,CAAC;AAEF,cAAc;AACd,MAAM,oBAAoB,GAAG,CAAC,IAA6B,EAAE,EAAE;IAC3D,QAAQ,IAAI,EAAE;QACV,KAAK,aAAa,CAAC,CAAC,OAAO,cAAO,CAAC;QACnC,KAAK,aAAa,CAAC,CAAC,OAAO,cAAO,CAAC;QACnC,KAAK,aAAa,CAAC,CAAC,OAAO,cAAO,CAAC;QACnC,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;KACxB;AACL,CAAC,CAAC","file":"float.js","sourcesContent":["// Licensed to the Apache Software Foundation (ASF) under one\n// or more contributor license agreements. See the NOTICE file\n// distributed with this work for additional information\n// regarding copyright ownership. The ASF licenses this file\n// to you under the Apache License, Version 2.0 (the\n// \"License\"); you may not use this file except in compliance\n// with the License. You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied. See the License for the\n// specific language governing permissions and limitations\n// under the License.\n\nimport { Data } from '../data';\nimport { Vector } from '../vector';\nimport { Chunked } from './chunked';\nimport { BaseVector } from './base';\nimport { VectorBuilderOptions } from './index';\nimport { vectorFromValuesWithType } from './index';\nimport { VectorBuilderOptionsAsync } from './index';\nimport { Float, Float16, Float32, Float64, FloatArray } from '../type';\nimport { VectorType as V, TypedArrayConstructor } from '../interfaces';\n\n/** @ignore */\ntype FloatVectorConstructors =\n typeof FloatVector |\n typeof Float16Vector |\n typeof Float32Vector |\n typeof Float64Vector ;\n\n/** @ignore */\ntype FromInput<T extends Float, TNull = any> =\n FloatArray |\n Iterable<T['TValue'] | TNull> |\n AsyncIterable<T['TValue'] | TNull> |\n VectorBuilderOptions<T, TNull> |\n VectorBuilderOptionsAsync<T, TNull> ;\n\n/** @ignore */\ntype FloatArrayCtor = TypedArrayConstructor<FloatArray>;\n\n/** @ignore */\nexport class FloatVector<T extends Float = Float> extends BaseVector<T> {\n\n // Guaranteed zero-copy variants\n public static from(this: typeof FloatVector, input: Uint16Array): Float16Vector;\n public static from(this: typeof FloatVector, input: Float32Array): Float32Vector;\n public static from(this: typeof FloatVector, input: Float64Array): Float64Vector;\n\n // Zero-copy if input is a TypedArray of the same type as the\n // Vector that from is called on, otherwise uses the Builders\n public static from<TNull = any>(this: typeof Float16Vector, input: FromInput<Float16, TNull>): Float16Vector;\n public static from<TNull = any>(this: typeof Float32Vector, input: FromInput<Float32, TNull>): Float32Vector;\n public static from<TNull = any>(this: typeof Float64Vector, input: FromInput<Float64, TNull>): Float64Vector;\n\n // Not zero-copy\n public static from<T extends Float, TNull = any>(this: typeof FloatVector, input: Iterable<T['TValue'] | TNull>): V<T>;\n public static from<T extends Float, TNull = any>(this: typeof FloatVector, input: AsyncIterable<T['TValue'] | TNull>): Promise<V<T>>;\n public static from<T extends Float, TNull = any>(this: typeof FloatVector, input: VectorBuilderOptions<T, TNull>): Chunked<T>;\n public static from<T extends Float, TNull = any>(this: typeof FloatVector, input: VectorBuilderOptionsAsync<T, TNull>): Promise<Chunked<T>>;\n /** @nocollapse */\n public static from<T extends Float, TNull = any>(this: FloatVectorConstructors, input: FromInput<T, TNull>) {\n\n let ArrowType = vectorTypeToDataType(this);\n\n if ((input instanceof ArrayBuffer) || ArrayBuffer.isView(input)) {\n let InputType = arrayTypeToDataType(input.constructor as FloatArrayCtor) || ArrowType;\n // Special case, infer the Arrow DataType from the input if calling the base\n // FloatVector.from with a TypedArray, e.g. `FloatVector.from(new Float32Array())`\n if (ArrowType === null) {\n ArrowType = InputType;\n }\n // If the DataType inferred from the Vector constructor matches the\n // DataType inferred from the input arguments, return zero-copy view\n if (ArrowType && ArrowType === InputType) {\n let type = new ArrowType();\n let length = input.byteLength / type.ArrayType.BYTES_PER_ELEMENT;\n // If the ArrowType is Float16 but the input type isn't a Uint16Array,\n // let the Float16Builder handle casting the input values to Uint16s.\n if (!convertTo16Bit(ArrowType, input.constructor)) {\n return Vector.new(Data.Float(type, 0, length, 0, null, input as FloatArray));\n }\n }\n }\n\n if (ArrowType) {\n // If the DataType inferred from the Vector constructor is different than\n // the DataType inferred from the input TypedArray, or if input isn't a\n // TypedArray, use the Builders to construct the result Vector\n return vectorFromValuesWithType(() => new ArrowType!() as T, input);\n }\n\n if ((input instanceof DataView) || (input instanceof ArrayBuffer)) {\n throw new TypeError(`Cannot infer float type from instance of ${input.constructor.name}`);\n }\n\n throw new TypeError('Unrecognized FloatVector input');\n }\n}\n\n/** @ignore */\nexport class Float16Vector extends FloatVector<Float16> {\n // Since JS doesn't have half floats, `toArray()` returns a zero-copy slice\n // of the underlying Uint16Array data. This behavior ensures we don't incur\n // extra compute or copies if you're calling `toArray()` in order to create\n // a buffer for something like WebGL. Buf if you're using JS and want typed\n // arrays of 4-to-8-byte precision, these methods will enumerate the values\n // and clamp to the desired byte lengths.\n public toFloat32Array() { return new Float32Array(this as Iterable<number>); }\n public toFloat64Array() { return new Float64Array(this as Iterable<number>); }\n}\n\n/** @ignore */\nexport class Float32Vector extends FloatVector<Float32> {}\n/** @ignore */\nexport class Float64Vector extends FloatVector<Float64> {}\n\nconst convertTo16Bit = (typeCtor: any, dataCtor: any) => {\n return (typeCtor === Float16) && (dataCtor !== Uint16Array);\n};\n\n/** @ignore */\nconst arrayTypeToDataType = (ctor: FloatArrayCtor) => {\n switch (ctor) {\n case Uint16Array: return Float16;\n case Float32Array: return Float32;\n case Float64Array: return Float64;\n default: return null;\n }\n};\n\n/** @ignore */\nconst vectorTypeToDataType = (ctor: FloatVectorConstructors) => {\n switch (ctor) {\n case Float16Vector: return Float16;\n case Float32Vector: return Float32;\n case Float64Vector: return Float64;\n default: return null;\n }\n};\n"]} |