github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/mult/dec.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mult 16 17 /* 18 #include "mo.h" 19 20 #cgo CFLAGS: -I../../../cgo 21 #cgo LDFLAGS: -L../../../cgo -lmo -lm 22 */ 23 import "C" 24 import ( 25 "unsafe" 26 27 "github.com/matrixorigin/matrixone/pkg/common/moerr" 28 "github.com/matrixorigin/matrixone/pkg/container/nulls" 29 "github.com/matrixorigin/matrixone/pkg/container/types" 30 "github.com/matrixorigin/matrixone/pkg/container/vector" 31 ) 32 33 func dec64PtrToC(p *types.Decimal64) *C.int64_t { 34 return (*C.int64_t)(unsafe.Pointer(p)) 35 } 36 37 func dec128PtrToC(p *types.Decimal128) *C.int64_t { 38 return (*C.int64_t)(unsafe.Pointer(p)) 39 } 40 41 func Decimal64VecMult(xs, ys, rs *vector.Vector) error { 42 xt := vector.MustTCols[types.Decimal64](xs) 43 yt := vector.MustTCols[types.Decimal64](ys) 44 rt := vector.MustTCols[types.Decimal128](rs) 45 flag := 0 46 if xs.IsScalar() { 47 flag |= LEFT_IS_SCALAR 48 } 49 if ys.IsScalar() { 50 flag |= RIGHT_IS_SCALAR 51 } 52 53 rc := C.Decimal64_VecMul(dec128PtrToC(&rt[0]), dec64PtrToC(&xt[0]), dec64PtrToC(&yt[0]), 54 C.uint64_t(len(rt)), (*C.uint64_t)(nulls.Ptr(rs.Nsp)), C.int32_t(flag)) 55 if rc != 0 { 56 return moerr.NewOutOfRangeNoCtx("decimal64", "decimal MUL") 57 } 58 return nil 59 } 60 61 func Decimal128VecMult(xs, ys, rs *vector.Vector) error { 62 xt := vector.MustTCols[types.Decimal128](xs) 63 yt := vector.MustTCols[types.Decimal128](ys) 64 rt := vector.MustTCols[types.Decimal128](rs) 65 flag := 0 66 if xs.IsScalar() { 67 flag |= LEFT_IS_SCALAR 68 } 69 if ys.IsScalar() { 70 flag |= RIGHT_IS_SCALAR 71 } 72 73 //int32_t Decimal128_VecMul(int64_t *r, int64_t *a, int64_t *b, uint64_t n, uint64_t *nulls, int32_t flag); 74 rc := C.Decimal128_VecMul(dec128PtrToC(&rt[0]), dec128PtrToC(&xt[0]), dec128PtrToC(&yt[0]), 75 C.uint64_t(len(rt)), (*C.uint64_t)(nulls.Ptr(rs.Nsp)), C.int32_t(flag)) 76 if rc != 0 { 77 return moerr.NewOutOfRangeNoCtx("decimal128", "decimal MUL") 78 } 79 return nil 80 }