github.com/apache/arrow/go/v14@v14.0.1/arrow/compute/internal/kernels/constant_factor.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  //go:build go1.18
    18  
    19  package kernels
    20  
    21  var (
    22  	multiplyConstantInt32Int32 func([]int32, []int32, int64) = multiplyConstantGo[int32, int32]
    23  	multiplyConstantInt32Int64 func([]int32, []int64, int64) = multiplyConstantGo[int32, int64]
    24  	multiplyConstantInt64Int32 func([]int64, []int32, int64) = multiplyConstantGo[int64, int32]
    25  	multiplyConstantInt64Int64 func([]int64, []int64, int64) = multiplyConstantGo[int64, int64]
    26  
    27  	divideConstantInt32Int32 func([]int32, []int32, int64) = divideConstantGo[int32, int32]
    28  	divideConstantInt32Int64 func([]int32, []int64, int64) = divideConstantGo[int32, int64]
    29  	divideConstantInt64Int32 func([]int64, []int32, int64) = divideConstantGo[int64, int32]
    30  	divideConstantInt64Int64 func([]int64, []int64, int64) = divideConstantGo[int64, int64]
    31  )
    32  
    33  func multiplyConstantGo[InT, OutT ~int32 | ~int64](input []InT, output []OutT, factor int64) {
    34  	for i, v := range input {
    35  		output[i] = OutT(v) * OutT(factor)
    36  	}
    37  }
    38  
    39  func divideConstantGo[InT, OutT ~int32 | ~int64](input []InT, output []OutT, factor int64) {
    40  	for i, v := range input {
    41  		output[i] = OutT(v / InT(factor))
    42  	}
    43  }
    44  
    45  func multiplyConstant(input, output any, factor int64) {
    46  	switch in := input.(type) {
    47  	case []int32:
    48  		switch out := output.(type) {
    49  		case []int32:
    50  			multiplyConstantInt32Int32(in, out, factor)
    51  		case []int64:
    52  			multiplyConstantInt32Int64(in, out, factor)
    53  		}
    54  	case []int64:
    55  		switch out := output.(type) {
    56  		case []int32:
    57  			multiplyConstantInt64Int32(in, out, factor)
    58  		case []int64:
    59  			multiplyConstantInt64Int64(in, out, factor)
    60  		}
    61  	}
    62  }
    63  
    64  func divideConstant(input, output any, factor int64) {
    65  	switch in := input.(type) {
    66  	case []int32:
    67  		switch out := output.(type) {
    68  		case []int32:
    69  			divideConstantInt32Int32(in, out, factor)
    70  		case []int64:
    71  			divideConstantInt32Int64(in, out, factor)
    72  		}
    73  	case []int64:
    74  		switch out := output.(type) {
    75  		case []int32:
    76  			divideConstantInt64Int32(in, out, factor)
    77  		case []int64:
    78  			divideConstantInt64Int64(in, out, factor)
    79  		}
    80  	}
    81  }