Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ require (
github.com/tidwall/btree v1.7.0
github.com/tidwall/pretty v1.2.1
github.com/tmc/langchaingo v0.1.13
github.com/unum-cloud/usearch/golang v0.0.0-20251010193336-541e882da5a9
github.com/unum-cloud/usearch/golang v0.0.0-20251130095425-a2f175991017
github.com/viterin/vek v0.4.3
go.starlark.net v0.0.0-20250701195324-d457b4515e0e
go.uber.org/automaxprocs v1.5.3
go.uber.org/ratelimit v0.2.0
Expand Down Expand Up @@ -133,6 +134,7 @@ require (
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/chewxy/math32 v1.10.1 // indirect
github.com/cilium/ebpf v0.9.1 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
Expand Down Expand Up @@ -216,6 +218,7 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
github.com/viterin/partial v1.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chewxy/math32 v1.10.1 h1:LFpeY0SLJXeaiej/eIp2L40VYfscTvKh/FSEZ68uMkU=
github.com/chewxy/math32 v1.10.1/go.mod h1:dOB2rcuFrCn6UHrze36WSLVPKtzPMRAQvBvUwkSsLqs=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
Expand Down Expand Up @@ -847,8 +849,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/unum-cloud/usearch/golang v0.0.0-20251010193336-541e882da5a9 h1:JrHCee+uqpF2zXooiKu7ymvKgnzlUIXtTlZ7vi21Tr0=
github.com/unum-cloud/usearch/golang v0.0.0-20251010193336-541e882da5a9/go.mod h1:NxBpQibuBBeA/V8RGbrNzVAv4OyWWL5yNao7mVz656k=
github.com/unum-cloud/usearch/golang v0.0.0-20251130095425-a2f175991017 h1:HoupsZEQjg+s7Dip8iTeCa87OcDGrGda/xOleoNXm4A=
github.com/unum-cloud/usearch/golang v0.0.0-20251130095425-a2f175991017/go.mod h1:NxBpQibuBBeA/V8RGbrNzVAv4OyWWL5yNao7mVz656k=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
Expand All @@ -861,6 +863,10 @@ github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tz
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/viterin/partial v1.1.0 h1:iH1l1xqBlapXsYzADS1dcbizg3iQUKTU1rbwkHv/80E=
github.com/viterin/partial v1.1.0/go.mod h1:oKGAo7/wylWkJTLrWX8n+f4aDPtQMQ6VG4dd2qur5QA=
github.com/viterin/vek v0.4.3 h1:cogdlNjd6EJYtNbmTN0lJCey2htrfSo1AHWpc6DVncQ=
github.com/viterin/vek v0.4.3/go.mod h1:A4JRAe8OvbhdzBL5ofzjBS0J29FyUrf95tQogvtHHUc=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
56 changes: 56 additions & 0 deletions pkg/common/assertx/float32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2023 Matrix Origin
//
// Licensed 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.

package assertx

import (
"math"
)

const float32EqualityThreshold = 1e-5

// InEpsilonF32Slices returns true if all the elements in v1 and v2 are within epsilon of each other.
func InEpsilonF32Slices(want, got [][]float32) bool {
if len(want) != len(got) {
return false
}

for i := range want {
if !InEpsilonF32Slice(want[i], got[i]) {
return false
}
}
return true
}

// InEpsilonF32Slice returns true if all the elements in v1 and v2 are within epsilon of each other.
// assert.InEpsilonSlice requires v1 to be non-zero.
func InEpsilonF32Slice(want, got []float32) bool {
if len(want) != len(got) {
return false
}

for i := range want {
if !InEpsilonF32(want[i], got[i]) {
return false
}
}
return true
}

// InEpsilonF32 returns true if v1 and v2 are within epsilon of each other.
// assert.InEpsilon requires v1 to be non-zero.
func InEpsilonF32(want, got float32) bool {
return want == got || math.Abs(float64(want)-float64(got)) < float32EqualityThreshold || (math.IsNaN(float64(want)) && math.IsNaN(float64(got)))
}
158 changes: 158 additions & 0 deletions pkg/common/assertx/float32_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright 2023 Matrix Origin
//
// Licensed 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.

package assertx

import "testing"

func TestInEpsilonF32(t *testing.T) {
type args struct {
want float32
got float32
}
tests := []struct {
name string
args args
want bool
}{

{
name: "Test 1 - difference is epsilon",
args: args{
want: 1.0,
got: 1.0 + float32EqualityThreshold,
},
want: false,
},
{
name: "Test 2.a - difference is less than epsilon",
args: args{
want: 2.0,
got: 2.0 + 0.5*float32EqualityThreshold,
},
want: true,
},
{
name: "Test 2.b - difference is more than epsilon",
args: args{
want: 2.0,
got: 2.0 + 2*float32EqualityThreshold,
},
want: false,
},
{
name: "Test 2.c - difference is -ve of epsilon",
args: args{
want: 2.0,
got: 2.0 - float32EqualityThreshold,
},
want: false,
},
{
name: "Test 3 - till 9th digit is same, 10th digit is different",
args: args{
want: 1.732050800_0,
got: 1.732050800_9,
},
want: true,
},
{
name: "Test 4 - 5th digit is different",
args: args{
want: 1.7320_0,
got: 1.7320_9,
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := InEpsilonF32(tt.args.want, tt.args.got); got != tt.want {
t.Errorf("%s InEpsilonF32() = %v, want %v", tt.name, got, tt.want)
}
})
}
}

func TestInEpsilonF32Slice(t *testing.T) {
type args struct {
want []float32
got []float32
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Test 1 - difference is epsilon",
args: args{
want: []float32{2.0, 3.0},
got: []float32{2.0 + float32EqualityThreshold, 3.0 + float32EqualityThreshold},
},
want: false,
},
{
name: "Test 2 - 6th digit is different",
args: args{
want: []float32{1.7320_0},
got: []float32{1.7320_1},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := InEpsilonF32Slice(tt.args.want, tt.args.got); got != tt.want {
t.Errorf("InEpsilonF32Slice() = %v, want %v", got, tt.want)
}
})
}
}

func TestInEpsilonF32Slices(t *testing.T) {
type args struct {
want [][]float32
got [][]float32
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Test 1 - difference is epsilon",
args: args{
want: [][]float32{{1.0, 3.0}, {4.0}},
got: [][]float32{{1.0 + float32EqualityThreshold, 3.0 + float32EqualityThreshold}, {4.0}},
},
want: false,
},
{
name: "Test 2 - difference is less than epsilon (next neg-power of epsilon & epsilon/2)",
args: args{
want: [][]float32{{2.0, 3.0}, {4.0}},
got: [][]float32{{2.0 + 1e-1*float32EqualityThreshold, 3.0 + float32EqualityThreshold/2}, {4.0}},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := InEpsilonF32Slices(tt.args.want, tt.args.got); got != tt.want {
t.Errorf("InEpsilonF32Slices() = %v, want %v", got, tt.want)
}
})
}
}
4 changes: 2 additions & 2 deletions pkg/common/assertx/float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func InEpsilonF64Slices(want, got [][]float64) bool {
return false
}

