Skip to content
Merged
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
3 changes: 2 additions & 1 deletion base/copier/copier.go → common/copier/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ package copier

import (
"encoding"
"github.com/juju/errors"
"reflect"

"github.com/juju/errors"
)

func Copy(dst, src interface{}) error {
Expand Down
3 changes: 2 additions & 1 deletion base/copier/copier_test.go → common/copier/copier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package copier

import (
"testing"

"github.com/juju/errors"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
"testing"
)

func TestPrimitives(t *testing.T) {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion base/jsonutil/json_test.go → common/jsonutil/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package jsonutil

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestUnmarshal(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions common/parallel/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package parallel
import (
"sync"

"github.com/gorse-io/gorse/base"
"github.com/gorse-io/gorse/common/util"
"github.com/juju/errors"
"github.com/samber/lo"
"modernc.org/mathutil"
Expand Down Expand Up @@ -56,7 +56,7 @@ func Parallel(nJobs, nWorkers int, worker func(workerId, jobId int) error) error
// start workers
workerId := j
wg.Go(func() {
defer base.CheckPanic()
defer util.CheckPanic()
for {
// read job
jobId, ok := <-c
Expand Down
10 changes: 5 additions & 5 deletions common/parallel/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"time"

mapset "github.com/deckarep/golang-set/v2"
"github.com/gorse-io/gorse/base"
"github.com/gorse-io/gorse/common/util"
"github.com/stretchr/testify/assert"
)

func TestParallel(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
a := base.RangeInt(10000)
a := util.RangeInt(10000)
b := make([]int, len(a))
workerIds := make([]int, len(a))
// multiple threads
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestParallel(t *testing.T) {
func TestFor(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
// multiple threads
a := base.RangeInt(10000)
a := util.RangeInt(10000)
b := make([]int, len(a))
For(len(a), 4, func(jobId int) {
b[jobId] = a[jobId]
Expand All @@ -73,7 +73,7 @@ func TestFor(t *testing.T) {

func TestForEach(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
a := base.RangeInt(10000)
a := util.RangeInt(10000)
b := make([]int, len(a))
// multiple threads
ForEach(a, 4, func(i, v int) {
Expand All @@ -94,7 +94,7 @@ func TestForEach(t *testing.T) {

func TestBatchParallel(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
a := base.RangeInt(10000)
a := util.RangeInt(10000)
b := make([]int, len(a))
workerIds := make([]int, len(a))
// multiple threads
Expand Down
2 changes: 1 addition & 1 deletion base/random.go → common/util/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package base
package util

import (
"math/rand"
Expand Down
2 changes: 1 addition & 1 deletion base/random_test.go → common/util/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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 base
package util

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion base/util.go → common/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package base
package util

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion base/util_test.go → common/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package base
package util

import (
"testing"
Expand Down
7 changes: 3 additions & 4 deletions dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/chewxy/math32"
mapset "github.com/deckarep/golang-set/v2"
"github.com/gorse-io/gorse/base"
"github.com/gorse-io/gorse/common/util"
"github.com/gorse-io/gorse/model"
"github.com/gorse-io/gorse/storage/data"
Expand Down Expand Up @@ -65,7 +64,7 @@ type CTRSplit interface {
CountContextLabels() int
CountPositive() int
CountNegative() int
GetIndex() base.UnifiedIndex
GetIndex() UnifiedIndex
GetTarget(i int) float32
Get(i int) ([]int32, []float32, float32)
}
Expand Down Expand Up @@ -230,7 +229,7 @@ func (d *Dataset) AddFeedback(userId, itemId string) {

func (d *Dataset) SampleUserNegatives(excludeSet CFSplit, numCandidates int) [][]int32 {
if len(d.negatives) == 0 {
rng := base.NewRandomGenerator(0)
rng := util.NewRandomGenerator(0)
d.negatives = make([][]int32, d.CountUsers())
for userIndex := 0; userIndex < d.CountUsers(); userIndex++ {
s1 := mapset.NewSet(d.GetUserFeedback()[userIndex]...)
Expand All @@ -252,7 +251,7 @@ func (d *Dataset) SplitCF(numTestUsers int, seed int64) (CFSplit, CFSplit) {
trainSet.itemFeedback, testSet.itemFeedback = make([][]int32, d.CountItems()), make([][]int32, d.CountItems())
trainSet.userDict, testSet.userDict = d.userDict, d.userDict
trainSet.itemDict, testSet.itemDict = d.itemDict, d.itemDict
rng := base.NewRandomGenerator(seed)
rng := util.NewRandomGenerator(seed)
if numTestUsers >= d.CountUsers() || numTestUsers <= 0 {
for userIndex := int32(0); userIndex < int32(d.CountUsers()); userIndex++ {
if len(d.userFeedback[userIndex]) > 0 {
Expand Down
6 changes: 2 additions & 4 deletions dataset/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package dataset

import "github.com/gorse-io/gorse/base"

type FreqDict struct {
si map[string]int32
is []string
Expand Down Expand Up @@ -77,8 +75,8 @@ func (d *FreqDict) Freq(id int32) int32 {
return d.cnt[id]
}

func (d *FreqDict) ToIndex() *base.Index {
return &base.Index{
func (d *FreqDict) ToIndex() *Index {
return &Index{
Numbers: d.si,
Names: d.is,
}
Expand Down
2 changes: 1 addition & 1 deletion base/index.go → dataset/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package base
package dataset

import (
"encoding/binary"
Expand Down
2 changes: 1 addition & 1 deletion base/index_test.go → dataset/index_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package base
package dataset

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion base/unified_index.go → dataset/unified_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package base
package dataset

import (
"encoding/binary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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 base
package dataset

import (
"bytes"
Expand Down
3 changes: 1 addition & 2 deletions master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/coreos/go-oidc/v3/oidc"
"github.com/emicklei/go-restful/v3"
"github.com/gorse-io/gorse/base"
"github.com/gorse-io/gorse/common/log"
"github.com/gorse-io/gorse/common/monitor"
"github.com/gorse-io/gorse/common/parallel"
Expand Down Expand Up @@ -305,7 +304,7 @@ func (m *Master) Shutdown() {
}

func (m *Master) RunTasksLoop() {
defer base.CheckPanic()
defer util.CheckPanic()
var (
err error
//firstLoop = true
Expand Down
13 changes: 6 additions & 7 deletions master/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/go-viper/mapstructure/v2"
"github.com/gorilla/securecookie"
_ "github.com/gorse-io/dashboard"
"github.com/gorse-io/gorse/base"
"github.com/gorse-io/gorse/cmd/version"
"github.com/gorse-io/gorse/common/expression"
"github.com/gorse-io/gorse/common/log"
Expand Down Expand Up @@ -1039,7 +1038,7 @@ func (m *Master) importExportUsers(response http.ResponseWriter, request *http.R
return
}
// validate user id
if err = base.ValidateId(user.UserId); err != nil {
if err = util.ValidateId(user.UserId); err != nil {
server.BadRequest(restful.NewResponse(response),
fmt.Errorf("invalid user id `%v` at line %d (%s)", user.UserId, lineCount, err.Error()))
return
Expand Down Expand Up @@ -1131,14 +1130,14 @@ func (m *Master) importExportItems(response http.ResponseWriter, request *http.R
return
}
// validate item id
if err = base.ValidateId(item.ItemId); err != nil {
if err = util.ValidateId(item.ItemId); err != nil {
server.BadRequest(restful.NewResponse(response),
fmt.Errorf("invalid item id `%v` at line %d (%s)", item.ItemId, lineCount, err.Error()))
return
}
// validate categories
for _, category := range item.Categories {
if err = base.ValidateId(category); err != nil {
if err = util.ValidateId(category); err != nil {
server.BadRequest(restful.NewResponse(response),
fmt.Errorf("invalid category `%v` at line %d (%s)", category, lineCount, err.Error()))
return
Expand Down Expand Up @@ -1243,19 +1242,19 @@ func (m *Master) importExportFeedback(response http.ResponseWriter, request *htt
return
}
// validate feedback type
if err = base.ValidateId(feedback.FeedbackType); err != nil {
if err = util.ValidateId(feedback.FeedbackType); err != nil {
server.BadRequest(restful.NewResponse(response),
fmt.Errorf("invalid feedback type `%v` at line %d (%s)", feedback.FeedbackType, lineCount, err.Error()))
return
}
// validate user id
if err = base.ValidateId(feedback.UserId); err != nil {
if err = util.ValidateId(feedback.UserId); err != nil {
server.BadRequest(restful.NewResponse(response),
fmt.Errorf("invalid user id `%v` at line %d (%s)", feedback.UserId, lineCount, err.Error()))
return
}
// validate item id
if err = base.ValidateId(feedback.ItemId); err != nil {
if err = util.ValidateId(feedback.ItemId); err != nil {
server.BadRequest(restful.NewResponse(response),
fmt.Errorf("invalid item id `%v` at line %d (%s)", feedback.ItemId, lineCount, err.Error()))
return
Expand Down
7 changes: 3 additions & 4 deletions master/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"github.com/gorse-io/gorse/base"
"github.com/gorse-io/gorse/common/monitor"
"github.com/gorse-io/gorse/common/util"
"github.com/gorse-io/gorse/config"
Expand All @@ -48,10 +47,10 @@ func newRankingDataset() (*dataset.Dataset, *dataset.Dataset) {
}

func newClickDataset() (*ctr.Dataset, *ctr.Dataset) {
dataset := &ctr.Dataset{
Index: base.NewUnifiedMapIndexBuilder().Build(),
dataSet := &ctr.Dataset{
Index: dataset.NewUnifiedMapIndexBuilder().Build(),
}
return dataset, dataset
return dataSet, dataSet
}

type mockMasterRPC struct {
Expand Down
Loading