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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
23 "github.com/apache/arrow/go/v6/arrow/float16"
24 "github.com/apache/arrow/go/v6/arrow/endian"
28 var Float16Traits float16Traits
31 // Float16SizeBytes specifies the number of bytes required to store a single float16 in memory
32 Float16SizeBytes = int(unsafe.Sizeof(uint16(0)))
35 type float16Traits struct{}
37 // BytesRequired returns the number of bytes required to store n elements in memory.
38 func (float16Traits) BytesRequired(n int) int { return Float16SizeBytes * n }
41 func (float16Traits) PutValue(b []byte, v float16.Num) {
42 endian.Native.PutUint16(b, uint16(v.Uint16()))
45 // CastFromBytes reinterprets the slice b to a slice of type uint16.
47 // NOTE: len(b) must be a multiple of Uint16SizeBytes.
48 func (float16Traits) CastFromBytes(b []byte) []float16.Num {
49 h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
52 s := (*reflect.SliceHeader)(unsafe.Pointer(&res))
54 s.Len = h.Len / Float16SizeBytes
55 s.Cap = h.Cap / Float16SizeBytes
60 // CastToBytes reinterprets the slice b to a slice of bytes.
61 func (float16Traits) CastToBytes(b []float16.Num) []byte {
62 h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
65 s := (*reflect.SliceHeader)(unsafe.Pointer(&res))
67 s.Len = h.Len * Float16SizeBytes
68 s.Cap = h.Cap * Float16SizeBytes
73 // Copy copies src to dst.
74 func (float16Traits) Copy(dst, src []float16.Num) { copy(dst, src) }