ewalker544 / libsvm-go

Full port of LIBSVM in the Go programming language
Apache License 2.0
101 stars 29 forks source link

The library needs to be optimized for better performance. #11

Open EddieChan1993 opened 1 year ago

EddieChan1993 commented 1 year ago

library's performance can be optimized. Currently, its design of directly opening model or training set files leads to a significant time cost in the preparation stage, because typically, both types of files are large in size.

func (problem *Problem) Read(file string, param *Parameter) error { // reads the problem from the specified file
    f, err := os.Open(file)
    if err != nil {
        return fmt.Errorf("Fail to open file %s\n", file)
    }

func (model *Model) ReadModel(file string) error {
    f, err := os.Open(file)
    if err != nil {
        return fmt.Errorf("Fail to open file %s\n", file)
    }
EddieChan1993 commented 1 year ago

You can refer to the code example below from golinear

// Load a previously saved model.
func LoadModel(filename string) (*Model, error) {
    cFilename := C.CString(filename)
    defer C.free(unsafe.Pointer(cFilename))

    model := &Model{C.load_model_wrap(cFilename), nil, nil}

    if model.model == nil {
        return nil, errors.New("Cannot read model: " + filename)
    }

    runtime.SetFinalizer(model, finalizeModel)

    return model, nil
}