Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Bozart
Oct 28, 2006

Give me the finger.
I've got to say that I'm really loving this language. It is simple enough to follow easily (particularly coming from Scala) and the std lib is just a fantastic learning tool.

Adbot
ADBOT LOVES YOU

Bozart
Oct 28, 2006

Give me the finger.
I am starting to suspect that the real reason they chose the name "go" was because it would allow an infinite number of puns :tinfoil:

Bozart
Oct 28, 2006

Give me the finger.
So, I wrote up a function which takes a channel, and returns a new interface which can replay the values in the original channel, and only pulls values from the original channel lazily. Maybe some of you have some suggestions / criticisms of it? I wrote it after some guy on the go-nuts irc channel said it wasn't possible, gently caress that guy. :argh:

http://play.golang.org/p/Ou4HbvKIay

actually, this is so much better:

http://play.golang.org/p/H4awi7EmSY

Bozart fucked around with this message at 05:52 on May 13, 2014

Bozart
Oct 28, 2006

Give me the finger.
Does anyone feel up to giving me some feedback on an ORM I am putting together? The core of it is done, I just want to know what people think of its interface & docs. However, I don't want it public yet so I'll have to give you access to my github repo. If you're interested then either pm me or post here.

Bozart
Oct 28, 2006

Give me the finger.

pram posted:

Is it actually relational? Theres already like 10 'ORM's and the only one I've seen with actual relational stuff is Beego

You bet. It is actually, really, really relational, in the sense that there are no nulls, all relations are distinct, and I don't implement an ordering.

Here's an example from the readme. This works.

Edit: either pm me or post your github account if you feel up to giving me some advice.

pre:
// Here's an example of sparse matrix multiplication using rel (relational meets linear):
type matrixElem struct {
	R int
	C int
	V float64
}
type multElemA struct {
	R  int
	M  int
	VA float64
}
type multElemB struct {
	M  int
	C  int
	VB float64
}
type multElemC struct {
	R  int
	C  int
	M  int
	VA float64
	VB float64
}
type groupTup struct {
	VA float64
	VB float64
}
type valTup struct {
	V float64
}
groupAdd := func(val <-chan groupTup) valTup {
	res := valTup{}
	for vi := range val {
		res.V += vi.VA * vi.VB
	}
	return res
}

// representation of a matrix:
//  1 2
//  3 4
A := New([]matrixElem{
	{1, 1, 1.0},
	{1, 2, 2.0},
	{2, 1, 3.0},
	{2, 2, 4.0},
}, [][]string{[]string{"R", "C"}})

// representation of a matrix:
//  4 17
//  9 17
B := New([]matrixElem{
	{1, 1, 4.0},
	{1, 2, 17.0},
	{2, 1, 9.0},
	{2, 2, 17.0},
}, [][]string{[]string{"R", "C"}})

C := A.Rename(multElemA{}).Join(B.Rename(multElemB{}), multElemC{}).
	GroupBy(matrixElem{}, groupAdd)
	
fmt.Println("\n%#v",C)

// Output: (might be in any order)
// rel.New([]struct {
//  R int     
//  C int     
//  V float64 
// }{
//  {1, 1, 22,  },
//  {1, 2, 51,  },
//  {2, 1, 48,  },
//  {2, 2, 119, },
// })

Bozart
Oct 28, 2006

Give me the finger.

Dommer416 posted:

I'll have to play with this! I look forward to it. Too bad I'm half asleep.

Alrighty, it's public at https://github.com/jonlawlor/rel

Bozart
Oct 28, 2006

Give me the finger.
Thanks for actually looking at the package! The single value allocation thing is a little ugly and I'll try incorporating your suggestion. I was planning on using sync.Pool to help with the amount of literal allocation that takes place, but the community's opinion of it seems mixed.

I really haven't gotten much feedback on the rel package because people take a look at its size, and the fact that it uses a ton of reflection, and run away as fast as they can.

