github.com/apache/arrow/go/v14@v14.0.2/internal/utils/transpose_ints_def.go (about) 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 utils 18 19 import ( 20 "errors" 21 22 "github.com/apache/arrow/go/v14/arrow" 23 ) 24 25 //go:generate go run ../../arrow/_tools/tmpl -i -data=transpose_ints.tmpldata -d arch=avx2 transpose_ints_simd.go.tmpl=transpose_ints_avx2_amd64.go 26 //go:generate go run ../../arrow/_tools/tmpl -i -data=transpose_ints.tmpldata -d arch=sse4 transpose_ints_simd.go.tmpl=transpose_ints_sse4_amd64.go 27 //go:generate go run ../../arrow/_tools/tmpl -i -data=transpose_ints.tmpldata transpose_ints_s390x.go.tmpl=transpose_ints_s390x.go 28 //go:generate go run ../../arrow/_tools/tmpl -i -data=transpose_ints.tmpldata transpose_ints_s390x.go.tmpl=transpose_ints_arm64.go 29 //go:generate go run ../../arrow/_tools/tmpl -i -data=transpose_ints.tmpldata transpose_ints_noasm.go.tmpl=transpose_ints_noasm.go 30 //go:generate go run ../../arrow/_tools/tmpl -i -data=transpose_ints.tmpldata transpose_ints.go.tmpl=transpose_ints.go 31 32 func bufToTyped(typ arrow.DataType, buf []byte, offset, length int) (interface{}, error) { 33 switch typ.ID() { 34 case arrow.INT8: 35 return arrow.Int8Traits.CastFromBytes(buf)[offset : offset+length], nil 36 case arrow.INT16: 37 return arrow.Int16Traits.CastFromBytes(buf)[offset : offset+length], nil 38 case arrow.INT32: 39 return arrow.Int32Traits.CastFromBytes(buf)[offset : offset+length], nil 40 case arrow.INT64: 41 return arrow.Int64Traits.CastFromBytes(buf)[offset : offset+length], nil 42 case arrow.UINT8: 43 return arrow.Uint8Traits.CastFromBytes(buf)[offset : offset+length], nil 44 case arrow.UINT16: 45 return arrow.Uint16Traits.CastFromBytes(buf)[offset : offset+length], nil 46 case arrow.UINT32: 47 return arrow.Uint32Traits.CastFromBytes(buf)[offset : offset+length], nil 48 case arrow.UINT64: 49 return arrow.Uint64Traits.CastFromBytes(buf)[offset : offset+length], nil 50 } 51 return nil, errors.New("only accepts integral types") 52 } 53 54 // TransposeIntsBuffers takes the data-types, byte buffers, and offsets of a source and destination 55 // buffer to perform TransposeInts on with the provided mapping data. 56 func TransposeIntsBuffers(inType, outType arrow.DataType, indata, outdata []byte, inOffset, outOffset int, length int, transposeMap []int32) error { 57 src, err := bufToTyped(inType, indata, inOffset, length) 58 if err != nil { 59 return err 60 } 61 dest, err := bufToTyped(outType, outdata, outOffset, length) 62 if err != nil { 63 return err 64 } 65 66 return TransposeInts(src, dest, transposeMap) 67 } 68 69 // TransposeInts expects two integral slices and the values they map to. Returning 70 // an error if either src or dest are not an integral type. 71 func TransposeInts(src, dest interface{}, mapping []int32) error { 72 switch s := src.(type) { 73 case []int8: 74 switch d := dest.(type) { 75 case []int8: 76 TransposeInt8Int8(s, d, mapping) 77 case []int16: 78 TransposeInt8Int16(s, d, mapping) 79 case []int32: 80 TransposeInt8Int32(s, d, mapping) 81 case []int64: 82 TransposeInt8Int64(s, d, mapping) 83 case []uint8: 84 TransposeInt8Uint8(s, d, mapping) 85 case []uint16: 86 TransposeInt8Uint16(s, d, mapping) 87 case []uint32: 88 TransposeInt8Uint32(s, d, mapping) 89 case []uint64: 90 TransposeInt8Uint64(s, d, mapping) 91 } 92 case []int16: 93 switch d := dest.(type) { 94 case []int8: 95 TransposeInt16Int8(s, d, mapping) 96 case []int16: 97 TransposeInt16Int16(s, d, mapping) 98 case []int32: 99 TransposeInt16Int32(s, d, mapping) 100 case []int64: 101 TransposeInt16Int64(s, d, mapping) 102 case []uint8: 103 TransposeInt16Uint8(s, d, mapping) 104 case []uint16: 105 TransposeInt16Uint16(s, d, mapping) 106 case []uint32: 107 TransposeInt16Uint32(s, d, mapping) 108 case []uint64: 109 TransposeInt16Uint64(s, d, mapping) 110 } 111 case []int32: 112 switch d := dest.(type) { 113 case []int8: 114 TransposeInt32Int8(s, d, mapping) 115 case []int16: 116 TransposeInt32Int16(s, d, mapping) 117 case []int32: 118 TransposeInt32Int32(s, d, mapping) 119 case []int64: 120 TransposeInt32Int64(s, d, mapping) 121 case []uint8: 122 TransposeInt32Uint8(s, d, mapping) 123 case []uint16: 124 TransposeInt32Uint16(s, d, mapping) 125 case []uint32: 126 TransposeInt32Uint32(s, d, mapping) 127 case []uint64: 128 TransposeInt32Uint64(s, d, mapping) 129 } 130 case []int64: 131 switch d := dest.(type) { 132 case []int8: 133 TransposeInt64Int8(s, d, mapping) 134 case []int16: 135 TransposeInt64Int16(s, d, mapping) 136 case []int32: 137 TransposeInt64Int32(s, d, mapping) 138 case []int64: 139 TransposeInt64Int64(s, d, mapping) 140 case []uint8: 141 TransposeInt64Uint8(s, d, mapping) 142 case []uint16: 143 TransposeInt64Uint16(s, d, mapping) 144 case []uint32: 145 TransposeInt64Uint32(s, d, mapping) 146 case []uint64: 147 TransposeInt64Uint64(s, d, mapping) 148 } 149 case []uint8: 150 switch d := dest.(type) { 151 case []int8: 152 TransposeUint8Int8(s, d, mapping) 153 case []int16: 154 TransposeUint8Int16(s, d, mapping) 155 case []int32: 156 TransposeUint8Int32(s, d, mapping) 157 case []int64: 158 TransposeUint8Int64(s, d, mapping) 159 case []uint8: 160 TransposeUint8Uint8(s, d, mapping) 161 case []uint16: 162 TransposeUint8Uint16(s, d, mapping) 163 case []uint32: 164 TransposeUint8Uint32(s, d, mapping) 165 case []uint64: 166 TransposeUint8Uint64(s, d, mapping) 167 } 168 case []uint16: 169 switch d := dest.(type) { 170 case []int8: 171 TransposeUint16Int8(s, d, mapping) 172 case []int16: 173 TransposeUint16Int16(s, d, mapping) 174 case []int32: 175 TransposeUint16Int32(s, d, mapping) 176 case []int64: 177 TransposeUint16Int64(s, d, mapping) 178 case []uint8: 179 TransposeUint16Uint8(s, d, mapping) 180 case []uint16: 181 TransposeUint16Uint16(s, d, mapping) 182 case []uint32: 183 TransposeUint16Uint32(s, d, mapping) 184 case []uint64: 185 TransposeUint16Uint64(s, d, mapping) 186 } 187 case []uint32: 188 switch d := dest.(type) { 189 case []int8: 190 TransposeUint32Int8(s, d, mapping) 191 case []int16: 192 TransposeUint32Int16(s, d, mapping) 193 case []int32: 194 TransposeUint32Int32(s, d, mapping) 195 case []int64: 196 TransposeUint32Int64(s, d, mapping) 197 case []uint8: 198 TransposeUint32Uint8(s, d, mapping) 199 case []uint16: 200 TransposeUint32Uint16(s, d, mapping) 201 case []uint32: 202 TransposeUint32Uint32(s, d, mapping) 203 case []uint64: 204 TransposeUint32Uint64(s, d, mapping) 205 } 206 case []uint64: 207 switch d := dest.(type) { 208 case []int8: 209 TransposeUint64Int8(s, d, mapping) 210 case []int16: 211 TransposeUint64Int16(s, d, mapping) 212 case []int32: 213 TransposeUint64Int32(s, d, mapping) 214 case []int64: 215 TransposeUint64Int64(s, d, mapping) 216 case []uint8: 217 TransposeUint64Uint8(s, d, mapping) 218 case []uint16: 219 TransposeUint64Uint16(s, d, mapping) 220 case []uint32: 221 TransposeUint64Uint32(s, d, mapping) 222 case []uint64: 223 TransposeUint64Uint64(s, d, mapping) 224 } 225 } 226 return nil 227 }