// 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.

//go:build go1.18

package kernels

import (
	

	
	
)

var castNumericUnsafe func(itype, otype arrow.Type, in, out []byte, len int) = castNumericGo

func [,  numeric]( [],  []) {
	for ,  := range  {
		[] = ()
	}
}

func [ numeric]( [],  []float16.Num) {
	for ,  := range  {
		[] = float16.New(float32())
	}
}

func [ numeric]( []float16.Num,  []) {
	for ,  := range  {
		[] = (.Float32())
	}
}

func reinterpret[ numeric | float16.Num]( []byte,  int) ( []) {
	return unsafe.Slice((*)(unsafe.Pointer(&[0])), )
}

func castNumberToNumberUnsafeImpl[ numeric]( arrow.Type,  [],  []byte) {
	switch  {
	case arrow.INT8:
		DoStaticCast(, reinterpret[int8](, len()))
	case arrow.UINT8:
		DoStaticCast(, reinterpret[uint8](, len()))
	case arrow.INT16:
		DoStaticCast(, reinterpret[int16](, len()))
	case arrow.UINT16:
		DoStaticCast(, reinterpret[uint16](, len()))
	case arrow.INT32:
		DoStaticCast(, reinterpret[int32](, len()))
	case arrow.UINT32:
		DoStaticCast(, reinterpret[uint32](, len()))
	case arrow.INT64:
		DoStaticCast(, reinterpret[int64](, len()))
	case arrow.UINT64:
		DoStaticCast(, reinterpret[uint64](, len()))
	case arrow.FLOAT16:
		DoFloat16Cast(, reinterpret[float16.Num](, len()))
	case arrow.FLOAT32:
		DoStaticCast(, reinterpret[float32](, len()))
	case arrow.FLOAT64:
		DoStaticCast(, reinterpret[float64](, len()))
	}
}

func castFloat16ToNumberUnsafeImpl( arrow.Type,  []float16.Num,  []byte) {
	switch  {
	case arrow.INT8:
		DoFloat16CastToNumber(, reinterpret[int8](, len()))
	case arrow.UINT8:
		DoFloat16CastToNumber(, reinterpret[uint8](, len()))
	case arrow.INT16:
		DoFloat16CastToNumber(, reinterpret[int16](, len()))
	case arrow.UINT16:
		DoFloat16CastToNumber(, reinterpret[uint16](, len()))
	case arrow.INT32:
		DoFloat16CastToNumber(, reinterpret[int32](, len()))
	case arrow.UINT32:
		DoFloat16CastToNumber(, reinterpret[uint32](, len()))
	case arrow.INT64:
		DoFloat16CastToNumber(, reinterpret[int64](, len()))
	case arrow.UINT64:
		DoFloat16CastToNumber(, reinterpret[uint64](, len()))
	case arrow.FLOAT16:
		copy(reinterpret[float16.Num](, len()), )
	case arrow.FLOAT32:
		DoFloat16CastToNumber(, reinterpret[float32](, len()))
	case arrow.FLOAT64:
		DoFloat16CastToNumber(, reinterpret[float64](, len()))
	}
}

func castNumericGo(,  arrow.Type, ,  []byte,  int) {
	switch  {
	case arrow.INT8:
		castNumberToNumberUnsafeImpl(, reinterpret[int8](, ), )
	case arrow.UINT8:
		castNumberToNumberUnsafeImpl(, reinterpret[uint8](, ), )
	case arrow.INT16:
		castNumberToNumberUnsafeImpl(, reinterpret[int16](, ), )
	case arrow.UINT16:
		castNumberToNumberUnsafeImpl(, reinterpret[uint16](, ), )
	case arrow.INT32:
		castNumberToNumberUnsafeImpl(, reinterpret[int32](, ), )
	case arrow.UINT32:
		castNumberToNumberUnsafeImpl(, reinterpret[uint32](, ), )
	case arrow.INT64:
		castNumberToNumberUnsafeImpl(, reinterpret[int64](, ), )
	case arrow.UINT64:
		castNumberToNumberUnsafeImpl(, reinterpret[uint64](, ), )
	case arrow.FLOAT16:
		castFloat16ToNumberUnsafeImpl(, reinterpret[float16.Num](, ), )
	case arrow.FLOAT32:
		castNumberToNumberUnsafeImpl(, reinterpret[float32](, ), )
	case arrow.FLOAT64:
		castNumberToNumberUnsafeImpl(, reinterpret[float64](, ), )
	}
}