domoritz commented on a change in pull request #10151:
URL: https://github.com/apache/arrow/pull/10151#discussion_r621665892
##########
File path: js/src/util/args.ts
##########
@@ -21,11 +21,26 @@ import { Column } from '../column';
import { Vector } from '../vector';
import { DataType } from '../type';
import { Chunked } from '../vector/chunked';
+import { BigIntArray, TypedArray } from '../interfaces';
+import { FloatVector, IntVector } from '../vector/index';
type RecordBatchCtor = typeof import('../recordbatch').RecordBatch;
const isArray = Array.isArray;
+/** @ignore */
+export function isTypedArray(arr: any): arr is TypedArray | BigIntArray {
+ return ArrayBuffer.isView(arr) && 'BYTES_PER_ELEMENT' in arr;
+}
+
+/** @ignore */
+function vectorFromTypedArray(array: TypedArray): Vector {
+ if (array instanceof Float32Array || array instanceof Float64Array) {
+ return FloatVector.from(array);
+ }
+ return IntVector.from(array);
Review comment:
Thanks for the help on Slack. I updated the pull request.
##########
File path: js/src/util/args.ts
##########
@@ -19,13 +19,55 @@ import { Data } from '../data';
import { Field } from '../schema';
import { Column } from '../column';
import { Vector } from '../vector';
-import { DataType } from '../type';
+import { DataType, Float32, Float64, FloatArray, IntArray, Int16, Int32,
Int64, Int8, Uint16, Uint32, Uint64, Uint8 } from '../type';
import { Chunked } from '../vector/chunked';
+import { BigIntArray, TypedArray as TypedArray_ } from '../interfaces';
+import { FloatArrayCtor } from '../vector/float';
+import { IntArrayCtor } from '../vector/int';
type RecordBatchCtor = typeof import('../recordbatch').RecordBatch;
const isArray = Array.isArray;
+type TypedArray = Exclude<TypedArray_ | BigIntArray, Uint8ClampedArray>;
+
+/** @ignore */
+export function isTypedArray(arr: any): arr is TypedArray {
+ return ArrayBuffer.isView(arr) && 'BYTES_PER_ELEMENT' in arr;
+}
+
+
+/** @ignore */
+type ArrayCtor = FloatArrayCtor | IntArrayCtor;
+
+/** @ignore */
+export function arrayTypeToDataType(ctor: ArrayCtor) {
+ switch (ctor) {
+ case Int8Array: return Int8;
+ case Int16Array: return Int16;
+ case Int32Array: return Int32;
+ case BigInt64Array: return Int64;
+ case Uint8Array: return Uint8;
+ case Uint16Array: return Uint16;
+ case Uint32Array: return Uint32;
+ case BigUint64Array: return Uint64;
+ case Float32Array: return Float32;
+ case Float64Array: return Float64;
+ default: return null;
+ }
+}
+
+/** @ignore */
+function vectorFromTypedArray(array: TypedArray): Vector {
Review comment:
We could make this function have the right types but since it's
internal, it doesn't matter as much.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]