Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
[minor] add radius argument to StrictSearch function for user custom …
Browse files Browse the repository at this point in the history
…radius search (#10)
  • Loading branch information
Yusuke Kato authored Mar 29, 2019
1 parent e34345d commit add7bd9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ alias:
GOPATH: "/go"
GO111MODULE: "on"
LD_LIBRARY_PATH: /usr/local/lib
NGT_VERSION: 1.6.1
NGT_VERSION: 1.7.0
REPO_NAME: "yahoojapan"
IMAGE_NAME: "gongt"
GITHUB_API: "https://api.github.com/"
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/yahoojapan/gongt

go 1.12

require (
github.com/kpango/glg v1.2.7
gonum.org/v1/hdf5 v0.0.0-20180702054324-c257073619f4
github.com/kpango/glg v1.3.0
gonum.org/v1/hdf5 v0.0.0-20190227001252-83207889d689
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/kpango/fastime v1.0.0 h1:tZeI+eEyHHYKkTkKOiOZ5MeeRJmliuZlGV7aK7S2rkE=
github.com/kpango/fastime v1.0.0/go.mod h1:Y5XY5bLG5yc7g2XmMUzc22XYV1XaH+KgUOHkDvLp4SA=
github.com/kpango/glg v1.2.7 h1:aVnv89IIWXSFNOm93SnDQGIKF27Jzz9olieOL2b23Xc=
github.com/kpango/glg v1.2.7/go.mod h1:sEwy6Va116x0eKdbVsilHPanIrsoE9AR/9vHwdo4ytQ=
gonum.org/v1/hdf5 v0.0.0-20180702054324-c257073619f4 h1:3GnLlVt6JOlXwffishXEToqGjH7hx/G8UK7RP7HTqX0=
gonum.org/v1/hdf5 v0.0.0-20180702054324-c257073619f4/go.mod h1:g+PDU5ogjIKcc3Cg4ALAK7X4c8bBQvPzPKWNW5NB7I0=
github.com/kpango/fastime v1.0.8 h1:Wif5eocdsIXmMG+8HHfRP/jD6UUl+/OVTJ+sMzvA1+E=
github.com/kpango/fastime v1.0.8/go.mod h1:Y5XY5bLG5yc7g2XmMUzc22XYV1XaH+KgUOHkDvLp4SA=
github.com/kpango/glg v1.3.0 h1:77BWdR0kKkFloM2eSAr0A7lWvUyAIlOhj4LV5n2hrB8=
github.com/kpango/glg v1.3.0/go.mod h1:7zzaAoMqvngad+sagWLjr00EQMJaqyGONdg0WYBAO3M=
gonum.org/v1/hdf5 v0.0.0-20190227001252-83207889d689 h1:kkaDDDkZcDezmnomcLvU906I4tjWroioOqEzkFIg/T8=
gonum.org/v1/hdf5 v0.0.0-20190227001252-83207889d689/go.mod h1:g+PDU5ogjIKcc3Cg4ALAK7X4c8bBQvPzPKWNW5NB7I0=
10 changes: 5 additions & 5 deletions gongt.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@ func (n *NGT) Open() *NGT {
}

// StrictSearch is C type stricted search function
func StrictSearch(vec []float64, size int, epsilon float32) ([]StrictSearchResult, error) {
return ngt.StrictSearch(vec, size, epsilon)
func StrictSearch(vec []float64, size int, epsilon, radius float32) ([]StrictSearchResult, error) {
return ngt.StrictSearch(vec, size, epsilon, radius)
}

// StrictSearch is C type stricted search function
func (n *NGT) StrictSearch(vec []float64, size int, epsilon float32) ([]StrictSearchResult, error) {
func (n *NGT) StrictSearch(vec []float64, size int, epsilon, radius float32) ([]StrictSearchResult, error) {
ebuf := C.ngt_create_error_object()
defer C.ngt_destroy_error_object(ebuf)

Expand All @@ -461,7 +461,7 @@ func (n *NGT) StrictSearch(vec []float64, size int, epsilon float32) ([]StrictSe
}

n.mu.RLock()
ret := C.ngt_search_index(n.index, (*C.double)(&vec[0]), C.int32_t(n.prop.Dimension), C.size_t(size), C.float(epsilon), results, ebuf)
ret := C.ngt_search_index(n.index, (*C.double)(&vec[0]), C.int32_t(n.prop.Dimension), C.size_t(size), C.float(epsilon), C.float(radius), results, ebuf)
n.mu.RUnlock()
if ret == ErrorCode {
return nil, newGoError(ebuf)
Expand Down Expand Up @@ -490,7 +490,7 @@ func Search(vec []float64, size int, epsilon float64) ([]SearchResult, error) {

// Search returns search result as []SearchResult
func (n *NGT) Search(vec []float64, size int, epsilon float64) ([]SearchResult, error) {
res, err := n.StrictSearch(vec, size, float32(epsilon))
res, err := n.StrictSearch(vec, size, float32(epsilon), -1.0)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions gongt_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ func ExampleNGT_Open() {
func ExampleStrictSearch() {
// Strict Vector Search
vector := []float64{1, 0, 0, 0, 0, 0}
res, err := gongt.StrictSearch(vector, 1, gongt.DefaultEpsilon)
res, err := gongt.StrictSearch(vector, 1, gongt.DefaultEpsilon, 1.1)
// Output:
_, _ = res, err
}

func ExampleNGT_StrictSearch() {
// Strict Vector Search
vector := []float64{1, 0, 0, 0, 0, 0}
res, err := gongt.Get().StrictSearch(vector, 1, gongt.DefaultEpsilon)
res, err := gongt.Get().StrictSearch(vector, 1, gongt.DefaultEpsilon, 0.9)
// Output:
//
_, _ = res, err
Expand Down
2 changes: 1 addition & 1 deletion gongt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestStrictSearch(t *testing.T) {
t.Errorf("Unexpected error: TestStrictSearch(%v)", errs)
}
for _, tt := range tests {
result, err := ngt.StrictSearch(tt.vector, 1, DefaultEpsilon)
result, err := ngt.StrictSearch(tt.vector, 1, DefaultEpsilon, -1.0)
if err != nil {
t.Errorf("Unexpected error: TestSearch(%v)", err)
}
Expand Down

0 comments on commit add7bd9

Please sign in to comment.