File size: 1,876 Bytes
78c921d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// automatically generated by the FlatBuffers compiler, do not modify

import { SparseMatrixIndexCSX } from './sparse-matrix-index-c-s-x.js';
import { SparseTensorIndexCOO } from './sparse-tensor-index-c-o-o.js';
import { SparseTensorIndexCSF } from './sparse-tensor-index-c-s-f.js';


export enum SparseTensorIndex{
  NONE = 0,
  SparseTensorIndexCOO = 1,
  SparseMatrixIndexCSX = 2,
  SparseTensorIndexCSF = 3
}

export function unionToSparseTensorIndex(
  type: SparseTensorIndex,
  accessor: (obj:SparseMatrixIndexCSX|SparseTensorIndexCOO|SparseTensorIndexCSF) => SparseMatrixIndexCSX|SparseTensorIndexCOO|SparseTensorIndexCSF|null
): SparseMatrixIndexCSX|SparseTensorIndexCOO|SparseTensorIndexCSF|null {
  switch(SparseTensorIndex[type]) {
    case 'NONE': return null;
    case 'SparseTensorIndexCOO': return accessor(new SparseTensorIndexCOO())! as SparseTensorIndexCOO;
    case 'SparseMatrixIndexCSX': return accessor(new SparseMatrixIndexCSX())! as SparseMatrixIndexCSX;
    case 'SparseTensorIndexCSF': return accessor(new SparseTensorIndexCSF())! as SparseTensorIndexCSF;
    default: return null;
  }
}

export function unionListToSparseTensorIndex(
  type: SparseTensorIndex,
  accessor: (index: number, obj:SparseMatrixIndexCSX|SparseTensorIndexCOO|SparseTensorIndexCSF) => SparseMatrixIndexCSX|SparseTensorIndexCOO|SparseTensorIndexCSF|null,
  index: number
): SparseMatrixIndexCSX|SparseTensorIndexCOO|SparseTensorIndexCSF|null {
  switch(SparseTensorIndex[type]) {
    case 'NONE': return null;
    case 'SparseTensorIndexCOO': return accessor(index, new SparseTensorIndexCOO())! as SparseTensorIndexCOO;
    case 'SparseMatrixIndexCSX': return accessor(index, new SparseMatrixIndexCSX())! as SparseMatrixIndexCSX;
    case 'SparseTensorIndexCSF': return accessor(index, new SparseTensorIndexCSF())! as SparseTensorIndexCSF;
    default: return null;
  }
}