File: SparseTensorIndexCSF.go

package info (click to toggle)
golang-github-apache-arrow-go 18.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,200 kB
  • sloc: asm: 477,547; ansic: 5,369; cpp: 759; sh: 585; makefile: 319; python: 190; sed: 5
file content (291 lines) | stat: -rw-r--r-- 9,665 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Code generated by the FlatBuffers compiler. DO NOT EDIT.

package flatbuf

import (
	flatbuffers "github.com/google/flatbuffers/go"
)

// / Compressed Sparse Fiber (CSF) sparse tensor index.
type SparseTensorIndexCSF struct {
	_tab flatbuffers.Table
}

func GetRootAsSparseTensorIndexCSF(buf []byte, offset flatbuffers.UOffsetT) *SparseTensorIndexCSF {
	n := flatbuffers.GetUOffsetT(buf[offset:])
	x := &SparseTensorIndexCSF{}
	x.Init(buf, n+offset)
	return x
}

func (rcv *SparseTensorIndexCSF) Init(buf []byte, i flatbuffers.UOffsetT) {
	rcv._tab.Bytes = buf
	rcv._tab.Pos = i
}

func (rcv *SparseTensorIndexCSF) Table() flatbuffers.Table {
	return rcv._tab
}

// / CSF is a generalization of compressed sparse row (CSR) index.
// / See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf)
// /
// / CSF index recursively compresses each dimension of a tensor into a set
// / of prefix trees. Each path from a root to leaf forms one tensor
// / non-zero index. CSF is implemented with two arrays of buffers and one
// / arrays of integers.
// /
// / For example, let X be a 2x3x4x5 tensor and let it have the following
// / 8 non-zero values:
// / ```text
// /   X[0, 0, 0, 1] := 1
// /   X[0, 0, 0, 2] := 2
// /   X[0, 1, 0, 0] := 3
// /   X[0, 1, 0, 2] := 4
// /   X[0, 1, 1, 0] := 5
// /   X[1, 1, 1, 0] := 6
// /   X[1, 1, 1, 1] := 7
// /   X[1, 1, 1, 2] := 8
// / ```
// / As a prefix tree this would be represented as:
// / ```text
// /         0          1
// /        / \         |
// /       0   1        1
// /      /   / \       |
// /     0   0   1      1
// /    /|  /|   |    /| |
// /   1 2 0 2   0   0 1 2
// / ```
// / The type of values in indptrBuffers
func (rcv *SparseTensorIndexCSF) IndptrType(obj *Int) *Int {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
	if o != 0 {
		x := rcv._tab.Indirect(o + rcv._tab.Pos)
		if obj == nil {
			obj = new(Int)
		}
		obj.Init(rcv._tab.Bytes, x)
		return obj
	}
	return nil
}

// / CSF is a generalization of compressed sparse row (CSR) index.
// / See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf)
// /
// / CSF index recursively compresses each dimension of a tensor into a set
// / of prefix trees. Each path from a root to leaf forms one tensor
// / non-zero index. CSF is implemented with two arrays of buffers and one
// / arrays of integers.
// /
// / For example, let X be a 2x3x4x5 tensor and let it have the following
// / 8 non-zero values:
// / ```text
// /   X[0, 0, 0, 1] := 1
// /   X[0, 0, 0, 2] := 2
// /   X[0, 1, 0, 0] := 3
// /   X[0, 1, 0, 2] := 4
// /   X[0, 1, 1, 0] := 5
// /   X[1, 1, 1, 0] := 6
// /   X[1, 1, 1, 1] := 7
// /   X[1, 1, 1, 2] := 8
// / ```
// / As a prefix tree this would be represented as:
// / ```text
// /         0          1
// /        / \         |
// /       0   1        1
// /      /   / \       |
// /     0   0   1      1
// /    /|  /|   |    /| |
// /   1 2 0 2   0   0 1 2
// / ```
// / The type of values in indptrBuffers
// / indptrBuffers stores the sparsity structure.
// / Each two consecutive dimensions in a tensor correspond to a buffer in
// / indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]`
// / and `indptrBuffers[dim][i + 1]` signify a range of nodes in
// / `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node.
// /
// / For example, the indptrBuffers for the above X is:
// / ```text
// /   indptrBuffer(X) = [
// /                       [0, 2, 3],
// /                       [0, 1, 3, 4],
// /                       [0, 2, 4, 5, 8]
// /                     ].
// / ```
func (rcv *SparseTensorIndexCSF) IndptrBuffers(obj *Buffer, j int) bool {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
	if o != 0 {
		x := rcv._tab.Vector(o)
		x += flatbuffers.UOffsetT(j) * 16
		obj.Init(rcv._tab.Bytes, x)
		return true
	}
	return false
}

func (rcv *SparseTensorIndexCSF) IndptrBuffersLength() int {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
	if o != 0 {
		return rcv._tab.VectorLen(o)
	}
	return 0
}

