Git Product home page Git Product logo

Comments (5)

cdipaolo avatar cdipaolo commented on August 16, 2024

This sounds like a good idea. I'm pretty stacked with work today but should be able to prototype something with the io.Writer tomorrow I think. I'll let you know.

from goml.

cdipaolo avatar cdipaolo commented on August 16, 2024

I'm likely going to add an io.Writer field to the model structs and just change the fmt.Printf calls to fmt.Fprintf, which (as seen below from the fmt package code) is equivalent if you set your writer to os.Stdout, so I'll default to that so there are no breaking changes. If you have any comments let me know.

I wouldn't want to remove the printing completely in case someone was relying on that feature for anything in an application. Similarly I think that the output is potentially nice if you're debugging something.

from https://golang.org/src/fmt/print.go

   184  // Fprintf formats according to a format specifier and writes to w.
   185  // It returns the number of bytes written and any write error encountered.
   186  func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
   187      p := newPrinter()
   188      p.doPrintf(format, a)
   189      n, err = w.Write(p.buf)
   190      p.free()
   191      return
   192  }
   193  
   194  // Printf formats according to a format specifier and writes to standard output.
   195  // It returns the number of bytes written and any write error encountered.
   196  func Printf(format string, a ...interface{}) (n int, err error) {
   197      return Fprintf(os.Stdout, format, a...)
   198  }

from goml.

mitchellh avatar mitchellh commented on August 16, 2024

That sounds perfect. Thanks!

from goml.

cdipaolo avatar cdipaolo commented on August 16, 2024

Tests Before Changes

➜  goml git:(master) go test ./...
ok      github.com/cdipaolo/goml/base   0.252s
ok      github.com/cdipaolo/goml/cluster    14.893s
ok      github.com/cdipaolo/goml/linear 46.546s
ok      github.com/cdipaolo/goml/perceptron 9.365s
ok      github.com/cdipaolo/goml/text   0.009s

Tests After Changes

➜  goml git:(logging) go test ./...
ok      github.com/cdipaolo/goml/base   0.287s
ok      github.com/cdipaolo/goml/cluster    11.707s
ok      github.com/cdipaolo/goml/linear 38.457s
ok      github.com/cdipaolo/goml/perceptron 9.029s
ok      github.com/cdipaolo/goml/text   0.006s

The speedup is a little surprising because I basically just removed one or two function calls per test. I suspect that printing to dev/null (with ioutil.Discard) might speed up tests a lot.

All models that did print to log not have an

        // Output is the io.Writer used for logging
        // and printing. Defaults to os.Stdout.
        Output io.Writer

struct field as a public variable that can be changed by the user. All calls to fmt.Printf were switched to fmt.Fprintf.

from goml.

cdipaolo avatar cdipaolo commented on August 16, 2024

If you have any other comments let me know and I can reopen this.

from goml.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.