Skip to content
Closed
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ 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
go.starlark.net v0.0.0-20250701195324-d457b4515e0e
go.uber.org/automaxprocs v1.5.3
go.uber.org/ratelimit v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,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 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
13 changes: 6 additions & 7 deletions pkg/container/vector/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/bytejson"
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/vectorize/moarray"
"github.com/matrixorigin/matrixone/pkg/vectorize/shuffle"
)

Expand Down Expand Up @@ -4331,13 +4330,13 @@ func (v *Vector) InplaceSortAndCompact() {
case types.T_array_float32:
col, area := MustVarlenaRawData(v)
sort.Slice(col, func(i, j int) bool {
return moarray.Compare(
return slices.Compare(
types.GetArray[float32](&col[i], area),
types.GetArray[float32](&col[j], area),
) < 0
})
newCol := slices.CompactFunc(col, func(a, b types.Varlena) bool {
return moarray.Compare(
return slices.Compare(
types.GetArray[float32](&a, area),
types.GetArray[float32](&b, area),
) == 0
Expand All @@ -4350,13 +4349,13 @@ func (v *Vector) InplaceSortAndCompact() {
case types.T_array_float64:
col, area := MustVarlenaRawData(v)
sort.Slice(col, func(i, j int) bool {
return moarray.Compare(
return slices.Compare(
types.GetArray[float64](&col[i], area),
types.GetArray[float64](&col[j], area),
) < 0
})
newCol := slices.CompactFunc(col, func(a, b types.Varlena) bool {
return moarray.Compare(
return slices.Compare(
types.GetArray[float64](&a, area),
types.GetArray[float64](&b, area),
) == 0
Expand Down Expand Up @@ -4511,15 +4510,15 @@ func (v *Vector) InplaceSort() {
case types.T_array_float32:
col, area := MustVarlenaRawData(v)
sort.Slice(col, func(i, j int) bool {
return moarray.Compare[float32](
return slices.Compare(
types.GetArray[float32](&col[i], area),
types.GetArray[float32](&col[j], area),
) < 0
})
case types.T_array_float64:
col, area := MustVarlenaRawData(v)
sort.Slice(col, func(i, j int) bool {
return moarray.Compare[float64](
return slices.Compare(
types.GetArray[float64](&col[i], area),
types.GetArray[float64](&col[j], area),
) < 0
Expand Down
Loading
Loading