id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
127,400
dinever/golf
context.go
Redirect
func (ctx *Context) Redirect(url string) { ctx.SetHeader("Location", url) ctx.SendStatus(302) }
go
func (ctx *Context) Redirect(url string) { ctx.SetHeader("Location", url) ctx.SendStatus(302) }
[ "func", "(", "ctx", "*", "Context", ")", "Redirect", "(", "url", "string", ")", "{", "ctx", ".", "SetHeader", "(", "\"", "\"", ",", "url", ")", "\n", "ctx", ".", "SendStatus", "(", "302", ")", "\n", "}" ]
// Redirect method sets the response as a 302 redirection.
[ "Redirect", "method", "sets", "the", "response", "as", "a", "302", "redirection", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L130-L133
127,401
dinever/golf
context.go
Redirect301
func (ctx *Context) Redirect301(url string) { ctx.SetHeader("Location", url) ctx.SendStatus(301) }
go
func (ctx *Context) Redirect301(url string) { ctx.SetHeader("Location", url) ctx.SendStatus(301) }
[ "func", "(", "ctx", "*", "Context", ")", "Redirect301", "(", "url", "string", ")", "{", "ctx", ".", "SetHeader", "(", "\"", "\"", ",", "url", ")", "\n", "ctx", ".", "SendStatus", "(", "301", ")", "\n", "}" ]
// Redirect301 method sets the response as a 301 redirection.
[ "Redirect301", "method", "sets", "the", "response", "as", "a", "301", "redirection", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L136-L139
127,402
dinever/golf
context.go
Cookie
func (ctx *Context) Cookie(key string) (string, error) { c, err := ctx.Request.Cookie(key) if err != nil { return "", err } return c.Value, nil }
go
func (ctx *Context) Cookie(key string) (string, error) { c, err := ctx.Request.Cookie(key) if err != nil { return "", err } return c.Value, nil }
[ "func", "(", "ctx", "*", "Context", ")", "Cookie", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "c", ",", "err", ":=", "ctx", ".", "Request", ".", "Cookie", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\...
// Cookie returns the value of the cookie by indicating the key.
[ "Cookie", "returns", "the", "value", "of", "the", "cookie", "by", "indicating", "the", "key", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L142-L148
127,403
dinever/golf
context.go
SetCookie
func (ctx *Context) SetCookie(key string, value string, expire int) { now := time.Now() cookie := &http.Cookie{ Name: key, Value: value, Path: "/", MaxAge: expire, } if expire != 0 { expireTime := now.Add(time.Duration(expire) * time.Second) cookie.Expires = expireTime } http.SetCookie(ctx.Respon...
go
func (ctx *Context) SetCookie(key string, value string, expire int) { now := time.Now() cookie := &http.Cookie{ Name: key, Value: value, Path: "/", MaxAge: expire, } if expire != 0 { expireTime := now.Add(time.Duration(expire) * time.Second) cookie.Expires = expireTime } http.SetCookie(ctx.Respon...
[ "func", "(", "ctx", "*", "Context", ")", "SetCookie", "(", "key", "string", ",", "value", "string", ",", "expire", "int", ")", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "cookie", ":=", "&", "http", ".", "Cookie", "{", "Name", ":", "ke...
// SetCookie set cookies for the request. If expire is 0, create a session cookie.
[ "SetCookie", "set", "cookies", "for", "the", "request", ".", "If", "expire", "is", "0", "create", "a", "session", "cookie", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L151-L164
127,404
dinever/golf
context.go
JSON
func (ctx *Context) JSON(obj interface{}) { json, err := json.Marshal(obj) if err != nil { panic(err) } ctx.SetHeader("Content-Type", "application/json") ctx.Send(json) }
go
func (ctx *Context) JSON(obj interface{}) { json, err := json.Marshal(obj) if err != nil { panic(err) } ctx.SetHeader("Content-Type", "application/json") ctx.Send(json) }
[ "func", "(", "ctx", "*", "Context", ")", "JSON", "(", "obj", "interface", "{", "}", ")", "{", "json", ",", "err", ":=", "json", ".", "Marshal", "(", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "...
// JSON Sends a JSON response.
[ "JSON", "Sends", "a", "JSON", "response", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L167-L174
127,405
dinever/golf
context.go
JSONIndent
func (ctx *Context) JSONIndent(obj interface{}, prefix, indent string) { jsonIndented, err := json.MarshalIndent(obj, prefix, indent) if err != nil { panic(err) } ctx.SetHeader("Content-Type", "application/json") ctx.Send(jsonIndented) }
go
func (ctx *Context) JSONIndent(obj interface{}, prefix, indent string) { jsonIndented, err := json.MarshalIndent(obj, prefix, indent) if err != nil { panic(err) } ctx.SetHeader("Content-Type", "application/json") ctx.Send(jsonIndented) }
[ "func", "(", "ctx", "*", "Context", ")", "JSONIndent", "(", "obj", "interface", "{", "}", ",", "prefix", ",", "indent", "string", ")", "{", "jsonIndented", ",", "err", ":=", "json", ".", "MarshalIndent", "(", "obj", ",", "prefix", ",", "indent", ")", ...
// JSONIndent Sends a JSON response, indenting the JSON as desired.
[ "JSONIndent", "Sends", "a", "JSON", "response", "indenting", "the", "JSON", "as", "desired", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L177-L184
127,406
dinever/golf
context.go
Send
func (ctx *Context) Send(body interface{}) { if ctx.IsSent { return } switch body.(type) { case []byte: ctx.Response.Write(body.([]byte)) case string: ctx.Response.Write([]byte(body.(string))) case *bytes.Buffer: ctx.Response.Write(body.(*bytes.Buffer).Bytes()) default: panic(fmt.Errorf("Body type not ...
go
func (ctx *Context) Send(body interface{}) { if ctx.IsSent { return } switch body.(type) { case []byte: ctx.Response.Write(body.([]byte)) case string: ctx.Response.Write([]byte(body.(string))) case *bytes.Buffer: ctx.Response.Write(body.(*bytes.Buffer).Bytes()) default: panic(fmt.Errorf("Body type not ...
[ "func", "(", "ctx", "*", "Context", ")", "Send", "(", "body", "interface", "{", "}", ")", "{", "if", "ctx", ".", "IsSent", "{", "return", "\n", "}", "\n", "switch", "body", ".", "(", "type", ")", "{", "case", "[", "]", "byte", ":", "ctx", ".", ...
// Send the response immediately. Set `ctx.IsSent` to `true` to make // sure that the response won't be sent twice.
[ "Send", "the", "response", "immediately", ".", "Set", "ctx", ".", "IsSent", "to", "true", "to", "make", "sure", "that", "the", "response", "won", "t", "be", "sent", "twice", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L188-L203
127,407
dinever/golf
context.go
Abort
func (ctx *Context) Abort(statusCode int, data ...map[string]interface{}) { ctx.App.handleError(ctx, statusCode, data...) }
go
func (ctx *Context) Abort(statusCode int, data ...map[string]interface{}) { ctx.App.handleError(ctx, statusCode, data...) }
[ "func", "(", "ctx", "*", "Context", ")", "Abort", "(", "statusCode", "int", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "ctx", ".", "App", ".", "handleError", "(", "ctx", ",", "statusCode", ",", "data", "...", ")...
// Abort method returns an HTTP Error by indicating the status code, the corresponding // handler inside `App.errorHandler` will be called, if user has not set // the corresponding error handler, the defaultErrorHandler will be called.
[ "Abort", "method", "returns", "an", "HTTP", "Error", "by", "indicating", "the", "status", "code", "the", "corresponding", "handler", "inside", "App", ".", "errorHandler", "will", "be", "called", "if", "user", "has", "not", "set", "the", "corresponding", "error...
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L237-L239
127,408
dinever/golf
context.go
Loader
func (ctx *Context) Loader(name string) *Context { ctx.templateLoader = name return ctx }
go
func (ctx *Context) Loader(name string) *Context { ctx.templateLoader = name return ctx }
[ "func", "(", "ctx", "*", "Context", ")", "Loader", "(", "name", "string", ")", "*", "Context", "{", "ctx", ".", "templateLoader", "=", "name", "\n", "return", "ctx", "\n", "}" ]
// Loader method sets the template loader for this context. This should be done before calling // `ctx.Render`.
[ "Loader", "method", "sets", "the", "template", "loader", "for", "this", "context", ".", "This", "should", "be", "done", "before", "calling", "ctx", ".", "Render", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L243-L246
127,409
dinever/golf
context.go
Render
func (ctx *Context) Render(file string, data ...map[string]interface{}) { if ctx.templateLoader == "" { panic(fmt.Errorf("Template loader has not been set")) } var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) } else { renderData = data[0] } renderData["xsr...
go
func (ctx *Context) Render(file string, data ...map[string]interface{}) { if ctx.templateLoader == "" { panic(fmt.Errorf("Template loader has not been set")) } var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) } else { renderData = data[0] } renderData["xsr...
[ "func", "(", "ctx", "*", "Context", ")", "Render", "(", "file", "string", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "if", "ctx", ".", "templateLoader", "==", "\"", "\"", "{", "panic", "(", "fmt", ".", "Errorf",...
// Render a template file using the built-in Go template engine.
[ "Render", "a", "template", "file", "using", "the", "built", "-", "in", "Go", "template", "engine", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L284-L300
127,410
dinever/golf
context.go
RenderFromString
func (ctx *Context) RenderFromString(tplSrc string, data ...map[string]interface{}) { var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) } else { renderData = data[0] } renderData["xsrf_token"] = ctx.xsrfToken() content, e := ctx.App.View.RenderFromString(ctx.t...
go
func (ctx *Context) RenderFromString(tplSrc string, data ...map[string]interface{}) { var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) } else { renderData = data[0] } renderData["xsrf_token"] = ctx.xsrfToken() content, e := ctx.App.View.RenderFromString(ctx.t...
[ "func", "(", "ctx", "*", "Context", ")", "RenderFromString", "(", "tplSrc", "string", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "var", "renderData", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "...
// RenderFromString renders a input string.
[ "RenderFromString", "renders", "a", "input", "string", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/context.go#L303-L316
127,411
dinever/golf
app.go
New
func New() *Application { app := new(Application) app.router = newRouter() app.staticRouter = make(map[string][]string) app.View = NewView() app.Config = NewConfig() app.errorHandler = make(map[int]ErrorHandlerFunc) app.middlewareChain = NewChain() app.DefaultErrorHandler = defaultErrorHandler app.pool.New = f...
go
func New() *Application { app := new(Application) app.router = newRouter() app.staticRouter = make(map[string][]string) app.View = NewView() app.Config = NewConfig() app.errorHandler = make(map[int]ErrorHandlerFunc) app.middlewareChain = NewChain() app.DefaultErrorHandler = defaultErrorHandler app.pool.New = f...
[ "func", "New", "(", ")", "*", "Application", "{", "app", ":=", "new", "(", "Application", ")", "\n", "app", ".", "router", "=", "newRouter", "(", ")", "\n", "app", ".", "staticRouter", "=", "make", "(", "map", "[", "string", "]", "[", "]", "string"...
// New is used for creating a new Golf Application instance.
[ "New", "is", "used", "for", "creating", "a", "new", "Golf", "Application", "instance", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L46-L60
127,412
dinever/golf
app.go
Use
func (app *Application) Use(m ...MiddlewareHandlerFunc) { for _, fn := range m { app.middlewareChain.Append(fn) } app.handlerChain = app.middlewareChain.Final(app.handler) }
go
func (app *Application) Use(m ...MiddlewareHandlerFunc) { for _, fn := range m { app.middlewareChain.Append(fn) } app.handlerChain = app.middlewareChain.Final(app.handler) }
[ "func", "(", "app", "*", "Application", ")", "Use", "(", "m", "...", "MiddlewareHandlerFunc", ")", "{", "for", "_", ",", "fn", ":=", "range", "m", "{", "app", ".", "middlewareChain", ".", "Append", "(", "fn", ")", "\n", "}", "\n", "app", ".", "hand...
// Use appends a middleware to the existing middleware chain.
[ "Use", "appends", "a", "middleware", "to", "the", "existing", "middleware", "chain", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L63-L68
127,413
dinever/golf
app.go
handler
func (app *Application) handler(ctx *Context) { for prefix, staticPathSlice := range app.staticRouter { if strings.HasPrefix(ctx.Request.URL.Path, prefix) { for _, staticPath := range staticPathSlice { filePath := path.Join(staticPath, ctx.Request.URL.Path[len(prefix):]) fileInfo, err := os.Stat(filePath)...
go
func (app *Application) handler(ctx *Context) { for prefix, staticPathSlice := range app.staticRouter { if strings.HasPrefix(ctx.Request.URL.Path, prefix) { for _, staticPath := range staticPathSlice { filePath := path.Join(staticPath, ctx.Request.URL.Path[len(prefix):]) fileInfo, err := os.Stat(filePath)...
[ "func", "(", "app", "*", "Application", ")", "handler", "(", "ctx", "*", "Context", ")", "{", "for", "prefix", ",", "staticPathSlice", ":=", "range", "app", ".", "staticRouter", "{", "if", "strings", ".", "HasPrefix", "(", "ctx", ".", "Request", ".", "...
// First search if any of the static route matches the request. // If not, look up the URL in the router.
[ "First", "search", "if", "any", "of", "the", "static", "route", "matches", "the", "request", ".", "If", "not", "look", "up", "the", "URL", "in", "the", "router", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L72-L94
127,414
dinever/golf
app.go
staticHandler
func staticHandler(ctx *Context, filePath string) { http.ServeFile(ctx.Response, ctx.Request, filePath) }
go
func staticHandler(ctx *Context, filePath string) { http.ServeFile(ctx.Response, ctx.Request, filePath) }
[ "func", "staticHandler", "(", "ctx", "*", "Context", ",", "filePath", "string", ")", "{", "http", ".", "ServeFile", "(", "ctx", ".", "Response", ",", "ctx", ".", "Request", ",", "filePath", ")", "\n", "}" ]
// Serve a static file
[ "Serve", "a", "static", "file" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L97-L99
127,415
dinever/golf
app.go
ServeHTTP
func (app *Application) ServeHTTP(res http.ResponseWriter, req *http.Request) { ctx := app.pool.Get().(*Context) ctx.reset() ctx.Request = req ctx.Response = res ctx.App = app app.handlerChain(ctx) app.pool.Put(ctx) }
go
func (app *Application) ServeHTTP(res http.ResponseWriter, req *http.Request) { ctx := app.pool.Get().(*Context) ctx.reset() ctx.Request = req ctx.Response = res ctx.App = app app.handlerChain(ctx) app.pool.Put(ctx) }
[ "func", "(", "app", "*", "Application", ")", "ServeHTTP", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "ctx", ":=", "app", ".", "pool", ".", "Get", "(", ")", ".", "(", "*", "Context", ")", "\n", "c...
// Basic entrance of an `http.ResponseWriter` and an `http.Request`.
[ "Basic", "entrance", "of", "an", "http", ".", "ResponseWriter", "and", "an", "http", ".", "Request", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L102-L110
127,416
dinever/golf
app.go
Run
func (app *Application) Run(addr string) { err := http.ListenAndServe(addr, app) if err != nil { panic(err) } }
go
func (app *Application) Run(addr string) { err := http.ListenAndServe(addr, app) if err != nil { panic(err) } }
[ "func", "(", "app", "*", "Application", ")", "Run", "(", "addr", "string", ")", "{", "err", ":=", "http", ".", "ListenAndServe", "(", "addr", ",", "app", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// Run the Golf Application.
[ "Run", "the", "Golf", "Application", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L113-L118
127,417
dinever/golf
app.go
RunTLS
func (app *Application) RunTLS(addr, certFile, keyFile string) { err := http.ListenAndServeTLS(addr, certFile, keyFile, app) if err != nil { panic(err) } }
go
func (app *Application) RunTLS(addr, certFile, keyFile string) { err := http.ListenAndServeTLS(addr, certFile, keyFile, app) if err != nil { panic(err) } }
[ "func", "(", "app", "*", "Application", ")", "RunTLS", "(", "addr", ",", "certFile", ",", "keyFile", "string", ")", "{", "err", ":=", "http", ".", "ListenAndServeTLS", "(", "addr", ",", "certFile", ",", "keyFile", ",", "app", ")", "\n", "if", "err", ...
// RunTLS runs the app with TLS support.
[ "RunTLS", "runs", "the", "app", "with", "TLS", "support", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L121-L126
127,418
dinever/golf
app.go
Static
func (app *Application) Static(url string, path string) { url = strings.TrimRight(url, "/") app.staticRouter[url] = append(app.staticRouter[url], path) }
go
func (app *Application) Static(url string, path string) { url = strings.TrimRight(url, "/") app.staticRouter[url] = append(app.staticRouter[url], path) }
[ "func", "(", "app", "*", "Application", ")", "Static", "(", "url", "string", ",", "path", "string", ")", "{", "url", "=", "strings", ".", "TrimRight", "(", "url", ",", "\"", "\"", ")", "\n", "app", ".", "staticRouter", "[", "url", "]", "=", "append...
// Static is used for registering a static folder
[ "Static", "is", "used", "for", "registering", "a", "static", "folder" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L129-L132
127,419
dinever/golf
app.go
Get
func (app *Application) Get(pattern string, handler HandlerFunc) { app.router.AddRoute("GET", pattern, handler) }
go
func (app *Application) Get(pattern string, handler HandlerFunc) { app.router.AddRoute("GET", pattern, handler) }
[ "func", "(", "app", "*", "Application", ")", "Get", "(", "pattern", "string", ",", "handler", "HandlerFunc", ")", "{", "app", ".", "router", ".", "AddRoute", "(", "\"", "\"", ",", "pattern", ",", "handler", ")", "\n", "}" ]
// Get method is used for registering a Get method route
[ "Get", "method", "is", "used", "for", "registering", "a", "Get", "method", "route" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L135-L137
127,420
dinever/golf
app.go
Error
func (app *Application) Error(statusCode int, handler ErrorHandlerFunc) { app.errorHandler[statusCode] = handler }
go
func (app *Application) Error(statusCode int, handler ErrorHandlerFunc) { app.errorHandler[statusCode] = handler }
[ "func", "(", "app", "*", "Application", ")", "Error", "(", "statusCode", "int", ",", "handler", "ErrorHandlerFunc", ")", "{", "app", ".", "errorHandler", "[", "statusCode", "]", "=", "handler", "\n", "}" ]
// Error method is used for registering an handler for a specified HTTP error code.
[ "Error", "method", "is", "used", "for", "registering", "an", "handler", "for", "a", "specified", "HTTP", "error", "code", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L170-L172
127,421
dinever/golf
app.go
handleError
func (app *Application) handleError(ctx *Context, statusCode int, data ...map[string]interface{}) { ctx.SendStatus(statusCode) handler, ok := app.errorHandler[statusCode] if !ok { defaultErrorHandler(ctx, data...) return } handler(ctx) }
go
func (app *Application) handleError(ctx *Context, statusCode int, data ...map[string]interface{}) { ctx.SendStatus(statusCode) handler, ok := app.errorHandler[statusCode] if !ok { defaultErrorHandler(ctx, data...) return } handler(ctx) }
[ "func", "(", "app", "*", "Application", ")", "handleError", "(", "ctx", "*", "Context", ",", "statusCode", "int", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "ctx", ".", "SendStatus", "(", "statusCode", ")", "\n", ...
// Handles a HTTP Error, if there is a corresponding handler set in the map // `errorHandler`, then call it. Otherwise call the `defaultErrorHandler`.
[ "Handles", "a", "HTTP", "Error", "if", "there", "is", "a", "corresponding", "handler", "set", "in", "the", "map", "errorHandler", "then", "call", "it", ".", "Otherwise", "call", "the", "defaultErrorHandler", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/app.go#L176-L184
127,422
dinever/golf
middleware.go
NewChain
func NewChain(handlerArray ...MiddlewareHandlerFunc) *Chain { c := new(Chain) c.middlewareHandlers = handlerArray return c }
go
func NewChain(handlerArray ...MiddlewareHandlerFunc) *Chain { c := new(Chain) c.middlewareHandlers = handlerArray return c }
[ "func", "NewChain", "(", "handlerArray", "...", "MiddlewareHandlerFunc", ")", "*", "Chain", "{", "c", ":=", "new", "(", "Chain", ")", "\n", "c", ".", "middlewareHandlers", "=", "handlerArray", "\n", "return", "c", "\n", "}" ]
// NewChain Creates a new middleware chain.
[ "NewChain", "Creates", "a", "new", "middleware", "chain", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L20-L24
127,423
dinever/golf
middleware.go
Final
func (c Chain) Final(fn HandlerFunc) HandlerFunc { for i := len(c.middlewareHandlers) - 1; i >= 0; i-- { fn = c.middlewareHandlers[i](fn) } return fn }
go
func (c Chain) Final(fn HandlerFunc) HandlerFunc { for i := len(c.middlewareHandlers) - 1; i >= 0; i-- { fn = c.middlewareHandlers[i](fn) } return fn }
[ "func", "(", "c", "Chain", ")", "Final", "(", "fn", "HandlerFunc", ")", "HandlerFunc", "{", "for", "i", ":=", "len", "(", "c", ".", "middlewareHandlers", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "fn", "=", "c", ".", "middlewareHan...
// Final indicates a final Handler, chain the multiple middlewares together with the // handler, and return them together as a handler.
[ "Final", "indicates", "a", "final", "Handler", "chain", "the", "multiple", "middlewares", "together", "with", "the", "handler", "and", "return", "them", "together", "as", "a", "handler", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L28-L33
127,424
dinever/golf
middleware.go
Append
func (c *Chain) Append(fn MiddlewareHandlerFunc) { c.middlewareHandlers = append(c.middlewareHandlers, fn) }
go
func (c *Chain) Append(fn MiddlewareHandlerFunc) { c.middlewareHandlers = append(c.middlewareHandlers, fn) }
[ "func", "(", "c", "*", "Chain", ")", "Append", "(", "fn", "MiddlewareHandlerFunc", ")", "{", "c", ".", "middlewareHandlers", "=", "append", "(", "c", ".", "middlewareHandlers", ",", "fn", ")", "\n", "}" ]
// Append a middleware to the middleware chain
[ "Append", "a", "middleware", "to", "the", "middleware", "chain" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L36-L38
127,425
dinever/golf
middleware.go
XSRFProtectionMiddleware
func XSRFProtectionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.Request.Method == "POST" || ctx.Request.Method == "PUT" || ctx.Request.Method == "DELETE" { if !ctx.checkXSRFToken() { ctx.Abort(403) return } } next(ctx) } return fn }
go
func XSRFProtectionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.Request.Method == "POST" || ctx.Request.Method == "PUT" || ctx.Request.Method == "DELETE" { if !ctx.checkXSRFToken() { ctx.Abort(403) return } } next(ctx) } return fn }
[ "func", "XSRFProtectionMiddleware", "(", "next", "HandlerFunc", ")", "HandlerFunc", "{", "fn", ":=", "func", "(", "ctx", "*", "Context", ")", "{", "if", "ctx", ".", "Request", ".", "Method", "==", "\"", "\"", "||", "ctx", ".", "Request", ".", "Method", ...
// XSRFProtectionMiddleware is the built-in middleware for XSRF protection.
[ "XSRFProtectionMiddleware", "is", "the", "built", "-", "in", "middleware", "for", "XSRF", "protection", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L118-L129
127,426
dinever/golf
middleware.go
RecoverMiddleware
func RecoverMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { defer func() { if err := recover(); err != nil { e := NewError(err) httpRequest, _ := httputil.DumpRequest(ctx.Request, true) log.Printf("[Recovery] panic recovered:\n%s\n%s\n%s", string(httpRequest), err, e.StackTraceSt...
go
func RecoverMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { defer func() { if err := recover(); err != nil { e := NewError(err) httpRequest, _ := httputil.DumpRequest(ctx.Request, true) log.Printf("[Recovery] panic recovered:\n%s\n%s\n%s", string(httpRequest), err, e.StackTraceSt...
[ "func", "RecoverMiddleware", "(", "next", "HandlerFunc", ")", "HandlerFunc", "{", "fn", ":=", "func", "(", "ctx", "*", "Context", ")", "{", "defer", "func", "(", ")", "{", "if", "err", ":=", "recover", "(", ")", ";", "err", "!=", "nil", "{", "e", "...
// RecoverMiddleware is the built-in middleware for recovering from errors.
[ "RecoverMiddleware", "is", "the", "built", "-", "in", "middleware", "for", "recovering", "from", "errors", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L132-L152
127,427
dinever/golf
middleware.go
SessionMiddleware
func SessionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.App.SessionManager != nil { ctx.retrieveSession() } next(ctx) } return fn }
go
func SessionMiddleware(next HandlerFunc) HandlerFunc { fn := func(ctx *Context) { if ctx.App.SessionManager != nil { ctx.retrieveSession() } next(ctx) } return fn }
[ "func", "SessionMiddleware", "(", "next", "HandlerFunc", ")", "HandlerFunc", "{", "fn", ":=", "func", "(", "ctx", "*", "Context", ")", "{", "if", "ctx", ".", "App", ".", "SessionManager", "!=", "nil", "{", "ctx", ".", "retrieveSession", "(", ")", "\n", ...
// SessionMiddleware handles session of the request
[ "SessionMiddleware", "handles", "session", "of", "the", "request" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/middleware.go#L155-L163
127,428
dinever/golf
router.go
ByName
func (p *Parameter) ByName(name string) (string, error) { if i, has := p.names[name]; has { return p.findParam(i) } return "", fmt.Errorf("Parameter not found") }
go
func (p *Parameter) ByName(name string) (string, error) { if i, has := p.names[name]; has { return p.findParam(i) } return "", fmt.Errorf("Parameter not found") }
[ "func", "(", "p", "*", "Parameter", ")", "ByName", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "i", ",", "has", ":=", "p", ".", "names", "[", "name", "]", ";", "has", "{", "return", "p", ".", "findParam", "(", "i", ...
//ByName returns the url parameter by name
[ "ByName", "returns", "the", "url", "parameter", "by", "name" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/router.go#L116-L121
127,429
dinever/golf
router.go
findParam
func (p *Parameter) findParam(idx int) (string, error) { index := len(p.names) - 1 urlPath := p.path pathLen := len(p.path) node := p.node for node != nil { if node.text[0] == ':' { ctn := lastIndexByte(urlPath, '/') if ctn == -1 { return "", fmt.Errorf("Parameter not found") } pathLen = ctn + 1...
go
func (p *Parameter) findParam(idx int) (string, error) { index := len(p.names) - 1 urlPath := p.path pathLen := len(p.path) node := p.node for node != nil { if node.text[0] == ':' { ctn := lastIndexByte(urlPath, '/') if ctn == -1 { return "", fmt.Errorf("Parameter not found") } pathLen = ctn + 1...
[ "func", "(", "p", "*", "Parameter", ")", "findParam", "(", "idx", "int", ")", "(", "string", ",", "error", ")", "{", "index", ":=", "len", "(", "p", ".", "names", ")", "-", "1", "\n", "urlPath", ":=", "p", ".", "path", "\n", "pathLen", ":=", "l...
//findParam walks up the matched node looking for parameters returns the last parameter
[ "findParam", "walks", "up", "the", "matched", "node", "looking", "for", "parameters", "returns", "the", "last", "parameter" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/router.go#L133-L157
127,430
dinever/golf
error.go
defaultErrorHandler
func defaultErrorHandler(ctx *Context, data ...map[string]interface{}) { var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) renderData["Code"] = ctx.statusCode renderData["Title"] = http.StatusText(ctx.statusCode) renderData["Message"] = http.StatusText(ctx.sta...
go
func defaultErrorHandler(ctx *Context, data ...map[string]interface{}) { var renderData map[string]interface{} if len(data) == 0 { renderData = make(map[string]interface{}) renderData["Code"] = ctx.statusCode renderData["Title"] = http.StatusText(ctx.statusCode) renderData["Message"] = http.StatusText(ctx.sta...
[ "func", "defaultErrorHandler", "(", "ctx", "*", "Context", ",", "data", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "var", "renderData", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "len", "(", "data", ")", "==...
// The default error handler
[ "The", "default", "error", "handler" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/error.go#L104-L129
127,431
dinever/golf
error.go
StackTraceString
func (e Error) StackTraceString() string { buf := new(bytes.Buffer) for _, v := range e.Stack { fmt.Fprintf(buf, "%s: %s\n\t%s\n", v.File, v.Number, v.Method) } return string(buf.Bytes()) }
go
func (e Error) StackTraceString() string { buf := new(bytes.Buffer) for _, v := range e.Stack { fmt.Fprintf(buf, "%s: %s\n\t%s\n", v.File, v.Number, v.Method) } return string(buf.Bytes()) }
[ "func", "(", "e", "Error", ")", "StackTraceString", "(", ")", "string", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "for", "_", ",", "v", ":=", "range", "e", ".", "Stack", "{", "fmt", ".", "Fprintf", "(", "buf", ",", "\"", ...
// StackTraceString returns the stack trace in a string format.
[ "StackTraceString", "returns", "the", "stack", "trace", "in", "a", "string", "format", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/error.go#L152-L158
127,432
dinever/golf
error.go
NewError
func NewError(msg interface{}) Error { var err error switch t := msg.(type) { case Error: return t case error: err = t default: err = fmt.Errorf("%v", t) } return Error{ err: err, Message: err.Error(), Class: reflect.TypeOf(err).String(), Stack: generateStack(3), } }
go
func NewError(msg interface{}) Error { var err error switch t := msg.(type) { case Error: return t case error: err = t default: err = fmt.Errorf("%v", t) } return Error{ err: err, Message: err.Error(), Class: reflect.TypeOf(err).String(), Stack: generateStack(3), } }
[ "func", "NewError", "(", "msg", "interface", "{", "}", ")", "Error", "{", "var", "err", "error", "\n\n", "switch", "t", ":=", "msg", ".", "(", "type", ")", "{", "case", "Error", ":", "return", "t", "\n", "case", "error", ":", "err", "=", "t", "\n...
// NewError creates a new error instance
[ "NewError", "creates", "a", "new", "error", "instance" ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/error.go#L166-L184
127,433
dinever/golf
session.go
NewMemorySessionManager
func NewMemorySessionManager() *MemorySessionManager { mgr := new(MemorySessionManager) mgr.sessions = make(map[string]*MemorySession) mgr.GarbageCollection() return mgr }
go
func NewMemorySessionManager() *MemorySessionManager { mgr := new(MemorySessionManager) mgr.sessions = make(map[string]*MemorySession) mgr.GarbageCollection() return mgr }
[ "func", "NewMemorySessionManager", "(", ")", "*", "MemorySessionManager", "{", "mgr", ":=", "new", "(", "MemorySessionManager", ")", "\n", "mgr", ".", "sessions", "=", "make", "(", "map", "[", "string", "]", "*", "MemorySession", ")", "\n", "mgr", ".", "Ga...
// NewMemorySessionManager creates a new session manager.
[ "NewMemorySessionManager", "creates", "a", "new", "session", "manager", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L31-L36
127,434
dinever/golf
session.go
Session
func (mgr *MemorySessionManager) Session(sid string) (Session, error) { mgr.lock.RLock() if s, ok := mgr.sessions[sid]; ok { s.createdAt = time.Now() mgr.lock.RUnlock() return s, nil } mgr.lock.RUnlock() return nil, fmt.Errorf("Can not retrieve session with id %s", sid) }
go
func (mgr *MemorySessionManager) Session(sid string) (Session, error) { mgr.lock.RLock() if s, ok := mgr.sessions[sid]; ok { s.createdAt = time.Now() mgr.lock.RUnlock() return s, nil } mgr.lock.RUnlock() return nil, fmt.Errorf("Can not retrieve session with id %s", sid) }
[ "func", "(", "mgr", "*", "MemorySessionManager", ")", "Session", "(", "sid", "string", ")", "(", "Session", ",", "error", ")", "{", "mgr", ".", "lock", ".", "RLock", "(", ")", "\n", "if", "s", ",", "ok", ":=", "mgr", ".", "sessions", "[", "sid", ...
// Session gets the session instance by indicating a session id.
[ "Session", "gets", "the", "session", "instance", "by", "indicating", "a", "session", "id", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L48-L57
127,435
dinever/golf
session.go
NewSession
func (mgr *MemorySessionManager) NewSession() (Session, error) { sid, err := mgr.sessionID() if err != nil { return nil, err } s := MemorySession{sid: sid, data: make(map[string]interface{}), createdAt: time.Now()} mgr.lock.Lock() mgr.sessions[sid] = &s mgr.lock.Unlock() return &s, nil }
go
func (mgr *MemorySessionManager) NewSession() (Session, error) { sid, err := mgr.sessionID() if err != nil { return nil, err } s := MemorySession{sid: sid, data: make(map[string]interface{}), createdAt: time.Now()} mgr.lock.Lock() mgr.sessions[sid] = &s mgr.lock.Unlock() return &s, nil }
[ "func", "(", "mgr", "*", "MemorySessionManager", ")", "NewSession", "(", ")", "(", "Session", ",", "error", ")", "{", "sid", ",", "err", ":=", "mgr", ".", "sessionID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n"...
// NewSession creates and returns a new session.
[ "NewSession", "creates", "and", "returns", "a", "new", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L60-L70
127,436
dinever/golf
session.go
GarbageCollection
func (mgr *MemorySessionManager) GarbageCollection() { for k, v := range mgr.sessions { if v.isExpired() { delete(mgr.sessions, k) } } time.AfterFunc(time.Duration(gcTimeInterval)*time.Second, mgr.GarbageCollection) }
go
func (mgr *MemorySessionManager) GarbageCollection() { for k, v := range mgr.sessions { if v.isExpired() { delete(mgr.sessions, k) } } time.AfterFunc(time.Duration(gcTimeInterval)*time.Second, mgr.GarbageCollection) }
[ "func", "(", "mgr", "*", "MemorySessionManager", ")", "GarbageCollection", "(", ")", "{", "for", "k", ",", "v", ":=", "range", "mgr", ".", "sessions", "{", "if", "v", ".", "isExpired", "(", ")", "{", "delete", "(", "mgr", ".", "sessions", ",", "k", ...
// GarbageCollection recycles expired sessions, delete them from the session manager.
[ "GarbageCollection", "recycles", "expired", "sessions", "delete", "them", "from", "the", "session", "manager", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L73-L80
127,437
dinever/golf
session.go
Set
func (s *MemorySession) Set(key string, value interface{}) error { s.data[key] = value return nil }
go
func (s *MemorySession) Set(key string, value interface{}) error { s.data[key] = value return nil }
[ "func", "(", "s", "*", "MemorySession", ")", "Set", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "s", ".", "data", "[", "key", "]", "=", "value", "\n", "return", "nil", "\n", "}" ]
// Set method sets the key value pair in the session.
[ "Set", "method", "sets", "the", "key", "value", "pair", "in", "the", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L109-L112
127,438
dinever/golf
session.go
Get
func (s *MemorySession) Get(key string) (interface{}, error) { if value, ok := s.data[key]; ok { return value, nil } return nil, fmt.Errorf("key %q in session (id %s) not found", key, s.sid) }
go
func (s *MemorySession) Get(key string) (interface{}, error) { if value, ok := s.data[key]; ok { return value, nil } return nil, fmt.Errorf("key %q in session (id %s) not found", key, s.sid) }
[ "func", "(", "s", "*", "MemorySession", ")", "Get", "(", "key", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "value", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", ";", "ok", "{", "return", "value", ",", "nil",...
// Get method gets the value by given a key in the session.
[ "Get", "method", "gets", "the", "value", "by", "given", "a", "key", "in", "the", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L115-L120
127,439
dinever/golf
session.go
Delete
func (s *MemorySession) Delete(key string) error { delete(s.data, key) return nil }
go
func (s *MemorySession) Delete(key string) error { delete(s.data, key) return nil }
[ "func", "(", "s", "*", "MemorySession", ")", "Delete", "(", "key", "string", ")", "error", "{", "delete", "(", "s", ".", "data", ",", "key", ")", "\n", "return", "nil", "\n", "}" ]
// Delete method deletes the value by given a key in the session.
[ "Delete", "method", "deletes", "the", "value", "by", "given", "a", "key", "in", "the", "session", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/session.go#L123-L126
127,440
dinever/golf
template.go
LoadTemplate
func (loader *FileSystemLoader) LoadTemplate(name string) (string, error) { f, err := os.Open(path.Join(loader.BaseDir, name)) if err != nil { return "", err } b, err := ioutil.ReadAll(f) return string(b), err }
go
func (loader *FileSystemLoader) LoadTemplate(name string) (string, error) { f, err := os.Open(path.Join(loader.BaseDir, name)) if err != nil { return "", err } b, err := ioutil.ReadAll(f) return string(b), err }
[ "func", "(", "loader", "*", "FileSystemLoader", ")", "LoadTemplate", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ".", "Join", "(", "loader", ".", "BaseDir", ",", "name", ...
// LoadTemplate loads a template from a file.
[ "LoadTemplate", "loads", "a", "template", "from", "a", "file", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L31-L38
127,441
dinever/golf
template.go
LoadTemplate
func (loader *MapLoader) LoadTemplate(name string) (string, error) { if src, ok := (*loader)[name]; ok { return src, nil } return "", Errorf("Could not find template " + name) }
go
func (loader *MapLoader) LoadTemplate(name string) (string, error) { if src, ok := (*loader)[name]; ok { return src, nil } return "", Errorf("Could not find template " + name) }
[ "func", "(", "loader", "*", "MapLoader", ")", "LoadTemplate", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "src", ",", "ok", ":=", "(", "*", "loader", ")", "[", "name", "]", ";", "ok", "{", "return", "src", ",", "nil",...
// LoadTemplate loads a template from the map.
[ "LoadTemplate", "loads", "a", "template", "from", "the", "map", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L45-L50
127,442
dinever/golf
template.go
Render
func (t *TemplateManager) Render(w io.Writer, name string, data interface{}) error { stack := []*Template{} tplSrc, err := t.getSrc(name) if err != nil { return err } err = t.push(&stack, tplSrc, name) if err != nil { return err } tpl, err := t.assemble(stack) if err != nil { return err } if err != nil...
go
func (t *TemplateManager) Render(w io.Writer, name string, data interface{}) error { stack := []*Template{} tplSrc, err := t.getSrc(name) if err != nil { return err } err = t.push(&stack, tplSrc, name) if err != nil { return err } tpl, err := t.assemble(stack) if err != nil { return err } if err != nil...
[ "func", "(", "t", "*", "TemplateManager", ")", "Render", "(", "w", "io", ".", "Writer", ",", "name", "string", ",", "data", "interface", "{", "}", ")", "error", "{", "stack", ":=", "[", "]", "*", "Template", "{", "}", "\n", "tplSrc", ",", "err", ...
// Render renders a template and writes it to the io.Writer interface.
[ "Render", "renders", "a", "template", "and", "writes", "it", "to", "the", "io", ".", "Writer", "interface", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L65-L93
127,443
dinever/golf
template.go
RenderFromString
func (t *TemplateManager) RenderFromString(w io.Writer, tplSrc string, data interface{}) error { stack := []*Template{} t.push(&stack, tplSrc, "_fromString") tpl, err := t.assemble(stack) if err != nil { return err } err = tpl.Execute(w, data) if err != nil { return err } return nil }
go
func (t *TemplateManager) RenderFromString(w io.Writer, tplSrc string, data interface{}) error { stack := []*Template{} t.push(&stack, tplSrc, "_fromString") tpl, err := t.assemble(stack) if err != nil { return err } err = tpl.Execute(w, data) if err != nil { return err } return nil }
[ "func", "(", "t", "*", "TemplateManager", ")", "RenderFromString", "(", "w", "io", ".", "Writer", ",", "tplSrc", "string", ",", "data", "interface", "{", "}", ")", "error", "{", "stack", ":=", "[", "]", "*", "Template", "{", "}", "\n", "t", ".", "p...
// RenderFromString renders a template from string.
[ "RenderFromString", "renders", "a", "template", "from", "string", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/template.go#L96-L110
127,444
dinever/golf
view.go
NewView
func NewView() *View { view := new(View) view.templateLoader = make(map[string]*TemplateManager) view.FuncMap = make(template.FuncMap) view.FuncMap["Html"] = func(s string) template.HTML { return template.HTML(s) } return view }
go
func NewView() *View { view := new(View) view.templateLoader = make(map[string]*TemplateManager) view.FuncMap = make(template.FuncMap) view.FuncMap["Html"] = func(s string) template.HTML { return template.HTML(s) } return view }
[ "func", "NewView", "(", ")", "*", "View", "{", "view", ":=", "new", "(", "View", ")", "\n", "view", ".", "templateLoader", "=", "make", "(", "map", "[", "string", "]", "*", "TemplateManager", ")", "\n", "view", ".", "FuncMap", "=", "make", "(", "te...
// NewView creates a new View instance.
[ "NewView", "creates", "a", "new", "View", "instance", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L19-L25
127,445
dinever/golf
view.go
Render
func (view *View) Render(loaderName string, filePath string, data map[string]interface{}) (string, error) { loader, ok := view.templateLoader[loaderName] if !ok { panic(errors.New("Template loader not found: " + loaderName)) } var buf bytes.Buffer err := loader.Render(&buf, filePath, data) if err != nil { ret...
go
func (view *View) Render(loaderName string, filePath string, data map[string]interface{}) (string, error) { loader, ok := view.templateLoader[loaderName] if !ok { panic(errors.New("Template loader not found: " + loaderName)) } var buf bytes.Buffer err := loader.Render(&buf, filePath, data) if err != nil { ret...
[ "func", "(", "view", "*", "View", ")", "Render", "(", "loaderName", "string", ",", "filePath", "string", ",", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "loader", ",", "ok", ":=", "view", "...
// Render renders a template by indicating the file path and the name of the template loader.
[ "Render", "renders", "a", "template", "by", "indicating", "the", "file", "path", "and", "the", "name", "of", "the", "template", "loader", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L28-L39
127,446
dinever/golf
view.go
RenderFromString
func (view *View) RenderFromString(loaderName string, tplSrc string, data map[string]interface{}) (string, error) { var buf bytes.Buffer // If loaderName is not indicated, use the default template library of Go, no syntax like // `extends` or `include` will be supported. if loaderName == "" { tmpl := template.New...
go
func (view *View) RenderFromString(loaderName string, tplSrc string, data map[string]interface{}) (string, error) { var buf bytes.Buffer // If loaderName is not indicated, use the default template library of Go, no syntax like // `extends` or `include` will be supported. if loaderName == "" { tmpl := template.New...
[ "func", "(", "view", "*", "View", ")", "RenderFromString", "(", "loaderName", "string", ",", "tplSrc", "string", ",", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "var", "buf", "bytes", ".", "B...
// RenderFromString does the same thing as render but renders a template by // indicating the template source from tplSrc.
[ "RenderFromString", "does", "the", "same", "thing", "as", "render", "but", "renders", "a", "template", "by", "indicating", "the", "template", "source", "from", "tplSrc", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L43-L62
127,447
dinever/golf
view.go
SetTemplateLoader
func (view *View) SetTemplateLoader(name string, path string) { loader := &TemplateManager{ Loader: &FileSystemLoader{ BaseDir: path, }, FuncMap: view.FuncMap, } view.templateLoader[name] = loader }
go
func (view *View) SetTemplateLoader(name string, path string) { loader := &TemplateManager{ Loader: &FileSystemLoader{ BaseDir: path, }, FuncMap: view.FuncMap, } view.templateLoader[name] = loader }
[ "func", "(", "view", "*", "View", ")", "SetTemplateLoader", "(", "name", "string", ",", "path", "string", ")", "{", "loader", ":=", "&", "TemplateManager", "{", "Loader", ":", "&", "FileSystemLoader", "{", "BaseDir", ":", "path", ",", "}", ",", "FuncMap"...
// SetTemplateLoader sets the template loader by indicating the name and the path.
[ "SetTemplateLoader", "sets", "the", "template", "loader", "by", "indicating", "the", "name", "and", "the", "path", "." ]
11abebbbb289ef6f35e518db394eaca39cee8732
https://github.com/dinever/golf/blob/11abebbbb289ef6f35e518db394eaca39cee8732/view.go#L65-L73
127,448
gorgonia/cu
cmd/genlib/signature.go
flagType
func flagType(name string) string { switch name { case "cuCtxCreate", "cuDevicePrimaryCtxSetFlags": return "ContextFlags" case "cuLinkCreate": panic("Unhandled") case "cuStreamCreate", "cuStreamCreateWithPriority": return "StreamFlags" case "cuEventCreate": return "EventFlags" case "cuTexRefSetFlags": r...
go
func flagType(name string) string { switch name { case "cuCtxCreate", "cuDevicePrimaryCtxSetFlags": return "ContextFlags" case "cuLinkCreate": panic("Unhandled") case "cuStreamCreate", "cuStreamCreateWithPriority": return "StreamFlags" case "cuEventCreate": return "EventFlags" case "cuTexRefSetFlags": r...
[ "func", "flagType", "(", "name", "string", ")", "string", "{", "switch", "name", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "\"", "\"", "\n", "case", "\"", "\"", ":", "panic", "(", "\"", "\"", ")", "\n", "case", "\"", "\"", ",", "...
// flag type returns the correct flag type for the Go signatures
[ "flag", "type", "returns", "the", "correct", "flag", "type", "for", "the", "Go", "signatures" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/genlib/signature.go#L207-L223
127,449
gorgonia/cu
stream.go
MakeStream
func MakeStream(flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreate(&s.s, C.uint(flags))) return s, err }
go
func MakeStream(flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreate(&s.s, C.uint(flags))) return s, err }
[ "func", "MakeStream", "(", "flags", "StreamFlags", ")", "(", "Stream", ",", "error", ")", "{", "var", "s", "Stream", "\n", "err", ":=", "result", "(", "C", ".", "cuStreamCreate", "(", "&", "s", ".", "s", ",", "C", ".", "uint", "(", "flags", ")", ...
// MakeStream creates a stream. The flags determines the behaviors of the stream.
[ "MakeStream", "creates", "a", "stream", ".", "The", "flags", "determines", "the", "behaviors", "of", "the", "stream", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/stream.go#L23-L27
127,450
gorgonia/cu
stream.go
MakeStreamWithPriority
func MakeStreamWithPriority(priority int, flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreateWithPriority(&s.s, C.uint(flags), C.int(priority))) return s, err }
go
func MakeStreamWithPriority(priority int, flags StreamFlags) (Stream, error) { var s Stream err := result(C.cuStreamCreateWithPriority(&s.s, C.uint(flags), C.int(priority))) return s, err }
[ "func", "MakeStreamWithPriority", "(", "priority", "int", ",", "flags", "StreamFlags", ")", "(", "Stream", ",", "error", ")", "{", "var", "s", "Stream", "\n", "err", ":=", "result", "(", "C", ".", "cuStreamCreateWithPriority", "(", "&", "s", ".", "s", ",...
// MakeStreamWithPriority creates a stream with the given priority. The flags determines the behaviors of the stream. // This API alters the scheduler priority of work in the stream. Work in a higher priority stream may preempt work already executing in a low priority stream. // // `priority` follows a convention where...
[ "MakeStreamWithPriority", "creates", "a", "stream", "with", "the", "given", "priority", ".", "The", "flags", "determines", "the", "behaviors", "of", "the", "stream", ".", "This", "API", "alters", "the", "scheduler", "priority", "of", "work", "in", "the", "stre...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/stream.go#L37-L41
127,451
gorgonia/cu
cmd/gencudnn/generatethis.go
generateCRUD
func generateCRUD(buf io.Writer, t *cc.TranslationUnit, fnType string) { decls, err := bindgen.Get(t, functions) handleErr(err) var a = make(map[string][]string) switch fnType { case "create": fmt.Fprintf(buf, "creations = ") case "get": fmt.Fprintf(buf, "getFns = ") case "set": fmt.Fprintf(buf, "setFns =...
go
func generateCRUD(buf io.Writer, t *cc.TranslationUnit, fnType string) { decls, err := bindgen.Get(t, functions) handleErr(err) var a = make(map[string][]string) switch fnType { case "create": fmt.Fprintf(buf, "creations = ") case "get": fmt.Fprintf(buf, "getFns = ") case "set": fmt.Fprintf(buf, "setFns =...
[ "func", "generateCRUD", "(", "buf", "io", ".", "Writer", ",", "t", "*", "cc", ".", "TranslationUnit", ",", "fnType", "string", ")", "{", "decls", ",", "err", ":=", "bindgen", ".", "Get", "(", "t", ",", "functions", ")", "\n", "handleErr", "(", "err",...
// generateCRUD creates lists of CRUD functions for the generateStubs function to consume
[ "generateCRUD", "creates", "lists", "of", "CRUD", "functions", "for", "the", "generateStubs", "function", "to", "consume" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/gencudnn/generatethis.go#L56-L139
127,452
gorgonia/cu
ctx.go
Close
func (ctx *Ctx) Close() error { var empty C.CUcontext if ctx.CUContext.ctx == empty { return nil } if ctx.errChan != nil { close(ctx.errChan) ctx.errChan = nil } if ctx.work != nil { close(ctx.work) ctx.work = nil } err := result(C.cuCtxDestroy(C.CUcontext(unsafe.Pointer(ctx.CUContext.ctx)))) ctx....
go
func (ctx *Ctx) Close() error { var empty C.CUcontext if ctx.CUContext.ctx == empty { return nil } if ctx.errChan != nil { close(ctx.errChan) ctx.errChan = nil } if ctx.work != nil { close(ctx.work) ctx.work = nil } err := result(C.cuCtxDestroy(C.CUcontext(unsafe.Pointer(ctx.CUContext.ctx)))) ctx....
[ "func", "(", "ctx", "*", "Ctx", ")", "Close", "(", ")", "error", "{", "var", "empty", "C", ".", "CUcontext", "\n", "if", "ctx", ".", "CUContext", ".", "ctx", "==", "empty", "{", "return", "nil", "\n", "}", "\n\n", "if", "ctx", ".", "errChan", "!=...
// Close destroys the CUDA context and associated resources that has been created. Additionally, all channels of communications will be closed.
[ "Close", "destroys", "the", "CUDA", "context", "and", "associated", "resources", "that", "has", "been", "created", ".", "Additionally", "all", "channels", "of", "communications", "will", "be", "closed", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/ctx.go#L84-L103
127,453
gorgonia/cu
dnn/pooling.go
NewPooling
func NewPooling(mode PoolingMode, maxpoolingNanOpt NanPropagation, shape, strides, padding []int) (retVal *Pooling, err error) { var internal C.cudnnPoolingDescriptor_t if err = result(C.cudnnCreatePoolingDescriptor(&internal)); err != nil { return nil, err } // checks shapes and strides if len(shape) != len(st...
go
func NewPooling(mode PoolingMode, maxpoolingNanOpt NanPropagation, shape, strides, padding []int) (retVal *Pooling, err error) { var internal C.cudnnPoolingDescriptor_t if err = result(C.cudnnCreatePoolingDescriptor(&internal)); err != nil { return nil, err } // checks shapes and strides if len(shape) != len(st...
[ "func", "NewPooling", "(", "mode", "PoolingMode", ",", "maxpoolingNanOpt", "NanPropagation", ",", "shape", ",", "strides", ",", "padding", "[", "]", "int", ")", "(", "retVal", "*", "Pooling", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "c...
// NewPooling creates a new Pooling op.
[ "NewPooling", "creates", "a", "new", "Pooling", "op", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/pooling.go#L31-L75
127,454
gorgonia/cu
dnn/pooling.go
OutputShape
func (p *Pooling) OutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { if dims == p.outDims && shapeEq(input.shape, p.inputTensor) { return cloneShape(p.outputShape), nil } return p.CalcOutputShape(input, dims) }
go
func (p *Pooling) OutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { if dims == p.outDims && shapeEq(input.shape, p.inputTensor) { return cloneShape(p.outputShape), nil } return p.CalcOutputShape(input, dims) }
[ "func", "(", "p", "*", "Pooling", ")", "OutputShape", "(", "input", "*", "TensorDescriptor", ",", "dims", "int", ")", "(", "retVal", "[", "]", "int", ",", "err", "error", ")", "{", "if", "dims", "==", "p", ".", "outDims", "&&", "shapeEq", "(", "inp...
// OutputShape computes the output shape given the input tensor. // // This method caches the outputShape. If a inputTensor is seen before, and the dims is exactly the same, then the cached output shape is used
[ "OutputShape", "computes", "the", "output", "shape", "given", "the", "input", "tensor", ".", "This", "method", "caches", "the", "outputShape", ".", "If", "a", "inputTensor", "is", "seen", "before", "and", "the", "dims", "is", "exactly", "the", "same", "then"...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/pooling.go#L95-L100
127,455
gorgonia/cu
dnn/pooling.go
CalcOutputShape
func (p *Pooling) CalcOutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { p.outDims = dims p.inputTensor = cloneShape(input.shape) switch dims { case 0: return nil, errors.Errorf("Cannot work on dims of 0") case 2: p.outputShape = make([]int, 4) n := (*C.int)(unsafe.Pointer(&p.outputS...
go
func (p *Pooling) CalcOutputShape(input *TensorDescriptor, dims int) (retVal []int, err error) { p.outDims = dims p.inputTensor = cloneShape(input.shape) switch dims { case 0: return nil, errors.Errorf("Cannot work on dims of 0") case 2: p.outputShape = make([]int, 4) n := (*C.int)(unsafe.Pointer(&p.outputS...
[ "func", "(", "p", "*", "Pooling", ")", "CalcOutputShape", "(", "input", "*", "TensorDescriptor", ",", "dims", "int", ")", "(", "retVal", "[", "]", "int", ",", "err", "error", ")", "{", "p", ".", "outDims", "=", "dims", "\n", "p", ".", "inputTensor", ...
// CalcOutputShape is like OutputShape, but doesn't go through a check for the cached value.
[ "CalcOutputShape", "is", "like", "OutputShape", "but", "doesn", "t", "go", "through", "a", "check", "for", "the", "cached", "value", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/pooling.go#L103-L129
127,456
gorgonia/cu
dnn/generated_activation.go
NewActivation
func NewActivation(mode ActivationMode, reluNanOpt NanPropagation, coef float64) (retVal *Activation, err error) { var internal C.cudnnActivationDescriptor_t if err := result(C.cudnnCreateActivationDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetActivationDescriptor(internal, mo...
go
func NewActivation(mode ActivationMode, reluNanOpt NanPropagation, coef float64) (retVal *Activation, err error) { var internal C.cudnnActivationDescriptor_t if err := result(C.cudnnCreateActivationDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetActivationDescriptor(internal, mo...
[ "func", "NewActivation", "(", "mode", "ActivationMode", ",", "reluNanOpt", "NanPropagation", ",", "coef", "float64", ")", "(", "retVal", "*", "Activation", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnActivationDescriptor_t", "\n", "if", "...
// NewActivation creates a new Activation.
[ "NewActivation", "creates", "a", "new", "Activation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_activation.go#L19-L37
127,457
gorgonia/cu
cucontext.go
Unlock
func (ctx CUContext) Unlock() error { if err := Synchronize(); err != nil { return err } runtime.UnlockOSThread() return nil }
go
func (ctx CUContext) Unlock() error { if err := Synchronize(); err != nil { return err } runtime.UnlockOSThread() return nil }
[ "func", "(", "ctx", "CUContext", ")", "Unlock", "(", ")", "error", "{", "if", "err", ":=", "Synchronize", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "runtime", ".", "UnlockOSThread", "(", ")", "\n", "return", "nil", "...
// Unlock unlocks unbinds the goroutine from the OS thread
[ "Unlock", "unlocks", "unbinds", "the", "goroutine", "from", "the", "OS", "thread" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cucontext.go#L57-L63
127,458
gorgonia/cu
dnn/generated_reduction.go
NewReduction
func NewReduction(reduceTensorOp ReduceTensorOp, reduceTensorCompType DataType, reduceTensorNanOpt NanPropagation, reduceTensorIndices ReduceTensorIndices, reduceTensorIndicesType IndicesType) (retVal *Reduction, err error) { var internal C.cudnnReduceTensorDescriptor_t if err := result(C.cudnnCreateReduceTensorDescr...
go
func NewReduction(reduceTensorOp ReduceTensorOp, reduceTensorCompType DataType, reduceTensorNanOpt NanPropagation, reduceTensorIndices ReduceTensorIndices, reduceTensorIndicesType IndicesType) (retVal *Reduction, err error) { var internal C.cudnnReduceTensorDescriptor_t if err := result(C.cudnnCreateReduceTensorDescr...
[ "func", "NewReduction", "(", "reduceTensorOp", "ReduceTensorOp", ",", "reduceTensorCompType", "DataType", ",", "reduceTensorNanOpt", "NanPropagation", ",", "reduceTensorIndices", "ReduceTensorIndices", ",", "reduceTensorIndicesType", "IndicesType", ")", "(", "retVal", "*", ...
// NewReduction creates a new Reduction.
[ "NewReduction", "creates", "a", "new", "Reduction", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_reduction.go#L21-L41
127,459
gorgonia/cu
cmd/gencudnn/conversion.go
FirstTensor
func (s GoSignature) FirstTensor() string { for _, p := range s.Params { if strings.Contains(p.Type, ctypes2GoTypes["cudnnTensorDescriptor_t"]) { return p.Name } } panic(fmt.Sprintf("No tensors to check in %v", s)) }
go
func (s GoSignature) FirstTensor() string { for _, p := range s.Params { if strings.Contains(p.Type, ctypes2GoTypes["cudnnTensorDescriptor_t"]) { return p.Name } } panic(fmt.Sprintf("No tensors to check in %v", s)) }
[ "func", "(", "s", "GoSignature", ")", "FirstTensor", "(", ")", "string", "{", "for", "_", ",", "p", ":=", "range", "s", ".", "Params", "{", "if", "strings", ".", "Contains", "(", "p", ".", "Type", ",", "ctypes2GoTypes", "[", "\"", "\"", "]", ")", ...
// FirstTensor finds the first tensor parameter of the function and returns the name
[ "FirstTensor", "finds", "the", "first", "tensor", "parameter", "of", "the", "function", "and", "returns", "the", "name" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/cmd/gencudnn/conversion.go#L79-L86
127,460
gorgonia/cu
blas/blas.go
Isamax
func (impl *Standard) Isamax(n int, x []float32, incX int) (retVal int) { // declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 ...
go
func (impl *Standard) Isamax(n int, x []float32, incX int) (retVal int) { // declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 ...
[ "func", "(", "impl", "*", "Standard", ")", "Isamax", "(", "n", "int", ",", "x", "[", "]", "float32", ",", "incX", "int", ")", "(", "retVal", "int", ")", "{", "// declared at cublasgen.h:384:17 enum CUBLAS_STATUS { ... } cublasIsamax ...", "if", "impl", ".", "e...
// Isamax returns the index of an element of x with the largest absolute value. // If there are multiple such indices the earliest is returned. // Isamax returns -1 if n == 0.
[ "Isamax", "returns", "the", "index", "of", "an", "element", "of", "x", "with", "the", "largest", "absolute", "value", ".", "If", "there", "are", "multiple", "such", "indices", "the", "earliest", "is", "returned", ".", "Isamax", "returns", "-", "1", "if", ...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/blas/blas.go#L911-L935
127,461
gorgonia/cu
blas/blas.go
Idamax
func (impl *Standard) Idamax(n int, x []float64, incX int) (retVal int) { // declared at cublasgen.h:390:17 enum CUBLAS_STATUS { ... } cublasIdamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 ...
go
func (impl *Standard) Idamax(n int, x []float64, incX int) (retVal int) { // declared at cublasgen.h:390:17 enum CUBLAS_STATUS { ... } cublasIdamax ... if impl.e != nil { return } if n < 0 { panic("blas: n < 0") } if incX == 0 { panic("blas: zero x index increment") } if n == 0 || incX < 0 { return -1 ...
[ "func", "(", "impl", "*", "Standard", ")", "Idamax", "(", "n", "int", ",", "x", "[", "]", "float64", ",", "incX", "int", ")", "(", "retVal", "int", ")", "{", "// declared at cublasgen.h:390:17 enum CUBLAS_STATUS { ... } cublasIdamax ...", "if", "impl", ".", "e...
// Idamax returns the index of an element of x with the largest absolute value. // If there are multiple such indices the earliest is returned. // Idamax returns -1 if n == 0.
[ "Idamax", "returns", "the", "index", "of", "an", "element", "of", "x", "with", "the", "largest", "absolute", "value", ".", "If", "there", "are", "multiple", "such", "indices", "the", "earliest", "is", "returned", ".", "Idamax", "returns", "-", "1", "if", ...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/blas/blas.go#L940-L964
127,462
gorgonia/cu
dnn/handle.go
NewContext
func NewContext() (retVal *Context) { var internal C.cudnnHandle_t if err := result(C.cudnnCreate(&internal)); err != nil { panic(err) } retVal = &Context{internal} return retVal }
go
func NewContext() (retVal *Context) { var internal C.cudnnHandle_t if err := result(C.cudnnCreate(&internal)); err != nil { panic(err) } retVal = &Context{internal} return retVal }
[ "func", "NewContext", "(", ")", "(", "retVal", "*", "Context", ")", "{", "var", "internal", "C", ".", "cudnnHandle_t", "\n", "if", "err", ":=", "result", "(", "C", ".", "cudnnCreate", "(", "&", "internal", ")", ")", ";", "err", "!=", "nil", "{", "p...
// NewContext creates a new Context. This is the only function that will panic if it is unable to create the context.
[ "NewContext", "creates", "a", "new", "Context", ".", "This", "is", "the", "only", "function", "that", "will", "panic", "if", "it", "is", "unable", "to", "create", "the", "context", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/handle.go#L27-L34
127,463
gorgonia/cu
dnn/handle.go
Close
func (ctx *Context) Close() error { var empty C.cudnnHandle_t if ctx.internal == empty { return nil } if err := result(C.cudnnDestroy(ctx.internal)); err != nil { return err } ctx.internal = empty return nil }
go
func (ctx *Context) Close() error { var empty C.cudnnHandle_t if ctx.internal == empty { return nil } if err := result(C.cudnnDestroy(ctx.internal)); err != nil { return err } ctx.internal = empty return nil }
[ "func", "(", "ctx", "*", "Context", ")", "Close", "(", ")", "error", "{", "var", "empty", "C", ".", "cudnnHandle_t", "\n", "if", "ctx", ".", "internal", "==", "empty", "{", "return", "nil", "\n", "}", "\n\n", "if", "err", ":=", "result", "(", "C", ...
// Close destroys the underlying context.
[ "Close", "destroys", "the", "underlying", "context", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/handle.go#L37-L48
127,464
gorgonia/cu
dnn/generated_API.go
RestoreDropoutDescriptor
func (dr *Dropout) RestoreDropoutDescriptor(handle *Context, dropout float32, states Memory, stateSizeInBytes uintptr, seed uint64) error { // call cudnnRestoreDropoutDescriptor return result(C.cudnnRestoreDropoutDescriptor(dr.internal, handle.internal, C.float(dropout), states.Pointer(), C.size_t(stateSizeInBytes), ...
go
func (dr *Dropout) RestoreDropoutDescriptor(handle *Context, dropout float32, states Memory, stateSizeInBytes uintptr, seed uint64) error { // call cudnnRestoreDropoutDescriptor return result(C.cudnnRestoreDropoutDescriptor(dr.internal, handle.internal, C.float(dropout), states.Pointer(), C.size_t(stateSizeInBytes), ...
[ "func", "(", "dr", "*", "Dropout", ")", "RestoreDropoutDescriptor", "(", "handle", "*", "Context", ",", "dropout", "float32", ",", "states", "Memory", ",", "stateSizeInBytes", "uintptr", ",", "seed", "uint64", ")", "error", "{", "// call cudnnRestoreDropoutDescrip...
// RestoreDropoutDescriptor restores a dropout descriptor to a previously saved-off state.
[ "RestoreDropoutDescriptor", "restores", "a", "dropout", "descriptor", "to", "a", "previously", "saved", "-", "off", "state", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L14-L17
127,465
gorgonia/cu
dnn/generated_API.go
AddTensor
func (co *Context) AddTensor(alpha float64, aDesc *TensorDescriptor, A Memory, beta float64, cDesc *TensorDescriptor, C_ Memory) error { var alphaC, betaC unsafe.Pointer switch aDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC ...
go
func (co *Context) AddTensor(alpha float64, aDesc *TensorDescriptor, A Memory, beta float64, cDesc *TensorDescriptor, C_ Memory) error { var alphaC, betaC unsafe.Pointer switch aDesc.dataType { case Float, Half: var alphaF, betaF C.float alphaF = C.float(float32(alpha)) betaF = C.float(float32(beta)) alphaC ...
[ "func", "(", "co", "*", "Context", ")", "AddTensor", "(", "alpha", "float64", ",", "aDesc", "*", "TensorDescriptor", ",", "A", "Memory", ",", "beta", "float64", ",", "cDesc", "*", "TensorDescriptor", ",", "C_", "Memory", ")", "error", "{", "var", "alphaC...
// AddTensor adds the scaled values of a bias tensor to another tensor. Each dimension of the bias tensor A must match the corresponding dimension of the destination tensor C or must be equal to 1. In the latter case, the same value from the bias tensor for those dimensions will be used to blend into the C tensor. // C...
[ "AddTensor", "adds", "the", "scaled", "values", "of", "a", "bias", "tensor", "to", "another", "tensor", ".", "Each", "dimension", "of", "the", "bias", "tensor", "A", "must", "match", "the", "corresponding", "dimension", "of", "the", "destination", "tensor", ...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L53-L73
127,466
gorgonia/cu
dnn/generated_API.go
GetReductionIndicesSize
func (co *Context) GetReductionIndicesSize(reduceTensorDesc *Reduction, aDesc *TensorDescriptor, cDesc *TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetReductionIndicesSize err = result(C.cudnnGetReductionIndicesSize(co.internal, reduceTensorDesc.internal, aDesc.interna...
go
func (co *Context) GetReductionIndicesSize(reduceTensorDesc *Reduction, aDesc *TensorDescriptor, cDesc *TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetReductionIndicesSize err = result(C.cudnnGetReductionIndicesSize(co.internal, reduceTensorDesc.internal, aDesc.interna...
[ "func", "(", "co", "*", "Context", ")", "GetReductionIndicesSize", "(", "reduceTensorDesc", "*", "Reduction", ",", "aDesc", "*", "TensorDescriptor", ",", "cDesc", "*", "TensorDescriptor", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var"...
// GetReductionIndicesSize is a helper function to return the minimum size of the index space to be passed to the reduction given the input and output tensors.
[ "GetReductionIndicesSize", "is", "a", "helper", "function", "to", "return", "the", "minimum", "size", "of", "the", "index", "space", "to", "be", "passed", "to", "the", "reduction", "given", "the", "input", "and", "output", "tensors", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L104-L110
127,467
gorgonia/cu
dnn/generated_API.go
ScaleTensor
func (co *Context) ScaleTensor(yDesc *TensorDescriptor, y Memory, alpha float64) error { var alphaC unsafe.Pointer switch yDesc.dataType { case Float, Half: var alphaF C.float alphaF = C.float(float32(alpha)) alphaC = unsafe.Pointer(&alphaF) case Double: var alphaF C.double alphaF = C.double(alpha) alph...
go
func (co *Context) ScaleTensor(yDesc *TensorDescriptor, y Memory, alpha float64) error { var alphaC unsafe.Pointer switch yDesc.dataType { case Float, Half: var alphaF C.float alphaF = C.float(float32(alpha)) alphaC = unsafe.Pointer(&alphaF) case Double: var alphaF C.double alphaF = C.double(alpha) alph...
[ "func", "(", "co", "*", "Context", ")", "ScaleTensor", "(", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ",", "alpha", "float64", ")", "error", "{", "var", "alphaC", "unsafe", ".", "Pointer", "\n", "switch", "yDesc", ".", "dataType", "{", "case"...
// ScaleTensor scale all the elements of a tensor by a given factor. // y is both an input and output
[ "ScaleTensor", "scale", "all", "the", "elements", "of", "a", "tensor", "by", "a", "given", "factor", ".", "y", "is", "both", "an", "input", "and", "output" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L148-L164
127,468
gorgonia/cu
dnn/generated_API.go
ConvolutionBackwardBias
func (co *Context) ConvolutionBackwardBias(alpha float64, dyDesc *TensorDescriptor, dy Memory, beta float64, dbDesc *TensorDescriptor, db Memory) error { // DOUBLECHECK: "cudnnConvolutionBackwardBias" returns Memory type in Parameter 6 var alphaC, betaC unsafe.Pointer switch dyDesc.dataType { case Float, Half: va...
go
func (co *Context) ConvolutionBackwardBias(alpha float64, dyDesc *TensorDescriptor, dy Memory, beta float64, dbDesc *TensorDescriptor, db Memory) error { // DOUBLECHECK: "cudnnConvolutionBackwardBias" returns Memory type in Parameter 6 var alphaC, betaC unsafe.Pointer switch dyDesc.dataType { case Float, Half: va...
[ "func", "(", "co", "*", "Context", ")", "ConvolutionBackwardBias", "(", "alpha", "float64", ",", "dyDesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "beta", "float64", ",", "dbDesc", "*", "TensorDescriptor", ",", "db", "Memory", ")", "error", "{", ...
// ConvolutionBackwardBias computes the convolution function gradient with respect to the bias, which is the sum of every element belonging to the same feature map across all of the images of the input tensor. Therefore, the number of elements produced is equal to the number of features maps of the input tensor.
[ "ConvolutionBackwardBias", "computes", "the", "convolution", "function", "gradient", "with", "respect", "to", "the", "bias", "which", "is", "the", "sum", "of", "every", "element", "belonging", "to", "the", "same", "feature", "map", "across", "all", "of", "the", ...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L237-L258
127,469
gorgonia/cu
dnn/generated_API.go
SoftmaxForward
func (co *Context) SoftmaxForward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSoftmaxForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case...
go
func (co *Context) SoftmaxForward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSoftmaxForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType { case...
[ "func", "(", "co", "*", "Context", ")", "SoftmaxForward", "(", "algo", "SoftmaxAlgorithm", ",", "mode", "SoftmaxMode", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "beta", "float64", ",", "yDesc", "*", "TensorDescr...
// SoftmaxForward computes the softmax function.
[ "SoftmaxForward", "computes", "the", "softmax", "function", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L358-L379
127,470
gorgonia/cu
dnn/generated_API.go
SoftmaxBackward
func (co *Context) SoftmaxBackward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, yDesc *TensorDescriptor, y Memory, dyDesc *TensorDescriptor, dy Memory, beta float64, dxDesc *TensorDescriptor, dx Memory) error { // DOUBLECHECK: "cudnnSoftmaxBackward" returns Memory type in Parameter 10 var alphaC, betaC uns...
go
func (co *Context) SoftmaxBackward(algo SoftmaxAlgorithm, mode SoftmaxMode, alpha float64, yDesc *TensorDescriptor, y Memory, dyDesc *TensorDescriptor, dy Memory, beta float64, dxDesc *TensorDescriptor, dx Memory) error { // DOUBLECHECK: "cudnnSoftmaxBackward" returns Memory type in Parameter 10 var alphaC, betaC uns...
[ "func", "(", "co", "*", "Context", ")", "SoftmaxBackward", "(", "algo", "SoftmaxAlgorithm", ",", "mode", "SoftmaxMode", ",", "alpha", "float64", ",", "yDesc", "*", "TensorDescriptor", ",", "y", "Memory", ",", "dyDesc", "*", "TensorDescriptor", ",", "dy", "Me...
// SoftmaxBackward computes the gradient of the softmax function.
[ "SoftmaxBackward", "computes", "the", "gradient", "of", "the", "softmax", "function", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L382-L403
127,471
gorgonia/cu
dnn/generated_API.go
LRNCrossChannelForward
func (co *Context) LRNCrossChannelForward(normDesc *LRN, lrnMode LRNMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnLRNCrossChannelForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType ...
go
func (co *Context) LRNCrossChannelForward(normDesc *LRN, lrnMode LRNMode, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnLRNCrossChannelForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDesc.dataType ...
[ "func", "(", "co", "*", "Context", ")", "LRNCrossChannelForward", "(", "normDesc", "*", "LRN", ",", "lrnMode", "LRNMode", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "beta", "float64", ",", "yDesc", "*", "Tensor...
// LRNCrossChannelForward performs the forward LRN layer computation.
[ "LRNCrossChannelForward", "performs", "the", "forward", "LRN", "layer", "computation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L502-L523
127,472
gorgonia/cu
dnn/generated_API.go
DivisiveNormalizationBackward
func (co *Context) DivisiveNormalizationBackward(normDesc *LRN, mode DivNormMode, alpha float64, xDesc *TensorDescriptor, x Memory, means Memory, dy Memory, temp Memory, temp2 Memory, beta float64, dXdMeansDesc *TensorDescriptor, dx Memory, dMeans Memory) error { // DOUBLECHECK: "cudnnDivisiveNormalizationBackward" re...
go
func (co *Context) DivisiveNormalizationBackward(normDesc *LRN, mode DivNormMode, alpha float64, xDesc *TensorDescriptor, x Memory, means Memory, dy Memory, temp Memory, temp2 Memory, beta float64, dXdMeansDesc *TensorDescriptor, dx Memory, dMeans Memory) error { // DOUBLECHECK: "cudnnDivisiveNormalizationBackward" re...
[ "func", "(", "co", "*", "Context", ")", "DivisiveNormalizationBackward", "(", "normDesc", "*", "LRN", ",", "mode", "DivNormMode", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "means", "Memory", ",", "dy", "Memory",...
// DivisiveNormalizationBackward performs the backward DivisiveNormalization layer computation.
[ "DivisiveNormalizationBackward", "performs", "the", "backward", "DivisiveNormalization", "layer", "computation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L575-L596
127,473
gorgonia/cu
dnn/generated_API.go
BatchNormalizationForwardTraining
func (co *Context) BatchNormalizationForwardTraining(mode BatchNormMode, alpha float64, beta float64, xDesc *TensorDescriptor, x Memory, yDesc *TensorDescriptor, y Memory, bnScaleBiasMeanVarDesc *TensorDescriptor, bnScale Memory, bnBias Memory, exponentialAverageFactor float64, resultRunningMean Memory, resultRunningVa...
go
func (co *Context) BatchNormalizationForwardTraining(mode BatchNormMode, alpha float64, beta float64, xDesc *TensorDescriptor, x Memory, yDesc *TensorDescriptor, y Memory, bnScaleBiasMeanVarDesc *TensorDescriptor, bnScale Memory, bnBias Memory, exponentialAverageFactor float64, resultRunningMean Memory, resultRunningVa...
[ "func", "(", "co", "*", "Context", ")", "BatchNormalizationForwardTraining", "(", "mode", "BatchNormMode", ",", "alpha", "float64", ",", "beta", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "yDesc", "*", "TensorDescriptor", ",", "...
// BatchNormalizationForwardTraining performs the forward BatchNormalization layer computation for training phase.
[ "BatchNormalizationForwardTraining", "performs", "the", "forward", "BatchNormalization", "layer", "computation", "for", "training", "phase", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L599-L620
127,474
gorgonia/cu
dnn/generated_API.go
BatchNormalizationBackward
func (co *Context) BatchNormalizationBackward(mode BatchNormMode, alphaDataDiff float64, betaDataDiff float64, alphaParamDiff float64, betaParamDiff float64, xDesc *TensorDescriptor, x Memory, dyDesc *TensorDescriptor, dy Memory, dxDesc *TensorDescriptor, dx Memory, dBnScaleBiasDesc *TensorDescriptor, bnScale Memory, d...
go
func (co *Context) BatchNormalizationBackward(mode BatchNormMode, alphaDataDiff float64, betaDataDiff float64, alphaParamDiff float64, betaParamDiff float64, xDesc *TensorDescriptor, x Memory, dyDesc *TensorDescriptor, dy Memory, dxDesc *TensorDescriptor, dx Memory, dBnScaleBiasDesc *TensorDescriptor, bnScale Memory, d...
[ "func", "(", "co", "*", "Context", ")", "BatchNormalizationBackward", "(", "mode", "BatchNormMode", ",", "alphaDataDiff", "float64", ",", "betaDataDiff", "float64", ",", "alphaParamDiff", "float64", ",", "betaParamDiff", "float64", ",", "xDesc", "*", "TensorDescript...
// BatchNormalizationBackward performs the backward BatchNormalization layer computation.
[ "BatchNormalizationBackward", "performs", "the", "backward", "BatchNormalization", "layer", "computation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L646-L674
127,475
gorgonia/cu
dnn/generated_API.go
SpatialTfGridGeneratorForward
func (co *Context) SpatialTfGridGeneratorForward(stDesc *SpatialTransformer, theta Memory, grid Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorForward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorForward return result(C.cudnnSpatialTfGridGeneratorForward(co.internal, stDesc.int...
go
func (co *Context) SpatialTfGridGeneratorForward(stDesc *SpatialTransformer, theta Memory, grid Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorForward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorForward return result(C.cudnnSpatialTfGridGeneratorForward(co.internal, stDesc.int...
[ "func", "(", "co", "*", "Context", ")", "SpatialTfGridGeneratorForward", "(", "stDesc", "*", "SpatialTransformer", ",", "theta", "Memory", ",", "grid", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSpatialTfGridGeneratorForward\" returns Memory type in Parameter 3", ...
// SpatialTfGridGeneratorForward generates a grid of coordinates in the input tensor corresponding to each pixel from the output tensor.
[ "SpatialTfGridGeneratorForward", "generates", "a", "grid", "of", "coordinates", "in", "the", "input", "tensor", "corresponding", "to", "each", "pixel", "from", "the", "output", "tensor", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L677-L681
127,476
gorgonia/cu
dnn/generated_API.go
SpatialTfGridGeneratorBackward
func (co *Context) SpatialTfGridGeneratorBackward(stDesc *SpatialTransformer, dgrid Memory, dtheta Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorBackward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorBackward return result(C.cudnnSpatialTfGridGeneratorBackward(co.internal, stDe...
go
func (co *Context) SpatialTfGridGeneratorBackward(stDesc *SpatialTransformer, dgrid Memory, dtheta Memory) error { // DOUBLECHECK: "cudnnSpatialTfGridGeneratorBackward" returns Memory type in Parameter 3 // call cudnnSpatialTfGridGeneratorBackward return result(C.cudnnSpatialTfGridGeneratorBackward(co.internal, stDe...
[ "func", "(", "co", "*", "Context", ")", "SpatialTfGridGeneratorBackward", "(", "stDesc", "*", "SpatialTransformer", ",", "dgrid", "Memory", ",", "dtheta", "Memory", ")", "error", "{", "// DOUBLECHECK: \"cudnnSpatialTfGridGeneratorBackward\" returns Memory type in Parameter 3"...
// SpatialTfGridGeneratorBackward computes the gradient of a grid generation operation.
[ "SpatialTfGridGeneratorBackward", "computes", "the", "gradient", "of", "a", "grid", "generation", "operation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L684-L688
127,477
gorgonia/cu
dnn/generated_API.go
SpatialTfSamplerForward
func (co *Context) SpatialTfSamplerForward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, grid Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSpatialTfSamplerForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDes...
go
func (co *Context) SpatialTfSamplerForward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, grid Memory, beta float64, yDesc *TensorDescriptor, y Memory) error { // DOUBLECHECK: "cudnnSpatialTfSamplerForward" returns Memory type in Parameter 8 var alphaC, betaC unsafe.Pointer switch xDes...
[ "func", "(", "co", "*", "Context", ")", "SpatialTfSamplerForward", "(", "stDesc", "*", "SpatialTransformer", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "grid", "Memory", ",", "beta", "float64", ",", "yDesc", "*",...
// SpatialTfSamplerForward performs a sampler operation and generates the output tensor using the grid given by the grid generator.
[ "SpatialTfSamplerForward", "performs", "a", "sampler", "operation", "and", "generates", "the", "output", "tensor", "using", "the", "grid", "given", "by", "the", "grid", "generator", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L691-L712
127,478
gorgonia/cu
dnn/generated_API.go
SpatialTfSamplerBackward
func (co *Context) SpatialTfSamplerBackward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, dxDesc *TensorDescriptor, dx Memory, alphaDgrid Memory, dyDesc *TensorDescriptor, dy Memory, grid Memory, betaDgrid Memory, dgrid Memory) error { // DOUBLECHECK: "cudnnSpatialTfSample...
go
func (co *Context) SpatialTfSamplerBackward(stDesc *SpatialTransformer, alpha float64, xDesc *TensorDescriptor, x Memory, beta float64, dxDesc *TensorDescriptor, dx Memory, alphaDgrid Memory, dyDesc *TensorDescriptor, dy Memory, grid Memory, betaDgrid Memory, dgrid Memory) error { // DOUBLECHECK: "cudnnSpatialTfSample...
[ "func", "(", "co", "*", "Context", ")", "SpatialTfSamplerBackward", "(", "stDesc", "*", "SpatialTransformer", ",", "alpha", "float64", ",", "xDesc", "*", "TensorDescriptor", ",", "x", "Memory", ",", "beta", "float64", ",", "dxDesc", "*", "TensorDescriptor", ",...
// SpatialTfSamplerBackward computes the gradient of a sampling operation.
[ "SpatialTfSamplerBackward", "computes", "the", "gradient", "of", "a", "sampling", "operation", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L715-L736
127,479
gorgonia/cu
dnn/generated_API.go
DropoutGetStatesSize
func (co *Context) DropoutGetStatesSize() (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnDropoutGetStatesSize err = result(C.cudnnDropoutGetStatesSize(co.internal, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
go
func (co *Context) DropoutGetStatesSize() (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnDropoutGetStatesSize err = result(C.cudnnDropoutGetStatesSize(co.internal, &sizeInBytesC)) sizeInBytes = uintptr(sizeInBytesC) return }
[ "func", "(", "co", "*", "Context", ")", "DropoutGetStatesSize", "(", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", "C", ".", "size_t", "\n", "// call cudnnDropoutGetStatesSize", "err", "=", "result", "(", "C", ".",...
// DropoutGetStatesSize is used to query the amount of space required to store the states of the random number generators used by cudnnDropoutForward function.
[ "DropoutGetStatesSize", "is", "used", "to", "query", "the", "amount", "of", "space", "required", "to", "store", "the", "states", "of", "the", "random", "number", "generators", "used", "by", "cudnnDropoutForward", "function", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L739-L745
127,480
gorgonia/cu
dnn/generated_API.go
DropoutBackward
func (co *Context) DropoutBackward(dropoutDesc *Dropout, dydesc *TensorDescriptor, dy Memory, dxdesc *TensorDescriptor, dx Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnDropoutBackward" returns Memory type in Parameter 5 // call cudnnDropoutBackward return result(C.cudnn...
go
func (co *Context) DropoutBackward(dropoutDesc *Dropout, dydesc *TensorDescriptor, dy Memory, dxdesc *TensorDescriptor, dx Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnDropoutBackward" returns Memory type in Parameter 5 // call cudnnDropoutBackward return result(C.cudnn...
[ "func", "(", "co", "*", "Context", ")", "DropoutBackward", "(", "dropoutDesc", "*", "Dropout", ",", "dydesc", "*", "TensorDescriptor", ",", "dy", "Memory", ",", "dxdesc", "*", "TensorDescriptor", ",", "dx", "Memory", ",", "reserveSpace", "Memory", ",", "rese...
// DropoutBackward performs backward dropout operation over dy returning results in dx. If during forward dropout operation value from x was propagated to y then during backward operation value from dy will be propagated to dx, otherwise, dx value will be set to 0.
[ "DropoutBackward", "performs", "backward", "dropout", "operation", "over", "dy", "returning", "results", "in", "dx", ".", "If", "during", "forward", "dropout", "operation", "value", "from", "x", "was", "propagated", "to", "y", "then", "during", "backward", "oper...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L755-L759
127,481
gorgonia/cu
dnn/generated_API.go
GetRNNWorkspaceSize
func (co *Context) GetRNNWorkspaceSize(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t if len(xDesc) != seqLength { return 0, errors.Errorf("Incorrect xDesc length. Want %d. Got %d", seqLength, len(xDesc)) } internals := make([]C.cudnnTensorDes...
go
func (co *Context) GetRNNWorkspaceSize(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t if len(xDesc) != seqLength { return 0, errors.Errorf("Incorrect xDesc length. Want %d. Got %d", seqLength, len(xDesc)) } internals := make([]C.cudnnTensorDes...
[ "func", "(", "co", "*", "Context", ")", "GetRNNWorkspaceSize", "(", "rnnDesc", "*", "RNN", ",", "seqLength", "int", ",", "xDesc", "[", "]", "*", "TensorDescriptor", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", ...
// GetRNNWorkspaceSize is used to query the amount of work space required to execute the RNN described by rnnDesc with inputs dimensions defined by xDesc.
[ "GetRNNWorkspaceSize", "is", "used", "to", "query", "the", "amount", "of", "work", "space", "required", "to", "execute", "the", "RNN", "described", "by", "rnnDesc", "with", "inputs", "dimensions", "defined", "by", "xDesc", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L762-L778
127,482
gorgonia/cu
dnn/generated_API.go
GetRNNParamsSize
func (co *Context) GetRNNParamsSize(rnnDesc *RNN, xDesc *TensorDescriptor, dataType DataType) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetRNNParamsSize err = result(C.cudnnGetRNNParamsSize(co.internal, rnnDesc.internal, xDesc.internal, &sizeInBytesC, dataType.C())) sizeInBytes = uin...
go
func (co *Context) GetRNNParamsSize(rnnDesc *RNN, xDesc *TensorDescriptor, dataType DataType) (sizeInBytes uintptr, err error) { var sizeInBytesC C.size_t // call cudnnGetRNNParamsSize err = result(C.cudnnGetRNNParamsSize(co.internal, rnnDesc.internal, xDesc.internal, &sizeInBytesC, dataType.C())) sizeInBytes = uin...
[ "func", "(", "co", "*", "Context", ")", "GetRNNParamsSize", "(", "rnnDesc", "*", "RNN", ",", "xDesc", "*", "TensorDescriptor", ",", "dataType", "DataType", ")", "(", "sizeInBytes", "uintptr", ",", "err", "error", ")", "{", "var", "sizeInBytesC", "C", ".", ...
// GetRNNParamsSize is used to query the amount of parameter space required to execute the RNN described by rnnDesc with inputs dimensions defined by xDesc.
[ "GetRNNParamsSize", "is", "used", "to", "query", "the", "amount", "of", "parameter", "space", "required", "to", "execute", "the", "RNN", "described", "by", "rnnDesc", "with", "inputs", "dimensions", "defined", "by", "xDesc", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L800-L806
127,483
gorgonia/cu
dnn/generated_API.go
RNNBackwardData
func (co *Context) RNNBackwardData(rnnDesc *RNN, seqLength int, yDesc []*TensorDescriptor, y Memory, dyDesc []*TensorDescriptor, dy Memory, dhyDesc *TensorDescriptor, dhy Memory, dcyDesc *TensorDescriptor, dcy Memory, wDesc *Filter, w Memory, hxDesc *TensorDescriptor, hx Memory, cxDesc *TensorDescriptor, cx Memory, dxD...
go
func (co *Context) RNNBackwardData(rnnDesc *RNN, seqLength int, yDesc []*TensorDescriptor, y Memory, dyDesc []*TensorDescriptor, dy Memory, dhyDesc *TensorDescriptor, dhy Memory, dcyDesc *TensorDescriptor, dcy Memory, wDesc *Filter, w Memory, hxDesc *TensorDescriptor, hx Memory, cxDesc *TensorDescriptor, cx Memory, dxD...
[ "func", "(", "co", "*", "Context", ")", "RNNBackwardData", "(", "rnnDesc", "*", "RNN", ",", "seqLength", "int", ",", "yDesc", "[", "]", "*", "TensorDescriptor", ",", "y", "Memory", ",", "dyDesc", "[", "]", "*", "TensorDescriptor", ",", "dy", "Memory", ...
// RNNBackwardData executes the recurrent neural network described by rnnDesc with output gradients dy, dhy, dhc, weights w and input gradients dx, dhx, dcx. workspace is required for intermediate storage. The data in reserveSpace must have previously been generated by cudnnRNNForwardTraining. The same reserveSpace dat...
[ "RNNBackwardData", "executes", "the", "recurrent", "neural", "network", "described", "by", "rnnDesc", "with", "output", "gradients", "dy", "dhy", "dhc", "weights", "w", "and", "input", "gradients", "dx", "dhx", "dcx", ".", "workspace", "is", "required", "for", ...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L870-L892
127,484
gorgonia/cu
dnn/generated_API.go
RNNBackwardWeights
func (co *Context) RNNBackwardWeights(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor, x Memory, hxDesc *TensorDescriptor, hx Memory, yDesc []*TensorDescriptor, y Memory, workspace Memory, workSpaceSizeInBytes uintptr, dwDesc *Filter, dw Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { inte...
go
func (co *Context) RNNBackwardWeights(rnnDesc *RNN, seqLength int, xDesc []*TensorDescriptor, x Memory, hxDesc *TensorDescriptor, hx Memory, yDesc []*TensorDescriptor, y Memory, workspace Memory, workSpaceSizeInBytes uintptr, dwDesc *Filter, dw Memory, reserveSpace Memory, reserveSpaceSizeInBytes uintptr) error { inte...
[ "func", "(", "co", "*", "Context", ")", "RNNBackwardWeights", "(", "rnnDesc", "*", "RNN", ",", "seqLength", "int", ",", "xDesc", "[", "]", "*", "TensorDescriptor", ",", "x", "Memory", ",", "hxDesc", "*", "TensorDescriptor", ",", "hx", "Memory", ",", "yDe...
// RNNBackwardWeights accumulates weight gradients dw from the recurrent neural network described by rnnDesc with inputs x, hx, and outputs y. The mode of operation in this case is additive, the weight gradients calculated will be added to those already existing in dw. workspace is required for intermediate storage. Th...
[ "RNNBackwardWeights", "accumulates", "weight", "gradients", "dw", "from", "the", "recurrent", "neural", "network", "described", "by", "rnnDesc", "with", "inputs", "x", "hx", "and", "outputs", "y", ".", "The", "mode", "of", "operation", "in", "this", "case", "i...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L896-L911
127,485
gorgonia/cu
dnn/generated_API.go
CTCLoss
func (co *Context) CTCLoss(probsDesc *TensorDescriptor, probs Memory, labels []int, labelLengths []int, inputLengths []int, costs Memory, gradientsDesc *TensorDescriptor, gradients Memory, algo CTCLossAlgo, ctcLossDesc *CTCLoss, workspace Memory, workSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnCTCLoss" ret...
go
func (co *Context) CTCLoss(probsDesc *TensorDescriptor, probs Memory, labels []int, labelLengths []int, inputLengths []int, costs Memory, gradientsDesc *TensorDescriptor, gradients Memory, algo CTCLossAlgo, ctcLossDesc *CTCLoss, workspace Memory, workSpaceSizeInBytes uintptr) error { // DOUBLECHECK: "cudnnCTCLoss" ret...
[ "func", "(", "co", "*", "Context", ")", "CTCLoss", "(", "probsDesc", "*", "TensorDescriptor", ",", "probs", "Memory", ",", "labels", "[", "]", "int", ",", "labelLengths", "[", "]", "int", ",", "inputLengths", "[", "]", "int", ",", "costs", "Memory", ",...
// CTCLoss returns the ctc costs and gradients, given the probabilities and labels.
[ "CTCLoss", "returns", "the", "ctc", "costs", "and", "gradients", "given", "the", "probabilities", "and", "labels", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_API.go#L914-L925
127,486
gorgonia/cu
batchedPatterns.go
LaunchAndSync
func (fn Function) LaunchAndSync(gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes int, stream Stream, kernelParams []unsafe.Pointer) error { argv := C.malloc(C.size_t(len(kernelParams) * pointerSize)) argp := C.malloc(C.size_t(len(kernelParams) * pointerSize)) defer C.free(argv) defer C...
go
func (fn Function) LaunchAndSync(gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes int, stream Stream, kernelParams []unsafe.Pointer) error { argv := C.malloc(C.size_t(len(kernelParams) * pointerSize)) argp := C.malloc(C.size_t(len(kernelParams) * pointerSize)) defer C.free(argv) defer C...
[ "func", "(", "fn", "Function", ")", "LaunchAndSync", "(", "gridDimX", ",", "gridDimY", ",", "gridDimZ", ",", "blockDimX", ",", "blockDimY", ",", "blockDimZ", ",", "sharedMemBytes", "int", ",", "stream", "Stream", ",", "kernelParams", "[", "]", "unsafe", ".",...
// LaunchAndSync launches the kernel and synchronizes the context
[ "LaunchAndSync", "launches", "the", "kernel", "and", "synchronizes", "the", "context" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batchedPatterns.go#L37-L60
127,487
gorgonia/cu
batchedPatterns.go
AllocAndCopy
func AllocAndCopy(p unsafe.Pointer, bytesize int64) (DevicePtr, error) { if bytesize == 0 { return 0, errors.Wrapf(InvalidValue, "Cannot allocate memory with size 0") } var d C.CUdeviceptr if err := result(C.cuAllocAndCopy(&d, p, C.size_t(bytesize))); err != nil { return 0, errors.Wrapf(err, "AllocAndCopy") }...
go
func AllocAndCopy(p unsafe.Pointer, bytesize int64) (DevicePtr, error) { if bytesize == 0 { return 0, errors.Wrapf(InvalidValue, "Cannot allocate memory with size 0") } var d C.CUdeviceptr if err := result(C.cuAllocAndCopy(&d, p, C.size_t(bytesize))); err != nil { return 0, errors.Wrapf(err, "AllocAndCopy") }...
[ "func", "AllocAndCopy", "(", "p", "unsafe", ".", "Pointer", ",", "bytesize", "int64", ")", "(", "DevicePtr", ",", "error", ")", "{", "if", "bytesize", "==", "0", "{", "return", "0", ",", "errors", ".", "Wrapf", "(", "InvalidValue", ",", "\"", "\"", "...
// AllocAndCopy abstracts away the common pattern of allocating and then copying a Go slice to the GPU
[ "AllocAndCopy", "abstracts", "away", "the", "common", "pattern", "of", "allocating", "and", "then", "copying", "a", "Go", "slice", "to", "the", "GPU" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batchedPatterns.go#L63-L73
127,488
gorgonia/cu
batch.go
NewBatchedContext
func NewBatchedContext(c Context, d Device) *BatchedContext { return &BatchedContext{ Context: c, Device: d, workAvailable: make(chan struct{}, 1), work: make(chan call, workBufLen), queue: make([]call, 0, workBufLen), fns: make([]C.uintptr_t, 0, workBufLen), results: m...
go
func NewBatchedContext(c Context, d Device) *BatchedContext { return &BatchedContext{ Context: c, Device: d, workAvailable: make(chan struct{}, 1), work: make(chan call, workBufLen), queue: make([]call, 0, workBufLen), fns: make([]C.uintptr_t, 0, workBufLen), results: m...
[ "func", "NewBatchedContext", "(", "c", "Context", ",", "d", "Device", ")", "*", "BatchedContext", "{", "return", "&", "BatchedContext", "{", "Context", ":", "c", ",", "Device", ":", "d", ",", "workAvailable", ":", "make", "(", "chan", "struct", "{", "}",...
// NewBatchedContext creates a batched CUDA context.
[ "NewBatchedContext", "creates", "a", "batched", "CUDA", "context", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L154-L168
127,489
gorgonia/cu
batch.go
Run
func (ctx *BatchedContext) Run(errChan chan error) error { runtime.LockOSThread() defer runtime.UnlockOSThread() for { select { case <-ctx.workAvailable: ctx.DoWork() if err := ctx.Errors(); err != nil { if errChan == nil { return err } errChan <- err } case w := <-ctx.Work(): ctx...
go
func (ctx *BatchedContext) Run(errChan chan error) error { runtime.LockOSThread() defer runtime.UnlockOSThread() for { select { case <-ctx.workAvailable: ctx.DoWork() if err := ctx.Errors(); err != nil { if errChan == nil { return err } errChan <- err } case w := <-ctx.Work(): ctx...
[ "func", "(", "ctx", "*", "BatchedContext", ")", "Run", "(", "errChan", "chan", "error", ")", "error", "{", "runtime", ".", "LockOSThread", "(", ")", "\n", "defer", "runtime", ".", "UnlockOSThread", "(", ")", "\n", "for", "{", "select", "{", "case", "<-...
// Run manages the running of the BatchedContext. Because it's expected to run in a goroutine, an error channel is to be passed in
[ "Run", "manages", "the", "running", "of", "the", "BatchedContext", ".", "Because", "it", "s", "expected", "to", "run", "in", "a", "goroutine", "an", "error", "channel", "is", "to", "be", "passed", "in" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L272-L290
127,490
gorgonia/cu
batch.go
Cleanup
func (ctx *BatchedContext) Cleanup() { for i, f := range ctx.frees { C.free(f) ctx.frees[i] = nil } ctx.frees = ctx.frees[:0] }
go
func (ctx *BatchedContext) Cleanup() { for i, f := range ctx.frees { C.free(f) ctx.frees[i] = nil } ctx.frees = ctx.frees[:0] }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "Cleanup", "(", ")", "{", "for", "i", ",", "f", ":=", "range", "ctx", ".", "frees", "{", "C", ".", "free", "(", "f", ")", "\n", "ctx", ".", "frees", "[", "i", "]", "=", "nil", "\n", "}", "\n", ...
// Cleanup is the cleanup function. It cleans up all the ancilliary allocations that has happened for all the batched calls. // This method should be called when the context is done with - otherwise there'd be a lot of leaked memory. // // The main reason why this method exists is because there is no way to reliably fr...
[ "Cleanup", "is", "the", "cleanup", "function", ".", "It", "cleans", "up", "all", "the", "ancilliary", "allocations", "that", "has", "happened", "for", "all", "the", "batched", "calls", ".", "This", "method", "should", "be", "called", "when", "the", "context"...
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L296-L302
127,491
gorgonia/cu
batch.go
Close
func (ctx *BatchedContext) Close() error { ctx.initialized = false return ctx.Context.Close() }
go
func (ctx *BatchedContext) Close() error { ctx.initialized = false return ctx.Context.Close() }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "Close", "(", ")", "error", "{", "ctx", ".", "initialized", "=", "false", "\n", "return", "ctx", ".", "Context", ".", "Close", "(", ")", "\n", "}" ]
// Close closes the batched context
[ "Close", "closes", "the", "batched", "context" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L305-L308
127,492
gorgonia/cu
batch.go
FirstError
func (ctx *BatchedContext) FirstError() error { for i, v := range ctx.results { if cuResult(v) != Success { return result(v) } ctx.results[i] = C.CUDA_SUCCESS } return nil }
go
func (ctx *BatchedContext) FirstError() error { for i, v := range ctx.results { if cuResult(v) != Success { return result(v) } ctx.results[i] = C.CUDA_SUCCESS } return nil }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "FirstError", "(", ")", "error", "{", "for", "i", ",", "v", ":=", "range", "ctx", ".", "results", "{", "if", "cuResult", "(", "v", ")", "!=", "Success", "{", "return", "result", "(", "v", ")", "\n", ...
// FirstError returns the first error if there was any
[ "FirstError", "returns", "the", "first", "error", "if", "there", "was", "any" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L314-L322
127,493
gorgonia/cu
batch.go
SetCurrent
func (ctx *BatchedContext) SetCurrent() { fn := &fnargs{ fn: C.fn_setCurrent, ctx: ctx.CUDAContext().ctx, } c := call{fn, false} ctx.enqueue(c) }
go
func (ctx *BatchedContext) SetCurrent() { fn := &fnargs{ fn: C.fn_setCurrent, ctx: ctx.CUDAContext().ctx, } c := call{fn, false} ctx.enqueue(c) }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "SetCurrent", "(", ")", "{", "fn", ":=", "&", "fnargs", "{", "fn", ":", "C", ".", "fn_setCurrent", ",", "ctx", ":", "ctx", ".", "CUDAContext", "(", ")", ".", "ctx", ",", "}", "\n", "c", ":=", "call"...
// SetCurrent sets the current context. This is usually unnecessary because SetCurrent will be called before batch processing the calls.
[ "SetCurrent", "sets", "the", "current", "context", ".", "This", "is", "usually", "unnecessary", "because", "SetCurrent", "will", "be", "called", "before", "batch", "processing", "the", "calls", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L325-L332
127,494
gorgonia/cu
batch.go
MemAlloc
func (ctx *BatchedContext) MemAlloc(bytesize int64) (retVal DevicePtr, err error) { fn := &fnargs{ fn: C.fn_mallocD, size: C.size_t(bytesize), } c := call{fn, true} return ctx.enqueue(c) }
go
func (ctx *BatchedContext) MemAlloc(bytesize int64) (retVal DevicePtr, err error) { fn := &fnargs{ fn: C.fn_mallocD, size: C.size_t(bytesize), } c := call{fn, true} return ctx.enqueue(c) }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "MemAlloc", "(", "bytesize", "int64", ")", "(", "retVal", "DevicePtr", ",", "err", "error", ")", "{", "fn", ":=", "&", "fnargs", "{", "fn", ":", "C", ".", "fn_mallocD", ",", "size", ":", "C", ".", "si...
// MemAlloc allocates memory. It is a blocking call.
[ "MemAlloc", "allocates", "memory", ".", "It", "is", "a", "blocking", "call", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L335-L342
127,495
gorgonia/cu
batch.go
errors
func (ctx *BatchedContext) errors() error { if !ctx.checkResults() { return nil } err := make(errorSlice, len(ctx.results)) for i, res := range ctx.results { err[i] = result(res) } return err }
go
func (ctx *BatchedContext) errors() error { if !ctx.checkResults() { return nil } err := make(errorSlice, len(ctx.results)) for i, res := range ctx.results { err[i] = result(res) } return err }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "errors", "(", ")", "error", "{", "if", "!", "ctx", ".", "checkResults", "(", ")", "{", "return", "nil", "\n", "}", "\n", "err", ":=", "make", "(", "errorSlice", ",", "len", "(", "ctx", ".", "results"...
// errors convert ctx.results into errors
[ "errors", "convert", "ctx", ".", "results", "into", "errors" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L470-L479
127,496
gorgonia/cu
batch.go
introspect
func (ctx *BatchedContext) introspect() string { var buf bytes.Buffer fmt.Fprintf(&buf, "Queue: %d", len(ctx.queue)) for _, v := range ctx.queue { fmt.Fprintf(&buf, "\n\t[QUEUE] %s", v.fnargs) } return buf.String() }
go
func (ctx *BatchedContext) introspect() string { var buf bytes.Buffer fmt.Fprintf(&buf, "Queue: %d", len(ctx.queue)) for _, v := range ctx.queue { fmt.Fprintf(&buf, "\n\t[QUEUE] %s", v.fnargs) } return buf.String() }
[ "func", "(", "ctx", "*", "BatchedContext", ")", "introspect", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\"", ",", "len", "(", "ctx", ".", "queue", ")", ")", "\n", "for...
// introspect is useful for finding out what calls are going to be made in the batched call
[ "introspect", "is", "useful", "for", "finding", "out", "what", "calls", "are", "going", "to", "be", "made", "in", "the", "batched", "call" ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/batch.go#L482-L489
127,497
gorgonia/cu
dnn/generated_lrn.go
NewLRN
func NewLRN(lrnN uint, lrnAlpha float64, lrnBeta float64, lrnK float64) (retVal *LRN, err error) { var internal C.cudnnLRNDescriptor_t if err := result(C.cudnnCreateLRNDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetLRNDescriptor(internal, C.uint(lrnN), C.double(lrnAlpha), C.dou...
go
func NewLRN(lrnN uint, lrnAlpha float64, lrnBeta float64, lrnK float64) (retVal *LRN, err error) { var internal C.cudnnLRNDescriptor_t if err := result(C.cudnnCreateLRNDescriptor(&internal)); err != nil { return nil, err } if err := result(C.cudnnSetLRNDescriptor(internal, C.uint(lrnN), C.double(lrnAlpha), C.dou...
[ "func", "NewLRN", "(", "lrnN", "uint", ",", "lrnAlpha", "float64", ",", "lrnBeta", "float64", ",", "lrnK", "float64", ")", "(", "retVal", "*", "LRN", ",", "err", "error", ")", "{", "var", "internal", "C", ".", "cudnnLRNDescriptor_t", "\n", "if", "err", ...
// NewLRN creates a new LRN.
[ "NewLRN", "creates", "a", "new", "LRN", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/dnn/generated_lrn.go#L20-L39
127,498
gorgonia/cu
addressing.go
PtrAttribute
func (d DevicePtr) PtrAttribute(attr PointerAttribute) (unsafe.Pointer, error) { var p unsafe.Pointer devPtr := C.CUdeviceptr(d) a := C.CUpointer_attribute(attr) if err := result(C.cuPointerGetAttribute(p, a, devPtr)); err != nil { return nil, err } return p, nil }
go
func (d DevicePtr) PtrAttribute(attr PointerAttribute) (unsafe.Pointer, error) { var p unsafe.Pointer devPtr := C.CUdeviceptr(d) a := C.CUpointer_attribute(attr) if err := result(C.cuPointerGetAttribute(p, a, devPtr)); err != nil { return nil, err } return p, nil }
[ "func", "(", "d", "DevicePtr", ")", "PtrAttribute", "(", "attr", "PointerAttribute", ")", "(", "unsafe", ".", "Pointer", ",", "error", ")", "{", "var", "p", "unsafe", ".", "Pointer", "\n", "devPtr", ":=", "C", ".", "CUdeviceptr", "(", "d", ")", "\n", ...
// PtrAttribute returns information about a pointer.
[ "PtrAttribute", "returns", "information", "about", "a", "pointer", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/addressing.go#L90-L98
127,499
gorgonia/cu
instrumentation.go
AverageQueueLength
func AverageQueueLength() int { ql.Lock() var s int for _, l := range q { s += l } avg := s / len(q) // yes, it's an integer division ql.Unlock() return avg }
go
func AverageQueueLength() int { ql.Lock() var s int for _, l := range q { s += l } avg := s / len(q) // yes, it's an integer division ql.Unlock() return avg }
[ "func", "AverageQueueLength", "(", ")", "int", "{", "ql", ".", "Lock", "(", ")", "\n", "var", "s", "int", "\n", "for", "_", ",", "l", ":=", "range", "q", "{", "s", "+=", "l", "\n", "}", "\n", "avg", ":=", "s", "/", "len", "(", "q", ")", "//...
// AverageQueueLength returns the average queue length recorded. This allows for optimizations.
[ "AverageQueueLength", "returns", "the", "average", "queue", "length", "recorded", ".", "This", "allows", "for", "optimizations", "." ]
89152d7e441439045736bc7640ff607ec371c26c
https://github.com/gorgonia/cu/blob/89152d7e441439045736bc7640ff607ec371c26c/instrumentation.go#L47-L56