dolphindb 3.0.39 → 3.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -330,7 +330,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
330
330
  pack(): Uint8Array;
331
331
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
332
332
  /** 将 DdbObj 转换为 js 原生数据类型
333
- - 标量对应 number, bigint 或者字符串
333
+ - 标量对应 number, bigint 或者字符串 (其中时间类型转换为常用的字符串表示)
334
334
  - 数组对应 js 原生数组
335
335
  - 表格对应 DdbTableData
336
336
  - 矩阵对应 DdbMatrixData
@@ -396,6 +396,8 @@ export declare function formati(obj: DdbVectorObj, index: number, options?: Insp
396
396
  export interface ConvertOptions {
397
397
  /** `'string'` blob 类型数据的格式 */
398
398
  blob?: 'string' | 'binary';
399
+ /** timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
400
+ timestamp?: 's' | 'ms';
399
401
  }
400
402
  export declare function convert(type: DdbType, value: DdbValue, le: boolean, { blob }?: ConvertOptions): string | number | bigint | boolean | Uint8Array | Int32Array | BigInt64Array | string[] | Int8Array | Int16Array | Float32Array | Float64Array | Uint8Array[] | number[] | DdbFunctionDefValue | DdbDurationValue | DdbDecimal32Value | DdbDecimal64Value | DdbDecimal32VectorValue | DdbDecimal64VectorValue | DdbDecimal128VectorValue | BigInt128Array | DdbSymbolExtendedValue | DdbArrayVectorValue | DdbMatrixValue | DdbObj<DdbValue>[] | DdbDurationVectorValue | DdbTensorValue | DdbChartValue;
401
403
  /** 转换一个向量到 js 原生数组 */
package/index.js CHANGED
@@ -1065,6 +1065,38 @@ export class DdbObj {
1065
1065
  ...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
1066
1066
  ];
1067
1067
  }
1068
+ case DdbForm.tensor: {
1069
+ const { le, value } = this;
1070
+ const { tensor_type, device_type, tensor_flags, dimensions, shape, strides, preserve_value, elem_count, data } = value;
1071
+ // 计算总的字节长度
1072
+ const totalLength = 10 + dimensions * 8 * 2 + 8 + 8 + data.length; // 12 字节元数据 + 维度信息 + 保留值和元素数量 + 数据部分
1073
+ const buffer = new ArrayBuffer(totalLength);
1074
+ const dv = new DataView(buffer);
1075
+ const uint8Array = new Uint8Array(buffer);
1076
+ // 写入元数据
1077
+ // uint8Array[0] = type;
1078
+ // uint8Array[1] = form;
1079
+ uint8Array[0] = tensor_type;
1080
+ uint8Array[1] = device_type;
1081
+ dv.setUint32(2, tensor_flags, le);
1082
+ dv.setInt32(6, dimensions, le);
1083
+ // 写入形状和步长
1084
+ const shapeStart = 10;
1085
+ const stridesStart = shapeStart + dimensions * 8;
1086
+ for (let d = 0; d < dimensions; d++) {
1087
+ dv.setBigInt64(shapeStart + d * 8, BigInt(shape[d]), le);
1088
+ dv.setBigInt64(stridesStart + d * 8, BigInt(strides[d]), le);
1089
+ }
1090
+ // 写入保留值和元素数量
1091
+ const preserveValueStart = stridesStart + dimensions * 8;
1092
+ dv.setBigInt64(preserveValueStart, preserve_value, le);
1093
+ const storageStart = preserveValueStart + 8;
1094
+ dv.setBigInt64(storageStart, BigInt(elem_count), le);
1095
+ // 写入数据
1096
+ const dataStart = storageStart + 8;
1097
+ uint8Array.set(data, dataStart);
1098
+ return [uint8Array];
1099
+ }
1068
1100
  default:
1069
1101
  throw new Error(t('vector {{type}} 暂不支持序列化', { type: get_type_name(type) }));
1070
1102
  }