]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/go/arrow/tensor/numeric.gen.go.tmpl
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / go / arrow / tensor / numeric.gen.go.tmpl
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package tensor
18
19 import (
20 "github.com/apache/arrow/go/v6/arrow"
21 "github.com/apache/arrow/go/v6/arrow/array"
22 )
23
24 {{range .In}}
25
26 // {{.Name}} is an n-dim array of {{.Type}}s.
27 type {{.Name}} struct {
28 tensorBase
29 values []{{or .QualifiedType .Type}}
30 }
31
32 // New{{.Name}} returns a new n-dimensional array of {{.Type}}s.
33 // If strides is nil, row-major strides will be inferred.
34 // If names is nil, a slice of empty strings will be created.
35 func New{{.Name}}(data *array.Data, shape, strides []int64, names []string) *{{.Name}} {
36 tsr := &{{.Name}}{tensorBase:*newTensor(arrow.PrimitiveTypes.{{.Name}}, data, shape, strides, names)}
37 vals := tsr.data.Buffers()[1]
38 if vals != nil {
39 tsr.values = arrow.{{.Name}}Traits.CastFromBytes(vals.Bytes())
40 beg := tsr.data.Offset()
41 end := beg + tsr.data.Len()
42 tsr.values = tsr.values[beg:end]
43 }
44 return tsr
45 }
46
47 func (tsr *{{.Name}}) Value(i []int64) {{or .QualifiedType .Type}} { j := int(tsr.offset(i)); return tsr.values[j] }
48 func (tsr *{{.Name}}) {{.Name}}Values() []{{or .QualifiedType .Type}} { return tsr.values }
49 {{end}}
50
51 var (
52 {{range .In}}
53 _ Interface = (*{{.Name}})(nil)
54 {{- end}}
55 )