// / indptrBuffers stores the sparsity structure.
// / Each two consecutive dimensions in a tensor correspond to a buffer in
// / indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]`
// / and `indptrBuffers[dim][i + 1]` signify a range of nodes in
// / `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node.
// /
// / For example, the indptrBuffers for the above X is:
// / ```text
// /   indptrBuffer(X) = [
// /                       [0, 2, 3],
// /                       [0, 1, 3, 4],
// /                       [0, 2, 4, 5, 8]
// /                     ].
// / ```
// / The type of values in indicesBuffers
func (rcv *SparseTensorIndexCSF) IndicesType(obj *Int) *Int {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
	if o != 0 {
		x := rcv._tab.Indirect(o + rcv._tab.Pos)
		if obj == nil {
			obj = new(Int)
		}
		obj.Init(rcv._tab.Bytes, x)
		return obj
	}
	return nil
}

// / The type of values in indicesBuffers
// / indicesBuffers stores values of nodes.
// / Each tensor dimension corresponds to a buffer in indicesBuffers.
// / For example, the indicesBuffers for the above X is:
// / ```text
// /   indicesBuffer(X) = [
// /                        [0, 1],
// /                        [0, 1, 1],
// /                        [0, 0, 1, 1],
// /                        [1, 2, 0, 2, 0, 0, 1, 2]
// /                      ].
// / ```
func (rcv *SparseTensorIndexCSF) IndicesBuffers(obj *Buffer, j int) bool {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
	if o != 0 {
		x := rcv._tab.Vector(o)
		x += flatbuffers.UOffsetT(j) * 16
		obj.Init(rcv._tab.Bytes, x)
		return true
	}
	return false
}

func (rcv *SparseTensorIndexCSF) IndicesBuffersLength() int {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
	if o != 0 {
		return rcv._tab.VectorLen(o)
	}
	return 0
}

// / indicesBuffers stores values of nodes.
// / Each tensor dimension corresponds to a buffer in indicesBuffers.
// / For example, the indicesBuffers for the above X is:
// / ```text
// /   indicesBuffer(X) = [
// /                        [0, 1],
// /                        [0, 1, 1],
// /                        [0, 0, 1, 1],
// /                        [1, 2, 0, 2, 0, 0, 1, 2]
// /                      ].
// / ```
// / axisOrder stores the sequence in which dimensions were traversed to
// / produce the prefix tree.
// / For example, the axisOrder for the above X is:
// / ```text
// /   axisOrder(X) = [0, 1, 2, 3].
// / ```
func (rcv *SparseTensorIndexCSF) AxisOrder(j int) int32 {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(12))
	if o != 0 {
		a := rcv._tab.Vector(o)
		return rcv._tab.GetInt32(a + flatbuffers.UOffsetT(j*4))
	}
	return 0
}

func (rcv *SparseTensorIndexCSF) AxisOrderLength() int {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(12))
	if o != 0 {
		return rcv._tab.VectorLen(o)
	}
	return 0
}

// / axisOrder stores the sequence in which dimensions were traversed to
// / produce the prefix tree.
// / For example, the axisOrder for the above X is:
// / ```text
// /   axisOrder(X) = [0, 1, 2, 3].
// / ```
func (rcv *SparseTensorIndexCSF) MutateAxisOrder(j int, n int32) bool {
	o := flatbuffers.UOffsetT(rcv._tab.Offset(12))
	if o != 0 {
		a := rcv._tab.Vector(o)
		return rcv._tab.MutateInt32(a+flatbuffers.UOffsetT(j*4), n)
	}
	return false
}

func SparseTensorIndexCSFStart(builder *flatbuffers.Builder) {
	builder.StartObject(5)
}
func SparseTensorIndexCSFAddIndptrType(builder *flatbuffers.Builder, indptrType flatbuffers.UOffsetT) {
	builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(indptrType), 0)
}
func SparseTensorIndexCSFAddIndptrBuffers(builder *flatbuffers.Builder, indptrBuffers flatbuffers.UOffsetT) {
	builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(indptrBuffers), 0)
}
func SparseTensorIndexCSFStartIndptrBuffersVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
	return builder.StartVector(16, numElems, 8)
}
func SparseTensorIndexCSFAddIndicesType(builder *flatbuffers.Builder, indicesType flatbuffers.UOffsetT) {
	builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(indicesType), 0)
}
func SparseTensorIndexCSFAddIndicesBuffers(builder *flatbuffers.Builder, indicesBuffers flatbuffers.UOffsetT) {
	builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(indicesBuffers), 0)
}
func SparseTensorIndexCSFStartIndicesBuffersVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
	return builder.StartVector(16, numElems, 8)
}
func SparseTensorIndexCSFAddAxisOrder(builder *flatbuffers.Builder, axisOrder flatbuffers.UOffsetT) {
	builder.PrependUOffsetTSlot(4, flatbuffers.UOffsetT(axisOrder), 0)
}
func SparseTensorIndexCSFStartAxisOrderVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
	return builder.StartVector(4, numElems, 4)
}
func SparseTensorIndexCSFEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
	return builder.EndObject()
}