For now I'm putting that project on the back burner while I implement the relational operations in idiomatic go. There is something really interesting about connecting relational algebra with Go's pipeline mechanisms, so I'm going to :ohdear: start a blog to walk people through them as gently as I can, which means no reflection, and no query rewrite. By now I've rewritten them all a few times, so it isn't too hard, and I'm still figuring out what's good and bad in different situations. For example, ordered relational operations are at a huge advantage because you can make assumptions about what tuples will be sent to each pipeline stage, while the rel package doesn't assume any ordering exists (it doesn't even define a sort function!) so I basically use hash-joins and hash-groups for everything.

Bozart
Oct 28, 2006

Give me the finger.

Azazel posted:

There is a reason people use empty structs, they are zero sized.

That isn't what he's talking about though. The rel.Relation interface has methods which take an example tuple into an interface{} so that it can reflect on it to determine how to construct result tuples. He's saying I should have callers construct a nil pointer of the appropriate type instead to avoid the overhead.

Bozart
Oct 28, 2006

Give me the finger.
So I have the first post ready in a new blog: http://jonlawlor.github.io/2014/07/18/distinct/ :sigh:

Do you guys have any feedback? Otherwise I guess I'll be posting it on reddit tomorrow.

Bozart
Oct 28, 2006

Give me the finger.
Also, for game dev you might want to wait for Go 1.5 which will have GC improvements.

Bozart
Oct 28, 2006

Give me the finger.
Jsor, as a followup, how are you supposed to get gonum running?

Going off of the readme at https://github.com/gonum/lapack didn't help. I'm running osx mav, installed gfortran:

code:
gfortran --version
GNU Fortran (GCC) 4.9.0
Ran the OpenBLAS make (which succeeded), ran go get on all of the gonum packages, ran the lapack bindings, then tried to run the code provided (with gonum in place of dane-unltd throughout).

No error messages, ran

code:
package main

import (
    "fmt"

    "github.com/gonum/blas/cblas"
    "github.com/gonum/blas/dbw"
    "github.com/gonum/lapack/clapack"
    "github.com/gonum/lapack/dla"
    // "github.com/gonum/" // commented out because it has no code
)

func init() {
    dbw.Register(cblas.Blas{})
    dla.Register(clapack.Lapack{})
}

func main() {
    A := dbw.NewGeneral(3, 2, []float64{1, 2, 3, 4, 5, 6})
    B := dbw.NewGeneral(3, 2, []float64{1, 2, 1, 2, 1, 2})

    tau := dbw.Allocate(2)

    f := dla.QR(A, tau)

    f.Solve(B)

    fmt.Println(B.Data)
}
And I just get an error:
test.go:18: undefined: clapack.Lapack

after about a zillion warnings in clapack:
../../gonum/lapack/clapack/lapack.go:21582:3: warning: plain '_Complex' requires a type specifier; assuming '_Complex double'
/usr/include/complex.h:37:17: note: expanded from macro 'complex'

So at this point I don't know what to do. Does gonum have some kind of installation guide that I'm missing?

Bozart
Oct 28, 2006

Give me the finger.

Scaevolus posted:

As much as I like Go, Julia is looking more promising for scientific workloads. Go's developers want a language to write networked services, so things like maximal performance (including FFI), good matrix support, and operator overloading aren't particularly high on their list of improvements.

http://www.evanmiller.org/why-im-betting-on-julia.html

I think it really depends on the particular application. I don't think most matlab code (or probably julia code) deals with matrix algebra - most of it is the plain old programming that everyone does.

I'm particularly excited about time series in matlab. I was going to take gonum for a test drive by implementing recursive lease squares estimation and/or a kalman filter, but first I'll have to figure out how to get it running. I will have to read up a little on julia to see what a comparable version there would look like.

Bozart
Oct 28, 2006

Give me the finger.
Does Docker alleviate some of that problem? I've never used it in a professional environment.

Bozart
Oct 28, 2006

Give me the finger.

SavageMessiah posted:

Docker is a containerization tool for linux, how on earth would it help with this problem?

It works in more environments than just linux. You could add 3rd party packages to the docker image, and then use that image for dev work. Then all of the devs are using the same version of each of the packages, which may alleviate the problem he described of multiple devs coordinating multiple packages. The downside may be as Look Around You mentioned being "frowned upon" but I don't know one way or the other, because as I said, I haven't used it professionally.

Also, they aren't urls in the imports, they are file paths relative to $GOROOT. They are only interpreted as urls by the go tool.

Bozart
Oct 28, 2006

Give me the finger.

Pham Nuwen posted:

This sounds like the equivalent of distributing a full Python installation with your program because of Python's version hell. (This is a thing people actually do)

To distribute it you would just distribute the compiled binary?

Bozart
Oct 28, 2006

Give me the finger.
Uh, aren't you supposed to say it is simple, lightweight, or minimalist?

edit:

More seriously, I don't know enough about the domain to give advice in that regard, but you could run golint, which would pick up:
code:
	for n := 1; true; n++ { ... }
can just be
code:
	for n := 1;; n++ { ... }
It is also a bit odd to me how the sockAccept function has to handle some of the wait group and then some of it is handled in connHandler, and some of it in sockWatchDog, and some in New. I would be quite worried that it could have edge cases where after calling quit, it either hangs or can try to send to a closed channel. There's got to be a way to consolidate.

Bozart fucked around with this message at 05:27 on Dec 30, 2014

Bozart
Oct 28, 2006

Give me the finger.
One thing you might want to do is get rid of lines sending on the q channel. Receives on a closed channel always succeed (with the zero value, but you're not using it...) so you could make q a chan struct{}, and then

code:
func (a *Adminsock) Quit() {
	close(a.q)
	a.w.Wait()
	close(a.Msgr)
}
Which has the advantage of quitting everything "at once" and taking up one less byte!.

The way I would change the code structure is to take the common parameters out sockAccept and connHandler, and put them into the Adminsock type. Then sockAccept would just be (*a Adminsock) sockAccept(), and connHandler would just be (*a Adminsock) connHandler(c net.Conn). It should also be possible to split out the wait group handling into a function like
code:
   (*a Adminsock) execute(c connHandler) { 
      a.Add(1)
      go func() {
          defer a.Done()
          a.connHandler(c)
      }()
   }
Also, instead of a wait group, it is possible to use just channels, although I am not sure if it would be faster. What you would do is have each iteration in sockAccept create a "done" channel, which is passed into the handler. When the handler finishes the done channel is closed. These done channels are sent into a channel of channels to an equivalent sockWatchdog, which waits to be told that the sockAccept function is no longer accepting, checks that all the done channels are closed, and then sends an all clear to quit.

As I said, I'm not sure that would be faster (although it might be under heavy load, because I believe there is less synchronization done when closing channels and blocking on them), but it is another approach, and it feels a bit more "go-like" to me. Do whatever works for you though.

Bozart
Oct 28, 2006

Give me the finger.
thats a good question to be honest

Bozart
Oct 28, 2006

Give me the finger.
can we stop with the dumb language wars and get back to dumb programs Sheesh

Bozart
Oct 28, 2006

Give me the finger.

sarehu posted:

Here is what annoyed me about Go's type system yesterday. I had several types of slice, and for each of them, I wanted to find the index of the element that matched a given player. In other languages I could just write func[T] lookup(elems []T, f func(T)bool) (index int, found bool) { ... }, or actually it would be a utility written for me, but instead I had to rewrite the same for loop several times. And the same again when I wanted to make a new slice with the matched element removed. I guess it doesn't matter though because Go is made by titans in their field, just like Git, a perfect version control system that is also above criticism.

Just curious, why isn't a map appropriate in this case?

Bozart
Oct 28, 2006

Give me the finger.

Khorne posted:

In case anyone runs into this issue, the 1.4.2 msi installer is broken. Use the archive to install instead.

I just used it yesterday, no problem.

Bozart
Oct 28, 2006

Give me the finger.

COOL CORN posted:

Go is confusing to me. I just got a coupon code for a Udemy course about it, and it seems super great from the outset, and a lot of companies are using it. But... only 5 pages here, and most of it is complaining about the language. Did it just never get any traction? Is it dying out?

Just not much activity in this thread to be honest. The reddit group has been growing in quality (particularly since the devs started doing AMAs) and it is on YC a lot.

Go is really good at some stuff - especially deployment!!! - pretty good at most stuff, and meh at some stuff. If you're looking for language feature xxx in it, you'll be one of the people hating on it. I absolutely love how readable random github repos in go are. I love the tooling. I'm at the point where it is my go to language, unless the task is an extremely poor fit.

Bozart
Oct 28, 2006

Give me the finger.
There is also an atom plugin.

Bozart
Oct 28, 2006

Give me the finger.

Mr. Crow posted:

How are the analytics libraries for go these days? Anything similar to pandas in Python?

Nothing like pandas really. The type system really fights against data frames. I implemented something like it using the reflect package but it was quite a mess and I would never use it for actual work.

Bozart
Oct 28, 2006

Give me the finger.

so loving future posted:

Yeah, pretty good example of thing that is probably awful in golang. Stick to pandas :/

To be fair pandas is pretty bad, but in golang it is only barely possible to do so it is even worse.

Bozart
Oct 28, 2006

Give me the finger.

Coffee Mugshot posted:

Go would love to have a good debugger, but it turns out debugging is hard. I think people take my favorite program, gdb, for granted.

That is what I put in the go user survey as something go could use. (Also I put multi-dimensional arrays but hey, that poo poo ain't coming anytime soon)

Adbot
ADBOT LOVES YOU

Bozart
Oct 28, 2006

Give me the finger.

bonds0097 posted:

What do you mean by multi-dimensional arrays? You can do slices of slices to arbitrary depth, right?

If you want to bounds check every single sub-slice, and not be able to rely on matrices being rectangular, sure.

e: there is a related benefit to having matrices laid out in memory in a specific way

Bozart fucked around with this message at 03:40 on Dec 15, 2016

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply