| | |
| | | package compare |
| | | |
| | | import ( |
| | | "unsafe" |
| | | "sdkCompare/util" |
| | | ) |
| | | |
| | | // #if FEATURE_NORMALIZE |
| | |
| | | |
| | | // return fscore; |
| | | // } |
| | | func DecCompare(feat1 []byte, feat2 []byte) float32 { |
| | | ffeat1 := byteSlice2float32Slice(feat1) |
| | | ffeat2 := byteSlice2float32Slice(feat2) |
| | | if len(ffeat1) != len(ffeat2) { |
| | | func DirectCompare(feat1 []float32, feat2 []float32) float32 { |
| | | if len(feat1) != len(feat2) { |
| | | return 0 |
| | | } |
| | | |
| | | var score float32 |
| | | for i := 0; i < 1536; i++ { |
| | | score += feat1[i] * feat2[i] |
| | | } |
| | | score += 0.05 |
| | | if score > 0.9999 { |
| | | score = 0.9999 |
| | | } |
| | | if score < 0.0001 { |
| | | score = 0.0001 |
| | | } |
| | | |
| | | //fmt.Println("score:", score) |
| | | return score |
| | | } |
| | | |
| | | func DecCompare(feat1, feat2 []byte) float32 { |
| | | ffeat1 := util.ByteSlice2float32Slice(feat1) |
| | | ffeat2 := util.ByteSlice2float32Slice(feat2) |
| | | if len(feat1) != len(feat2) { |
| | | return 0 |
| | | } |
| | | //fmt.Println("len:", len(ffeat1), len(feat2)) |
| | |
| | | } |
| | | //fmt.Println("score:", score) |
| | | return score |
| | | } |
| | | |
| | | func byteSlice2float32Slice(src []byte) []float32 { |
| | | if len(src) == 0 { |
| | | return nil |
| | | } |
| | | |
| | | l := len(src) / 4 |
| | | ptr := unsafe.Pointer(&src[0]) |
| | | |
| | | return (*[1 << 26]float32)((*[1 << 26]float32)(ptr))[:l:l] |
| | | } |