for i := 0; i < len(want); i++ {
for i := range want {
if !InEpsilonF64Slice(want[i], got[i]) {
return false
}
Expand All @@ -51,7 +51,7 @@ func InEpsilonF64Slice(want, got []float64) bool {
return false
}

for i := 0; i < len(want); i++ {
for i := range want {
if !InEpsilonF64(want[i], got[i]) {
return false
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/compare/arraycompare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package compare

import (
"slices"

"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/vectorize/moarray"
"github.com/matrixorigin/matrixone/pkg/vm/process"
)

Expand Down Expand Up @@ -72,7 +73,7 @@ func CompareArrayFromBytes[T types.RealNumbers](_x, _y []byte, desc bool) int {
y := types.BytesToArray[T](_y)

if desc {
return moarray.Compare[T](y, x)
return slices.Compare(y, x)
}
return moarray.Compare[T](x, y)
return slices.Compare(x, y)
}
10 changes: 5 additions & 5 deletions pkg/container/vector/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package vector

import (
"bytes"
"slices"

"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/vectorize/moarray"
)

// FindFirstIndexInSortedSlice finds the first index of v in a sorted slice s
Expand Down Expand Up @@ -308,10 +308,10 @@ func ArrayGetMinMax[T types.RealNumbers](vec *Vector) (minv, maxv []T) {
minv, maxv = val, val
first = false
} else {
if moarray.Compare[T](minv, val) > 0 {
if slices.Compare(minv, val) > 0 {
minv = val
}
if moarray.Compare[T](maxv, val) < 0 {
if slices.Compare(maxv, val) < 0 {
maxv = val
}
}
Expand All @@ -321,10 +321,10 @@ func ArrayGetMinMax[T types.RealNumbers](vec *Vector) (minv, maxv []T) {
minv, maxv = val, val
for i, j := 1, vec.Length(); i < j; i++ {
val := types.GetArray[T](&col[i], area)
if moarray.Compare[T](minv, val) > 0 {
if slices.Compare(minv, val) > 0 {
minv = val
}
if moarray.Compare[T](maxv, val) < 0 {
if slices.Compare(maxv, val) < 0 {
maxv = val
}
}
Expand Down
Loading
Loading