diff --git a/gocv/Godeps/Godeps.json b/gocv/Godeps/Godeps.json new file mode 100644 index 0000000..a3785d1 --- /dev/null +++ b/gocv/Godeps/Godeps.json @@ -0,0 +1,26 @@ +{ + "ImportPath": "github.com/lazywei/go-opencv/gocv", + "GoVersion": "go1.4.1", + "Deps": [ + { + "ImportPath": "github.com/davecgh/go-spew/spew", + "Rev": "1aaf839fb07e099361e445273993ccd9adc21b07" + }, + { + "ImportPath": "github.com/gonum/blas", + "Rev": "22132bfa8c9d291d8c11a6a817e4da1fa1c35c39" + }, + { + "ImportPath": "github.com/gonum/internal/asm", + "Rev": "9988c755e4ebb6828adce026d571114b6ee26a6b" + }, + { + "ImportPath": "github.com/gonum/matrix/mat64", + "Rev": "7c0d216f456e1c5fe498437367134ccdf6b35ded" + }, + { + "ImportPath": "github.com/stretchr/testify/assert", + "Rev": "f0b02af48e5ee31c78b949e9ed67c37e08d1a897" + } + ] +} diff --git a/gocv/Godeps/Readme b/gocv/Godeps/Readme new file mode 100644 index 0000000..4cdaa53 --- /dev/null +++ b/gocv/Godeps/Readme @@ -0,0 +1,5 @@ +This directory tree is generated automatically by godep. + +Please do not edit. + +See https://github.com/tools/godep for more information. diff --git a/gocv/Godeps/_workspace/.gitignore b/gocv/Godeps/_workspace/.gitignore new file mode 100644 index 0000000..f037d68 --- /dev/null +++ b/gocv/Godeps/_workspace/.gitignore @@ -0,0 +1,2 @@ +/pkg +/bin diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go new file mode 100644 index 0000000..0ce0df1 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "fmt" + "io" + "reflect" + "sort" + "strconv" + "unsafe" +) + +const ( + // ptrSize is the size of a pointer on the current arch. + ptrSize = unsafe.Sizeof((*byte)(nil)) +) + +var ( + // offsetPtr, offsetScalar, and offsetFlag are the offsets for the + // internal reflect.Value fields. These values are valid before golang + // commit ecccf07e7f9d which changed the format. The are also valid + // after commit 82f48826c6c7 which changed the format again to mirror + // the original format. Code in the init function updates these offsets + // as necessary. + offsetPtr = uintptr(ptrSize) + offsetScalar = uintptr(0) + offsetFlag = uintptr(ptrSize * 2) + + // flagKindWidth and flagKindShift indicate various bits that the + // reflect package uses internally to track kind information. + // + // flagRO indicates whether or not the value field of a reflect.Value is + // read-only. + // + // flagIndir indicates whether the value field of a reflect.Value is + // the actual data or a pointer to the data. + // + // These values are valid before golang commit 90a7c3c86944 which + // changed their positions. Code in the init function updates these + // flags as necessary. + flagKindWidth = uintptr(5) + flagKindShift = uintptr(flagKindWidth - 1) + flagRO = uintptr(1 << 0) + flagIndir = uintptr(1 << 1) +) + +func init() { + // Older versions of reflect.Value stored small integers directly in the + // ptr field (which is named val in the older versions). Versions + // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named + // scalar for this purpose which unfortunately came before the flag + // field, so the offset of the flag field is different for those + // versions. + // + // This code constructs a new reflect.Value from a known small integer + // and checks if the size of the reflect.Value struct indicates it has + // the scalar field. When it does, the offsets are updated accordingly. + vv := reflect.ValueOf(0xf00) + if unsafe.Sizeof(vv) == (ptrSize * 4) { + offsetScalar = ptrSize * 2 + offsetFlag = ptrSize * 3 + } + + // Commit 90a7c3c86944 changed the flag positions such that the low + // order bits are the kind. This code extracts the kind from the flags + // field and ensures it's the correct type. When it's not, the flag + // order has been changed to the newer format, so the flags are updated + // accordingly. + upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag) + upfv := *(*uintptr)(upf) + flagKindMask := uintptr((1<>flagKindShift != uintptr(reflect.Int) { + flagKindShift = 0 + flagRO = 1 << 5 + flagIndir = 1 << 6 + } +} + +// unsafeReflectValue converts the passed reflect.Value into a one that bypasses +// the typical safety restrictions preventing access to unaddressable and +// unexported data. It works by digging the raw pointer to the underlying +// value out of the protected value and generating a new unprotected (unsafe) +// reflect.Value to it. +// +// This allows us to check for implementations of the Stringer and error +// interfaces to be used for pretty printing ordinarily unaddressable and +// inaccessible values such as unexported struct fields. +func unsafeReflectValue(v reflect.Value) (rv reflect.Value) { + indirects := 1 + vt := v.Type() + upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr) + rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag)) + if rvf&flagIndir != 0 { + vt = reflect.PtrTo(v.Type()) + indirects++ + } else if offsetScalar != 0 { + // The value is in the scalar field when it's not one of the + // reference types. + switch vt.Kind() { + case reflect.Uintptr: + case reflect.Chan: + case reflect.Func: + case reflect.Map: + case reflect.Ptr: + case reflect.UnsafePointer: + default: + upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + + offsetScalar) + } + } + + pv := reflect.NewAt(vt, upv) + rv = pv + for i := 0; i < indirects; i++ { + rv = rv.Elem() + } + return rv +} + +// Some constants in the form of bytes to avoid string overhead. This mirrors +// the technique used in the fmt package. +var ( + panicBytes = []byte("(PANIC=") + plusBytes = []byte("+") + iBytes = []byte("i") + trueBytes = []byte("true") + falseBytes = []byte("false") + interfaceBytes = []byte("(interface {})") + commaNewlineBytes = []byte(",\n") + newlineBytes = []byte("\n") + openBraceBytes = []byte("{") + openBraceNewlineBytes = []byte("{\n") + closeBraceBytes = []byte("}") + asteriskBytes = []byte("*") + colonBytes = []byte(":") + colonSpaceBytes = []byte(": ") + openParenBytes = []byte("(") + closeParenBytes = []byte(")") + spaceBytes = []byte(" ") + pointerChainBytes = []byte("->") + nilAngleBytes = []byte("") + maxNewlineBytes = []byte("\n") + maxShortBytes = []byte("") + circularBytes = []byte("") + circularShortBytes = []byte("") + invalidAngleBytes = []byte("") + openBracketBytes = []byte("[") + closeBracketBytes = []byte("]") + percentBytes = []byte("%") + precisionBytes = []byte(".") + openAngleBytes = []byte("<") + closeAngleBytes = []byte(">") + openMapBytes = []byte("map[") + closeMapBytes = []byte("]") + lenEqualsBytes = []byte("len=") + capEqualsBytes = []byte("cap=") +) + +// hexDigits is used to map a decimal value to a hex digit. +var hexDigits = "0123456789abcdef" + +// catchPanic handles any panics that might occur during the handleMethods +// calls. +func catchPanic(w io.Writer, v reflect.Value) { + if err := recover(); err != nil { + w.Write(panicBytes) + fmt.Fprintf(w, "%v", err) + w.Write(closeParenBytes) + } +} + +// handleMethods attempts to call the Error and String methods on the underlying +// type the passed reflect.Value represents and outputes the result to Writer w. +// +// It handles panics in any called methods by catching and displaying the error +// as the formatted value. +func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) { + // We need an interface to check if the type implements the error or + // Stringer interface. However, the reflect package won't give us an + // interface on certain things like unexported struct fields in order + // to enforce visibility rules. We use unsafe to bypass these restrictions + // since this package does not mutate the values. + if !v.CanInterface() { + v = unsafeReflectValue(v) + } + + // Choose whether or not to do error and Stringer interface lookups against + // the base type or a pointer to the base type depending on settings. + // Technically calling one of these methods with a pointer receiver can + // mutate the value, however, types which choose to satisify an error or + // Stringer interface with a pointer receiver should not be mutating their + // state inside these interface methods. + var viface interface{} + if !cs.DisablePointerMethods { + if !v.CanAddr() { + v = unsafeReflectValue(v) + } + viface = v.Addr().Interface() + } else { + if v.CanAddr() { + v = v.Addr() + } + viface = v.Interface() + } + + // Is it an error or Stringer? + switch iface := viface.(type) { + case error: + defer catchPanic(w, v) + if cs.ContinueOnMethod { + w.Write(openParenBytes) + w.Write([]byte(iface.Error())) + w.Write(closeParenBytes) + w.Write(spaceBytes) + return false + } + + w.Write([]byte(iface.Error())) + return true + + case fmt.Stringer: + defer catchPanic(w, v) + if cs.ContinueOnMethod { + w.Write(openParenBytes) + w.Write([]byte(iface.String())) + w.Write(closeParenBytes) + w.Write(spaceBytes) + return false + } + w.Write([]byte(iface.String())) + return true + } + return false +} + +// printBool outputs a boolean value as true or false to Writer w. +func printBool(w io.Writer, val bool) { + if val { + w.Write(trueBytes) + } else { + w.Write(falseBytes) + } +} + +// printInt outputs a signed integer value to Writer w. +func printInt(w io.Writer, val int64, base int) { + w.Write([]byte(strconv.FormatInt(val, base))) +} + +// printUint outputs an unsigned integer value to Writer w. +func printUint(w io.Writer, val uint64, base int) { + w.Write([]byte(strconv.FormatUint(val, base))) +} + +// printFloat outputs a floating point value using the specified precision, +// which is expected to be 32 or 64bit, to Writer w. +func printFloat(w io.Writer, val float64, precision int) { + w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision))) +} + +// printComplex outputs a complex value using the specified float precision +// for the real and imaginary parts to Writer w. +func printComplex(w io.Writer, c complex128, floatPrecision int) { + r := real(c) + w.Write(openParenBytes) + w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision))) + i := imag(c) + if i >= 0 { + w.Write(plusBytes) + } + w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision))) + w.Write(iBytes) + w.Write(closeParenBytes) +} + +// printHexPtr outputs a uintptr formatted as hexidecimal with a leading '0x' +// prefix to Writer w. +func printHexPtr(w io.Writer, p uintptr) { + // Null pointer. + num := uint64(p) + if num == 0 { + w.Write(nilAngleBytes) + return + } + + // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix + buf := make([]byte, 18) + + // It's simpler to construct the hex string right to left. + base := uint64(16) + i := len(buf) - 1 + for num >= base { + buf[i] = hexDigits[num%base] + num /= base + i-- + } + buf[i] = hexDigits[num] + + // Add '0x' prefix. + i-- + buf[i] = 'x' + i-- + buf[i] = '0' + + // Strip unused leading bytes. + buf = buf[i:] + w.Write(buf) +} + +// valuesSorter implements sort.Interface to allow a slice of reflect.Value +// elements to be sorted. +type valuesSorter struct { + values []reflect.Value +} + +// Len returns the number of values in the slice. It is part of the +// sort.Interface implementation. +func (s *valuesSorter) Len() int { + return len(s.values) +} + +// Swap swaps the values at the passed indices. It is part of the +// sort.Interface implementation. +func (s *valuesSorter) Swap(i, j int) { + s.values[i], s.values[j] = s.values[j], s.values[i] +} + +// Less returns whether the value at index i should sort before the +// value at index j. It is part of the sort.Interface implementation. +func (s *valuesSorter) Less(i, j int) bool { + switch s.values[i].Kind() { + case reflect.Bool: + return !s.values[i].Bool() && s.values[j].Bool() + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + return s.values[i].Int() < s.values[j].Int() + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + return s.values[i].Uint() < s.values[j].Uint() + case reflect.Float32, reflect.Float64: + return s.values[i].Float() < s.values[j].Float() + case reflect.String: + return s.values[i].String() < s.values[j].String() + case reflect.Uintptr: + return s.values[i].Uint() < s.values[j].Uint() + } + return s.values[i].String() < s.values[j].String() +} + +// sortValues is a generic sort function for native types: int, uint, bool, +// string and uintptr. Other inputs are sorted according to their +// Value.String() value to ensure display stability. +func sortValues(values []reflect.Value) { + if len(values) == 0 { + return + } + sort.Sort(&valuesSorter{values}) +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common_test.go new file mode 100644 index 0000000..3bea81f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common_test.go @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew_test + +import ( + "fmt" + "github.com/davecgh/go-spew/spew" + "reflect" + "testing" +) + +// custom type to test Stinger interface on non-pointer receiver. +type stringer string + +// String implements the Stringer interface for testing invocation of custom +// stringers on types with non-pointer receivers. +func (s stringer) String() string { + return "stringer " + string(s) +} + +// custom type to test Stinger interface on pointer receiver. +type pstringer string + +// String implements the Stringer interface for testing invocation of custom +// stringers on types with only pointer receivers. +func (s *pstringer) String() string { + return "stringer " + string(*s) +} + +// xref1 and xref2 are cross referencing structs for testing circular reference +// detection. +type xref1 struct { + ps2 *xref2 +} +type xref2 struct { + ps1 *xref1 +} + +// indirCir1, indirCir2, and indirCir3 are used to generate an indirect circular +// reference for testing detection. +type indirCir1 struct { + ps2 *indirCir2 +} +type indirCir2 struct { + ps3 *indirCir3 +} +type indirCir3 struct { + ps1 *indirCir1 +} + +// embed is used to test embedded structures. +type embed struct { + a string +} + +// embedwrap is used to test embedded structures. +type embedwrap struct { + *embed + e *embed +} + +// panicer is used to intentionally cause a panic for testing spew properly +// handles them +type panicer int + +func (p panicer) String() string { + panic("test panic") +} + +// customError is used to test custom error interface invocation. +type customError int + +func (e customError) Error() string { + return fmt.Sprintf("error: %d", int(e)) +} + +// stringizeWants converts a slice of wanted test output into a format suitable +// for a test error message. +func stringizeWants(wants []string) string { + s := "" + for i, want := range wants { + if i > 0 { + s += fmt.Sprintf("want%d: %s", i+1, want) + } else { + s += "want: " + want + } + } + return s +} + +// testFailed returns whether or not a test failed by checking if the result +// of the test is in the slice of wanted strings. +func testFailed(result string, wants []string) bool { + for _, want := range wants { + if result == want { + return false + } + } + return true +} + +// TestSortValues ensures the sort functionality for relect.Value based sorting +// works as intended. +func TestSortValues(t *testing.T) { + getInterfaces := func(values []reflect.Value) []interface{} { + interfaces := []interface{}{} + for _, v := range values { + interfaces = append(interfaces, v.Interface()) + } + return interfaces + } + + v := reflect.ValueOf + + a := v("a") + b := v("b") + c := v("c") + embedA := v(embed{"a"}) + embedB := v(embed{"b"}) + embedC := v(embed{"c"}) + tests := []struct { + input []reflect.Value + expected []reflect.Value + }{ + // No values. + { + []reflect.Value{}, + []reflect.Value{}, + }, + // Bools. + { + []reflect.Value{v(false), v(true), v(false)}, + []reflect.Value{v(false), v(false), v(true)}, + }, + // Ints. + { + []reflect.Value{v(2), v(1), v(3)}, + []reflect.Value{v(1), v(2), v(3)}, + }, + // Uints. + { + []reflect.Value{v(uint8(2)), v(uint8(1)), v(uint8(3))}, + []reflect.Value{v(uint8(1)), v(uint8(2)), v(uint8(3))}, + }, + // Floats. + { + []reflect.Value{v(2.0), v(1.0), v(3.0)}, + []reflect.Value{v(1.0), v(2.0), v(3.0)}, + }, + // Strings. + { + []reflect.Value{b, a, c}, + []reflect.Value{a, b, c}, + }, + // Uintptrs. + { + []reflect.Value{v(uintptr(2)), v(uintptr(1)), v(uintptr(3))}, + []reflect.Value{v(uintptr(1)), v(uintptr(2)), v(uintptr(3))}, + }, + // Invalid. + { + []reflect.Value{embedB, embedA, embedC}, + []reflect.Value{embedB, embedA, embedC}, + }, + } + for _, test := range tests { + spew.SortValues(test.input) + // reflect.DeepEqual cannot really make sense of reflect.Value, + // probably because of all the pointer tricks. For instance, + // v(2.0) != v(2.0) on a 32-bits system. Turn them into interface{} + // instead. + input := getInterfaces(test.input) + expected := getInterfaces(test.expected) + if !reflect.DeepEqual(input, expected) { + t.Errorf("Sort mismatch:\n %v != %v", input, expected) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go new file mode 100644 index 0000000..e516675 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "fmt" + "io" + "os" +) + +// ConfigState houses the configuration options used by spew to format and +// display values. There is a global instance, Config, that is used to control +// all top-level Formatter and Dump functionality. Each ConfigState instance +// provides methods equivalent to the top-level functions. +// +// The zero value for ConfigState provides no indentation. You would typically +// want to set it to a space or a tab. +// +// Alternatively, you can use NewDefaultConfig to get a ConfigState instance +// with default settings. See the documentation of NewDefaultConfig for default +// values. +type ConfigState struct { + // Indent specifies the string to use for each indentation level. The + // global config instance that all top-level functions use set this to a + // single space by default. If you would like more indentation, you might + // set this to a tab with "\t" or perhaps two spaces with " ". + Indent string + + // MaxDepth controls the maximum number of levels to descend into nested + // data structures. The default, 0, means there is no limit. + // + // NOTE: Circular data structures are properly detected, so it is not + // necessary to set this value unless you specifically want to limit deeply + // nested data structures. + MaxDepth int + + // DisableMethods specifies whether or not error and Stringer interfaces are + // invoked for types that implement them. + DisableMethods bool + + // DisablePointerMethods specifies whether or not to check for and invoke + // error and Stringer interfaces on types which only accept a pointer + // receiver when the current type is not a pointer. + // + // NOTE: This might be an unsafe action since calling one of these methods + // with a pointer receiver could technically mutate the value, however, + // in practice, types which choose to satisify an error or Stringer + // interface with a pointer receiver should not be mutating their state + // inside these interface methods. + DisablePointerMethods bool + + // ContinueOnMethod specifies whether or not recursion should continue once + // a custom error or Stringer interface is invoked. The default, false, + // means it will print the results of invoking the custom error or Stringer + // interface and return immediately instead of continuing to recurse into + // the internals of the data type. + // + // NOTE: This flag does not have any effect if method invocation is disabled + // via the DisableMethods or DisablePointerMethods options. + ContinueOnMethod bool + + // SortKeys specifies map keys should be sorted before being printed. Use + // this to have a more deterministic, diffable output. Note that only + // native types (bool, int, uint, floats, uintptr and string) are supported + // with other types sorted according to the reflect.Value.String() output + // which guarantees display stability. + SortKeys bool +} + +// Config is the active configuration of the top-level functions. +// The configuration can be changed by modifying the contents of spew.Config. +var Config = ConfigState{Indent: " "} + +// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the formatted string as a value that satisfies error. See NewFormatter +// for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Errorf(format, c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Errorf(format string, a ...interface{}) (err error) { + return fmt.Errorf(format, c.convertArgs(a)...) +} + +// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Fprint(w, c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (n int, err error) { + return fmt.Fprint(w, c.convertArgs(a)...) +} + +// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Fprintf(w, format, c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { + return fmt.Fprintf(w, format, c.convertArgs(a)...) +} + +// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it +// passed with a Formatter interface returned by c.NewFormatter. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Fprintln(w, c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (n int, err error) { + return fmt.Fprintln(w, c.convertArgs(a)...) +} + +// Print is a wrapper for fmt.Print that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Print(c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Print(a ...interface{}) (n int, err error) { + return fmt.Print(c.convertArgs(a)...) +} + +// Printf is a wrapper for fmt.Printf that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Printf(format, c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Printf(format string, a ...interface{}) (n int, err error) { + return fmt.Printf(format, c.convertArgs(a)...) +} + +// Println is a wrapper for fmt.Println that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Println(c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Println(a ...interface{}) (n int, err error) { + return fmt.Println(c.convertArgs(a)...) +} + +// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the resulting string. See NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Sprint(c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Sprint(a ...interface{}) string { + return fmt.Sprint(c.convertArgs(a)...) +} + +// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were +// passed with a Formatter interface returned by c.NewFormatter. It returns +// the resulting string. See NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Sprintf(format, c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Sprintf(format string, a ...interface{}) string { + return fmt.Sprintf(format, c.convertArgs(a)...) +} + +// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it +// were passed with a Formatter interface returned by c.NewFormatter. It +// returns the resulting string. See NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Sprintln(c.NewFormatter(a), c.NewFormatter(b)) +func (c *ConfigState) Sprintln(a ...interface{}) string { + return fmt.Sprintln(c.convertArgs(a)...) +} + +/* +NewFormatter returns a custom formatter that satisfies the fmt.Formatter +interface. As a result, it integrates cleanly with standard fmt package +printing functions. The formatter is useful for inline printing of smaller data +types similar to the standard %v format specifier. + +The custom formatter only responds to the %v (most compact), %+v (adds pointer +addresses), %#v (adds types), and %#+v (adds types and pointer addresses) verb +combinations. Any other verbs such as %x and %q will be sent to the the +standard fmt package for formatting. In addition, the custom formatter ignores +the width and precision arguments (however they will still work on the format +specifiers not handled by the custom formatter). + +Typically this function shouldn't be called directly. It is much easier to make +use of the custom formatter by calling one of the convenience functions such as +c.Printf, c.Println, or c.Printf. +*/ +func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter { + return newFormatter(c, v) +} + +// Fdump formats and displays the passed arguments to io.Writer w. It formats +// exactly the same as Dump. +func (c *ConfigState) Fdump(w io.Writer, a ...interface{}) { + fdump(c, w, a...) +} + +/* +Dump displays the passed parameters to standard out with newlines, customizable +indentation, and additional debug information such as complete types and all +pointer addresses used to indirect to the final value. It provides the +following features over the built-in printing facilities provided by the fmt +package: + + * Pointers are dereferenced and followed + * Circular data structures are detected and handled properly + * Custom Stringer/error interfaces are optionally invoked, including + on unexported types + * Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + * Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output + +The configuration options are controlled by modifying the public members +of c. See ConfigState for options documentation. + +See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to +get the formatted result as a string. +*/ +func (c *ConfigState) Dump(a ...interface{}) { + fdump(c, os.Stdout, a...) +} + +// Sdump returns a string with the passed arguments formatted exactly the same +// as Dump. +func (c *ConfigState) Sdump(a ...interface{}) string { + var buf bytes.Buffer + fdump(c, &buf, a...) + return buf.String() +} + +// convertArgs accepts a slice of arguments and returns a slice of the same +// length with each argument converted to a spew Formatter interface using +// the ConfigState associated with s. +func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) { + formatters = make([]interface{}, len(args)) + for index, arg := range args { + formatters[index] = newFormatter(c, arg) + } + return formatters +} + +// NewDefaultConfig returns a ConfigState with the following default settings. +// +// Indent: " " +// MaxDepth: 0 +// DisableMethods: false +// DisablePointerMethods: false +// ContinueOnMethod: false +// SortKeys: false +func NewDefaultConfig() *ConfigState { + return &ConfigState{Indent: " "} +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/doc.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/doc.go new file mode 100644 index 0000000..a0d73ac --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/doc.go @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +Package spew implements a deep pretty printer for Go data structures to aid in +debugging. + +A quick overview of the additional features spew provides over the built-in +printing facilities for Go data types are as follows: + + * Pointers are dereferenced and followed + * Circular data structures are detected and handled properly + * Custom Stringer/error interfaces are optionally invoked, including + on unexported types + * Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + * Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output (only when using + Dump style) + +There are two different approaches spew allows for dumping Go data structures: + + * Dump style which prints with newlines, customizable indentation, + and additional debug information such as types and all pointer addresses + used to indirect to the final value + * A custom Formatter interface that integrates cleanly with the standard fmt + package and replaces %v, %+v, %#v, and %#+v to provide inline printing + similar to the default %v while providing the additional functionality + outlined above and passing unsupported format verbs such as %x and %q + along to fmt + +Quick Start + +This section demonstrates how to quickly get started with spew. See the +sections below for further details on formatting and configuration options. + +To dump a variable with full newlines, indentation, type, and pointer +information use Dump, Fdump, or Sdump: + spew.Dump(myVar1, myVar2, ...) + spew.Fdump(someWriter, myVar1, myVar2, ...) + str := spew.Sdump(myVar1, myVar2, ...) + +Alternatively, if you would prefer to use format strings with a compacted inline +printing style, use the convenience wrappers Printf, Fprintf, etc with +%v (most compact), %+v (adds pointer addresses), %#v (adds types), or +%#+v (adds types and pointer addresses): + spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) + spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) + spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) + spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) + +Configuration Options + +Configuration of spew is handled by fields in the ConfigState type. For +convenience, all of the top-level functions use a global state available +via the spew.Config global. + +It is also possible to create a ConfigState instance that provides methods +equivalent to the top-level functions. This allows concurrent configuration +options. See the ConfigState documentation for more details. + +The following configuration options are available: + * Indent + String to use for each indentation level for Dump functions. + It is a single space by default. A popular alternative is "\t". + + * MaxDepth + Maximum number of levels to descend into nested data structures. + There is no limit by default. + + * DisableMethods + Disables invocation of error and Stringer interface methods. + Method invocation is enabled by default. + + * DisablePointerMethods + Disables invocation of error and Stringer interface methods on types + which only accept pointer receivers from non-pointer variables. + Pointer method invocation is enabled by default. + + * ContinueOnMethod + Enables recursion into types after invoking error and Stringer interface + methods. Recursion after method invocation is disabled by default. + + * SortKeys + Specifies map keys should be sorted before being printed. Use + this to have a more deterministic, diffable output. Note that + only native types (bool, int, uint, floats, uintptr and string) + are supported with other types sorted according to the + reflect.Value.String() output which guarantees display stability. + Natural map order is used by default. + +Dump Usage + +Simply call spew.Dump with a list of variables you want to dump: + + spew.Dump(myVar1, myVar2, ...) + +You may also call spew.Fdump if you would prefer to output to an arbitrary +io.Writer. For example, to dump to standard error: + + spew.Fdump(os.Stderr, myVar1, myVar2, ...) + +A third option is to call spew.Sdump to get the formatted output as a string: + + str := spew.Sdump(myVar1, myVar2, ...) + +Sample Dump Output + +See the Dump example for details on the setup of the types and variables being +shown here. + + (main.Foo) { + unexportedField: (*main.Bar)(0xf84002e210)({ + flag: (main.Flag) flagTwo, + data: (uintptr) + }), + ExportedField: (map[interface {}]interface {}) (len=1) { + (string) (len=3) "one": (bool) true + } + } + +Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C +command as shown. + ([]uint8) (len=32 cap=32) { + 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | + 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| + 00000020 31 32 |12| + } + +Custom Formatter + +Spew provides a custom formatter that implements the fmt.Formatter interface +so that it integrates cleanly with standard fmt package printing functions. The +formatter is useful for inline printing of smaller data types similar to the +standard %v format specifier. + +The custom formatter only responds to the %v (most compact), %+v (adds pointer +addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb +combinations. Any other verbs such as %x and %q will be sent to the the +standard fmt package for formatting. In addition, the custom formatter ignores +the width and precision arguments (however they will still work on the format +specifiers not handled by the custom formatter). + +Custom Formatter Usage + +The simplest way to make use of the spew custom formatter is to call one of the +convenience functions such as spew.Printf, spew.Println, or spew.Printf. The +functions have syntax you are most likely already familiar with: + + spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) + spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) + spew.Println(myVar, myVar2) + spew.Fprintf(os.Stderr, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) + spew.Fprintf(os.Stderr, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) + +See the Index for the full list convenience functions. + +Sample Formatter Output + +Double pointer to a uint8: + %v: <**>5 + %+v: <**>(0xf8400420d0->0xf8400420c8)5 + %#v: (**uint8)5 + %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5 + +Pointer to circular struct with a uint8 field and a pointer to itself: + %v: <*>{1 <*>} + %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)} + %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)} + %#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)} + +See the Printf example for details on the setup of variables being shown +here. + +Errors + +Since it is possible for custom Stringer/error interfaces to panic, spew +detects them and handles them internally by printing the panic information +inline with the output. Since spew is intended to provide deep pretty printing +capabilities on structures, it intentionally does not return any errors. +*/ +package spew diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go new file mode 100644 index 0000000..983d23f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go @@ -0,0 +1,506 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "encoding/hex" + "fmt" + "io" + "os" + "reflect" + "regexp" + "strconv" + "strings" +) + +var ( + // uint8Type is a reflect.Type representing a uint8. It is used to + // convert cgo types to uint8 slices for hexdumping. + uint8Type = reflect.TypeOf(uint8(0)) + + // cCharRE is a regular expression that matches a cgo char. + // It is used to detect character arrays to hexdump them. + cCharRE = regexp.MustCompile("^.*\\._Ctype_char$") + + // cUnsignedCharRE is a regular expression that matches a cgo unsigned + // char. It is used to detect unsigned character arrays to hexdump + // them. + cUnsignedCharRE = regexp.MustCompile("^.*\\._Ctype_unsignedchar$") + + // cUint8tCharRE is a regular expression that matches a cgo uint8_t. + // It is used to detect uint8_t arrays to hexdump them. + cUint8tCharRE = regexp.MustCompile("^.*\\._Ctype_uint8_t$") +) + +// dumpState contains information about the state of a dump operation. +type dumpState struct { + w io.Writer + depth int + pointers map[uintptr]int + ignoreNextType bool + ignoreNextIndent bool + cs *ConfigState +} + +// indent performs indentation according to the depth level and cs.Indent +// option. +func (d *dumpState) indent() { + if d.ignoreNextIndent { + d.ignoreNextIndent = false + return + } + d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) +} + +// unpackValue returns values inside of non-nil interfaces when possible. +// This is useful for data types like structs, arrays, slices, and maps which +// can contain varying types packed inside an interface. +func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Interface && !v.IsNil() { + v = v.Elem() + } + return v +} + +// dumpPtr handles formatting of pointers by indirecting them as necessary. +func (d *dumpState) dumpPtr(v reflect.Value) { + // Remove pointers at or below the current depth from map used to detect + // circular refs. + for k, depth := range d.pointers { + if depth >= d.depth { + delete(d.pointers, k) + } + } + + // Keep list of all dereferenced pointers to show later. + pointerChain := make([]uintptr, 0) + + // Figure out how many levels of indirection there are by dereferencing + // pointers and unpacking interfaces down the chain while detecting circular + // references. + nilFound := false + cycleFound := false + indirects := 0 + ve := v + for ve.Kind() == reflect.Ptr { + if ve.IsNil() { + nilFound = true + break + } + indirects++ + addr := ve.Pointer() + pointerChain = append(pointerChain, addr) + if pd, ok := d.pointers[addr]; ok && pd < d.depth { + cycleFound = true + indirects-- + break + } + d.pointers[addr] = d.depth + + ve = ve.Elem() + if ve.Kind() == reflect.Interface { + if ve.IsNil() { + nilFound = true + break + } + ve = ve.Elem() + } + } + + // Display type information. + d.w.Write(openParenBytes) + d.w.Write(bytes.Repeat(asteriskBytes, indirects)) + d.w.Write([]byte(ve.Type().String())) + d.w.Write(closeParenBytes) + + // Display pointer information. + if len(pointerChain) > 0 { + d.w.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + d.w.Write(pointerChainBytes) + } + printHexPtr(d.w, addr) + } + d.w.Write(closeParenBytes) + } + + // Display dereferenced value. + d.w.Write(openParenBytes) + switch { + case nilFound == true: + d.w.Write(nilAngleBytes) + + case cycleFound == true: + d.w.Write(circularBytes) + + default: + d.ignoreNextType = true + d.dump(ve) + } + d.w.Write(closeParenBytes) +} + +// dumpSlice handles formatting of arrays and slices. Byte (uint8 under +// reflection) arrays and slices are dumped in hexdump -C fashion. +func (d *dumpState) dumpSlice(v reflect.Value) { + // Determine whether this type should be hex dumped or not. Also, + // for types which should be hexdumped, try to use the underlying data + // first, then fall back to trying to convert them to a uint8 slice. + var buf []uint8 + doConvert := false + doHexDump := false + numEntries := v.Len() + if numEntries > 0 { + vt := v.Index(0).Type() + vts := vt.String() + switch { + // C types that need to be converted. + case cCharRE.MatchString(vts): + fallthrough + case cUnsignedCharRE.MatchString(vts): + fallthrough + case cUint8tCharRE.MatchString(vts): + doConvert = true + + // Try to use existing uint8 slices and fall back to converting + // and copying if that fails. + case vt.Kind() == reflect.Uint8: + // We need an addressable interface to convert the type back + // into a byte slice. However, the reflect package won't give + // us an interface on certain things like unexported struct + // fields in order to enforce visibility rules. We use unsafe + // to bypass these restrictions since this package does not + // mutate the values. + vs := v + if !vs.CanInterface() || !vs.CanAddr() { + vs = unsafeReflectValue(vs) + } + vs = vs.Slice(0, numEntries) + + // Use the existing uint8 slice if it can be type + // asserted. + iface := vs.Interface() + if slice, ok := iface.([]uint8); ok { + buf = slice + doHexDump = true + break + } + + // The underlying data needs to be converted if it can't + // be type asserted to a uint8 slice. + doConvert = true + } + + // Copy and convert the underlying type if needed. + if doConvert && vt.ConvertibleTo(uint8Type) { + // Convert and copy each element into a uint8 byte + // slice. + buf = make([]uint8, numEntries) + for i := 0; i < numEntries; i++ { + vv := v.Index(i) + buf[i] = uint8(vv.Convert(uint8Type).Uint()) + } + doHexDump = true + } + } + + // Hexdump the entire slice as needed. + if doHexDump { + indent := strings.Repeat(d.cs.Indent, d.depth) + str := indent + hex.Dump(buf) + str = strings.Replace(str, "\n", "\n"+indent, -1) + str = strings.TrimRight(str, d.cs.Indent) + d.w.Write([]byte(str)) + return + } + + // Recursively call dump for each item. + for i := 0; i < numEntries; i++ { + d.dump(d.unpackValue(v.Index(i))) + if i < (numEntries - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } +} + +// dump is the main workhorse for dumping a value. It uses the passed reflect +// value to figure out what kind of object we are dealing with and formats it +// appropriately. It is a recursive function, however circular data structures +// are detected and handled properly. +func (d *dumpState) dump(v reflect.Value) { + // Handle invalid reflect values immediately. + kind := v.Kind() + if kind == reflect.Invalid { + d.w.Write(invalidAngleBytes) + return + } + + // Handle pointers specially. + if kind == reflect.Ptr { + d.indent() + d.dumpPtr(v) + return + } + + // Print type information unless already handled elsewhere. + if !d.ignoreNextType { + d.indent() + d.w.Write(openParenBytes) + d.w.Write([]byte(v.Type().String())) + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + d.ignoreNextType = false + + // Display length and capacity if the built-in len and cap functions + // work with the value's kind and the len/cap itself is non-zero. + valueLen, valueCap := 0, 0 + switch v.Kind() { + case reflect.Array, reflect.Slice, reflect.Chan: + valueLen, valueCap = v.Len(), v.Cap() + case reflect.Map, reflect.String: + valueLen = v.Len() + } + if valueLen != 0 || valueCap != 0 { + d.w.Write(openParenBytes) + if valueLen != 0 { + d.w.Write(lenEqualsBytes) + printInt(d.w, int64(valueLen), 10) + } + if valueCap != 0 { + if valueLen != 0 { + d.w.Write(spaceBytes) + } + d.w.Write(capEqualsBytes) + printInt(d.w, int64(valueCap), 10) + } + d.w.Write(closeParenBytes) + d.w.Write(spaceBytes) + } + + // Call Stringer/error interfaces if they exist and the handle methods flag + // is enabled + if !d.cs.DisableMethods { + if (kind != reflect.Invalid) && (kind != reflect.Interface) { + if handled := handleMethods(d.cs, d.w, v); handled { + return + } + } + } + + switch kind { + case reflect.Invalid: + // Do nothing. We should never get here since invalid has already + // been handled above. + + case reflect.Bool: + printBool(d.w, v.Bool()) + + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + printInt(d.w, v.Int(), 10) + + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + printUint(d.w, v.Uint(), 10) + + case reflect.Float32: + printFloat(d.w, v.Float(), 32) + + case reflect.Float64: + printFloat(d.w, v.Float(), 64) + + case reflect.Complex64: + printComplex(d.w, v.Complex(), 32) + + case reflect.Complex128: + printComplex(d.w, v.Complex(), 64) + + case reflect.Slice: + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + d.dumpSlice(v) + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.String: + d.w.Write([]byte(strconv.Quote(v.String()))) + + case reflect.Interface: + // The only time we should get here is for nil interfaces due to + // unpackValue calls. + if v.IsNil() { + d.w.Write(nilAngleBytes) + } + + case reflect.Ptr: + // Do nothing. We should never get here since pointers have already + // been handled above. + + case reflect.Map: + // nil maps should be indicated as different than empty maps + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + numEntries := v.Len() + keys := v.MapKeys() + if d.cs.SortKeys { + sortValues(keys) + } + for i, key := range keys { + d.dump(d.unpackValue(key)) + d.w.Write(colonSpaceBytes) + d.ignoreNextIndent = true + d.dump(d.unpackValue(v.MapIndex(key))) + if i < (numEntries - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.Struct: + d.w.Write(openBraceNewlineBytes) + d.depth++ + if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { + d.indent() + d.w.Write(maxNewlineBytes) + } else { + vt := v.Type() + numFields := v.NumField() + for i := 0; i < numFields; i++ { + d.indent() + vtf := vt.Field(i) + d.w.Write([]byte(vtf.Name)) + d.w.Write(colonSpaceBytes) + d.ignoreNextIndent = true + d.dump(d.unpackValue(v.Field(i))) + if i < (numFields - 1) { + d.w.Write(commaNewlineBytes) + } else { + d.w.Write(newlineBytes) + } + } + } + d.depth-- + d.indent() + d.w.Write(closeBraceBytes) + + case reflect.Uintptr: + printHexPtr(d.w, uintptr(v.Uint())) + + case reflect.UnsafePointer, reflect.Chan, reflect.Func: + printHexPtr(d.w, v.Pointer()) + + // There were not any other types at the time this code was written, but + // fall back to letting the default fmt package handle it in case any new + // types are added. + default: + if v.CanInterface() { + fmt.Fprintf(d.w, "%v", v.Interface()) + } else { + fmt.Fprintf(d.w, "%v", v.String()) + } + } +} + +// fdump is a helper function to consolidate the logic from the various public +// methods which take varying writers and config states. +func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { + for _, arg := range a { + if arg == nil { + w.Write(interfaceBytes) + w.Write(spaceBytes) + w.Write(nilAngleBytes) + w.Write(newlineBytes) + continue + } + + d := dumpState{w: w, cs: cs} + d.pointers = make(map[uintptr]int) + d.dump(reflect.ValueOf(arg)) + d.w.Write(newlineBytes) + } +} + +// Fdump formats and displays the passed arguments to io.Writer w. It formats +// exactly the same as Dump. +func Fdump(w io.Writer, a ...interface{}) { + fdump(&Config, w, a...) +} + +// Sdump returns a string with the passed arguments formatted exactly the same +// as Dump. +func Sdump(a ...interface{}) string { + var buf bytes.Buffer + fdump(&Config, &buf, a...) + return buf.String() +} + +/* +Dump displays the passed parameters to standard out with newlines, customizable +indentation, and additional debug information such as complete types and all +pointer addresses used to indirect to the final value. It provides the +following features over the built-in printing facilities provided by the fmt +package: + + * Pointers are dereferenced and followed + * Circular data structures are detected and handled properly + * Custom Stringer/error interfaces are optionally invoked, including + on unexported types + * Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + * Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output + +The configuration options are controlled by an exported package global, +spew.Config. See ConfigState for options documentation. + +See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to +get the formatted result as a string. +*/ +func Dump(a ...interface{}) { + fdump(&Config, os.Stdout, a...) +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump_test.go new file mode 100644 index 0000000..9e0e65f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump_test.go @@ -0,0 +1,986 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +Test Summary: +NOTE: For each test, a nil pointer, a single pointer and double pointer to the +base test element are also tested to ensure proper indirection across all types. + +- Max int8, int16, int32, int64, int +- Max uint8, uint16, uint32, uint64, uint +- Boolean true and false +- Standard complex64 and complex128 +- Array containing standard ints +- Array containing type with custom formatter on pointer receiver only +- Array containing interfaces +- Array containing bytes +- Slice containing standard float32 values +- Slice containing type with custom formatter on pointer receiver only +- Slice containing interfaces +- Slice containing bytes +- Nil slice +- Standard string +- Nil interface +- Sub-interface +- Map with string keys and int vals +- Map with custom formatter type on pointer receiver only keys and vals +- Map with interface keys and values +- Map with nil interface value +- Struct with primitives +- Struct that contains another struct +- Struct that contains custom type with Stringer pointer interface via both + exported and unexported fields +- Struct that contains embedded struct and field to same struct +- Uintptr to 0 (null pointer) +- Uintptr address of real variable +- Unsafe.Pointer to 0 (null pointer) +- Unsafe.Pointer to address of real variable +- Nil channel +- Standard int channel +- Function with no params and no returns +- Function with param and no returns +- Function with multiple params and multiple returns +- Struct that is circular through self referencing +- Structs that are circular through cross referencing +- Structs that are indirectly circular +- Type that panics in its Stringer interface +*/ + +package spew_test + +import ( + "bytes" + "fmt" + "github.com/davecgh/go-spew/spew" + "testing" + "unsafe" +) + +// dumpTest is used to describe a test to be perfomed against the Dump method. +type dumpTest struct { + in interface{} + wants []string +} + +// dumpTests houses all of the tests to be performed against the Dump method. +var dumpTests = make([]dumpTest, 0) + +// addDumpTest is a helper method to append the passed input and desired result +// to dumpTests +func addDumpTest(in interface{}, wants ...string) { + test := dumpTest{in, wants} + dumpTests = append(dumpTests, test) +} + +func addIntDumpTests() { + // Max int8. + v := int8(127) + nv := (*int8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "int8" + vs := "127" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Max int16. + v2 := int16(32767) + nv2 := (*int16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "int16" + v2s := "32767" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Max int32. + v3 := int32(2147483647) + nv3 := (*int32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "int32" + v3s := "2147483647" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Max int64. + v4 := int64(9223372036854775807) + nv4 := (*int64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "int64" + v4s := "9223372036854775807" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") + + // Max int. + v5 := int(2147483647) + nv5 := (*int)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "int" + v5s := "2147483647" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n") + addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n") + addDumpTest(nv5, "(*"+v5t+")()\n") +} + +func addUintDumpTests() { + // Max uint8. + v := uint8(255) + nv := (*uint8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uint8" + vs := "255" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Max uint16. + v2 := uint16(65535) + nv2 := (*uint16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Max uint32. + v3 := uint32(4294967295) + nv3 := (*uint32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "uint32" + v3s := "4294967295" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Max uint64. + v4 := uint64(18446744073709551615) + nv4 := (*uint64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "uint64" + v4s := "18446744073709551615" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") + + // Max uint. + v5 := uint(4294967295) + nv5 := (*uint)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "uint" + v5s := "4294967295" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n") + addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n") + addDumpTest(nv5, "(*"+v5t+")()\n") +} + +func addBoolDumpTests() { + // Boolean true. + v := bool(true) + nv := (*bool)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "bool" + vs := "true" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Boolean false. + v2 := bool(false) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "bool" + v2s := "false" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") +} + +func addFloatDumpTests() { + // Standard float32. + v := float32(3.1415) + nv := (*float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "float32" + vs := "3.1415" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Standard float64. + v2 := float64(3.1415926) + nv2 := (*float64)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "float64" + v2s := "3.1415926" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") +} + +func addComplexDumpTests() { + // Standard complex64. + v := complex(float32(6), -2) + nv := (*complex64)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "complex64" + vs := "(6-2i)" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Standard complex128. + v2 := complex(float64(-6), 2) + nv2 := (*complex128)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "complex128" + v2s := "(-6+2i)" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") +} + +func addArrayDumpTests() { + // Array containing standard ints. + v := [3]int{1, 2, 3} + vLen := fmt.Sprintf("%d", len(v)) + vCap := fmt.Sprintf("%d", cap(v)) + nv := (*[3]int)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "int" + vs := "(len=" + vLen + " cap=" + vCap + ") {\n (" + vt + ") 1,\n (" + + vt + ") 2,\n (" + vt + ") 3\n}" + addDumpTest(v, "([3]"+vt+") "+vs+"\n") + addDumpTest(pv, "(*[3]"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**[3]"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*[3]"+vt+")()\n") + + // Array containing type with custom formatter on pointer receiver only. + v2i0 := pstringer("1") + v2i1 := pstringer("2") + v2i2 := pstringer("3") + v2 := [3]pstringer{v2i0, v2i1, v2i2} + v2i0Len := fmt.Sprintf("%d", len(v2i0)) + v2i1Len := fmt.Sprintf("%d", len(v2i1)) + v2i2Len := fmt.Sprintf("%d", len(v2i2)) + v2Len := fmt.Sprintf("%d", len(v2)) + v2Cap := fmt.Sprintf("%d", cap(v2)) + nv2 := (*[3]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.pstringer" + v2s := "(len=" + v2Len + " cap=" + v2Cap + ") {\n (" + v2t + ") (len=" + + v2i0Len + ") stringer 1,\n (" + v2t + ") (len=" + v2i1Len + + ") stringer 2,\n (" + v2t + ") (len=" + v2i2Len + ") " + + "stringer 3\n}" + addDumpTest(v2, "([3]"+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*[3]"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**[3]"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*[3]"+v2t+")()\n") + + // Array containing interfaces. + v3i0 := "one" + v3 := [3]interface{}{v3i0, int(2), uint(3)} + v3i0Len := fmt.Sprintf("%d", len(v3i0)) + v3Len := fmt.Sprintf("%d", len(v3)) + v3Cap := fmt.Sprintf("%d", cap(v3)) + nv3 := (*[3]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[3]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") {\n (" + v3t2 + ") " + + "(len=" + v3i0Len + ") \"one\",\n (" + v3t3 + ") 2,\n (" + + v3t4 + ") 3\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Array containing bytes. + v4 := [34]byte{ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, + } + v4Len := fmt.Sprintf("%d", len(v4)) + v4Cap := fmt.Sprintf("%d", cap(v4)) + nv4 := (*[34]byte)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "[34]uint8" + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20" + + " |............... |\n" + + " 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30" + + " |!\"#$%&'()*+,-./0|\n" + + " 00000020 31 32 " + + " |12|\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") +} + +func addSliceDumpTests() { + // Slice containing standard float32 values. + v := []float32{3.14, 6.28, 12.56} + vLen := fmt.Sprintf("%d", len(v)) + vCap := fmt.Sprintf("%d", cap(v)) + nv := (*[]float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "float32" + vs := "(len=" + vLen + " cap=" + vCap + ") {\n (" + vt + ") 3.14,\n (" + + vt + ") 6.28,\n (" + vt + ") 12.56\n}" + addDumpTest(v, "([]"+vt+") "+vs+"\n") + addDumpTest(pv, "(*[]"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**[]"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*[]"+vt+")()\n") + + // Slice containing type with custom formatter on pointer receiver only. + v2i0 := pstringer("1") + v2i1 := pstringer("2") + v2i2 := pstringer("3") + v2 := []pstringer{v2i0, v2i1, v2i2} + v2i0Len := fmt.Sprintf("%d", len(v2i0)) + v2i1Len := fmt.Sprintf("%d", len(v2i1)) + v2i2Len := fmt.Sprintf("%d", len(v2i2)) + v2Len := fmt.Sprintf("%d", len(v2)) + v2Cap := fmt.Sprintf("%d", cap(v2)) + nv2 := (*[]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.pstringer" + v2s := "(len=" + v2Len + " cap=" + v2Cap + ") {\n (" + v2t + ") (len=" + + v2i0Len + ") stringer 1,\n (" + v2t + ") (len=" + v2i1Len + + ") stringer 2,\n (" + v2t + ") (len=" + v2i2Len + ") " + + "stringer 3\n}" + addDumpTest(v2, "([]"+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*[]"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**[]"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*[]"+v2t+")()\n") + + // Slice containing interfaces. + v3i0 := "one" + v3 := []interface{}{v3i0, int(2), uint(3), nil} + v3i0Len := fmt.Sprintf("%d", len(v3i0)) + v3Len := fmt.Sprintf("%d", len(v3)) + v3Cap := fmt.Sprintf("%d", cap(v3)) + nv3 := (*[]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3t5 := "interface {}" + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") {\n (" + v3t2 + ") " + + "(len=" + v3i0Len + ") \"one\",\n (" + v3t3 + ") 2,\n (" + + v3t4 + ") 3,\n (" + v3t5 + ") \n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Slice containing bytes. + v4 := []byte{ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, + } + v4Len := fmt.Sprintf("%d", len(v4)) + v4Cap := fmt.Sprintf("%d", cap(v4)) + nv4 := (*[]byte)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "[]uint8" + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20" + + " |............... |\n" + + " 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30" + + " |!\"#$%&'()*+,-./0|\n" + + " 00000020 31 32 " + + " |12|\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") + + // Nil slice. + v5 := []int(nil) + nv5 := (*[]int)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "[]int" + v5s := "" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n") + addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n") + addDumpTest(nv5, "(*"+v5t+")()\n") +} + +func addStringDumpTests() { + // Standard string. + v := "test" + vLen := fmt.Sprintf("%d", len(v)) + nv := (*string)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "string" + vs := "(len=" + vLen + ") \"test\"" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +func addInterfaceDumpTests() { + // Nil interface. + var v interface{} + nv := (*interface{})(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "interface {}" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Sub-interface. + v2 := interface{}(uint16(65535)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") +} + +func addMapDumpTests() { + // Map with string keys and int vals. + k := "one" + kk := "two" + m := map[string]int{k: 1, kk: 2} + klen := fmt.Sprintf("%d", len(k)) // not kLen to shut golint up + kkLen := fmt.Sprintf("%d", len(kk)) + mLen := fmt.Sprintf("%d", len(m)) + nilMap := map[string]int(nil) + nm := (*map[string]int)(nil) + pm := &m + mAddr := fmt.Sprintf("%p", pm) + pmAddr := fmt.Sprintf("%p", &pm) + mt := "map[string]int" + mt1 := "string" + mt2 := "int" + ms := "(len=" + mLen + ") {\n (" + mt1 + ") (len=" + klen + ") " + + "\"one\": (" + mt2 + ") 1,\n (" + mt1 + ") (len=" + kkLen + + ") \"two\": (" + mt2 + ") 2\n}" + ms2 := "(len=" + mLen + ") {\n (" + mt1 + ") (len=" + kkLen + ") " + + "\"two\": (" + mt2 + ") 2,\n (" + mt1 + ") (len=" + klen + + ") \"one\": (" + mt2 + ") 1\n}" + addDumpTest(m, "("+mt+") "+ms+"\n", "("+mt+") "+ms2+"\n") + addDumpTest(pm, "(*"+mt+")("+mAddr+")("+ms+")\n", + "(*"+mt+")("+mAddr+")("+ms2+")\n") + addDumpTest(&pm, "(**"+mt+")("+pmAddr+"->"+mAddr+")("+ms+")\n", + "(**"+mt+")("+pmAddr+"->"+mAddr+")("+ms2+")\n") + addDumpTest(nm, "(*"+mt+")()\n") + addDumpTest(nilMap, "("+mt+") \n") + + // Map with custom formatter type on pointer receiver only keys and vals. + k2 := pstringer("one") + v2 := pstringer("1") + m2 := map[pstringer]pstringer{k2: v2} + k2Len := fmt.Sprintf("%d", len(k2)) + v2Len := fmt.Sprintf("%d", len(v2)) + m2Len := fmt.Sprintf("%d", len(m2)) + nilMap2 := map[pstringer]pstringer(nil) + nm2 := (*map[pstringer]pstringer)(nil) + pm2 := &m2 + m2Addr := fmt.Sprintf("%p", pm2) + pm2Addr := fmt.Sprintf("%p", &pm2) + m2t := "map[spew_test.pstringer]spew_test.pstringer" + m2t1 := "spew_test.pstringer" + m2t2 := "spew_test.pstringer" + m2s := "(len=" + m2Len + ") {\n (" + m2t1 + ") (len=" + k2Len + ") " + + "stringer one: (" + m2t2 + ") (len=" + v2Len + ") stringer 1\n}" + addDumpTest(m2, "("+m2t+") "+m2s+"\n") + addDumpTest(pm2, "(*"+m2t+")("+m2Addr+")("+m2s+")\n") + addDumpTest(&pm2, "(**"+m2t+")("+pm2Addr+"->"+m2Addr+")("+m2s+")\n") + addDumpTest(nm2, "(*"+m2t+")()\n") + addDumpTest(nilMap2, "("+m2t+") \n") + + // Map with interface keys and values. + k3 := "one" + k3Len := fmt.Sprintf("%d", len(k3)) + m3 := map[interface{}]interface{}{k3: 1} + m3Len := fmt.Sprintf("%d", len(m3)) + nilMap3 := map[interface{}]interface{}(nil) + nm3 := (*map[interface{}]interface{})(nil) + pm3 := &m3 + m3Addr := fmt.Sprintf("%p", pm3) + pm3Addr := fmt.Sprintf("%p", &pm3) + m3t := "map[interface {}]interface {}" + m3t1 := "string" + m3t2 := "int" + m3s := "(len=" + m3Len + ") {\n (" + m3t1 + ") (len=" + k3Len + ") " + + "\"one\": (" + m3t2 + ") 1\n}" + addDumpTest(m3, "("+m3t+") "+m3s+"\n") + addDumpTest(pm3, "(*"+m3t+")("+m3Addr+")("+m3s+")\n") + addDumpTest(&pm3, "(**"+m3t+")("+pm3Addr+"->"+m3Addr+")("+m3s+")\n") + addDumpTest(nm3, "(*"+m3t+")()\n") + addDumpTest(nilMap3, "("+m3t+") \n") + + // Map with nil interface value. + k4 := "nil" + k4Len := fmt.Sprintf("%d", len(k4)) + m4 := map[string]interface{}{k4: nil} + m4Len := fmt.Sprintf("%d", len(m4)) + nilMap4 := map[string]interface{}(nil) + nm4 := (*map[string]interface{})(nil) + pm4 := &m4 + m4Addr := fmt.Sprintf("%p", pm4) + pm4Addr := fmt.Sprintf("%p", &pm4) + m4t := "map[string]interface {}" + m4t1 := "string" + m4t2 := "interface {}" + m4s := "(len=" + m4Len + ") {\n (" + m4t1 + ") (len=" + k4Len + ")" + + " \"nil\": (" + m4t2 + ") \n}" + addDumpTest(m4, "("+m4t+") "+m4s+"\n") + addDumpTest(pm4, "(*"+m4t+")("+m4Addr+")("+m4s+")\n") + addDumpTest(&pm4, "(**"+m4t+")("+pm4Addr+"->"+m4Addr+")("+m4s+")\n") + addDumpTest(nm4, "(*"+m4t+")()\n") + addDumpTest(nilMap4, "("+m4t+") \n") +} + +func addStructDumpTests() { + // Struct with primitives. + type s1 struct { + a int8 + b uint8 + } + v := s1{127, 255} + nv := (*s1)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.s1" + vt2 := "int8" + vt3 := "uint8" + vs := "{\n a: (" + vt2 + ") 127,\n b: (" + vt3 + ") 255\n}" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Struct that contains another struct. + type s2 struct { + s1 s1 + b bool + } + v2 := s2{s1{127, 255}, true} + nv2 := (*s2)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.s2" + v2t2 := "spew_test.s1" + v2t3 := "int8" + v2t4 := "uint8" + v2t5 := "bool" + v2s := "{\n s1: (" + v2t2 + ") {\n a: (" + v2t3 + ") 127,\n b: (" + + v2t4 + ") 255\n },\n b: (" + v2t5 + ") true\n}" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Struct that contains custom type with Stringer pointer interface via both + // exported and unexported fields. + type s3 struct { + s pstringer + S pstringer + } + v3 := s3{"test", "test2"} + nv3 := (*s3)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.s3" + v3t2 := "spew_test.pstringer" + v3s := "{\n s: (" + v3t2 + ") (len=4) stringer test,\n S: (" + v3t2 + + ") (len=5) stringer test2\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") + + // Struct that contains embedded struct and field to same struct. + e := embed{"embedstr"} + eLen := fmt.Sprintf("%d", len("embedstr")) + v4 := embedwrap{embed: &e, e: &e} + nv4 := (*embedwrap)(nil) + pv4 := &v4 + eAddr := fmt.Sprintf("%p", &e) + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "spew_test.embedwrap" + v4t2 := "spew_test.embed" + v4t3 := "string" + v4s := "{\n embed: (*" + v4t2 + ")(" + eAddr + ")({\n a: (" + v4t3 + + ") (len=" + eLen + ") \"embedstr\"\n }),\n e: (*" + v4t2 + + ")(" + eAddr + ")({\n a: (" + v4t3 + ") (len=" + eLen + ")" + + " \"embedstr\"\n })\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n") + addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n") + addDumpTest(nv4, "(*"+v4t+")()\n") +} + +func addUintptrDumpTests() { + // Null pointer. + v := uintptr(0) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uintptr" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + + // Address of real variable. + i := 1 + v2 := uintptr(unsafe.Pointer(&i)) + nv2 := (*uintptr)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uintptr" + v2s := fmt.Sprintf("%p", &i) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") +} + +func addUnsafePointerDumpTests() { + // Null pointer. + v := unsafe.Pointer(uintptr(0)) + nv := (*unsafe.Pointer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "unsafe.Pointer" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Address of real variable. + i := 1 + v2 := unsafe.Pointer(&i) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "unsafe.Pointer" + v2s := fmt.Sprintf("%p", &i) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +func addChanDumpTests() { + // Nil channel. + var v chan int + pv := &v + nv := (*chan int)(nil) + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "chan int" + vs := "" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Real channel. + v2 := make(chan int) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "chan int" + v2s := fmt.Sprintf("%p", v2) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") +} + +func addFuncDumpTests() { + // Function with no params and no returns. + v := addIntDumpTests + nv := (*func())(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "func()" + vs := fmt.Sprintf("%p", v) + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") + + // Function with param and no returns. + v2 := TestDump + nv2 := (*func(*testing.T))(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "func(*testing.T)" + v2s := fmt.Sprintf("%p", v2) + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n") + addDumpTest(nv2, "(*"+v2t+")()\n") + + // Function with multiple params and multiple returns. + var v3 = func(i int, s string) (b bool, err error) { + return true, nil + } + nv3 := (*func(int, string) (bool, error))(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "func(int, string) (bool, error)" + v3s := fmt.Sprintf("%p", v3) + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n") + addDumpTest(nv3, "(*"+v3t+")()\n") +} + +func addCircularDumpTests() { + // Struct that is circular through self referencing. + type circular struct { + c *circular + } + v := circular{nil} + v.c = &v + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.circular" + vs := "{\n c: (*" + vt + ")(" + vAddr + ")({\n c: (*" + vt + ")(" + + vAddr + ")()\n })\n}" + vs2 := "{\n c: (*" + vt + ")(" + vAddr + ")()\n}" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs2+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs2+")\n") + + // Structs that are circular through cross referencing. + v2 := xref1{nil} + ts2 := xref2{&v2} + v2.ps2 = &ts2 + pv2 := &v2 + ts2Addr := fmt.Sprintf("%p", &ts2) + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.xref1" + v2t2 := "spew_test.xref2" + v2s := "{\n ps2: (*" + v2t2 + ")(" + ts2Addr + ")({\n ps1: (*" + v2t + + ")(" + v2Addr + ")({\n ps2: (*" + v2t2 + ")(" + ts2Addr + + ")()\n })\n })\n}" + v2s2 := "{\n ps2: (*" + v2t2 + ")(" + ts2Addr + ")({\n ps1: (*" + v2t + + ")(" + v2Addr + ")()\n })\n}" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s2+")\n") + addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s2+")\n") + + // Structs that are indirectly circular. + v3 := indirCir1{nil} + tic2 := indirCir2{nil} + tic3 := indirCir3{&v3} + tic2.ps3 = &tic3 + v3.ps2 = &tic2 + pv3 := &v3 + tic2Addr := fmt.Sprintf("%p", &tic2) + tic3Addr := fmt.Sprintf("%p", &tic3) + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.indirCir1" + v3t2 := "spew_test.indirCir2" + v3t3 := "spew_test.indirCir3" + v3s := "{\n ps2: (*" + v3t2 + ")(" + tic2Addr + ")({\n ps3: (*" + v3t3 + + ")(" + tic3Addr + ")({\n ps1: (*" + v3t + ")(" + v3Addr + + ")({\n ps2: (*" + v3t2 + ")(" + tic2Addr + + ")()\n })\n })\n })\n}" + v3s2 := "{\n ps2: (*" + v3t2 + ")(" + tic2Addr + ")({\n ps3: (*" + v3t3 + + ")(" + tic3Addr + ")({\n ps1: (*" + v3t + ")(" + v3Addr + + ")()\n })\n })\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s2+")\n") + addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s2+")\n") +} + +func addPanicDumpTests() { + // Type that panics in its Stringer interface. + v := panicer(127) + nv := (*panicer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.panicer" + vs := "(PANIC=test panic)127" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +func addErrorDumpTests() { + // Type that has a custom Error interface. + v := customError(127) + nv := (*customError)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.customError" + vs := "error: 127" + addDumpTest(v, "("+vt+") "+vs+"\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n") + addDumpTest(nv, "(*"+vt+")()\n") +} + +// TestDump executes all of the tests described by dumpTests. +func TestDump(t *testing.T) { + // Setup tests. + addIntDumpTests() + addUintDumpTests() + addBoolDumpTests() + addFloatDumpTests() + addComplexDumpTests() + addArrayDumpTests() + addSliceDumpTests() + addStringDumpTests() + addInterfaceDumpTests() + addMapDumpTests() + addStructDumpTests() + addUintptrDumpTests() + addUnsafePointerDumpTests() + addChanDumpTests() + addFuncDumpTests() + addCircularDumpTests() + addPanicDumpTests() + addErrorDumpTests() + addCgoDumpTests() + + t.Logf("Running %d tests", len(dumpTests)) + for i, test := range dumpTests { + buf := new(bytes.Buffer) + spew.Fdump(buf, test.in) + s := buf.String() + if testFailed(s, test.wants) { + t.Errorf("Dump #%d\n got: %s %s", i, s, stringizeWants(test.wants)) + continue + } + } +} + +func TestDumpSortedKeys(t *testing.T) { + cfg := spew.ConfigState{SortKeys: true} + s := cfg.Sdump(map[int]string{1: "1", 3: "3", 2: "2"}) + expected := `(map[int]string) (len=3) { +(int) 1: (string) (len=1) "1", +(int) 2: (string) (len=1) "2", +(int) 3: (string) (len=1) "3" +} +` + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dumpcgo_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dumpcgo_test.go new file mode 100644 index 0000000..9b8a358 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dumpcgo_test.go @@ -0,0 +1,97 @@ +// Copyright (c) 2013 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when both cgo is supported and "-tags testcgo" is added to the go test +// command line. This means the cgo tests are only added (and hence run) when +// specifially requested. This configuration is used because spew itself +// does not require cgo to run even though it does handle certain cgo types +// specially. Rather than forcing all clients to require cgo and an external +// C compiler just to run the tests, this scheme makes them optional. +// +build cgo,testcgo + +package spew_test + +import ( + "fmt" + "github.com/davecgh/go-spew/spew/testdata" +) + +func addCgoDumpTests() { + // C char pointer. + v := testdata.GetCgoCharPointer() + nv := testdata.GetCgoNullCharPointer() + pv := &v + vcAddr := fmt.Sprintf("%p", v) + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "*testdata._Ctype_char" + vs := "116" + addDumpTest(v, "("+vt+")("+vcAddr+")("+vs+")\n") + addDumpTest(pv, "(*"+vt+")("+vAddr+"->"+vcAddr+")("+vs+")\n") + addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+"->"+vcAddr+")("+vs+")\n") + addDumpTest(nv, "("+vt+")()\n") + + // C char array. + v2, v2l, v2c := testdata.GetCgoCharArray() + v2Len := fmt.Sprintf("%d", v2l) + v2Cap := fmt.Sprintf("%d", v2c) + v2t := "[6]testdata._Ctype_char" + v2s := "(len=" + v2Len + " cap=" + v2Cap + ") " + + "{\n 00000000 74 65 73 74 32 00 " + + " |test2.|\n}" + addDumpTest(v2, "("+v2t+") "+v2s+"\n") + + // C unsigned char array. + v3, v3l, v3c := testdata.GetCgoUnsignedCharArray() + v3Len := fmt.Sprintf("%d", v3l) + v3Cap := fmt.Sprintf("%d", v3c) + v3t := "[6]testdata._Ctype_unsignedchar" + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") " + + "{\n 00000000 74 65 73 74 33 00 " + + " |test3.|\n}" + addDumpTest(v3, "("+v3t+") "+v3s+"\n") + + // C signed char array. + v4, v4l, v4c := testdata.GetCgoSignedCharArray() + v4Len := fmt.Sprintf("%d", v4l) + v4Cap := fmt.Sprintf("%d", v4c) + v4t := "[6]testdata._Ctype_schar" + v4t2 := "testdata._Ctype_schar" + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 101,\n (" + v4t2 + + ") 115,\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 52,\n (" + v4t2 + + ") 0\n}" + addDumpTest(v4, "("+v4t+") "+v4s+"\n") + + // C uint8_t array. + v5, v5l, v5c := testdata.GetCgoUint8tArray() + v5Len := fmt.Sprintf("%d", v5l) + v5Cap := fmt.Sprintf("%d", v5c) + v5t := "[6]testdata._Ctype_uint8_t" + v5s := "(len=" + v5Len + " cap=" + v5Cap + ") " + + "{\n 00000000 74 65 73 74 35 00 " + + " |test5.|\n}" + addDumpTest(v5, "("+v5t+") "+v5s+"\n") + + // C typedefed unsigned char array. + v6, v6l, v6c := testdata.GetCgoTypdefedUnsignedCharArray() + v6Len := fmt.Sprintf("%d", v6l) + v6Cap := fmt.Sprintf("%d", v6c) + v6t := "[6]testdata._Ctype_custom_uchar_t" + v6s := "(len=" + v6Len + " cap=" + v6Cap + ") " + + "{\n 00000000 74 65 73 74 36 00 " + + " |test6.|\n}" + addDumpTest(v6, "("+v6t+") "+v6s+"\n") +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dumpnocgo_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dumpnocgo_test.go new file mode 100644 index 0000000..52a0971 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dumpnocgo_test.go @@ -0,0 +1,26 @@ +// Copyright (c) 2013 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when either cgo is not supported or "-tags testcgo" is not added to the go +// test command line. This file intentionally does not setup any cgo tests in +// this scenario. +// +build !cgo !testcgo + +package spew_test + +func addCgoDumpTests() { + // Don't add any tests for cgo since this file is only compiled when + // there should not be any cgo tests. +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/example_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/example_test.go new file mode 100644 index 0000000..a7acd14 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/example_test.go @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew_test + +import ( + "fmt" + "github.com/davecgh/go-spew/spew" +) + +type Flag int + +const ( + flagOne Flag = iota + flagTwo +) + +var flagStrings = map[Flag]string{ + flagOne: "flagOne", + flagTwo: "flagTwo", +} + +func (f Flag) String() string { + if s, ok := flagStrings[f]; ok { + return s + } + return fmt.Sprintf("Unknown flag (%d)", int(f)) +} + +type Bar struct { + flag Flag + data uintptr +} + +type Foo struct { + unexportedField Bar + ExportedField map[interface{}]interface{} +} + +// This example demonstrates how to use Dump to dump variables to stdout. +func ExampleDump() { + // The following package level declarations are assumed for this example: + /* + type Flag int + + const ( + flagOne Flag = iota + flagTwo + ) + + var flagStrings = map[Flag]string{ + flagOne: "flagOne", + flagTwo: "flagTwo", + } + + func (f Flag) String() string { + if s, ok := flagStrings[f]; ok { + return s + } + return fmt.Sprintf("Unknown flag (%d)", int(f)) + } + + type Bar struct { + flag Flag + data uintptr + } + + type Foo struct { + unexportedField Bar + ExportedField map[interface{}]interface{} + } + */ + + // Setup some sample data structures for the example. + bar := Bar{Flag(flagTwo), uintptr(0)} + s1 := Foo{bar, map[interface{}]interface{}{"one": true}} + f := Flag(5) + b := []byte{ + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, + } + + // Dump! + spew.Dump(s1, f, b) + + // Output: + // (spew_test.Foo) { + // unexportedField: (spew_test.Bar) { + // flag: (spew_test.Flag) flagTwo, + // data: (uintptr) + // }, + // ExportedField: (map[interface {}]interface {}) (len=1) { + // (string) (len=3) "one": (bool) true + // } + // } + // (spew_test.Flag) Unknown flag (5) + // ([]uint8) (len=34 cap=34) { + // 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | + // 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| + // 00000020 31 32 |12| + // } + // +} + +// This example demonstrates how to use Printf to display a variable with a +// format string and inline formatting. +func ExamplePrintf() { + // Create a double pointer to a uint 8. + ui8 := uint8(5) + pui8 := &ui8 + ppui8 := &pui8 + + // Create a circular data type. + type circular struct { + ui8 uint8 + c *circular + } + c := circular{ui8: 1} + c.c = &c + + // Print! + spew.Printf("ppui8: %v\n", ppui8) + spew.Printf("circular: %v\n", c) + + // Output: + // ppui8: <**>5 + // circular: {1 <*>{1 <*>}} +} + +// This example demonstrates how to use a ConfigState. +func ExampleConfigState() { + // Modify the indent level of the ConfigState only. The global + // configuration is not modified. + scs := spew.ConfigState{Indent: "\t"} + + // Output using the ConfigState instance. + v := map[string]int{"one": 1} + scs.Printf("v: %v\n", v) + scs.Dump(v) + + // Output: + // v: map[one:1] + // (map[string]int) (len=1) { + // (string) (len=3) "one": (int) 1 + // } +} + +// This example demonstrates how to use ConfigState.Dump to dump variables to +// stdout +func ExampleConfigState_Dump() { + // See the top-level Dump example for details on the types used in this + // example. + + // Create two ConfigState instances with different indentation. + scs := spew.ConfigState{Indent: "\t"} + scs2 := spew.ConfigState{Indent: " "} + + // Setup some sample data structures for the example. + bar := Bar{Flag(flagTwo), uintptr(0)} + s1 := Foo{bar, map[interface{}]interface{}{"one": true}} + + // Dump using the ConfigState instances. + scs.Dump(s1) + scs2.Dump(s1) + + // Output: + // (spew_test.Foo) { + // unexportedField: (spew_test.Bar) { + // flag: (spew_test.Flag) flagTwo, + // data: (uintptr) + // }, + // ExportedField: (map[interface {}]interface {}) (len=1) { + // (string) (len=3) "one": (bool) true + // } + // } + // (spew_test.Foo) { + // unexportedField: (spew_test.Bar) { + // flag: (spew_test.Flag) flagTwo, + // data: (uintptr) + // }, + // ExportedField: (map[interface {}]interface {}) (len=1) { + // (string) (len=3) "one": (bool) true + // } + // } + // +} + +// This example demonstrates how to use ConfigState.Printf to display a variable +// with a format string and inline formatting. +func ExampleConfigState_Printf() { + // See the top-level Dump example for details on the types used in this + // example. + + // Create two ConfigState instances and modify the method handling of the + // first ConfigState only. + scs := spew.NewDefaultConfig() + scs2 := spew.NewDefaultConfig() + scs.DisableMethods = true + + // Alternatively + // scs := spew.ConfigState{Indent: " ", DisableMethods: true} + // scs2 := spew.ConfigState{Indent: " "} + + // This is of type Flag which implements a Stringer and has raw value 1. + f := flagTwo + + // Dump using the ConfigState instances. + scs.Printf("f: %v\n", f) + scs2.Printf("f: %v\n", f) + + // Output: + // f: 1 + // f: flagTwo +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/format.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/format.go new file mode 100644 index 0000000..cc152ae --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/format.go @@ -0,0 +1,419 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "bytes" + "fmt" + "reflect" + "strconv" + "strings" +) + +// supportedFlags is a list of all the character flags supported by fmt package. +const supportedFlags = "0-+# " + +// formatState implements the fmt.Formatter interface and contains information +// about the state of a formatting operation. The NewFormatter function can +// be used to get a new Formatter which can be used directly as arguments +// in standard fmt package printing calls. +type formatState struct { + value interface{} + fs fmt.State + depth int + pointers map[uintptr]int + ignoreNextType bool + cs *ConfigState +} + +// buildDefaultFormat recreates the original format string without precision +// and width information to pass in to fmt.Sprintf in the case of an +// unrecognized type. Unless new types are added to the language, this +// function won't ever be called. +func (f *formatState) buildDefaultFormat() (format string) { + buf := bytes.NewBuffer(percentBytes) + + for _, flag := range supportedFlags { + if f.fs.Flag(int(flag)) { + buf.WriteRune(flag) + } + } + + buf.WriteRune('v') + + format = buf.String() + return format +} + +// constructOrigFormat recreates the original format string including precision +// and width information to pass along to the standard fmt package. This allows +// automatic deferral of all format strings this package doesn't support. +func (f *formatState) constructOrigFormat(verb rune) (format string) { + buf := bytes.NewBuffer(percentBytes) + + for _, flag := range supportedFlags { + if f.fs.Flag(int(flag)) { + buf.WriteRune(flag) + } + } + + if width, ok := f.fs.Width(); ok { + buf.WriteString(strconv.Itoa(width)) + } + + if precision, ok := f.fs.Precision(); ok { + buf.Write(precisionBytes) + buf.WriteString(strconv.Itoa(precision)) + } + + buf.WriteRune(verb) + + format = buf.String() + return format +} + +// unpackValue returns values inside of non-nil interfaces when possible and +// ensures that types for values which have been unpacked from an interface +// are displayed when the show types flag is also set. +// This is useful for data types like structs, arrays, slices, and maps which +// can contain varying types packed inside an interface. +func (f *formatState) unpackValue(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Interface { + f.ignoreNextType = false + if !v.IsNil() { + v = v.Elem() + } + } + return v +} + +// formatPtr handles formatting of pointers by indirecting them as necessary. +func (f *formatState) formatPtr(v reflect.Value) { + // Display nil if top level pointer is nil. + showTypes := f.fs.Flag('#') + if v.IsNil() && (!showTypes || f.ignoreNextType) { + f.fs.Write(nilAngleBytes) + return + } + + // Remove pointers at or below the current depth from map used to detect + // circular refs. + for k, depth := range f.pointers { + if depth >= f.depth { + delete(f.pointers, k) + } + } + + // Keep list of all dereferenced pointers to possibly show later. + pointerChain := make([]uintptr, 0) + + // Figure out how many levels of indirection there are by derferencing + // pointers and unpacking interfaces down the chain while detecting circular + // references. + nilFound := false + cycleFound := false + indirects := 0 + ve := v + for ve.Kind() == reflect.Ptr { + if ve.IsNil() { + nilFound = true + break + } + indirects++ + addr := ve.Pointer() + pointerChain = append(pointerChain, addr) + if pd, ok := f.pointers[addr]; ok && pd < f.depth { + cycleFound = true + indirects-- + break + } + f.pointers[addr] = f.depth + + ve = ve.Elem() + if ve.Kind() == reflect.Interface { + if ve.IsNil() { + nilFound = true + break + } + ve = ve.Elem() + } + } + + // Display type or indirection level depending on flags. + if showTypes && !f.ignoreNextType { + f.fs.Write(openParenBytes) + f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) + f.fs.Write([]byte(ve.Type().String())) + f.fs.Write(closeParenBytes) + } else { + if nilFound || cycleFound { + indirects += strings.Count(ve.Type().String(), "*") + } + f.fs.Write(openAngleBytes) + f.fs.Write([]byte(strings.Repeat("*", indirects))) + f.fs.Write(closeAngleBytes) + } + + // Display pointer information depending on flags. + if f.fs.Flag('+') && (len(pointerChain) > 0) { + f.fs.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + f.fs.Write(pointerChainBytes) + } + printHexPtr(f.fs, addr) + } + f.fs.Write(closeParenBytes) + } + + // Display dereferenced value. + switch { + case nilFound == true: + f.fs.Write(nilAngleBytes) + + case cycleFound == true: + f.fs.Write(circularShortBytes) + + default: + f.ignoreNextType = true + f.format(ve) + } +} + +// format is the main workhorse for providing the Formatter interface. It +// uses the passed reflect value to figure out what kind of object we are +// dealing with and formats it appropriately. It is a recursive function, +// however circular data structures are detected and handled properly. +func (f *formatState) format(v reflect.Value) { + // Handle invalid reflect values immediately. + kind := v.Kind() + if kind == reflect.Invalid { + f.fs.Write(invalidAngleBytes) + return + } + + // Handle pointers specially. + if kind == reflect.Ptr { + f.formatPtr(v) + return + } + + // Print type information unless already handled elsewhere. + if !f.ignoreNextType && f.fs.Flag('#') { + f.fs.Write(openParenBytes) + f.fs.Write([]byte(v.Type().String())) + f.fs.Write(closeParenBytes) + } + f.ignoreNextType = false + + // Call Stringer/error interfaces if they exist and the handle methods + // flag is enabled. + if !f.cs.DisableMethods { + if (kind != reflect.Invalid) && (kind != reflect.Interface) { + if handled := handleMethods(f.cs, f.fs, v); handled { + return + } + } + } + + switch kind { + case reflect.Invalid: + // Do nothing. We should never get here since invalid has already + // been handled above. + + case reflect.Bool: + printBool(f.fs, v.Bool()) + + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: + printInt(f.fs, v.Int(), 10) + + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: + printUint(f.fs, v.Uint(), 10) + + case reflect.Float32: + printFloat(f.fs, v.Float(), 32) + + case reflect.Float64: + printFloat(f.fs, v.Float(), 64) + + case reflect.Complex64: + printComplex(f.fs, v.Complex(), 32) + + case reflect.Complex128: + printComplex(f.fs, v.Complex(), 64) + + case reflect.Slice: + if v.IsNil() { + f.fs.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: + f.fs.Write(openBracketBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + numEntries := v.Len() + for i := 0; i < numEntries; i++ { + if i > 0 { + f.fs.Write(spaceBytes) + } + f.ignoreNextType = true + f.format(f.unpackValue(v.Index(i))) + } + } + f.depth-- + f.fs.Write(closeBracketBytes) + + case reflect.String: + f.fs.Write([]byte(v.String())) + + case reflect.Interface: + // The only time we should get here is for nil interfaces due to + // unpackValue calls. + if v.IsNil() { + f.fs.Write(nilAngleBytes) + } + + case reflect.Ptr: + // Do nothing. We should never get here since pointers have already + // been handled above. + + case reflect.Map: + // nil maps should be indicated as different than empty maps + if v.IsNil() { + f.fs.Write(nilAngleBytes) + break + } + + f.fs.Write(openMapBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + keys := v.MapKeys() + if f.cs.SortKeys { + sortValues(keys) + } + for i, key := range keys { + if i > 0 { + f.fs.Write(spaceBytes) + } + f.ignoreNextType = true + f.format(f.unpackValue(key)) + f.fs.Write(colonBytes) + f.ignoreNextType = true + f.format(f.unpackValue(v.MapIndex(key))) + } + } + f.depth-- + f.fs.Write(closeMapBytes) + + case reflect.Struct: + numFields := v.NumField() + f.fs.Write(openBraceBytes) + f.depth++ + if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { + f.fs.Write(maxShortBytes) + } else { + vt := v.Type() + for i := 0; i < numFields; i++ { + if i > 0 { + f.fs.Write(spaceBytes) + } + vtf := vt.Field(i) + if f.fs.Flag('+') || f.fs.Flag('#') { + f.fs.Write([]byte(vtf.Name)) + f.fs.Write(colonBytes) + } + f.format(f.unpackValue(v.Field(i))) + } + } + f.depth-- + f.fs.Write(closeBraceBytes) + + case reflect.Uintptr: + printHexPtr(f.fs, uintptr(v.Uint())) + + case reflect.UnsafePointer, reflect.Chan, reflect.Func: + printHexPtr(f.fs, v.Pointer()) + + // There were not any other types at the time this code was written, but + // fall back to letting the default fmt package handle it if any get added. + default: + format := f.buildDefaultFormat() + if v.CanInterface() { + fmt.Fprintf(f.fs, format, v.Interface()) + } else { + fmt.Fprintf(f.fs, format, v.String()) + } + } +} + +// Format satisfies the fmt.Formatter interface. See NewFormatter for usage +// details. +func (f *formatState) Format(fs fmt.State, verb rune) { + f.fs = fs + + // Use standard formatting for verbs that are not v. + if verb != 'v' { + format := f.constructOrigFormat(verb) + fmt.Fprintf(fs, format, f.value) + return + } + + if f.value == nil { + if fs.Flag('#') { + fs.Write(interfaceBytes) + } + fs.Write(nilAngleBytes) + return + } + + f.format(reflect.ValueOf(f.value)) +} + +// newFormatter is a helper function to consolidate the logic from the various +// public methods which take varying config states. +func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { + fs := &formatState{value: v, cs: cs} + fs.pointers = make(map[uintptr]int) + return fs +} + +/* +NewFormatter returns a custom formatter that satisfies the fmt.Formatter +interface. As a result, it integrates cleanly with standard fmt package +printing functions. The formatter is useful for inline printing of smaller data +types similar to the standard %v format specifier. + +The custom formatter only responds to the %v (most compact), %+v (adds pointer +addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb +combinations. Any other verbs such as %x and %q will be sent to the the +standard fmt package for formatting. In addition, the custom formatter ignores +the width and precision arguments (however they will still work on the format +specifiers not handled by the custom formatter). + +Typically this function shouldn't be called directly. It is much easier to make +use of the custom formatter by calling one of the convenience functions such as +Printf, Println, or Fprintf. +*/ +func NewFormatter(v interface{}) fmt.Formatter { + return newFormatter(&Config, v) +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/format_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/format_test.go new file mode 100644 index 0000000..4dd0ac2 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/format_test.go @@ -0,0 +1,1488 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +Test Summary: +NOTE: For each test, a nil pointer, a single pointer and double pointer to the +base test element are also tested to ensure proper indirection across all types. + +- Max int8, int16, int32, int64, int +- Max uint8, uint16, uint32, uint64, uint +- Boolean true and false +- Standard complex64 and complex128 +- Array containing standard ints +- Array containing type with custom formatter on pointer receiver only +- Array containing interfaces +- Slice containing standard float32 values +- Slice containing type with custom formatter on pointer receiver only +- Slice containing interfaces +- Nil slice +- Standard string +- Nil interface +- Sub-interface +- Map with string keys and int vals +- Map with custom formatter type on pointer receiver only keys and vals +- Map with interface keys and values +- Map with nil interface value +- Struct with primitives +- Struct that contains another struct +- Struct that contains custom type with Stringer pointer interface via both + exported and unexported fields +- Struct that contains embedded struct and field to same struct +- Uintptr to 0 (null pointer) +- Uintptr address of real variable +- Unsafe.Pointer to 0 (null pointer) +- Unsafe.Pointer to address of real variable +- Nil channel +- Standard int channel +- Function with no params and no returns +- Function with param and no returns +- Function with multiple params and multiple returns +- Struct that is circular through self referencing +- Structs that are circular through cross referencing +- Structs that are indirectly circular +- Type that panics in its Stringer interface +- Type that has a custom Error interface +- %x passthrough with uint +- %#x passthrough with uint +- %f passthrough with precision +- %f passthrough with width and precision +- %d passthrough with width +- %q passthrough with string +*/ + +package spew_test + +import ( + "bytes" + "fmt" + "github.com/davecgh/go-spew/spew" + "testing" + "unsafe" +) + +// formatterTest is used to describe a test to be perfomed against NewFormatter. +type formatterTest struct { + format string + in interface{} + wants []string +} + +// formatterTests houses all of the tests to be performed against NewFormatter. +var formatterTests = make([]formatterTest, 0) + +// addFormatterTest is a helper method to append the passed input and desired +// result to formatterTests. +func addFormatterTest(format string, in interface{}, wants ...string) { + test := formatterTest{format, in, wants} + formatterTests = append(formatterTests, test) +} + +func addIntFormatterTests() { + // Max int8. + v := int8(127) + nv := (*int8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "int8" + vs := "127" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Max int16. + v2 := int16(32767) + nv2 := (*int16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "int16" + v2s := "32767" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Max int32. + v3 := int32(2147483647) + nv3 := (*int32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "int32" + v3s := "2147483647" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + + // Max int64. + v4 := int64(9223372036854775807) + nv4 := (*int64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "int64" + v4s := "9223372036854775807" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") + + // Max int. + v5 := int(2147483647) + nv5 := (*int)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "int" + v5s := "2147483647" + addFormatterTest("%v", v5, v5s) + addFormatterTest("%v", pv5, "<*>"+v5s) + addFormatterTest("%v", &pv5, "<**>"+v5s) + addFormatterTest("%v", nv5, "") + addFormatterTest("%+v", v5, v5s) + addFormatterTest("%+v", pv5, "<*>("+v5Addr+")"+v5s) + addFormatterTest("%+v", &pv5, "<**>("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%+v", nv5, "") + addFormatterTest("%#v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#v", pv5, "(*"+v5t+")"+v5s) + addFormatterTest("%#v", &pv5, "(**"+v5t+")"+v5s) + addFormatterTest("%#v", nv5, "(*"+v5t+")"+"") + addFormatterTest("%#+v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#+v", pv5, "(*"+v5t+")("+v5Addr+")"+v5s) + addFormatterTest("%#+v", &pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%#+v", nv5, "(*"+v5t+")"+"") +} + +func addUintFormatterTests() { + // Max uint8. + v := uint8(255) + nv := (*uint8)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uint8" + vs := "255" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Max uint16. + v2 := uint16(65535) + nv2 := (*uint16)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Max uint32. + v3 := uint32(4294967295) + nv3 := (*uint32)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "uint32" + v3s := "4294967295" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + + // Max uint64. + v4 := uint64(18446744073709551615) + nv4 := (*uint64)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "uint64" + v4s := "18446744073709551615" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") + + // Max uint. + v5 := uint(4294967295) + nv5 := (*uint)(nil) + pv5 := &v5 + v5Addr := fmt.Sprintf("%p", pv5) + pv5Addr := fmt.Sprintf("%p", &pv5) + v5t := "uint" + v5s := "4294967295" + addFormatterTest("%v", v5, v5s) + addFormatterTest("%v", pv5, "<*>"+v5s) + addFormatterTest("%v", &pv5, "<**>"+v5s) + addFormatterTest("%v", nv5, "") + addFormatterTest("%+v", v5, v5s) + addFormatterTest("%+v", pv5, "<*>("+v5Addr+")"+v5s) + addFormatterTest("%+v", &pv5, "<**>("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%+v", nv5, "") + addFormatterTest("%#v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#v", pv5, "(*"+v5t+")"+v5s) + addFormatterTest("%#v", &pv5, "(**"+v5t+")"+v5s) + addFormatterTest("%#v", nv5, "(*"+v5t+")"+"") + addFormatterTest("%#+v", v5, "("+v5t+")"+v5s) + addFormatterTest("%#+v", pv5, "(*"+v5t+")("+v5Addr+")"+v5s) + addFormatterTest("%#+v", &pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")"+v5s) + addFormatterTest("%#v", nv5, "(*"+v5t+")"+"") +} + +func addBoolFormatterTests() { + // Boolean true. + v := bool(true) + nv := (*bool)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "bool" + vs := "true" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Boolean false. + v2 := bool(false) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "bool" + v2s := "false" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addFloatFormatterTests() { + // Standard float32. + v := float32(3.1415) + nv := (*float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "float32" + vs := "3.1415" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Standard float64. + v2 := float64(3.1415926) + nv2 := (*float64)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "float64" + v2s := "3.1415926" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") +} + +func addComplexFormatterTests() { + // Standard complex64. + v := complex(float32(6), -2) + nv := (*complex64)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "complex64" + vs := "(6-2i)" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Standard complex128. + v2 := complex(float64(-6), 2) + nv2 := (*complex128)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "complex128" + v2s := "(-6+2i)" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") +} + +func addArrayFormatterTests() { + // Array containing standard ints. + v := [3]int{1, 2, 3} + nv := (*[3]int)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "[3]int" + vs := "[1 2 3]" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Array containing type with custom formatter on pointer receiver only. + v2 := [3]pstringer{"1", "2", "3"} + nv2 := (*[3]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "[3]spew_test.pstringer" + v2s := "[stringer 1 stringer 2 stringer 3]" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Array containing interfaces. + v3 := [3]interface{}{"one", int(2), uint(3)} + nv3 := (*[3]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[3]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3s := "[one 2 3]" + v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3]" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") +} + +func addSliceFormatterTests() { + // Slice containing standard float32 values. + v := []float32{3.14, 6.28, 12.56} + nv := (*[]float32)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "[]float32" + vs := "[3.14 6.28 12.56]" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Slice containing type with custom formatter on pointer receiver only. + v2 := []pstringer{"1", "2", "3"} + nv2 := (*[]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "[]spew_test.pstringer" + v2s := "[stringer 1 stringer 2 stringer 3]" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Slice containing interfaces. + v3 := []interface{}{"one", int(2), uint(3), nil} + nv3 := (*[]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "[]interface {}" + v3t2 := "string" + v3t3 := "int" + v3t4 := "uint" + v3t5 := "interface {}" + v3s := "[one 2 3 ]" + v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3 (" + v3t5 + + ")]" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") + + // Nil slice. + var v4 []int + nv4 := (*[]int)(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "[]int" + v4s := "" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") +} + +func addStringFormatterTests() { + // Standard string. + v := "test" + nv := (*string)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "string" + vs := "test" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") +} + +func addInterfaceFormatterTests() { + // Nil interface. + var v interface{} + nv := (*interface{})(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "interface {}" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Sub-interface. + v2 := interface{}(uint16(65535)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uint16" + v2s := "65535" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addMapFormatterTests() { + // Map with string keys and int vals. + v := map[string]int{"one": 1, "two": 2} + nilMap := map[string]int(nil) + nv := (*map[string]int)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "map[string]int" + vs := "map[one:1 two:2]" + vs2 := "map[two:2 one:1]" + addFormatterTest("%v", v, vs, vs2) + addFormatterTest("%v", pv, "<*>"+vs, "<*>"+vs2) + addFormatterTest("%v", &pv, "<**>"+vs, "<**>"+vs2) + addFormatterTest("%+v", nilMap, "") + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs, vs2) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs, "<*>("+vAddr+")"+vs2) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs, + "<**>("+pvAddr+"->"+vAddr+")"+vs2) + addFormatterTest("%+v", nilMap, "") + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs, "("+vt+")"+vs2) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs, "(*"+vt+")"+vs2) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs, "(**"+vt+")"+vs2) + addFormatterTest("%#v", nilMap, "("+vt+")"+"") + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs, "("+vt+")"+vs2) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs, + "(*"+vt+")("+vAddr+")"+vs2) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs, + "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs2) + addFormatterTest("%#+v", nilMap, "("+vt+")"+"") + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Map with custom formatter type on pointer receiver only keys and vals. + v2 := map[pstringer]pstringer{"one": "1"} + nv2 := (*map[pstringer]pstringer)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "map[spew_test.pstringer]spew_test.pstringer" + v2s := "map[stringer one:stringer 1]" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Map with interface keys and values. + v3 := map[interface{}]interface{}{"one": 1} + nv3 := (*map[interface{}]interface{})(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "map[interface {}]interface {}" + v3t1 := "string" + v3t2 := "int" + v3s := "map[one:1]" + v3s2 := "map[(" + v3t1 + ")one:(" + v3t2 + ")1]" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") + + // Map with nil interface value + v4 := map[string]interface{}{"nil": nil} + nv4 := (*map[string]interface{})(nil) + pv4 := &v4 + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "map[string]interface {}" + v4t1 := "interface {}" + v4s := "map[nil:]" + v4s2 := "map[nil:(" + v4t1 + ")]" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%+v", v4, v4s) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s2) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s2) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s2) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s2) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s2) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s2) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") +} + +func addStructFormatterTests() { + // Struct with primitives. + type s1 struct { + a int8 + b uint8 + } + v := s1{127, 255} + nv := (*s1)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.s1" + vt2 := "int8" + vt3 := "uint8" + vs := "{127 255}" + vs2 := "{a:127 b:255}" + vs3 := "{a:(" + vt2 + ")127 b:(" + vt3 + ")255}" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs2) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs2) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs2) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs3) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs3) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs3) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs3) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs3) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs3) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Struct that contains another struct. + type s2 struct { + s1 s1 + b bool + } + v2 := s2{s1{127, 255}, true} + nv2 := (*s2)(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.s2" + v2t2 := "spew_test.s1" + v2t3 := "int8" + v2t4 := "uint8" + v2t5 := "bool" + v2s := "{{127 255} true}" + v2s2 := "{s1:{a:127 b:255} b:true}" + v2s3 := "{s1:(" + v2t2 + "){a:(" + v2t3 + ")127 b:(" + v2t4 + ")255} b:(" + + v2t5 + ")true}" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s2) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s2) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s2) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s3) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s3) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s3) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s3) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s3) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s3) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Struct that contains custom type with Stringer pointer interface via both + // exported and unexported fields. + type s3 struct { + s pstringer + S pstringer + } + v3 := s3{"test", "test2"} + nv3 := (*s3)(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.s3" + v3t2 := "spew_test.pstringer" + v3s := "{stringer test stringer test2}" + v3s2 := "{s:stringer test S:stringer test2}" + v3s3 := "{s:(" + v3t2 + ")stringer test S:(" + v3t2 + ")stringer test2}" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s2) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s2) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s2) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s3) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s3) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s3) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s3) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s3) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s3) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") + + // Struct that contains embedded struct and field to same struct. + e := embed{"embedstr"} + v4 := embedwrap{embed: &e, e: &e} + nv4 := (*embedwrap)(nil) + pv4 := &v4 + eAddr := fmt.Sprintf("%p", &e) + v4Addr := fmt.Sprintf("%p", pv4) + pv4Addr := fmt.Sprintf("%p", &pv4) + v4t := "spew_test.embedwrap" + v4t2 := "spew_test.embed" + v4t3 := "string" + v4s := "{<*>{embedstr} <*>{embedstr}}" + v4s2 := "{embed:<*>(" + eAddr + "){a:embedstr} e:<*>(" + eAddr + + "){a:embedstr}}" + v4s3 := "{embed:(*" + v4t2 + "){a:(" + v4t3 + ")embedstr} e:(*" + v4t2 + + "){a:(" + v4t3 + ")embedstr}}" + v4s4 := "{embed:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 + + ")embedstr} e:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 + ")embedstr}}" + addFormatterTest("%v", v4, v4s) + addFormatterTest("%v", pv4, "<*>"+v4s) + addFormatterTest("%v", &pv4, "<**>"+v4s) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%+v", v4, v4s2) + addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s2) + addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s2) + addFormatterTest("%+v", nv4, "") + addFormatterTest("%#v", v4, "("+v4t+")"+v4s3) + addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s3) + addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s3) + addFormatterTest("%#v", nv4, "(*"+v4t+")"+"") + addFormatterTest("%#+v", v4, "("+v4t+")"+v4s4) + addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s4) + addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s4) + addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"") +} + +func addUintptrFormatterTests() { + // Null pointer. + v := uintptr(0) + nv := (*uintptr)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "uintptr" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Address of real variable. + i := 1 + v2 := uintptr(unsafe.Pointer(&i)) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "uintptr" + v2s := fmt.Sprintf("%p", &i) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addUnsafePointerFormatterTests() { + // Null pointer. + v := unsafe.Pointer(uintptr(0)) + nv := (*unsafe.Pointer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "unsafe.Pointer" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Address of real variable. + i := 1 + v2 := unsafe.Pointer(&i) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "unsafe.Pointer" + v2s := fmt.Sprintf("%p", &i) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addChanFormatterTests() { + // Nil channel. + var v chan int + pv := &v + nv := (*chan int)(nil) + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "chan int" + vs := "" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Real channel. + v2 := make(chan int) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "chan int" + v2s := fmt.Sprintf("%p", v2) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) +} + +func addFuncFormatterTests() { + // Function with no params and no returns. + v := addIntFormatterTests + nv := (*func())(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "func()" + vs := fmt.Sprintf("%p", v) + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") + + // Function with param and no returns. + v2 := TestFormatter + nv2 := (*func(*testing.T))(nil) + pv2 := &v2 + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "func(*testing.T)" + v2s := fmt.Sprintf("%p", v2) + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s) + addFormatterTest("%v", &pv2, "<**>"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%+v", v2, v2s) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%+v", nv2, "") + addFormatterTest("%#v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s) + addFormatterTest("%#v", nv2, "(*"+v2t+")"+"") + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s) + addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"") + + // Function with multiple params and multiple returns. + var v3 = func(i int, s string) (b bool, err error) { + return true, nil + } + nv3 := (*func(int, string) (bool, error))(nil) + pv3 := &v3 + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "func(int, string) (bool, error)" + v3s := fmt.Sprintf("%p", v3) + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s) + addFormatterTest("%v", &pv3, "<**>"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%+v", v3, v3s) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%+v", nv3, "") + addFormatterTest("%#v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s) + addFormatterTest("%#v", nv3, "(*"+v3t+")"+"") + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s) + addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"") +} + +func addCircularFormatterTests() { + // Struct that is circular through self referencing. + type circular struct { + c *circular + } + v := circular{nil} + v.c = &v + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.circular" + vs := "{<*>{<*>}}" + vs2 := "{<*>}" + vs3 := "{c:<*>(" + vAddr + "){c:<*>(" + vAddr + ")}}" + vs4 := "{c:<*>(" + vAddr + ")}" + vs5 := "{c:(*" + vt + "){c:(*" + vt + ")}}" + vs6 := "{c:(*" + vt + ")}" + vs7 := "{c:(*" + vt + ")(" + vAddr + "){c:(*" + vt + ")(" + vAddr + + ")}}" + vs8 := "{c:(*" + vt + ")(" + vAddr + ")}" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs2) + addFormatterTest("%v", &pv, "<**>"+vs2) + addFormatterTest("%+v", v, vs3) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs4) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs4) + addFormatterTest("%#v", v, "("+vt+")"+vs5) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs6) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs6) + addFormatterTest("%#+v", v, "("+vt+")"+vs7) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs8) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs8) + + // Structs that are circular through cross referencing. + v2 := xref1{nil} + ts2 := xref2{&v2} + v2.ps2 = &ts2 + pv2 := &v2 + ts2Addr := fmt.Sprintf("%p", &ts2) + v2Addr := fmt.Sprintf("%p", pv2) + pv2Addr := fmt.Sprintf("%p", &pv2) + v2t := "spew_test.xref1" + v2t2 := "spew_test.xref2" + v2s := "{<*>{<*>{<*>}}}" + v2s2 := "{<*>{<*>}}" + v2s3 := "{ps2:<*>(" + ts2Addr + "){ps1:<*>(" + v2Addr + "){ps2:<*>(" + + ts2Addr + ")}}}" + v2s4 := "{ps2:<*>(" + ts2Addr + "){ps1:<*>(" + v2Addr + ")}}" + v2s5 := "{ps2:(*" + v2t2 + "){ps1:(*" + v2t + "){ps2:(*" + v2t2 + + ")}}}" + v2s6 := "{ps2:(*" + v2t2 + "){ps1:(*" + v2t + ")}}" + v2s7 := "{ps2:(*" + v2t2 + ")(" + ts2Addr + "){ps1:(*" + v2t + + ")(" + v2Addr + "){ps2:(*" + v2t2 + ")(" + ts2Addr + + ")}}}" + v2s8 := "{ps2:(*" + v2t2 + ")(" + ts2Addr + "){ps1:(*" + v2t + + ")(" + v2Addr + ")}}" + addFormatterTest("%v", v2, v2s) + addFormatterTest("%v", pv2, "<*>"+v2s2) + addFormatterTest("%v", &pv2, "<**>"+v2s2) + addFormatterTest("%+v", v2, v2s3) + addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s4) + addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s4) + addFormatterTest("%#v", v2, "("+v2t+")"+v2s5) + addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s6) + addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s6) + addFormatterTest("%#+v", v2, "("+v2t+")"+v2s7) + addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s8) + addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s8) + + // Structs that are indirectly circular. + v3 := indirCir1{nil} + tic2 := indirCir2{nil} + tic3 := indirCir3{&v3} + tic2.ps3 = &tic3 + v3.ps2 = &tic2 + pv3 := &v3 + tic2Addr := fmt.Sprintf("%p", &tic2) + tic3Addr := fmt.Sprintf("%p", &tic3) + v3Addr := fmt.Sprintf("%p", pv3) + pv3Addr := fmt.Sprintf("%p", &pv3) + v3t := "spew_test.indirCir1" + v3t2 := "spew_test.indirCir2" + v3t3 := "spew_test.indirCir3" + v3s := "{<*>{<*>{<*>{<*>}}}}" + v3s2 := "{<*>{<*>{<*>}}}" + v3s3 := "{ps2:<*>(" + tic2Addr + "){ps3:<*>(" + tic3Addr + "){ps1:<*>(" + + v3Addr + "){ps2:<*>(" + tic2Addr + ")}}}}" + v3s4 := "{ps2:<*>(" + tic2Addr + "){ps3:<*>(" + tic3Addr + "){ps1:<*>(" + + v3Addr + ")}}}" + v3s5 := "{ps2:(*" + v3t2 + "){ps3:(*" + v3t3 + "){ps1:(*" + v3t + + "){ps2:(*" + v3t2 + ")}}}}" + v3s6 := "{ps2:(*" + v3t2 + "){ps3:(*" + v3t3 + "){ps1:(*" + v3t + + ")}}}" + v3s7 := "{ps2:(*" + v3t2 + ")(" + tic2Addr + "){ps3:(*" + v3t3 + ")(" + + tic3Addr + "){ps1:(*" + v3t + ")(" + v3Addr + "){ps2:(*" + v3t2 + + ")(" + tic2Addr + ")}}}}" + v3s8 := "{ps2:(*" + v3t2 + ")(" + tic2Addr + "){ps3:(*" + v3t3 + ")(" + + tic3Addr + "){ps1:(*" + v3t + ")(" + v3Addr + ")}}}" + addFormatterTest("%v", v3, v3s) + addFormatterTest("%v", pv3, "<*>"+v3s2) + addFormatterTest("%v", &pv3, "<**>"+v3s2) + addFormatterTest("%+v", v3, v3s3) + addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s4) + addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s4) + addFormatterTest("%#v", v3, "("+v3t+")"+v3s5) + addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s6) + addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s6) + addFormatterTest("%#+v", v3, "("+v3t+")"+v3s7) + addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s8) + addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s8) +} + +func addPanicFormatterTests() { + // Type that panics in its Stringer interface. + v := panicer(127) + nv := (*panicer)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.panicer" + vs := "(PANIC=test panic)127" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") +} + +func addErrorFormatterTests() { + // Type that has a custom Error interface. + v := customError(127) + nv := (*customError)(nil) + pv := &v + vAddr := fmt.Sprintf("%p", pv) + pvAddr := fmt.Sprintf("%p", &pv) + vt := "spew_test.customError" + vs := "error: 127" + addFormatterTest("%v", v, vs) + addFormatterTest("%v", pv, "<*>"+vs) + addFormatterTest("%v", &pv, "<**>"+vs) + addFormatterTest("%v", nv, "") + addFormatterTest("%+v", v, vs) + addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs) + addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%+v", nv, "") + addFormatterTest("%#v", v, "("+vt+")"+vs) + addFormatterTest("%#v", pv, "(*"+vt+")"+vs) + addFormatterTest("%#v", &pv, "(**"+vt+")"+vs) + addFormatterTest("%#v", nv, "(*"+vt+")"+"") + addFormatterTest("%#+v", v, "("+vt+")"+vs) + addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs) + addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs) + addFormatterTest("%#+v", nv, "(*"+vt+")"+"") +} + +func addPassthroughFormatterTests() { + // %x passthrough with uint. + v := uint(4294967295) + pv := &v + vAddr := fmt.Sprintf("%x", pv) + pvAddr := fmt.Sprintf("%x", &pv) + vs := "ffffffff" + addFormatterTest("%x", v, vs) + addFormatterTest("%x", pv, vAddr) + addFormatterTest("%x", &pv, pvAddr) + + // %#x passthrough with uint. + v2 := int(2147483647) + pv2 := &v2 + v2Addr := fmt.Sprintf("%#x", pv2) + pv2Addr := fmt.Sprintf("%#x", &pv2) + v2s := "0x7fffffff" + addFormatterTest("%#x", v2, v2s) + addFormatterTest("%#x", pv2, v2Addr) + addFormatterTest("%#x", &pv2, pv2Addr) + + // %f passthrough with precision. + addFormatterTest("%.2f", 3.1415, "3.14") + addFormatterTest("%.3f", 3.1415, "3.142") + addFormatterTest("%.4f", 3.1415, "3.1415") + + // %f passthrough with width and precision. + addFormatterTest("%5.2f", 3.1415, " 3.14") + addFormatterTest("%6.3f", 3.1415, " 3.142") + addFormatterTest("%7.4f", 3.1415, " 3.1415") + + // %d passthrough with width. + addFormatterTest("%3d", 127, "127") + addFormatterTest("%4d", 127, " 127") + addFormatterTest("%5d", 127, " 127") + + // %q passthrough with string. + addFormatterTest("%q", "test", "\"test\"") +} + +// TestFormatter executes all of the tests described by formatterTests. +func TestFormatter(t *testing.T) { + // Setup tests. + addIntFormatterTests() + addUintFormatterTests() + addBoolFormatterTests() + addFloatFormatterTests() + addComplexFormatterTests() + addArrayFormatterTests() + addSliceFormatterTests() + addStringFormatterTests() + addInterfaceFormatterTests() + addMapFormatterTests() + addStructFormatterTests() + addUintptrFormatterTests() + addUnsafePointerFormatterTests() + addChanFormatterTests() + addFuncFormatterTests() + addCircularFormatterTests() + addPanicFormatterTests() + addErrorFormatterTests() + addPassthroughFormatterTests() + + t.Logf("Running %d tests", len(formatterTests)) + for i, test := range formatterTests { + buf := new(bytes.Buffer) + spew.Fprintf(buf, test.format, test.in) + s := buf.String() + if testFailed(s, test.wants) { + t.Errorf("Formatter #%d format: %s got: %s %s", i, test.format, s, + stringizeWants(test.wants)) + continue + } + } +} + +func TestPrintSortedKeys(t *testing.T) { + cfg := spew.ConfigState{SortKeys: true} + s := cfg.Sprint(map[int]string{1: "1", 3: "3", 2: "2"}) + expected := "map[1:1 2:2 3:3]" + if s != expected { + t.Errorf("Sorted keys mismatch:\n %v %v", s, expected) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/internal_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/internal_test.go new file mode 100644 index 0000000..10dc0b1 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/internal_test.go @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* +This test file is part of the spew package rather than than the spew_test +package because it needs access to internals to properly test certain cases +which are not possible via the public interface since they should never happen. +*/ + +package spew + +import ( + "bytes" + "reflect" + "testing" + "unsafe" +) + +// dummyFmtState implements a fake fmt.State to use for testing invalid +// reflect.Value handling. This is necessary because the fmt package catches +// invalid values before invoking the formatter on them. +type dummyFmtState struct { + bytes.Buffer +} + +func (dfs *dummyFmtState) Flag(f int) bool { + if f == int('+') { + return true + } + return false +} + +func (dfs *dummyFmtState) Precision() (int, bool) { + return 0, false +} + +func (dfs *dummyFmtState) Width() (int, bool) { + return 0, false +} + +// TestInvalidReflectValue ensures the dump and formatter code handles an +// invalid reflect value properly. This needs access to internal state since it +// should never happen in real code and therefore can't be tested via the public +// API. +func TestInvalidReflectValue(t *testing.T) { + i := 1 + + // Dump invalid reflect value. + v := new(reflect.Value) + buf := new(bytes.Buffer) + d := dumpState{w: buf, cs: &Config} + d.dump(*v) + s := buf.String() + want := "" + if s != want { + t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want) + } + i++ + + // Formatter invalid reflect value. + buf2 := new(dummyFmtState) + f := formatState{value: *v, cs: &Config, fs: buf2} + f.format(*v) + s = buf2.String() + want = "" + if s != want { + t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want) + } +} + +// changeKind uses unsafe to intentionally change the kind of a reflect.Value to +// the maximum kind value which does not exist. This is needed to test the +// fallback code which punts to the standard fmt library for new types that +// might get added to the language. +func changeKind(v *reflect.Value, readOnly bool) { + rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + offsetFlag)) + *rvf = *rvf | ((1< + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew + +import ( + "fmt" + "io" +) + +// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the formatted string as a value that satisfies error. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b)) +func Errorf(format string, a ...interface{}) (err error) { + return fmt.Errorf(format, convertArgs(a)...) +} + +// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b)) +func Fprint(w io.Writer, a ...interface{}) (n int, err error) { + return fmt.Fprint(w, convertArgs(a)...) +} + +// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b)) +func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { + return fmt.Fprintf(w, format, convertArgs(a)...) +} + +// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it +// passed with a default Formatter interface returned by NewFormatter. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b)) +func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { + return fmt.Fprintln(w, convertArgs(a)...) +} + +// Print is a wrapper for fmt.Print that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b)) +func Print(a ...interface{}) (n int, err error) { + return fmt.Print(convertArgs(a)...) +} + +// Printf is a wrapper for fmt.Printf that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b)) +func Printf(format string, a ...interface{}) (n int, err error) { + return fmt.Printf(format, convertArgs(a)...) +} + +// Println is a wrapper for fmt.Println that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the number of bytes written and any write error encountered. See +// NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b)) +func Println(a ...interface{}) (n int, err error) { + return fmt.Println(convertArgs(a)...) +} + +// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the resulting string. See NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b)) +func Sprint(a ...interface{}) string { + return fmt.Sprint(convertArgs(a)...) +} + +// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were +// passed with a default Formatter interface returned by NewFormatter. It +// returns the resulting string. See NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b)) +func Sprintf(format string, a ...interface{}) string { + return fmt.Sprintf(format, convertArgs(a)...) +} + +// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it +// were passed with a default Formatter interface returned by NewFormatter. It +// returns the resulting string. See NewFormatter for formatting details. +// +// This function is shorthand for the following syntax: +// +// fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b)) +func Sprintln(a ...interface{}) string { + return fmt.Sprintln(convertArgs(a)...) +} + +// convertArgs accepts a slice of arguments and returns a slice of the same +// length with each argument converted to a default spew Formatter interface. +func convertArgs(args []interface{}) (formatters []interface{}) { + formatters = make([]interface{}, len(args)) + for index, arg := range args { + formatters[index] = NewFormatter(arg) + } + return formatters +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/spew_test.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/spew_test.go new file mode 100644 index 0000000..3831ed2 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/spew_test.go @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2013 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package spew_test + +import ( + "bytes" + "fmt" + "github.com/davecgh/go-spew/spew" + "io/ioutil" + "os" + "testing" +) + +// spewFunc is used to identify which public function of the spew package or +// ConfigState a test applies to. +type spewFunc int + +const ( + fCSFdump spewFunc = iota + fCSFprint + fCSFprintf + fCSFprintln + fCSPrint + fCSPrintln + fCSSdump + fCSSprint + fCSSprintf + fCSSprintln + fCSErrorf + fCSNewFormatter + fErrorf + fFprint + fFprintln + fPrint + fPrintln + fSdump + fSprint + fSprintf + fSprintln +) + +// Map of spewFunc values to names for pretty printing. +var spewFuncStrings = map[spewFunc]string{ + fCSFdump: "ConfigState.Fdump", + fCSFprint: "ConfigState.Fprint", + fCSFprintf: "ConfigState.Fprintf", + fCSFprintln: "ConfigState.Fprintln", + fCSSdump: "ConfigState.Sdump", + fCSPrint: "ConfigState.Print", + fCSPrintln: "ConfigState.Println", + fCSSprint: "ConfigState.Sprint", + fCSSprintf: "ConfigState.Sprintf", + fCSSprintln: "ConfigState.Sprintln", + fCSErrorf: "ConfigState.Errorf", + fCSNewFormatter: "ConfigState.NewFormatter", + fErrorf: "spew.Errorf", + fFprint: "spew.Fprint", + fFprintln: "spew.Fprintln", + fPrint: "spew.Print", + fPrintln: "spew.Println", + fSdump: "spew.Sdump", + fSprint: "spew.Sprint", + fSprintf: "spew.Sprintf", + fSprintln: "spew.Sprintln", +} + +func (f spewFunc) String() string { + if s, ok := spewFuncStrings[f]; ok { + return s + } + return fmt.Sprintf("Unknown spewFunc (%d)", int(f)) +} + +// spewTest is used to describe a test to be performed against the public +// functions of the spew package or ConfigState. +type spewTest struct { + cs *spew.ConfigState + f spewFunc + format string + in interface{} + want string +} + +// spewTests houses the tests to be performed against the public functions of +// the spew package and ConfigState. +// +// These tests are only intended to ensure the public functions are exercised +// and are intentionally not exhaustive of types. The exhaustive type +// tests are handled in the dump and format tests. +var spewTests []spewTest + +// redirStdout is a helper function to return the standard output from f as a +// byte slice. +func redirStdout(f func()) ([]byte, error) { + tempFile, err := ioutil.TempFile("", "ss-test") + if err != nil { + return nil, err + } + fileName := tempFile.Name() + defer os.Remove(fileName) // Ignore error + + origStdout := os.Stdout + os.Stdout = tempFile + f() + os.Stdout = origStdout + tempFile.Close() + + return ioutil.ReadFile(fileName) +} + +func initSpewTests() { + // Config states with various settings. + scsDefault := spew.NewDefaultConfig() + scsNoMethods := &spew.ConfigState{Indent: " ", DisableMethods: true} + scsNoPmethods := &spew.ConfigState{Indent: " ", DisablePointerMethods: true} + scsMaxDepth := &spew.ConfigState{Indent: " ", MaxDepth: 1} + scsContinue := &spew.ConfigState{Indent: " ", ContinueOnMethod: true} + + // Variables for tests on types which implement Stringer interface with and + // without a pointer receiver. + ts := stringer("test") + tps := pstringer("test") + + // depthTester is used to test max depth handling for structs, array, slices + // and maps. + type depthTester struct { + ic indirCir1 + arr [1]string + slice []string + m map[string]int + } + dt := depthTester{indirCir1{nil}, [1]string{"arr"}, []string{"slice"}, + map[string]int{"one": 1}} + + // Variable for tests on types which implement error interface. + te := customError(10) + + spewTests = []spewTest{ + {scsDefault, fCSFdump, "", int8(127), "(int8) 127\n"}, + {scsDefault, fCSFprint, "", int16(32767), "32767"}, + {scsDefault, fCSFprintf, "%v", int32(2147483647), "2147483647"}, + {scsDefault, fCSFprintln, "", int(2147483647), "2147483647\n"}, + {scsDefault, fCSPrint, "", int64(9223372036854775807), "9223372036854775807"}, + {scsDefault, fCSPrintln, "", uint8(255), "255\n"}, + {scsDefault, fCSSdump, "", uint8(64), "(uint8) 64\n"}, + {scsDefault, fCSSprint, "", complex(1, 2), "(1+2i)"}, + {scsDefault, fCSSprintf, "%v", complex(float32(3), 4), "(3+4i)"}, + {scsDefault, fCSSprintln, "", complex(float64(5), 6), "(5+6i)\n"}, + {scsDefault, fCSErrorf, "%#v", uint16(65535), "(uint16)65535"}, + {scsDefault, fCSNewFormatter, "%v", uint32(4294967295), "4294967295"}, + {scsDefault, fErrorf, "%v", uint64(18446744073709551615), "18446744073709551615"}, + {scsDefault, fFprint, "", float32(3.14), "3.14"}, + {scsDefault, fFprintln, "", float64(6.28), "6.28\n"}, + {scsDefault, fPrint, "", true, "true"}, + {scsDefault, fPrintln, "", false, "false\n"}, + {scsDefault, fSdump, "", complex(-10, -20), "(complex128) (-10-20i)\n"}, + {scsDefault, fSprint, "", complex(-1, -2), "(-1-2i)"}, + {scsDefault, fSprintf, "%v", complex(float32(-3), -4), "(-3-4i)"}, + {scsDefault, fSprintln, "", complex(float64(-5), -6), "(-5-6i)\n"}, + {scsNoMethods, fCSFprint, "", ts, "test"}, + {scsNoMethods, fCSFprint, "", &ts, "<*>test"}, + {scsNoMethods, fCSFprint, "", tps, "test"}, + {scsNoMethods, fCSFprint, "", &tps, "<*>test"}, + {scsNoPmethods, fCSFprint, "", ts, "stringer test"}, + {scsNoPmethods, fCSFprint, "", &ts, "<*>stringer test"}, + {scsNoPmethods, fCSFprint, "", tps, "test"}, + {scsNoPmethods, fCSFprint, "", &tps, "<*>stringer test"}, + {scsMaxDepth, fCSFprint, "", dt, "{{} [] [] map[]}"}, + {scsMaxDepth, fCSFdump, "", dt, "(spew_test.depthTester) {\n" + + " ic: (spew_test.indirCir1) {\n \n },\n" + + " arr: ([1]string) (len=1 cap=1) {\n \n },\n" + + " slice: ([]string) (len=1 cap=1) {\n \n },\n" + + " m: (map[string]int) (len=1) {\n \n }\n}\n"}, + {scsContinue, fCSFprint, "", ts, "(stringer test) test"}, + {scsContinue, fCSFdump, "", ts, "(spew_test.stringer) " + + "(len=4) (stringer test) \"test\"\n"}, + {scsContinue, fCSFprint, "", te, "(error: 10) 10"}, + {scsContinue, fCSFdump, "", te, "(spew_test.customError) " + + "(error: 10) 10\n"}, + } +} + +// TestSpew executes all of the tests described by spewTests. +func TestSpew(t *testing.T) { + initSpewTests() + + t.Logf("Running %d tests", len(spewTests)) + for i, test := range spewTests { + buf := new(bytes.Buffer) + switch test.f { + case fCSFdump: + test.cs.Fdump(buf, test.in) + + case fCSFprint: + test.cs.Fprint(buf, test.in) + + case fCSFprintf: + test.cs.Fprintf(buf, test.format, test.in) + + case fCSFprintln: + test.cs.Fprintln(buf, test.in) + + case fCSPrint: + b, err := redirStdout(func() { test.cs.Print(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fCSPrintln: + b, err := redirStdout(func() { test.cs.Println(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fCSSdump: + str := test.cs.Sdump(test.in) + buf.WriteString(str) + + case fCSSprint: + str := test.cs.Sprint(test.in) + buf.WriteString(str) + + case fCSSprintf: + str := test.cs.Sprintf(test.format, test.in) + buf.WriteString(str) + + case fCSSprintln: + str := test.cs.Sprintln(test.in) + buf.WriteString(str) + + case fCSErrorf: + err := test.cs.Errorf(test.format, test.in) + buf.WriteString(err.Error()) + + case fCSNewFormatter: + fmt.Fprintf(buf, test.format, test.cs.NewFormatter(test.in)) + + case fErrorf: + err := spew.Errorf(test.format, test.in) + buf.WriteString(err.Error()) + + case fFprint: + spew.Fprint(buf, test.in) + + case fFprintln: + spew.Fprintln(buf, test.in) + + case fPrint: + b, err := redirStdout(func() { spew.Print(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fPrintln: + b, err := redirStdout(func() { spew.Println(test.in) }) + if err != nil { + t.Errorf("%v #%d %v", test.f, i, err) + continue + } + buf.Write(b) + + case fSdump: + str := spew.Sdump(test.in) + buf.WriteString(str) + + case fSprint: + str := spew.Sprint(test.in) + buf.WriteString(str) + + case fSprintf: + str := spew.Sprintf(test.format, test.in) + buf.WriteString(str) + + case fSprintln: + str := spew.Sprintln(test.in) + buf.WriteString(str) + + default: + t.Errorf("%v #%d unrecognized function", test.f, i) + continue + } + s := buf.String() + if test.want != s { + t.Errorf("ConfigState #%d\n got: %s want: %s", i, s, test.want) + continue + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/testdata/dumpcgo.go b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/testdata/dumpcgo.go new file mode 100644 index 0000000..5c87dd4 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/testdata/dumpcgo.go @@ -0,0 +1,82 @@ +// Copyright (c) 2013 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when both cgo is supported and "-tags testcgo" is added to the go test +// command line. This code should really only be in the dumpcgo_test.go file, +// but unfortunately Go will not allow cgo in test files, so this is a +// workaround to allow cgo types to be tested. This configuration is used +// because spew itself does not require cgo to run even though it does handle +// certain cgo types specially. Rather than forcing all clients to require cgo +// and an external C compiler just to run the tests, this scheme makes them +// optional. +// +build cgo,testcgo + +package testdata + +/* +#include +typedef unsigned char custom_uchar_t; + +char *ncp = 0; +char *cp = "test"; +char ca[6] = {'t', 'e', 's', 't', '2', '\0'}; +unsigned char uca[6] = {'t', 'e', 's', 't', '3', '\0'}; +signed char sca[6] = {'t', 'e', 's', 't', '4', '\0'}; +uint8_t ui8ta[6] = {'t', 'e', 's', 't', '5', '\0'}; +custom_uchar_t tuca[6] = {'t', 'e', 's', 't', '6', '\0'}; +*/ +import "C" + +// GetCgoNullCharPointer returns a null char pointer via cgo. This is only +// used for tests. +func GetCgoNullCharPointer() interface{} { + return C.ncp +} + +// GetCgoCharPointer returns a char pointer via cgo. This is only used for +// tests. +func GetCgoCharPointer() interface{} { + return C.cp +} + +// GetCgoCharArray returns a char array via cgo and the array's len and cap. +// This is only used for tests. +func GetCgoCharArray() (interface{}, int, int) { + return C.ca, len(C.ca), cap(C.ca) +} + +// GetCgoUnsignedCharArray returns an unsigned char array via cgo and the +// array's len and cap. This is only used for tests. +func GetCgoUnsignedCharArray() (interface{}, int, int) { + return C.uca, len(C.uca), cap(C.uca) +} + +// GetCgoSignedCharArray returns a signed char array via cgo and the array's len +// and cap. This is only used for tests. +func GetCgoSignedCharArray() (interface{}, int, int) { + return C.sca, len(C.sca), cap(C.sca) +} + +// GetCgoUint8tArray returns a uint8_t array via cgo and the array's len and +// cap. This is only used for tests. +func GetCgoUint8tArray() (interface{}, int, int) { + return C.ui8ta, len(C.ui8ta), cap(C.ui8ta) +} + +// GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via +// cgo and the array's len and cap. This is only used for tests. +func GetCgoTypdefedUnsignedCharArray() (interface{}, int, int) { + return C.tuca, len(C.tuca), cap(C.tuca) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/.test-coverage.sh b/gocv/Godeps/_workspace/src/github.com/gonum/blas/.test-coverage.sh new file mode 100644 index 0000000..3df03f5 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/.test-coverage.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# based on http://stackoverflow.com/questions/21126011/is-it-possible-to-post-coverage-for-multiple-packages-to-coveralls +# with script found at https://github.com/gopns/gopns/blob/master/test-coverage.sh + +echo "mode: set" > acc.out +returnval=`go test -v -coverprofile=profile.out` +echo ${returnval} +if [[ ${returnval} != *FAIL* ]] +then + if [ -f profile.out ] + then + cat profile.out | grep -v "mode: set" >> acc.out + fi +else + exit 1 +fi + +for Dir in $(find ./* -maxdepth 10 -type d ); +do + if ls $Dir/*.go &> /dev/null; + then + echo $Dir + returnval=`go test -v -coverprofile=profile.out $Dir` + echo ${returnval} + if [[ ${returnval} != *FAIL* ]] + then + if [ -f profile.out ] + then + cat profile.out | grep -v "mode: set" >> acc.out + fi + else + exit 1 + fi + fi +done +if [ -n "$COVERALLS_TOKEN" ] +then + $HOME/gopath/bin/goveralls -coverprofile=acc.out -service=travis-ci -repotoken $COVERALLS_TOKEN +fi + +rm -rf ./profile.out +rm -rf ./acc.out diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/.travis.yml b/gocv/Godeps/_workspace/src/github.com/gonum/blas/.travis.yml new file mode 100644 index 0000000..5384952 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/.travis.yml @@ -0,0 +1,68 @@ +language: go + +env: + global: + - secure: "gewG9b13l2/JJkag584f/e7vbH+CN5sE/v5IxJLI24vVBsta0L/rUiRN5e/NRXiyNDT4X2XV6R6BLED8VaUo3vDSWHBFtRAuwbMswxRcjDuIGph53zTNukhEwbFThEhZO5vO9T1tECXK1D8ktgQjmqwQ171InUy2loLFWloUTF4=" # at some point, when testing on osx + matrix: + - BLAS_LIB=OpenBLAS && GOARCH=amd64 + #- BLAS_LIB=native && GOCROSS=386 && GO386=387 # GOCROSS will be renamed GOARCH to avoid gvm (?) from fiddling with it + # at some point, when travis allows builds on darwin + #- BLAS_LIB=Accellerate + # at some point, when the issue with drotgm is resolved + #- BLAS_LIB=ATLAS + + +go: + - 1.3.3 + - 1.4.1 + - tip + +before_install: + - sudo apt-get update -qq + - if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi + - go get github.com/mattn/goveralls + + +install: + - if [[ "$BLAS_LIB" == "ATLAS" ]]; then sudo apt-get install -qq libatlas-base-dev; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo apt-get install -qq gfortran; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then pushd ~; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo git clone --depth=1 git://github.com/xianyi/OpenBLAS; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then pushd OpenBLAS; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo make FC=gfortran &> /dev/null; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo make PREFIX=/usr install; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then popd; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then curl http://www.netlib.org/blas/blast-forum/cblas.tgz | tar -zx; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then pushd CBLAS; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo mv Makefile.LINUX Makefile.in; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo BLLIB=/usr/lib/libopenblas.a make alllib; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then sudo mv lib/cblas_LINUX.a /usr/lib/libcblas.a; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then popd; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then popd; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then export CGO_LDFLAGS="-L/usr/lib -lopenblas"; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then go get github.com/gonum/blas; fi # get rid of this when the fork is merged + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then pushd cgo; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then go install -v -x; fi + - if [[ "$BLAS_LIB" == "OpenBLAS" ]]; then popd; fi + - if [[ "$GOCROSS" == "386" && "$TRAVIS_GO_VERSION" != "tip" ]]; then export GOARCH=386; fi + - if [[ "$GOARCH" == "386" ]]; then gvm cross linux 386; fi + + +script: + - go version + - go env + - env + - if [[ "$BLAS_LIB" == "native" ]]; then pushd native; fi + - go get -d -t -v ./... + - go test -x -v ./... + - diff <(gofmt -d .) <("") + - if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash -c "${TRAVIS_BUILD_DIR}/.test-coverage.sh"; fi + +after_failure: failure + +notifications: + email: + recipients: + - jonathan.lawlor@gmail.com + on_success: change + on_failure: always diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/README.md b/gocv/Godeps/_workspace/src/github.com/gonum/blas/README.md new file mode 100644 index 0000000..76f60a0 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/README.md @@ -0,0 +1,95 @@ +# Gonum BLAS [![Build Status](https://travis-ci.org/gonum/blas.svg?branch=master)](https://travis-ci.org/gonum/blas) [![Coverage Status](https://img.shields.io/coveralls/gonum/blas.svg)](https://coveralls.io/r/gonum/blas) + +A collection of packages to provide BLAS functionality for the [Go programming +language](http://golang.org) + +## Installation +```sh + go get github.com/gonum/blas +``` + +### BLAS C-bindings + +If you want to use OpenBLAS, install it in any directory: +```sh + git clone https://github.com/xianyi/OpenBLAS + cd OpenBLAS + make +``` + +The blas/cgo package provides bindings to C-backed BLAS packages. blas/cgo needs the `CGO_LDFLAGS` +environment variable to point to the blas installation. More information can be found in the +[cgo command documentation](http://golang.org/cmd/cgo/). + +Then install the blas/cgo package: +```sh + CGO_LDFLAGS="-L/path/to/OpenBLAS -lopenblas" go install github.com/gonum/blas/cgo +``` + +For Windows you can download binary packages for OpenBLAS at +[SourceForge](http://sourceforge.net/projects/openblas/files/). + +If you want to use a different BLAS package such as the Intel MKL you can +adjust the `CGO_LDFLAGS` variable: +```sh + CGO_LDFLAGS="-lmkl_rt" go install github.com/gonum/blas/cgo +``` + +On OS X the easiest solution is to use the libraries provided by the system: +```sh + CGO_LDFLAGS="-framework Accelerate" go install github.com/gonum/blas/cgo +``` + +## Packages + +### blas + +Defines [BLAS API](http://www.netlib.org/blas/blast-forum/cinterface.pdf) split in several interfaces + +### blas/native + +Go implementation of the BLAS API (incomplete, implements the float64 API) + +### blas/cgo + +Binding to a C implementation of the cblas interface (e.g. ATLAS, OpenBLAS, Intel MKL) + +The recommended (free) option for good performance on both Linux and Darwin is OpenBLAS. + +### blas/blas64 + +Wrapper for an implementation of the double precision real (i.e., `float64`) part +of the blas API + +```Go +package main + +import ( + "fmt" + + "github.com/gonum/blas/blas64" +) + +func main() { + v := blas64.Vector{Inc: 1, Data: []float64{1, 1, 1}} + fmt.Println("v has length:", blas64.Nrm2(len(v.Data), v)) +} +``` + +### blas/cblas128 + +Wrapper for an implementation of the double precision complex (i.e., `complex128`) +part of the blas API + +Currently blas/cblas128 requires blas/cgo. + +## Issues + +If you find any bugs, feel free to file an issue on the github issue tracker. +Discussions on API changes, added features, code review, or similar requests +are preferred on the [gonum-dev Google Group](https://groups.google.com/forum/#!forum/gonum-dev). + +## License + +Please see [github.com/gonum/license](https://github.com/gonum/license) for general +license information, contributors, authors, etc on the Gonum suite of packages. diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/blas.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/blas.go new file mode 100644 index 0000000..6c14aac --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/blas.go @@ -0,0 +1,388 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +/* +Package blas provides interfaces for the BLAS linear algebra standard. + +All methods must perform appropriate parameter checking and panic if +provided parameters that do not conform to the requirements specified +by the BLAS standard. + +Quick Reference Guide to the BLAS from http://www.netlib.org/lapack/lug/node145.html + +This version is modified to remove the "order" option. All matrix operations are +on row-order matrices. + +Level 1 BLAS + + dim scalar vector vector scalars 5-element prefixes + struct + + _rotg ( a, b ) S, D + _rotmg( d1, d2, a, b ) S, D + _rot ( n, x, incX, y, incY, c, s ) S, D + _rotm ( n, x, incX, y, incY, param ) S, D + _swap ( n, x, incX, y, incY ) S, D, C, Z + _scal ( n, alpha, x, incX ) S, D, C, Z, Cs, Zd + _copy ( n, x, incX, y, incY ) S, D, C, Z + _axpy ( n, alpha, x, incX, y, incY ) S, D, C, Z + _dot ( n, x, incX, y, incY ) S, D, Ds + _dotu ( n, x, incX, y, incY ) C, Z + _dotc ( n, x, incX, y, incY ) C, Z + __dot ( n, alpha, x, incX, y, incY ) Sds + _nrm2 ( n, x, incX ) S, D, Sc, Dz + _asum ( n, x, incX ) S, D, Sc, Dz + I_amax( n, x, incX ) s, d, c, z + +Level 2 BLAS + + options dim b-width scalar matrix vector scalar vector prefixes + + _gemv ( trans, m, n, alpha, a, lda, x, incX, beta, y, incY ) S, D, C, Z + _gbmv ( trans, m, n, kL, kU, alpha, a, lda, x, incX, beta, y, incY ) S, D, C, Z + _hemv ( uplo, n, alpha, a, lda, x, incX, beta, y, incY ) C, Z + _hbmv ( uplo, n, k, alpha, a, lda, x, incX, beta, y, incY ) C, Z + _hpmv ( uplo, n, alpha, ap, x, incX, beta, y, incY ) C, Z + _symv ( uplo, n, alpha, a, lda, x, incX, beta, y, incY ) S, D + _sbmv ( uplo, n, k, alpha, a, lda, x, incX, beta, y, incY ) S, D + _spmv ( uplo, n, alpha, ap, x, incX, beta, y, incY ) S, D + _trmv ( uplo, trans, diag, n, a, lda, x, incX ) S, D, C, Z + _tbmv ( uplo, trans, diag, n, k, a, lda, x, incX ) S, D, C, Z + _tpmv ( uplo, trans, diag, n, ap, x, incX ) S, D, C, Z + _trsv ( uplo, trans, diag, n, a, lda, x, incX ) S, D, C, Z + _tbsv ( uplo, trans, diag, n, k, a, lda, x, incX ) S, D, C, Z + _tpsv ( uplo, trans, diag, n, ap, x, incX ) S, D, C, Z + + options dim scalar vector vector matrix prefixes + + _ger ( m, n, alpha, x, incX, y, incY, a, lda ) S, D + _geru ( m, n, alpha, x, incX, y, incY, a, lda ) C, Z + _gerc ( m, n, alpha, x, incX, y, incY, a, lda ) C, Z + _her ( uplo, n, alpha, x, incX, a, lda ) C, Z + _hpr ( uplo, n, alpha, x, incX, ap ) C, Z + _her2 ( uplo, n, alpha, x, incX, y, incY, a, lda ) C, Z + _hpr2 ( uplo, n, alpha, x, incX, y, incY, ap ) C, Z + _syr ( uplo, n, alpha, x, incX, a, lda ) S, D + _spr ( uplo, n, alpha, x, incX, ap ) S, D + _syr2 ( uplo, n, alpha, x, incX, y, incY, a, lda ) S, D + _spr2 ( uplo, n, alpha, x, incX, y, incY, ap ) S, D + +Level 3 BLAS + + options dim scalar matrix matrix scalar matrix prefixes + + _gemm ( transA, transB, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc ) S, D, C, Z + _symm ( side, uplo, m, n, alpha, a, lda, b, ldb, beta, c, ldc ) S, D, C, Z + _hemm ( side, uplo, m, n, alpha, a, lda, b, ldb, beta, c, ldc ) C, Z + _syrk ( uplo, trans, n, k, alpha, a, lda, beta, c, ldc ) S, D, C, Z + _herk ( uplo, trans, n, k, alpha, a, lda, beta, c, ldc ) C, Z + _syr2k( uplo, trans, n, k, alpha, a, lda, b, ldb, beta, c, ldc ) S, D, C, Z + _her2k( uplo, trans, n, k, alpha, a, lda, b, ldb, beta, c, ldc ) C, Z + _trmm ( side, uplo, transA, diag, m, n, alpha, a, lda, b, ldb ) S, D, C, Z + _trsm ( side, uplo, transA, diag, m, n, alpha, a, lda, b, ldb ) S, D, C, Z + +Meaning of prefixes + + S - float32 C - complex64 + D - float64 Z - complex128 + +Matrix types + + GE - GEneral GB - General Band + SY - SYmmetric SB - Symmetric Band SP - Symmetric Packed + HE - HErmitian HB - Hermitian Band HP - Hermitian Packed + TR - TRiangular TB - Triangular Band TP - Triangular Packed + +Options + + trans = NoTrans, Trans, ConjTrans + uplo = Upper, Lower + diag = Nonunit, Unit + side = Left, Right (A or op(A) on the left, or A or op(A) on the right) + +For real matrices, Trans and ConjTrans have the same meaning. +For Hermitian matrices, trans = Trans is not allowed. +For complex symmetric matrices, trans = ConjTrans is not allowed. +*/ +package blas + +// Flag constants indicate Givens transformation H matrix state. +type Flag int + +const ( + Identity Flag = iota - 2 // H is the identity matrix; no rotation is needed. + Rescaling // H specifies rescaling. + OffDiagonal // Off-diagonal elements of H are units. + Diagonal // Diagonal elements of H are units. +) + +// SrotmParams contains Givens transformation parameters returned +// by the Float32 Srotm method. +type SrotmParams struct { + Flag + H [4]float32 // Column-major 2 by 2 matrix. +} + +// DrotmParams contains Givens transformation parameters returned +// by the Float64 Drotm method. +type DrotmParams struct { + Flag + H [4]float64 // Column-major 2 by 2 matrix. +} + +// Transpose is used to specify the transposition operation for a +// routine. +type Transpose int + +const ( + NoTrans Transpose = 111 + iota + Trans + ConjTrans +) + +// Uplo is used to specify whether the matrix is an upper or lower +// triangular matrix. +type Uplo int + +const ( + All Uplo = 120 + iota + Upper + Lower +) + +// Diag is used to specify whether the matrix is a unit or non-unit +// triangular matrix. +type Diag int + +const ( + NonUnit Diag = 131 + iota + Unit +) + +// Side is used to specify from which side a multiplication operation +// is performed. +type Side int + +const ( + Left Side = 141 + iota + Right +) + +// Float32 implements the single precision real BLAS routines. +type Float32 interface { + Float32Level1 + Float32Level2 + Float32Level3 +} + +// Float32Level1 implements the single precision real BLAS Level 1 routines. +type Float32Level1 interface { + Sdsdot(n int, alpha float32, x []float32, incX int, y []float32, incY int) float32 + Dsdot(n int, x []float32, incX int, y []float32, incY int) float64 + Sdot(n int, x []float32, incX int, y []float32, incY int) float32 + Snrm2(n int, x []float32, incX int) float32 + Sasum(n int, x []float32, incX int) float32 + Isamax(n int, x []float32, incX int) int + Sswap(n int, x []float32, incX int, y []float32, incY int) + Scopy(n int, x []float32, incX int, y []float32, incY int) + Saxpy(n int, alpha float32, x []float32, incX int, y []float32, incY int) + Srotg(a, b float32) (c, s, r, z float32) + Srotmg(d1, d2, b1, b2 float32) (p SrotmParams, rd1, rd2, rb1 float32) + Srot(n int, x []float32, incX int, y []float32, incY int, c, s float32) + Srotm(n int, x []float32, incX int, y []float32, incY int, p SrotmParams) + Sscal(n int, alpha float32, x []float32, incX int) +} + +// Float32Level2 implements the single precision real BLAS Level 2 routines. +type Float32Level2 interface { + Sgemv(tA Transpose, m, n int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) + Sgbmv(tA Transpose, m, n, kL, kU int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) + Strmv(ul Uplo, tA Transpose, d Diag, n int, a []float32, lda int, x []float32, incX int) + Stbmv(ul Uplo, tA Transpose, d Diag, n, k int, a []float32, lda int, x []float32, incX int) + Stpmv(ul Uplo, tA Transpose, d Diag, n int, ap []float32, x []float32, incX int) + Strsv(ul Uplo, tA Transpose, d Diag, n int, a []float32, lda int, x []float32, incX int) + Stbsv(ul Uplo, tA Transpose, d Diag, n, k int, a []float32, lda int, x []float32, incX int) + Stpsv(ul Uplo, tA Transpose, d Diag, n int, ap []float32, x []float32, incX int) + Ssymv(ul Uplo, n int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) + Ssbmv(ul Uplo, n, k int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) + Sspmv(ul Uplo, n int, alpha float32, ap []float32, x []float32, incX int, beta float32, y []float32, incY int) + Sger(m, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int) + Ssyr(ul Uplo, n int, alpha float32, x []float32, incX int, a []float32, lda int) + Sspr(ul Uplo, n int, alpha float32, x []float32, incX int, ap []float32) + Ssyr2(ul Uplo, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int) + Sspr2(ul Uplo, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32) +} + +// Float32Level3 implements the single precision real BLAS Level 3 routines. +type Float32Level3 interface { + Sgemm(tA, tB Transpose, m, n, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) + Ssymm(s Side, ul Uplo, m, n int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) + Ssyrk(ul Uplo, t Transpose, n, k int, alpha float32, a []float32, lda int, beta float32, c []float32, ldc int) + Ssyr2k(ul Uplo, t Transpose, n, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) + Strmm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha float32, a []float32, lda int, b []float32, ldb int) + Strsm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha float32, a []float32, lda int, b []float32, ldb int) +} + +// Float64 implements the single precision real BLAS routines. +type Float64 interface { + Float64Level1 + Float64Level2 + Float64Level3 +} + +// Float64Level1 implements the double precision real BLAS Level 1 routines. +type Float64Level1 interface { + Ddot(n int, x []float64, incX int, y []float64, incY int) float64 + Dnrm2(n int, x []float64, incX int) float64 + Dasum(n int, x []float64, incX int) float64 + Idamax(n int, x []float64, incX int) int + Dswap(n int, x []float64, incX int, y []float64, incY int) + Dcopy(n int, x []float64, incX int, y []float64, incY int) + Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) + Drotg(a, b float64) (c, s, r, z float64) + Drotmg(d1, d2, b1, b2 float64) (p DrotmParams, rd1, rd2, rb1 float64) + Drot(n int, x []float64, incX int, y []float64, incY int, c float64, s float64) + Drotm(n int, x []float64, incX int, y []float64, incY int, p DrotmParams) + Dscal(n int, alpha float64, x []float64, incX int) +} + +// Float64Level2 implements the double precision real BLAS Level 2 routines. +type Float64Level2 interface { + Dgemv(tA Transpose, m, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) + Dgbmv(tA Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) + Dtrmv(ul Uplo, tA Transpose, d Diag, n int, a []float64, lda int, x []float64, incX int) + Dtbmv(ul Uplo, tA Transpose, d Diag, n, k int, a []float64, lda int, x []float64, incX int) + Dtpmv(ul Uplo, tA Transpose, d Diag, n int, ap []float64, x []float64, incX int) + Dtrsv(ul Uplo, tA Transpose, d Diag, n int, a []float64, lda int, x []float64, incX int) + Dtbsv(ul Uplo, tA Transpose, d Diag, n, k int, a []float64, lda int, x []float64, incX int) + Dtpsv(ul Uplo, tA Transpose, d Diag, n int, ap []float64, x []float64, incX int) + Dsymv(ul Uplo, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) + Dsbmv(ul Uplo, n, k int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) + Dspmv(ul Uplo, n int, alpha float64, ap []float64, x []float64, incX int, beta float64, y []float64, incY int) + Dger(m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) + Dsyr(ul Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int) + Dspr(ul Uplo, n int, alpha float64, x []float64, incX int, ap []float64) + Dsyr2(ul Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) + Dspr2(ul Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64) +} + +// Float64Level3 implements the double precision real BLAS Level 3 routines. +type Float64Level3 interface { + Dgemm(tA, tB Transpose, m, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) + Dsymm(s Side, ul Uplo, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) + Dsyrk(ul Uplo, t Transpose, n, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int) + Dsyr2k(ul Uplo, t Transpose, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) + Dtrmm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) + Dtrsm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) +} + +// Complex64 implements the single precision complex BLAS routines. +type Complex64 interface { + Complex64Level1 + Complex64Level2 + Complex64Level3 +} + +// Complex64Level1 implements the single precision complex BLAS Level 1 routines. +type Complex64Level1 interface { + Cdotu(n int, x []complex64, incX int, y []complex64, incY int) (dotu complex64) + Cdotc(n int, x []complex64, incX int, y []complex64, incY int) (dotc complex64) + Scnrm2(n int, x []complex64, incX int) float32 + Scasum(n int, x []complex64, incX int) float32 + Icamax(n int, x []complex64, incX int) int + Cswap(n int, x []complex64, incX int, y []complex64, incY int) + Ccopy(n int, x []complex64, incX int, y []complex64, incY int) + Caxpy(n int, alpha complex64, x []complex64, incX int, y []complex64, incY int) + Cscal(n int, alpha complex64, x []complex64, incX int) + Csscal(n int, alpha float32, x []complex64, incX int) +} + +// Complex64Level2 implements the single precision complex BLAS routines Level 2 routines. +type Complex64Level2 interface { + Cgemv(tA Transpose, m, n int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) + Cgbmv(tA Transpose, m, n, kL, kU int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) + Ctrmv(ul Uplo, tA Transpose, d Diag, n int, a []complex64, lda int, x []complex64, incX int) + Ctbmv(ul Uplo, tA Transpose, d Diag, n, k int, a []complex64, lda int, x []complex64, incX int) + Ctpmv(ul Uplo, tA Transpose, d Diag, n int, ap []complex64, x []complex64, incX int) + Ctrsv(ul Uplo, tA Transpose, d Diag, n int, a []complex64, lda int, x []complex64, incX int) + Ctbsv(ul Uplo, tA Transpose, d Diag, n, k int, a []complex64, lda int, x []complex64, incX int) + Ctpsv(ul Uplo, tA Transpose, d Diag, n int, ap []complex64, x []complex64, incX int) + Chemv(ul Uplo, n int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) + Chbmv(ul Uplo, n, k int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) + Chpmv(ul Uplo, n int, alpha complex64, ap []complex64, x []complex64, incX int, beta complex64, y []complex64, incY int) + Cgeru(m, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) + Cgerc(m, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) + Cher(ul Uplo, n int, alpha float32, x []complex64, incX int, a []complex64, lda int) + Chpr(ul Uplo, n int, alpha float32, x []complex64, incX int, a []complex64) + Cher2(ul Uplo, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) + Chpr2(ul Uplo, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, ap []complex64) +} + +// Complex64Level3 implements the single precision complex BLAS Level 3 routines. +type Complex64Level3 interface { + Cgemm(tA, tB Transpose, m, n, k int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) + Csymm(s Side, ul Uplo, m, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) + Csyrk(ul Uplo, t Transpose, n, k int, alpha complex64, a []complex64, lda int, beta complex64, c []complex64, ldc int) + Csyr2k(ul Uplo, t Transpose, n, k int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) + Ctrmm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int) + Ctrsm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int) + Chemm(s Side, ul Uplo, m, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) + Cherk(ul Uplo, t Transpose, n, k int, alpha float32, a []complex64, lda int, beta float32, c []complex64, ldc int) + Cher2k(ul Uplo, t Transpose, n, k int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta float32, c []complex64, ldc int) +} + +// Complex128 implements the double precision complex BLAS routines. +type Complex128 interface { + Complex128Level1 + Complex128Level2 + Complex128Level3 +} + +// Complex128Level1 implements the double precision complex BLAS Level 1 routines. +type Complex128Level1 interface { + Zdotu(n int, x []complex128, incX int, y []complex128, incY int) (dotu complex128) + Zdotc(n int, x []complex128, incX int, y []complex128, incY int) (dotc complex128) + Dznrm2(n int, x []complex128, incX int) float64 + Dzasum(n int, x []complex128, incX int) float64 + Izamax(n int, x []complex128, incX int) int + Zswap(n int, x []complex128, incX int, y []complex128, incY int) + Zcopy(n int, x []complex128, incX int, y []complex128, incY int) + Zaxpy(n int, alpha complex128, x []complex128, incX int, y []complex128, incY int) + Zscal(n int, alpha complex128, x []complex128, incX int) + Zdscal(n int, alpha float64, x []complex128, incX int) +} + +// Complex128Level2 implements the double precision complex BLAS Level 2 routines. +type Complex128Level2 interface { + Zgemv(tA Transpose, m, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) + Zgbmv(tA Transpose, m, n int, kL int, kU int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) + Ztrmv(ul Uplo, tA Transpose, d Diag, n int, a []complex128, lda int, x []complex128, incX int) + Ztbmv(ul Uplo, tA Transpose, d Diag, n, k int, a []complex128, lda int, x []complex128, incX int) + Ztpmv(ul Uplo, tA Transpose, d Diag, n int, ap []complex128, x []complex128, incX int) + Ztrsv(ul Uplo, tA Transpose, d Diag, n int, a []complex128, lda int, x []complex128, incX int) + Ztbsv(ul Uplo, tA Transpose, d Diag, n, k int, a []complex128, lda int, x []complex128, incX int) + Ztpsv(ul Uplo, tA Transpose, d Diag, n int, ap []complex128, x []complex128, incX int) + Zhemv(ul Uplo, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) + Zhbmv(ul Uplo, n, k int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) + Zhpmv(ul Uplo, n int, alpha complex128, ap []complex128, x []complex128, incX int, beta complex128, y []complex128, incY int) + Zgeru(m, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) + Zgerc(m, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) + Zher(ul Uplo, n int, alpha float64, x []complex128, incX int, a []complex128, lda int) + Zhpr(ul Uplo, n int, alpha float64, x []complex128, incX int, a []complex128) + Zher2(ul Uplo, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) + Zhpr2(ul Uplo, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, ap []complex128) +} + +// Complex128Level3 implements the double precision complex BLAS Level 3 routines. +type Complex128Level3 interface { + Zgemm(tA, tB Transpose, m, n, k int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) + Zsymm(s Side, ul Uplo, m, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) + Zsyrk(ul Uplo, t Transpose, n, k int, alpha complex128, a []complex128, lda int, beta complex128, c []complex128, ldc int) + Zsyr2k(ul Uplo, t Transpose, n, k int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) + Ztrmm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int) + Ztrsm(s Side, ul Uplo, tA Transpose, d Diag, m, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int) + Zhemm(s Side, ul Uplo, m, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) + Zherk(ul Uplo, t Transpose, n, k int, alpha float64, a []complex128, lda int, beta float64, c []complex128, ldc int) + Zher2k(ul Uplo, t Transpose, n, k int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta float64, c []complex128, ldc int) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/blas64/blas64.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/blas64/blas64.go new file mode 100644 index 0000000..87b8533 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/blas64/blas64.go @@ -0,0 +1,286 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package blas64 provides a simple interface to the float64 BLAS API. +package blas64 + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/native" +) + +var blas64 blas.Float64 = native.Implementation{} + +// Use sets the BLAS float64 implementation to be used by subsequent BLAS calls. +// The default implementation is native.Implementation. +func Use(b blas.Float64) { + blas64 = b +} + +// Implementation returns the current BLAS float64 implementation. +// +// Implementation allows direct calls to the current the BLAS float64 implementation +// giving finer control of parameters. +func Implementation() blas.Float64 { + return blas64 +} + +// Vector represents a vector with an associated element increment. +type Vector struct { + Inc int + Data []float64 +} + +// General represents a matrix using the conventional storage scheme. +type General struct { + Rows, Cols int + Stride int + Data []float64 +} + +// Band represents a band matrix using the band storage scheme. +type Band struct { + Rows, Cols int + KL, KU int + Stride int + Data []float64 +} + +// Triangular represents a triangular matrix using the conventional storage scheme. +type Triangular struct { + N int + Stride int + Data []float64 + Uplo blas.Uplo + Diag blas.Diag +} + +// TriangularBand represents a triangular matrix using the band storage scheme. +type TriangularBand struct { + N, K int + Stride int + Data []float64 + Uplo blas.Uplo + Diag blas.Diag +} + +// TriangularPacked represents a triangular matrix using the packed storage scheme. +type TriangularPacked struct { + N int + Data []float64 + Uplo blas.Uplo + Diag blas.Diag +} + +// Symmetric represents a symmetric matrix using the conventional storage scheme. +type Symmetric struct { + N int + Stride int + Data []float64 + Uplo blas.Uplo +} + +// SymmetricBand represents a symmetric matrix using the band storage scheme. +type SymmetricBand struct { + N, K int + Stride int + Data []float64 + Uplo blas.Uplo +} + +// SymmetricPacked represents a symmetric matrix using the packed storage scheme. +type SymmetricPacked struct { + N int + Data []float64 + Uplo blas.Uplo +} + +// Level 1 + +const negInc = "blas64: negative vector increment" + +func Dot(n int, x, y Vector) float64 { + return blas64.Ddot(n, x.Data, x.Inc, y.Data, y.Inc) +} + +// Nrm2 will panic if the vector increment is negative. +func Nrm2(n int, x Vector) float64 { + if x.Inc < 0 { + panic(negInc) + } + return blas64.Dnrm2(n, x.Data, x.Inc) +} + +// Asum will panic if the vector increment is negative. +func Asum(n int, x Vector) float64 { + if x.Inc < 0 { + panic(negInc) + } + return blas64.Dasum(n, x.Data, x.Inc) +} + +// Iamax will panic if the vector increment is negative. +func Iamax(n int, x Vector) int { + if x.Inc < 0 { + panic(negInc) + } + return blas64.Idamax(n, x.Data, x.Inc) +} + +func Swap(n int, x, y Vector) { + blas64.Dswap(n, x.Data, x.Inc, y.Data, y.Inc) +} + +func Copy(n int, x, y Vector) { + blas64.Dcopy(n, x.Data, x.Inc, y.Data, y.Inc) +} + +func Axpy(n int, alpha float64, x, y Vector) { + blas64.Daxpy(n, alpha, x.Data, x.Inc, y.Data, y.Inc) +} + +func Rotg(a, b float64) (c, s, r, z float64) { + return blas64.Drotg(a, b) +} + +func Rotmg(d1, d2, b1, b2 float64) (p blas.DrotmParams, rd1, rd2, rb1 float64) { + return blas64.Drotmg(d1, d2, b1, b2) +} + +func Rot(n int, x, y Vector, c, s float64) { + blas64.Drot(n, x.Data, x.Inc, y.Data, y.Inc, c, s) +} + +func Rotm(n int, x, y Vector, p blas.DrotmParams) { + blas64.Drotm(n, x.Data, x.Inc, y.Data, y.Inc, p) +} + +// Scal will panic if the vector increment is negative +func Scal(n int, alpha float64, x Vector) { + if x.Inc < 0 { + panic(negInc) + } + blas64.Dscal(n, alpha, x.Data, x.Inc) +} + +// Level 2 + +func Gemv(tA blas.Transpose, alpha float64, a General, x Vector, beta float64, y Vector) { + blas64.Dgemv(tA, a.Rows, a.Cols, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Gbmv(tA blas.Transpose, alpha float64, a Band, x Vector, beta float64, y Vector) { + blas64.Dgbmv(tA, a.Rows, a.Cols, a.KL, a.KU, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Trmv(tA blas.Transpose, a Triangular, x Vector) { + blas64.Dtrmv(a.Uplo, tA, a.Diag, a.N, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tbmv(tA blas.Transpose, a TriangularBand, x Vector) { + blas64.Dtbmv(a.Uplo, tA, a.Diag, a.N, a.K, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tpmv(tA blas.Transpose, a TriangularPacked, x Vector) { + blas64.Dtpmv(a.Uplo, tA, a.Diag, a.N, a.Data, x.Data, x.Inc) +} + +func Trsv(tA blas.Transpose, a Triangular, x Vector) { + blas64.Dtrsv(a.Uplo, tA, a.Diag, a.N, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tbsv(tA blas.Transpose, a TriangularBand, x Vector) { + blas64.Dtbsv(a.Uplo, tA, a.Diag, a.N, a.K, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tpsv(tA blas.Transpose, a TriangularPacked, x Vector) { + blas64.Dtpsv(a.Uplo, tA, a.Diag, a.N, a.Data, x.Data, x.Inc) +} + +func Symv(alpha float64, a Symmetric, x Vector, beta float64, y Vector) { + blas64.Dsymv(a.Uplo, a.N, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Sbmv(alpha float64, a SymmetricBand, x Vector, beta float64, y Vector) { + blas64.Dsbmv(a.Uplo, a.N, a.K, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Spmv(alpha float64, a SymmetricPacked, x Vector, beta float64, y Vector) { + blas64.Dspmv(a.Uplo, a.N, alpha, a.Data, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Ger(alpha float64, x, y Vector, a General) { + blas64.Dger(a.Rows, a.Cols, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride) +} + +func Syr(alpha float64, x Vector, a Symmetric) { + blas64.Dsyr(a.Uplo, a.N, alpha, x.Data, x.Inc, a.Data, a.Stride) +} + +func Spr(alpha float64, x Vector, a SymmetricPacked) { + blas64.Dspr(a.Uplo, a.N, alpha, x.Data, x.Inc, a.Data) +} + +func Syr2(alpha float64, x, y Vector, a Symmetric) { + blas64.Dsyr2(a.Uplo, a.N, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride) +} + +func Spr2(alpha float64, x, y Vector, a SymmetricPacked) { + blas64.Dspr2(a.Uplo, a.N, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data) +} + +// Level 3 + +func Gemm(tA, tB blas.Transpose, alpha float64, a, b General, beta float64, c General) { + var m, n, k int + if tA == blas.NoTrans { + m, k = a.Rows, a.Cols + } else { + m, k = a.Cols, a.Rows + } + if tB == blas.NoTrans { + n = b.Cols + } else { + n = b.Rows + } + blas64.Dgemm(tA, tB, m, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Symm(s blas.Side, alpha float64, a Symmetric, b General, beta float64, c General) { + var m, n int + if s == blas.Left { + m, n = a.N, b.Cols + } else { + m, n = b.Rows, a.N + } + blas64.Dsymm(s, a.Uplo, m, n, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Syrk(t blas.Transpose, alpha float64, a General, beta float64, c Symmetric) { + var n, k int + if t == blas.NoTrans { + n, k = a.Rows, a.Cols + } else { + n, k = a.Cols, a.Rows + } + blas64.Dsyrk(c.Uplo, t, n, k, alpha, a.Data, a.Stride, beta, c.Data, c.Stride) +} + +func Syr2k(t blas.Transpose, alpha float64, a, b General, beta float64, c Symmetric) { + var n, k int + if t == blas.NoTrans { + n, k = a.Rows, a.Cols + } else { + n, k = a.Cols, a.Rows + } + blas64.Dsyr2k(c.Uplo, t, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Trmm(s blas.Side, tA blas.Transpose, alpha float64, a Triangular, b General) { + blas64.Dtrmm(s, a.Uplo, tA, a.Diag, b.Rows, b.Cols, alpha, a.Data, a.Stride, b.Data, b.Stride) +} + +func Trsm(s blas.Side, tA blas.Transpose, alpha float64, a Triangular, b General) { + blas64.Dtrsm(s, a.Uplo, tA, a.Diag, b.Rows, b.Cols, alpha, a.Data, a.Stride, b.Data, b.Stride) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cblas128/cblas128.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cblas128/cblas128.go new file mode 100644 index 0000000..1c86510 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cblas128/cblas128.go @@ -0,0 +1,327 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package cblas128 provides a simple interface to the complex128 BLAS API. +package cblas128 + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/cgo" +) + +// TODO(kortschak): Change this and the comment below to native.Implementation +// when blas/native covers the complex BLAS API. +var cblas128 blas.Complex128 = cgo.Implementation{} + +// Use sets the BLAS complex128 implementation to be used by subsequent BLAS calls. +// The default implementation is cgo.Implementation. +func Use(b blas.Complex128) { + cblas128 = b +} + +// Implementation returns the current BLAS complex128 implementation. +// +// Implementation allows direct calls to the current the BLAS complex128 implementation +// giving finer control of parameters. +func Implementation() blas.Complex128 { + return cblas128 +} + +// Vector represents a vector with an associated element increment. +type Vector struct { + Inc int + Data []complex128 +} + +// General represents a matrix using the conventional storage scheme. +type General struct { + Rows, Cols int + Stride int + Data []complex128 +} + +// Band represents a band matrix using the band storage scheme. +type Band struct { + Rows, Cols int + KL, KU int + Stride int + Data []complex128 +} + +// Triangular represents a triangular matrix using the conventional storage scheme. +type Triangular struct { + N int + Stride int + Data []complex128 + Uplo blas.Uplo + Diag blas.Diag +} + +// TriangularBand represents a triangular matrix using the band storage scheme. +type TriangularBand struct { + N, K int + Stride int + Data []complex128 + Uplo blas.Uplo + Diag blas.Diag +} + +// TriangularPacked represents a triangular matrix using the packed storage scheme. +type TriangularPacked struct { + N int + Data []complex128 + Uplo blas.Uplo + Diag blas.Diag +} + +// Symmetric represents a symmetric matrix using the conventional storage scheme. +type Symmetric struct { + N int + Stride int + Data []complex128 + Uplo blas.Uplo +} + +// SymmetricBand represents a symmetric matrix using the band storage scheme. +type SymmetricBand struct { + N, K int + Stride int + Data []complex128 + Uplo blas.Uplo +} + +// SymmetricPacked represents a symmetric matrix using the packed storage scheme. +type SymmetricPacked struct { + N int + Data []complex128 + Uplo blas.Uplo +} + +// Hermitian represents an Hermitian matrix using the conventional storage scheme. +type Hermitian Symmetric + +// HermitianBand represents an Hermitian matrix using the band storage scheme. +type HermitianBand SymmetricBand + +// HermitianPacked represents an Hermitian matrix using the packed storage scheme. +type HermitianPacked SymmetricPacked + +// Level 1 + +const negInc = "cblas128: negative vector increment" + +func Dotu(n int, x, y Vector) complex128 { + return cblas128.Zdotu(n, x.Data, x.Inc, y.Data, y.Inc) +} + +func Dotc(n int, x, y Vector) complex128 { + return cblas128.Zdotc(n, x.Data, x.Inc, y.Data, y.Inc) +} + +// Nrm2 will panic if the vector increment is negative. +func Nrm2(n int, x Vector) float64 { + if x.Inc < 0 { + panic(negInc) + } + return cblas128.Dznrm2(n, x.Data, x.Inc) +} + +// Asum will panic if the vector increment is negative. +func Asum(n int, x Vector) float64 { + if x.Inc < 0 { + panic(negInc) + } + return cblas128.Dzasum(n, x.Data, x.Inc) +} + +// Iamax will panic if the vector increment is negative. +func Iamax(n int, x Vector) int { + if x.Inc < 0 { + panic(negInc) + } + return cblas128.Izamax(n, x.Data, x.Inc) +} + +func Swap(n int, x, y Vector) { + cblas128.Zswap(n, x.Data, x.Inc, y.Data, y.Inc) +} + +func Copy(n int, x, y Vector) { + cblas128.Zcopy(n, x.Data, x.Inc, y.Data, y.Inc) +} + +func Axpy(n int, alpha complex128, x, y Vector) { + cblas128.Zaxpy(n, alpha, x.Data, x.Inc, y.Data, y.Inc) +} + +// Scal will panic if the vector increment is negative +func Scal(n int, alpha complex128, x Vector) { + if x.Inc < 0 { + panic(negInc) + } + cblas128.Zscal(n, alpha, x.Data, x.Inc) +} + +// Dscal will panic if the vector increment is negative +func Dscal(n int, alpha float64, x Vector) { + if x.Inc < 0 { + panic(negInc) + } + cblas128.Zdscal(n, alpha, x.Data, x.Inc) +} + +// Level 2 + +func Gemv(tA blas.Transpose, alpha complex128, a General, x Vector, beta complex128, y Vector) { + cblas128.Zgemv(tA, a.Rows, a.Cols, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Gbmv(tA blas.Transpose, alpha complex128, a Band, x Vector, beta complex128, y Vector) { + cblas128.Zgbmv(tA, a.Rows, a.Cols, a.KL, a.KU, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Trmv(tA blas.Transpose, a Triangular, x Vector) { + cblas128.Ztrmv(a.Uplo, tA, a.Diag, a.N, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tbmv(tA blas.Transpose, a TriangularBand, x Vector) { + cblas128.Ztbmv(a.Uplo, tA, a.Diag, a.N, a.K, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tpmv(tA blas.Transpose, a TriangularPacked, x Vector) { + cblas128.Ztpmv(a.Uplo, tA, a.Diag, a.N, a.Data, x.Data, x.Inc) +} + +func Trsv(tA blas.Transpose, a Triangular, x Vector) { + cblas128.Ztrsv(a.Uplo, tA, a.Diag, a.N, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tbsv(tA blas.Transpose, a TriangularBand, x Vector) { + cblas128.Ztbsv(a.Uplo, tA, a.Diag, a.N, a.K, a.Data, a.Stride, x.Data, x.Inc) +} + +func Tpsv(tA blas.Transpose, a TriangularPacked, x Vector) { + cblas128.Ztpsv(a.Uplo, tA, a.Diag, a.N, a.Data, x.Data, x.Inc) +} + +func Hemv(alpha complex128, a Hermitian, x Vector, beta complex128, y Vector) { + cblas128.Zhemv(a.Uplo, a.N, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Hbmv(alpha complex128, a HermitianBand, x Vector, beta complex128, y Vector) { + cblas128.Zhbmv(a.Uplo, a.N, a.K, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Hpmv(alpha complex128, a HermitianPacked, x Vector, beta complex128, y Vector) { + cblas128.Zhpmv(a.Uplo, a.N, alpha, a.Data, x.Data, x.Inc, beta, y.Data, y.Inc) +} + +func Geru(alpha complex128, x, y Vector, a General) { + cblas128.Zgeru(a.Rows, a.Cols, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride) +} + +func Gerc(alpha complex128, x, y Vector, a General) { + cblas128.Zgerc(a.Rows, a.Cols, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride) +} + +func Her(alpha float64, x Vector, a Hermitian) { + cblas128.Zher(a.Uplo, a.N, alpha, x.Data, x.Inc, a.Data, a.Stride) +} + +func Hpr(alpha float64, x Vector, a HermitianPacked) { + cblas128.Zhpr(a.Uplo, a.N, alpha, x.Data, x.Inc, a.Data) +} + +func Her2(alpha complex128, x, y Vector, a Hermitian) { + cblas128.Zher2(a.Uplo, a.N, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride) +} + +func Hpr2(alpha complex128, x, y Vector, a HermitianPacked) { + cblas128.Zhpr2(a.Uplo, a.N, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data) +} + +// Level 3 + +func Gemm(tA, tB blas.Transpose, alpha complex128, a, b General, beta complex128, c General) { + var m, n, k int + if tA == blas.NoTrans { + m, k = a.Rows, a.Cols + } else { + m, k = a.Cols, a.Rows + } + if tB == blas.NoTrans { + n = b.Cols + } else { + n = b.Rows + } + cblas128.Zgemm(tA, tB, m, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Symm(s blas.Side, alpha complex128, a Symmetric, b General, beta complex128, c General) { + var m, n int + if s == blas.Left { + m, n = a.N, b.Cols + } else { + m, n = b.Rows, a.N + } + cblas128.Zsymm(s, a.Uplo, m, n, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Syrk(t blas.Transpose, alpha complex128, a General, beta complex128, c Symmetric) { + var n, k int + if t == blas.NoTrans { + n, k = a.Rows, a.Cols + } else { + n, k = a.Cols, a.Rows + } + cblas128.Zsyrk(c.Uplo, t, n, k, alpha, a.Data, a.Stride, beta, c.Data, c.Stride) +} + +func Syr2k(t blas.Transpose, alpha complex128, a, b General, beta complex128, c Symmetric) { + var n, k int + if t == blas.NoTrans { + n, k = a.Rows, a.Cols + } else { + n, k = a.Cols, a.Rows + } + cblas128.Zsyr2k(c.Uplo, t, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Trmm(s blas.Side, tA blas.Transpose, alpha complex128, a Triangular, b General) { + cblas128.Ztrmm(s, a.Uplo, tA, a.Diag, b.Rows, b.Cols, alpha, a.Data, a.Stride, b.Data, b.Stride) +} + +func Trsm(s blas.Side, tA blas.Transpose, alpha complex128, a Triangular, b General) { + cblas128.Ztrsm(s, a.Uplo, tA, a.Diag, b.Rows, b.Cols, alpha, a.Data, a.Stride, b.Data, b.Stride) +} + +func Hemm(s blas.Side, alpha complex128, a Hermitian, b General, beta complex128, c General) { + var m, n int + if s == blas.Left { + m, n = a.N, b.Cols + } else { + m, n = b.Rows, a.N + } + cblas128.Zhemm(s, a.Uplo, m, n, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} + +func Herk(t blas.Transpose, alpha float64, a General, beta float64, c Hermitian) { + var n, k int + if t == blas.NoTrans { + n, k = a.Rows, a.Cols + } else { + n, k = a.Cols, a.Rows + } + cblas128.Zherk(c.Uplo, t, n, k, alpha, a.Data, a.Stride, beta, c.Data, c.Stride) +} + +func Her2k(t blas.Transpose, alpha complex128, a, b General, beta float64, c Hermitian) { + var n, k int + if t == blas.NoTrans { + n, k = a.Rows, a.Cols + } else { + n, k = a.Cols, a.Rows + } + cblas128.Zher2k(c.Uplo, t, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/bench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/bench_test.go new file mode 100644 index 0000000..574bfb1 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/bench_test.go @@ -0,0 +1,18 @@ +package cgo + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/testblas" +) + +const ( + Sm = testblas.SmallMat + Med = testblas.MediumMat + Lg = testblas.LargeMat + Hg = testblas.HugeMat +) + +const ( + T = blas.Trans + NT = blas.NoTrans +) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/blas.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/blas.go new file mode 100644 index 0000000..67b74fe --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/blas.go @@ -0,0 +1,3400 @@ +// Do not manually edit this file. It was created by the genBlas.pl script from cblas.h. + +// Copyright ©2014 The Gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package cgo provides bindings to a C BLAS library. +package cgo + +/* +#cgo CFLAGS: -g -O2 +#include "cblas.h" +*/ +import "C" + +import ( + "unsafe" + + "github.com/gonum/blas" +) + +// Type check assertions: +var ( + _ blas.Float32 = Implementation{} + _ blas.Float64 = Implementation{} + _ blas.Complex64 = Implementation{} + _ blas.Complex128 = Implementation{} +) + +// Type order is used to specify the matrix storage format. We still interact with +// an API that allows client calls to specify order, so this is here to document that fact. +type order int + +const ( + rowMajor order = 101 + iota +) + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +type Implementation struct{} + +// Special cases... + +type srotmParams struct { + flag float32 + h [4]float32 +} + +type drotmParams struct { + flag float64 + h [4]float64 +} + +func (Implementation) Srotg(a float32, b float32) (c float32, s float32, r float32, z float32) { + C.cblas_srotg((*C.float)(&a), (*C.float)(&b), (*C.float)(&c), (*C.float)(&s)) + return c, s, a, b +} +func (Implementation) Srotmg(d1 float32, d2 float32, b1 float32, b2 float32) (p blas.SrotmParams, rd1 float32, rd2 float32, rb1 float32) { + var pi srotmParams + C.cblas_srotmg((*C.float)(&d1), (*C.float)(&d2), (*C.float)(&b1), C.float(b2), (*C.float)(unsafe.Pointer(&pi))) + return blas.SrotmParams{Flag: blas.Flag(pi.flag), H: pi.h}, d1, d2, b1 +} +func (Implementation) Srotm(n int, x []float32, incX int, y []float32, incY int, p blas.SrotmParams) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + if p.Flag < blas.Identity || p.Flag > blas.Diagonal { + panic("blas: illegal blas.Flag value") + } + pi := srotmParams{ + flag: float32(p.Flag), + h: p.H, + } + C.cblas_srotm(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(unsafe.Pointer(&pi))) +} +func (Implementation) Drotg(a float64, b float64) (c float64, s float64, r float64, z float64) { + C.cblas_drotg((*C.double)(&a), (*C.double)(&b), (*C.double)(&c), (*C.double)(&s)) + return c, s, a, b +} +func (Implementation) Drotmg(d1 float64, d2 float64, b1 float64, b2 float64) (p blas.DrotmParams, rd1 float64, rd2 float64, rb1 float64) { + var pi drotmParams + C.cblas_drotmg((*C.double)(&d1), (*C.double)(&d2), (*C.double)(&b1), C.double(b2), (*C.double)(unsafe.Pointer(&pi))) + return blas.DrotmParams{Flag: blas.Flag(pi.flag), H: pi.h}, d1, d2, b1 +} +func (Implementation) Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + if p.Flag < blas.Identity || p.Flag > blas.Diagonal { + panic("blas: illegal blas.Flag value") + } + pi := drotmParams{ + flag: float64(p.Flag), + h: p.H, + } + C.cblas_drotm(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(unsafe.Pointer(&pi))) +} +func (Implementation) Cdotu(n int, x []complex64, incX int, y []complex64, incY int) (dotu complex64) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_cdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) + return dotu +} +func (Implementation) Cdotc(n int, x []complex64, incX int, y []complex64, incY int) (dotc complex64) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_cdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) + return dotc +} +func (Implementation) Zdotu(n int, x []complex128, incX int, y []complex128, incY int) (dotu complex128) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_zdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) + return dotu +} +func (Implementation) Zdotc(n int, x []complex128, incX int, y []complex128, incY int) (dotc complex128) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_zdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) + return dotc +} + +func (Implementation) Sdsdot(n int, alpha float32, x []float32, incX int, y []float32, incY int) float32 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + return float32(C.cblas_sdsdot(C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY))) +} +func (Implementation) Dsdot(n int, x []float32, incX int, y []float32, incY int) float64 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + return float64(C.cblas_dsdot(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY))) +} +func (Implementation) Sdot(n int, x []float32, incX int, y []float32, incY int) float32 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + return float32(C.cblas_sdot(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY))) +} +func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int) float64 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + return float64(C.cblas_ddot(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY))) +} +func (Implementation) Snrm2(n int, x []float32, incX int) float32 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float32(C.cblas_snrm2(C.int(n), (*C.float)(&x[0]), C.int(incX))) +} +func (Implementation) Sasum(n int, x []float32, incX int) float32 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float32(C.cblas_sasum(C.int(n), (*C.float)(&x[0]), C.int(incX))) +} +func (Implementation) Dnrm2(n int, x []float64, incX int) float64 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float64(C.cblas_dnrm2(C.int(n), (*C.double)(&x[0]), C.int(incX))) +} +func (Implementation) Dasum(n int, x []float64, incX int) float64 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float64(C.cblas_dasum(C.int(n), (*C.double)(&x[0]), C.int(incX))) +} +func (Implementation) Scnrm2(n int, x []complex64, incX int) float32 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float32(C.cblas_scnrm2(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) +} +func (Implementation) Scasum(n int, x []complex64, incX int) float32 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float32(C.cblas_scasum(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) +} +func (Implementation) Dznrm2(n int, x []complex128, incX int) float64 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float64(C.cblas_dznrm2(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) +} +func (Implementation) Dzasum(n int, x []complex128, incX int) float64 { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return 0 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return float64(C.cblas_dzasum(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) +} +func (Implementation) Isamax(n int, x []float32, incX int) int { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if n == 0 || incX < 0 { + return -1 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return int(C.cblas_isamax(C.int(n), (*C.float)(&x[0]), C.int(incX))) +} +func (Implementation) Idamax(n int, x []float64, incX int) int { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if n == 0 || incX < 0 { + return -1 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return int(C.cblas_idamax(C.int(n), (*C.double)(&x[0]), C.int(incX))) +} +func (Implementation) Icamax(n int, x []complex64, incX int) int { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if n == 0 || incX < 0 { + return -1 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return int(C.cblas_icamax(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) +} +func (Implementation) Izamax(n int, x []complex128, incX int) int { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if n == 0 || incX < 0 { + return -1 + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + return int(C.cblas_izamax(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) +} +func (Implementation) Sswap(n int, x []float32, incX int, y []float32, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_sswap(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Scopy(n int, x []float32, incX int, y []float32, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_scopy(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Saxpy(n int, alpha float32, x []float32, incX int, y []float32, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_saxpy(C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Dswap(n int, x []float64, incX int, y []float64, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_dswap(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Dcopy(n int, x []float64, incX int, y []float64, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_dcopy(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_daxpy(C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Cswap(n int, x []complex64, incX int, y []complex64, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_cswap(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Ccopy(n int, x []complex64, incX int, y []complex64, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_ccopy(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Caxpy(n int, alpha complex64, x []complex64, incX int, y []complex64, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_caxpy(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zswap(n int, x []complex128, incX int, y []complex128, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_zswap(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zcopy(n int, x []complex128, incX int, y []complex128, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_zcopy(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zaxpy(n int, alpha complex128, x []complex128, incX int, y []complex128, incY int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_zaxpy(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Srot(n int, x []float32, incX int, y []float32, incY int, c float32, s float32) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_srot(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), C.float(c), C.float(s)) +} +func (Implementation) Drot(n int, x []float64, incX int, y []float64, incY int, c float64, s float64) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_drot(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), C.double(c), C.double(s)) +} +func (Implementation) Sscal(n int, alpha float32, x []float32, incX int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + C.cblas_sscal(C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Dscal(n int, alpha float64, x []float64, incX int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + C.cblas_dscal(C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Cscal(n int, alpha complex64, x []complex64, incX int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + C.cblas_cscal(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Zscal(n int, alpha complex128, x []complex128, incX int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + C.cblas_zscal(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Csscal(n int, alpha float32, x []complex64, incX int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incX < 0 { + return + } + if incX > 0 && (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + C.cblas_csscal(C.int(n), C.float(alpha), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Zdscal(n int, alpha float64, x []complex128, incX int) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_zdscal(C.int(n), C.double(alpha), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Sgemv(tA blas.Transpose, m int, n int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_sgemv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX), C.float(beta), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Sgbmv(tA blas.Transpose, m int, n int, kL int, kU int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if kL < 0 { + panic("blas: kL < 0") + } + if kU < 0 { + panic("blas: kU < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+kL+kU+1 > len(a) || lda < kL+kU+1 { + panic("blas: index of a out of range") + } + C.cblas_sgbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), C.int(kL), C.int(kU), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX), C.float(beta), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Strmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float32, lda int, x []float32, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_strmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Stbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []float32, lda int, x []float32, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_stbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Stpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float32, x []float32, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_stpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.float)(&ap[0]), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Strsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float32, lda int, x []float32, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_strsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Stbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []float32, lda int, x []float32, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_stbsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Stpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float32, x []float32, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_stpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.float)(&ap[0]), (*C.float)(&x[0]), C.int(incX)) +} +func (Implementation) Dgemv(tA blas.Transpose, m int, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dgemv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX), C.double(beta), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Dgbmv(tA blas.Transpose, m int, n int, kL int, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if kL < 0 { + panic("blas: kL < 0") + } + if kU < 0 { + panic("blas: kU < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+kL+kU+1 > len(a) || lda < kL+kU+1 { + panic("blas: index of a out of range") + } + C.cblas_dgbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), C.int(kL), C.int(kU), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX), C.double(beta), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dtrmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_dtbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_dtpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.double)(&ap[0]), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dtrsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Dtbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_dtbsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Dtpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_dtpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.double)(&ap[0]), (*C.double)(&x[0]), C.int(incX)) +} +func (Implementation) Cgemv(tA blas.Transpose, m int, n int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_cgemv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Cgbmv(tA blas.Transpose, m int, n int, kL int, kU int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if kL < 0 { + panic("blas: kL < 0") + } + if kU < 0 { + panic("blas: kU < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+kL+kU+1 > len(a) || lda < kL+kU+1 { + panic("blas: index of a out of range") + } + C.cblas_cgbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), C.int(kL), C.int(kU), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Ctrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []complex64, lda int, x []complex64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ctrmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ctbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []complex64, lda int, x []complex64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_ctbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ctpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []complex64, x []complex64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_ctpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ctrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []complex64, lda int, x []complex64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ctrsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ctbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []complex64, lda int, x []complex64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_ctbsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ctpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []complex64, x []complex64, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_ctpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Zgemv(tA blas.Transpose, m int, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_zgemv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zgbmv(tA blas.Transpose, m int, n int, kL int, kU int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if kL < 0 { + panic("blas: kL < 0") + } + if kU < 0 { + panic("blas: kU < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + var lenX, lenY int + if tA == blas.NoTrans { + lenX, lenY = n, m + } else { + lenX, lenY = m, n + } + if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+kL+kU+1 > len(a) || lda < kL+kU+1 { + panic("blas: index of a out of range") + } + C.cblas_zgbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.int(m), C.int(n), C.int(kL), C.int(kU), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Ztrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []complex128, lda int, x []complex128, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ztrmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ztbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []complex128, lda int, x []complex128, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_ztbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ztpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []complex128, x []complex128, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_ztpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ztrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []complex128, lda int, x []complex128, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ztrsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ztbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, k int, a []complex128, lda int, x []complex128, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_ztbsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), C.int(k), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ztpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []complex128, x []complex128, incX int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_ztpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) +} +func (Implementation) Ssymv(ul blas.Uplo, n int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ssymv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX), C.float(beta), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Ssbmv(ul blas.Uplo, n int, k int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_ssbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.int(k), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&x[0]), C.int(incX), C.float(beta), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Sspmv(ul blas.Uplo, n int, alpha float32, ap []float32, x []float32, incX int, beta float32, y []float32, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_sspmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&ap[0]), (*C.float)(&x[0]), C.int(incX), C.float(beta), (*C.float)(&y[0]), C.int(incY)) +} +func (Implementation) Sger(m int, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int) { + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_sger(C.enum_CBLAS_ORDER(rowMajor), C.int(m), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(&a[0]), C.int(lda)) +} +func (Implementation) Ssyr(ul blas.Uplo, n int, alpha float32, x []float32, incX int, a []float32, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ssyr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&a[0]), C.int(lda)) +} +func (Implementation) Sspr(ul blas.Uplo, n int, alpha float32, x []float32, incX int, ap []float32) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_sspr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&ap[0])) +} +func (Implementation) Ssyr2(ul blas.Uplo, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_ssyr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(&a[0]), C.int(lda)) +} +func (Implementation) Sspr2(ul blas.Uplo, n int, alpha float32, x []float32, incX int, y []float32, incY int, ap []float32) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_sspr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(&ap[0])) +} +func (Implementation) Dsymv(ul blas.Uplo, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dsymv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX), C.double(beta), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Dsbmv(ul blas.Uplo, n int, k int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_dsbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.int(k), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&x[0]), C.int(incX), C.double(beta), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Dspmv(ul blas.Uplo, n int, alpha float64, ap []float64, x []float64, incX int, beta float64, y []float64, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_dspmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&ap[0]), (*C.double)(&x[0]), C.int(incX), C.double(beta), (*C.double)(&y[0]), C.int(incY)) +} +func (Implementation) Dger(m int, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dger(C.enum_CBLAS_ORDER(rowMajor), C.int(m), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(&a[0]), C.int(lda)) +} +func (Implementation) Dsyr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dsyr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&a[0]), C.int(lda)) +} +func (Implementation) Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, ap []float64) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_dspr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&ap[0])) +} +func (Implementation) Dsyr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_dsyr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(&a[0]), C.int(lda)) +} +func (Implementation) Dspr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, ap []float64) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_dspr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(&ap[0])) +} +func (Implementation) Chemv(ul blas.Uplo, n int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_chemv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Chbmv(ul blas.Uplo, n int, k int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_chbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Chpmv(ul blas.Uplo, n int, alpha complex64, ap []complex64, x []complex64, incX int, beta complex64, y []complex64, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_chpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Cgeru(m int, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) { + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_cgeru(C.enum_CBLAS_ORDER(rowMajor), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Cgerc(m int, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) { + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_cgerc(C.enum_CBLAS_ORDER(rowMajor), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Cher(ul blas.Uplo, n int, alpha float32, x []complex64, incX int, a []complex64, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_cher(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Chpr(ul blas.Uplo, n int, alpha float32, x []complex64, incX int, ap []complex64) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_chpr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&ap[0])) +} +func (Implementation) Cher2(ul blas.Uplo, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_cher2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Chpr2(ul blas.Uplo, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, ap []complex64) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_chpr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&ap[0])) +} +func (Implementation) Zhemv(ul blas.Uplo, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_zhemv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zhbmv(ul blas.Uplo, n int, k int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+k+1 > len(a) || lda < k+1 { + panic("blas: index of a out of range") + } + C.cblas_zhbmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zhpmv(ul blas.Uplo, n int, alpha complex128, ap []complex128, x []complex128, incX int, beta complex128, y []complex128, incY int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_zhpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) +} +func (Implementation) Zgeru(m int, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) { + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_zgeru(C.enum_CBLAS_ORDER(rowMajor), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Zgerc(m int, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) { + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(m-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_zgerc(C.enum_CBLAS_ORDER(rowMajor), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Zher(ul blas.Uplo, n int, alpha float64, x []complex128, incX int, a []complex128, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_zher(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Zhpr(ul blas.Uplo, n int, alpha float64, x []complex128, incX int, ap []complex128) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + C.cblas_zhpr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&ap[0])) +} +func (Implementation) Zher2(ul blas.Uplo, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + if lda*(n-1)+n > len(a) || lda < max(1, n) { + panic("blas: index of a out of range") + } + C.cblas_zher2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&a[0]), C.int(lda)) +} +func (Implementation) Zhpr2(ul blas.Uplo, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, ap []complex128) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if n < 0 { + panic("blas: n < 0") + } + if n*(n+1)/2 > len(ap) { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { + panic("blas: x index out of range") + } + if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { + panic("blas: y index out of range") + } + C.cblas_zhpr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&ap[0])) +} +func (Implementation) Sgemm(tA blas.Transpose, tB blas.Transpose, m int, n int, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if tB != blas.NoTrans && tB != blas.Trans && tB != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var rowA, colA, rowB, colB int + if tA == blas.NoTrans { + rowA, colA = m, k + } else { + rowA, colA = k, m + } + if tB == blas.NoTrans { + rowB, colB = k, n + } else { + rowB, colB = n, k + } + if lda*(rowA-1)+colA > len(a) || lda < max(1, colA) { + panic("blas: index of a out of range") + } + if ldb*(rowB-1)+colB > len(b) || ldb < max(1, colB) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_sgemm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_TRANSPOSE(tB), C.int(m), C.int(n), C.int(k), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&b[0]), C.int(ldb), C.float(beta), (*C.float)(&c[0]), C.int(ldc)) +} +func (Implementation) Ssymm(s blas.Side, ul blas.Uplo, m int, n int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_ssymm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.int(m), C.int(n), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&b[0]), C.int(ldb), C.float(beta), (*C.float)(&c[0]), C.int(ldc)) +} +func (Implementation) Ssyrk(ul blas.Uplo, t blas.Transpose, n int, k int, alpha float32, a []float32, lda int, beta float32, c []float32, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_ssyrk(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), C.float(alpha), (*C.float)(&a[0]), C.int(lda), C.float(beta), (*C.float)(&c[0]), C.int(ldc)) +} +func (Implementation) Ssyr2k(ul blas.Uplo, t blas.Transpose, n int, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldb*(row-1)+col > len(b) || ldb < max(1, col) { + panic("blas: index of b out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_ssyr2k(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&b[0]), C.int(ldb), C.float(beta), (*C.float)(&c[0]), C.int(ldc)) +} +func (Implementation) Strmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha float32, a []float32, lda int, b []float32, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_strmm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&b[0]), C.int(ldb)) +} +func (Implementation) Strsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha float32, a []float32, lda int, b []float32, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_strsm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), C.float(alpha), (*C.float)(&a[0]), C.int(lda), (*C.float)(&b[0]), C.int(ldb)) +} +func (Implementation) Dgemm(tA blas.Transpose, tB blas.Transpose, m int, n int, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if tB != blas.NoTrans && tB != blas.Trans && tB != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var rowA, colA, rowB, colB int + if tA == blas.NoTrans { + rowA, colA = m, k + } else { + rowA, colA = k, m + } + if tB == blas.NoTrans { + rowB, colB = k, n + } else { + rowB, colB = n, k + } + if lda*(rowA-1)+colA > len(a) || lda < max(1, colA) { + panic("blas: index of a out of range") + } + if ldb*(rowB-1)+colB > len(b) || ldb < max(1, colB) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_dgemm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_TRANSPOSE(tB), C.int(m), C.int(n), C.int(k), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&b[0]), C.int(ldb), C.double(beta), (*C.double)(&c[0]), C.int(ldc)) +} +func (Implementation) Dsymm(s blas.Side, ul blas.Uplo, m int, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_dsymm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.int(m), C.int(n), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&b[0]), C.int(ldb), C.double(beta), (*C.double)(&c[0]), C.int(ldc)) +} +func (Implementation) Dsyrk(ul blas.Uplo, t blas.Transpose, n int, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_dsyrk(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), C.double(alpha), (*C.double)(&a[0]), C.int(lda), C.double(beta), (*C.double)(&c[0]), C.int(ldc)) +} +func (Implementation) Dsyr2k(ul blas.Uplo, t blas.Transpose, n int, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldb*(row-1)+col > len(b) || ldb < max(1, col) { + panic("blas: index of b out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_dsyr2k(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&b[0]), C.int(ldb), C.double(beta), (*C.double)(&c[0]), C.int(ldc)) +} +func (Implementation) Dtrmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha float64, a []float64, lda int, b []float64, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_dtrmm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&b[0]), C.int(ldb)) +} +func (Implementation) Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha float64, a []float64, lda int, b []float64, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_dtrsm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), C.double(alpha), (*C.double)(&a[0]), C.int(lda), (*C.double)(&b[0]), C.int(ldb)) +} +func (Implementation) Cgemm(tA blas.Transpose, tB blas.Transpose, m int, n int, k int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if tB != blas.NoTrans && tB != blas.Trans && tB != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var rowA, colA, rowB, colB int + if tA == blas.NoTrans { + rowA, colA = m, k + } else { + rowA, colA = k, m + } + if tB == blas.NoTrans { + rowB, colB = k, n + } else { + rowB, colB = n, k + } + if lda*(rowA-1)+colA > len(a) || lda < max(1, colA) { + panic("blas: index of a out of range") + } + if ldb*(rowB-1)+colB > len(b) || ldb < max(1, colB) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_cgemm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_TRANSPOSE(tB), C.int(m), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Csymm(s blas.Side, ul blas.Uplo, m int, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_csymm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Csyrk(ul blas.Uplo, t blas.Transpose, n int, k int, alpha complex64, a []complex64, lda int, beta complex64, c []complex64, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_csyrk(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Csyr2k(ul blas.Uplo, t blas.Transpose, n int, k int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldb*(row-1)+col > len(b) || ldb < max(1, col) { + panic("blas: index of b out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_csyr2k(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Ctrmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_ctrmm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb)) +} +func (Implementation) Ctrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_ctrsm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb)) +} +func (Implementation) Zgemm(tA blas.Transpose, tB blas.Transpose, m int, n int, k int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if tB != blas.NoTrans && tB != blas.Trans && tB != blas.ConjTrans { + panic("blas: illegal transpose") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var rowA, colA, rowB, colB int + if tA == blas.NoTrans { + rowA, colA = m, k + } else { + rowA, colA = k, m + } + if tB == blas.NoTrans { + rowB, colB = k, n + } else { + rowB, colB = n, k + } + if lda*(rowA-1)+colA > len(a) || lda < max(1, colA) { + panic("blas: index of a out of range") + } + if ldb*(rowB-1)+colB > len(b) || ldb < max(1, colB) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zgemm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_TRANSPOSE(tB), C.int(m), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Zsymm(s blas.Side, ul blas.Uplo, m int, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zsymm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Zsyrk(ul blas.Uplo, t blas.Transpose, n int, k int, alpha complex128, a []complex128, lda int, beta complex128, c []complex128, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zsyrk(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Zsyr2k(ul blas.Uplo, t blas.Transpose, n int, k int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.Trans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldb*(row-1)+col > len(b) || ldb < max(1, col) { + panic("blas: index of b out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zsyr2k(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Ztrmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_ztrmm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb)) +} +func (Implementation) Ztrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m int, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic("blas: illegal transpose") + } + if d != blas.NonUnit && d != blas.Unit { + panic("blas: illegal diagonal") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + C.cblas_ztrsm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb)) +} +func (Implementation) Chemm(s blas.Side, ul blas.Uplo, m int, n int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta complex64, c []complex64, ldc int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_chemm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Cherk(ul blas.Uplo, t blas.Transpose, n int, k int, alpha float32, a []complex64, lda int, beta float32, c []complex64, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_cherk(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), C.float(alpha), unsafe.Pointer(&a[0]), C.int(lda), C.float(beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Cher2k(ul blas.Uplo, t blas.Transpose, n int, k int, alpha complex64, a []complex64, lda int, b []complex64, ldb int, beta float32, c []complex64, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldb*(row-1)+col > len(b) || ldb < max(1, col) { + panic("blas: index of b out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_cher2k(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), C.float(beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Zhemm(s blas.Side, ul blas.Uplo, m int, n int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta complex128, c []complex128, ldc int) { + if s != blas.Left && s != blas.Right { + panic("blas: illegal side") + } + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if m < 0 { + panic("blas: m < 0") + } + if n < 0 { + panic("blas: n < 0") + } + var k int + if s == blas.Left { + k = m + } else { + k = n + } + if lda*(k-1)+k > len(a) || lda < max(1, k) { + panic("blas: index of a out of range") + } + if ldb*(m-1)+n > len(b) || ldb < max(1, n) { + panic("blas: index of b out of range") + } + if ldc*(m-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zhemm(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_SIDE(s), C.enum_CBLAS_UPLO(ul), C.int(m), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), unsafe.Pointer(&beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Zherk(ul blas.Uplo, t blas.Transpose, n int, k int, alpha float64, a []complex128, lda int, beta float64, c []complex128, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zherk(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), C.double(alpha), unsafe.Pointer(&a[0]), C.int(lda), C.double(beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} +func (Implementation) Zher2k(ul blas.Uplo, t blas.Transpose, n int, k int, alpha complex128, a []complex128, lda int, b []complex128, ldb int, beta float64, c []complex128, ldc int) { + if ul != blas.Upper && ul != blas.Lower { + panic("blas: illegal triangle") + } + if t != blas.NoTrans && t != blas.ConjTrans { + panic("blas: illegal transpose") + } + if n < 0 { + panic("blas: n < 0") + } + if k < 0 { + panic("blas: k < 0") + } + var row, col int + if t == blas.NoTrans { + row, col = n, k + } else { + row, col = k, n + } + if lda*(row-1)+col > len(a) || lda < max(1, col) { + panic("blas: index of a out of range") + } + if ldb*(row-1)+col > len(b) || ldb < max(1, col) { + panic("blas: index of b out of range") + } + if ldc*(n-1)+n > len(c) || ldc < max(1, n) { + panic("blas: index of c out of range") + } + C.cblas_zher2k(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(t), C.int(n), C.int(k), unsafe.Pointer(&alpha), unsafe.Pointer(&a[0]), C.int(lda), unsafe.Pointer(&b[0]), C.int(ldb), C.double(beta), unsafe.Pointer(&c[0]), C.int(ldc)) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/cblas.h b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/cblas.h new file mode 100644 index 0000000..b8ac9a5 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/cblas.h @@ -0,0 +1,596 @@ +#ifndef CBLAS_H + +#ifndef CBLAS_ENUM_DEFINED_H + #define CBLAS_ENUM_DEFINED_H + enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 }; + enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, + AtlasConj=114}; + enum CBLAS_UPLO {CblasUpper=121, CblasLower=122}; + enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132}; + enum CBLAS_SIDE {CblasLeft=141, CblasRight=142}; +#endif + +#ifndef CBLAS_ENUM_ONLY +#define CBLAS_H +#define CBLAS_INDEX int + +int cblas_errprn(int ierr, int info, char *form, ...); + +/* + * =========================================================================== + * Prototypes for level 1 BLAS functions (complex are recast as routines) + * =========================================================================== + */ +float cblas_sdsdot(const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY); +double cblas_dsdot(const int N, const float *X, const int incX, const float *Y, + const int incY); +float cblas_sdot(const int N, const float *X, const int incX, + const float *Y, const int incY); +double cblas_ddot(const int N, const double *X, const int incX, + const double *Y, const int incY); +/* + * Functions having prefixes Z and C only + */ +void cblas_cdotu_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotu); +void cblas_cdotc_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotc); + +void cblas_zdotu_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotu); +void cblas_zdotc_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotc); + + +/* + * Functions having prefixes S D SC DZ + */ +float cblas_snrm2(const int N, const float *X, const int incX); +float cblas_sasum(const int N, const float *X, const int incX); + +double cblas_dnrm2(const int N, const double *X, const int incX); +double cblas_dasum(const int N, const double *X, const int incX); + +float cblas_scnrm2(const int N, const void *X, const int incX); +float cblas_scasum(const int N, const void *X, const int incX); + +double cblas_dznrm2(const int N, const void *X, const int incX); +double cblas_dzasum(const int N, const void *X, const int incX); + + +/* + * Functions having standard 4 prefixes (S D C Z) + */ +CBLAS_INDEX cblas_isamax(const int N, const float *X, const int incX); +CBLAS_INDEX cblas_idamax(const int N, const double *X, const int incX); +CBLAS_INDEX cblas_icamax(const int N, const void *X, const int incX); +CBLAS_INDEX cblas_izamax(const int N, const void *X, const int incX); + +/* + * =========================================================================== + * Prototypes for level 1 BLAS routines + * =========================================================================== + */ + +/* + * Routines with standard 4 prefixes (s, d, c, z) + */ +void cblas_sswap(const int N, float *X, const int incX, + float *Y, const int incY); +void cblas_scopy(const int N, const float *X, const int incX, + float *Y, const int incY); +void cblas_saxpy(const int N, const float alpha, const float *X, + const int incX, float *Y, const int incY); +void catlas_saxpby(const int N, const float alpha, const float *X, + const int incX, const float beta, float *Y, const int incY); +void catlas_sset + (const int N, const float alpha, float *X, const int incX); + +void cblas_dswap(const int N, double *X, const int incX, + double *Y, const int incY); +void cblas_dcopy(const int N, const double *X, const int incX, + double *Y, const int incY); +void cblas_daxpy(const int N, const double alpha, const double *X, + const int incX, double *Y, const int incY); +void catlas_daxpby(const int N, const double alpha, const double *X, + const int incX, const double beta, double *Y, const int incY); +void catlas_dset + (const int N, const double alpha, double *X, const int incX); + +void cblas_cswap(const int N, void *X, const int incX, + void *Y, const int incY); +void cblas_ccopy(const int N, const void *X, const int incX, + void *Y, const int incY); +void cblas_caxpy(const int N, const void *alpha, const void *X, + const int incX, void *Y, const int incY); +void catlas_caxpby(const int N, const void *alpha, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void catlas_cset + (const int N, const void *alpha, void *X, const int incX); + +void cblas_zswap(const int N, void *X, const int incX, + void *Y, const int incY); +void cblas_zcopy(const int N, const void *X, const int incX, + void *Y, const int incY); +void cblas_zaxpy(const int N, const void *alpha, const void *X, + const int incX, void *Y, const int incY); +void catlas_zaxpby(const int N, const void *alpha, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void catlas_zset + (const int N, const void *alpha, void *X, const int incX); + + +/* + * Routines with S and D prefix only + */ +void cblas_srotg(float *a, float *b, float *c, float *s); +void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P); +void cblas_srot(const int N, float *X, const int incX, + float *Y, const int incY, const float c, const float s); +void cblas_srotm(const int N, float *X, const int incX, + float *Y, const int incY, const float *P); + +void cblas_drotg(double *a, double *b, double *c, double *s); +void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P); +void cblas_drot(const int N, double *X, const int incX, + double *Y, const int incY, const double c, const double s); +void cblas_drotm(const int N, double *X, const int incX, + double *Y, const int incY, const double *P); + + +/* + * Routines with S D C Z CS and ZD prefixes + */ +void cblas_sscal(const int N, const float alpha, float *X, const int incX); +void cblas_dscal(const int N, const double alpha, double *X, const int incX); +void cblas_cscal(const int N, const void *alpha, void *X, const int incX); +void cblas_zscal(const int N, const void *alpha, void *X, const int incX); +void cblas_csscal(const int N, const float alpha, void *X, const int incX); +void cblas_zdscal(const int N, const double alpha, void *X, const int incX); + +/* + * Extra reference routines provided by ATLAS, but not mandated by the standard + */ +void cblas_crotg(void *a, void *b, void *c, void *s); +void cblas_zrotg(void *a, void *b, void *c, void *s); +void cblas_csrot(const int N, void *X, const int incX, void *Y, const int incY, + const float c, const float s); +void cblas_zdrot(const int N, void *X, const int incX, void *Y, const int incY, + const double c, const double s); + +/* + * =========================================================================== + * Prototypes for level 2 BLAS + * =========================================================================== + */ + +/* + * Routines with standard 4 prefixes (S, D, C, Z) + */ +void cblas_sgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const float alpha, const float *A, const int lda, + const float *X, const int incX, const float beta, + float *Y, const int incY); +void cblas_sgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const float alpha, + const float *A, const int lda, const float *X, + const int incX, const float beta, float *Y, const int incY); +void cblas_strmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *A, const int lda, + float *X, const int incX); +void cblas_stbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const float *A, const int lda, + float *X, const int incX); +void cblas_stpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *Ap, float *X, const int incX); +void cblas_strsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *A, const int lda, float *X, + const int incX); +void cblas_stbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const float *A, const int lda, + float *X, const int incX); +void cblas_stpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *Ap, float *X, const int incX); + +void cblas_dgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const double alpha, const double *A, const int lda, + const double *X, const int incX, const double beta, + double *Y, const int incY); +void cblas_dgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const double alpha, + const double *A, const int lda, const double *X, + const int incX, const double beta, double *Y, const int incY); +void cblas_dtrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *A, const int lda, + double *X, const int incX); +void cblas_dtbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const double *A, const int lda, + double *X, const int incX); +void cblas_dtpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *Ap, double *X, const int incX); +void cblas_dtrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *A, const int lda, double *X, + const int incX); +void cblas_dtbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const double *A, const int lda, + double *X, const int incX); +void cblas_dtpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *Ap, double *X, const int incX); + +void cblas_cgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *X, const int incX, const void *beta, + void *Y, const int incY); +void cblas_cgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const void *alpha, + const void *A, const int lda, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void cblas_ctrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, + void *X, const int incX); +void cblas_ctbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ctpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); +void cblas_ctrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, void *X, + const int incX); +void cblas_ctbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ctpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); + +void cblas_zgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *X, const int incX, const void *beta, + void *Y, const int incY); +void cblas_zgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const void *alpha, + const void *A, const int lda, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void cblas_ztrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, + void *X, const int incX); +void cblas_ztbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ztpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); +void cblas_ztrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, void *X, + const int incX); +void cblas_ztbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ztpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); + + +/* + * Routines with S and D prefixes only + */ +void cblas_ssymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, + const float beta, float *Y, const int incY); +void cblas_ssbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const float alpha, const float *A, + const int lda, const float *X, const int incX, + const float beta, float *Y, const int incY); +void cblas_sspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *Ap, + const float *X, const int incX, + const float beta, float *Y, const int incY); +void cblas_sger(const enum CBLAS_ORDER Order, const int M, const int N, + const float alpha, const float *X, const int incX, + const float *Y, const int incY, float *A, const int lda); +void cblas_ssyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, float *A, const int lda); +void cblas_sspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, float *Ap); +void cblas_ssyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY, float *A, + const int lda); +void cblas_sspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY, float *Ap); + +void cblas_dsymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, + const double beta, double *Y, const int incY); +void cblas_dsbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const double alpha, const double *A, + const int lda, const double *X, const int incX, + const double beta, double *Y, const int incY); +void cblas_dspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *Ap, + const double *X, const int incX, + const double beta, double *Y, const int incY); +void cblas_dger(const enum CBLAS_ORDER Order, const int M, const int N, + const double alpha, const double *X, const int incX, + const double *Y, const int incY, double *A, const int lda); +void cblas_dsyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, double *A, const int lda); +void cblas_dspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, double *Ap); +void cblas_dsyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, const double *Y, const int incY, double *A, + const int lda); +void cblas_dspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, const double *Y, const int incY, double *Ap); + + +/* + * Routines with C and Z prefixes only + */ +void cblas_chemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_chbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_chpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *Ap, + const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_cgeru(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_cgerc(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_cher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const void *X, const int incX, + void *A, const int lda); +void cblas_chpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const void *X, + const int incX, void *Ap); +void cblas_cher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_chpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *Ap); + +void cblas_zhemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_zhbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_zhpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *Ap, + const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_zgeru(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_zgerc(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_zher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const void *X, const int incX, + void *A, const int lda); +void cblas_zhpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const void *X, + const int incX, void *Ap); +void cblas_zher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_zhpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *Ap); + +/* + * =========================================================================== + * Prototypes for level 3 BLAS + * =========================================================================== + */ + +/* + * Routines with standard 4 prefixes (S, D, C, Z) + */ +void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const float alpha, const float *A, + const int lda, const float *B, const int ldb, + const float beta, float *C, const int ldc); +void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const float alpha, const float *A, const int lda, + const float *B, const int ldb, const float beta, + float *C, const int ldc); +void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const float alpha, const float *A, const int lda, + const float beta, float *C, const int ldc); +void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const float alpha, const float *A, const int lda, + const float *B, const int ldb, const float beta, + float *C, const int ldc); +void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const float alpha, const float *A, const int lda, + float *B, const int ldb); +void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const float alpha, const float *A, const int lda, + float *B, const int ldb); + +void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const double alpha, const double *A, + const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc); +void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const double alpha, const double *A, const int lda, + const double *B, const int ldb, const double beta, + double *C, const int ldc); +void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const double alpha, const double *A, const int lda, + const double beta, double *C, const int ldc); +void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const double alpha, const double *A, const int lda, + const double *B, const int ldb, const double beta, + double *C, const int ldc); +void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const double alpha, const double *A, const int lda, + double *B, const int ldb); +void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const double alpha, const double *A, const int lda, + double *B, const int ldb); + +void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const void *alpha, const void *A, + const int lda, const void *B, const int ldb, + const void *beta, void *C, const int ldc); +void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *beta, void *C, const int ldc); +void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); +void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); + +void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const void *alpha, const void *A, + const int lda, const void *B, const int ldb, + const void *beta, void *C, const int ldc); +void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *beta, void *C, const int ldc); +void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); +void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); + + +/* + * Routines with prefixes C and Z only + */ +void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const float alpha, const void *A, const int lda, + const float beta, void *C, const int ldc); +void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const float beta, + void *C, const int ldc); +void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const double alpha, const void *A, const int lda, + const double beta, void *C, const int ldc); +void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const double beta, + void *C, const int ldc); + +int cblas_errprn(int ierr, int info, char *form, ...); + +#endif /* end #ifdef CBLAS_ENUM_ONLY */ +#endif diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgemmbench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgemmbench_test.go new file mode 100644 index 0000000..e9bb393 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgemmbench_test.go @@ -0,0 +1,47 @@ +package cgo + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func BenchmarkDgemmSmSmSm(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Sm, Sm, Sm, NT, NT) +} + +func BenchmarkDgemmMedMedMed(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, NT, NT) +} + +func BenchmarkDgemmMedLgMed(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Lg, Med, NT, NT) +} + +func BenchmarkDgemmLgLgLg(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Lg, Lg, Lg, NT, NT) +} + +func BenchmarkDgemmLgSmLg(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Lg, Sm, Lg, NT, NT) +} + +func BenchmarkDgemmLgLgSm(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Lg, Lg, Sm, NT, NT) +} + +func BenchmarkDgemmHgHgSm(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Hg, Hg, Sm, NT, NT) +} + +func BenchmarkDgemmMedMedMedTNT(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, T, NT) +} + +func BenchmarkDgemmMedMedMedNTT(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, NT, T) +} + +func BenchmarkDgemmMedMedMedTT(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, T, T) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgemvbench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgemvbench_test.go new file mode 100644 index 0000000..c761711 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgemvbench_test.go @@ -0,0 +1,87 @@ +package cgo + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func BenchmarkDgemvSmSmNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Sm, 1, 1) +} + +func BenchmarkDgemvSmSmNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Sm, 2, 3) +} + +func BenchmarkDgemvSmSmTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Sm, 1, 1) +} + +func BenchmarkDgemvSmSmTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Sm, 2, 3) +} + +func BenchmarkDgemvMedMedNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Med, Med, 1, 1) +} + +func BenchmarkDgemvMedMedNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Med, Med, 2, 3) +} + +func BenchmarkDgemvMedMedTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Med, Med, 1, 1) +} + +func BenchmarkDgemvMedMedTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Med, Med, 2, 3) +} + +func BenchmarkDgemvLgLgNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Lg, 1, 1) +} + +func BenchmarkDgemvLgLgNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Lg, 2, 3) +} + +func BenchmarkDgemvLgLgTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Lg, 1, 1) +} + +func BenchmarkDgemvLgLgTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Lg, 2, 3) +} + +func BenchmarkDgemvLgSmNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Sm, 1, 1) +} + +func BenchmarkDgemvLgSmNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Sm, 2, 3) +} + +func BenchmarkDgemvLgSmTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Sm, 1, 1) +} + +func BenchmarkDgemvLgSmTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Sm, 2, 3) +} + +func BenchmarkDgemvSmLgNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Lg, 1, 1) +} + +func BenchmarkDgemvSmLgNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Lg, 2, 3) +} + +func BenchmarkDgemvSmLgTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Lg, 1, 1) +} + +func BenchmarkDgemvSmLgTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Lg, 2, 3) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgerbench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgerbench_test.go new file mode 100644 index 0000000..2656f2e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/dgerbench_test.go @@ -0,0 +1,47 @@ +package cgo + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func BenchmarkDgerSmSmInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Sm, 1, 1) +} + +func BenchmarkDgerSmSmIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Sm, 2, 3) +} + +func BenchmarkDgerMedMedInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Med, Med, 1, 1) +} + +func BenchmarkDgerMedMedIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Med, Med, 2, 3) +} + +func BenchmarkDgerLgLgInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Lg, 1, 1) +} + +func BenchmarkDgerLgLgIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Lg, 2, 3) +} + +func BenchmarkDgerLgSmInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Sm, 1, 1) +} + +func BenchmarkDgerLgSmIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Sm, 2, 3) +} + +func BenchmarkDgerSmLgInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Lg, 1, 1) +} + +func BenchmarkDgerSmLgIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Lg, 2, 3) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/genBlas.pl b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/genBlas.pl new file mode 100644 index 0000000..4c04730 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/genBlas.pl @@ -0,0 +1,607 @@ +#!/usr/bin/env perl +# Copyright ©2014 The Gonum Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +use strict; +use warnings; + +my $excludeComplex = 0; +my $excludeAtlas = 1; +my $cblasHeader = "cblas.h"; + +open(my $cblas, "<", $cblasHeader) or die; +open(my $goblas, ">", "blas.go") or die; + +my %done = ("cblas_errprn" => 1, + "cblas_srotg" => 1, + "cblas_srotmg" => 1, + "cblas_srotm" => 1, + "cblas_drotg" => 1, + "cblas_drotmg" => 1, + "cblas_drotm" => 1, + "cblas_crotg" => 1, + "cblas_zrotg" => 1, + "cblas_cdotu_sub" => 1, + "cblas_cdotc_sub" => 1, + "cblas_zdotu_sub" => 1, + "cblas_zdotc_sub" => 1, + ); + +if ($excludeAtlas) { + $done{'cblas_csrot'} = 1; + $done{'cblas_zdrot'} = 1; +} + +printf $goblas < b { + return a + } + return b +} + +type Implementation struct{} + +// Special cases... + +type srotmParams struct { + flag float32 + h [4]float32 +} + +type drotmParams struct { + flag float64 + h [4]float64 +} + +func (Implementation) Srotg(a float32, b float32) (c float32, s float32, r float32, z float32) { + C.cblas_srotg((*C.float)(&a), (*C.float)(&b), (*C.float)(&c), (*C.float)(&s)) + return c, s, a, b +} +func (Implementation) Srotmg(d1 float32, d2 float32, b1 float32, b2 float32) (p blas.SrotmParams, rd1 float32, rd2 float32, rb1 float32) { + var pi srotmParams + C.cblas_srotmg((*C.float)(&d1), (*C.float)(&d2), (*C.float)(&b1), C.float(b2), (*C.float)(unsafe.Pointer(&pi))) + return blas.SrotmParams{Flag: blas.Flag(pi.flag), H: pi.h}, d1, d2, b1 +} +func (Implementation) Srotm(n int, x []float32, incX int, y []float32, incY int, p blas.SrotmParams) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + if p.Flag < blas.Identity || p.Flag > blas.Diagonal { + panic("blas: illegal blas.Flag value") + } + pi := srotmParams{ + flag: float32(p.Flag), + h: p.H, + } + C.cblas_srotm(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(unsafe.Pointer(&pi))) +} +func (Implementation) Drotg(a float64, b float64) (c float64, s float64, r float64, z float64) { + C.cblas_drotg((*C.double)(&a), (*C.double)(&b), (*C.double)(&c), (*C.double)(&s)) + return c, s, a, b +} +func (Implementation) Drotmg(d1 float64, d2 float64, b1 float64, b2 float64) (p blas.DrotmParams, rd1 float64, rd2 float64, rb1 float64) { + var pi drotmParams + C.cblas_drotmg((*C.double)(&d1), (*C.double)(&d2), (*C.double)(&b1), C.double(b2), (*C.double)(unsafe.Pointer(&pi))) + return blas.DrotmParams{Flag: blas.Flag(pi.flag), H: pi.h}, d1, d2, b1 +} +func (Implementation) Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + if p.Flag < blas.Identity || p.Flag > blas.Diagonal { + panic("blas: illegal blas.Flag value") + } + pi := drotmParams{ + flag: float64(p.Flag), + h: p.H, + } + C.cblas_drotm(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(unsafe.Pointer(&pi))) +} +func (Implementation) Cdotu(n int, x []complex64, incX int, y []complex64, incY int) (dotu complex64) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_cdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) + return dotu +} +func (Implementation) Cdotc(n int, x []complex64, incX int, y []complex64, incY int) (dotc complex64) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_cdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) + return dotc +} +func (Implementation) Zdotu(n int, x []complex128, incX int, y []complex128, incY int) (dotu complex128) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_zdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) + return dotu +} +func (Implementation) Zdotc(n int, x []complex128, incX int, y []complex128, incY int) (dotc complex128) { + if n < 0 { + panic("blas: n < 0") + } + if incX == 0 { + panic("blas: zero x index increment") + } + if incY == 0 { + panic("blas: zero y index increment") + } + if (n-1)*incX >= len(x) { + panic("blas: x index out of range") + } + if (n-1)*incY >= len(y) { + panic("blas: y index out of range") + } + C.cblas_zdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) + return dotc +} +EOH + +printf $goblas <; + +# horrible munging of text... +$header =~ s/#[^\n\r]*//g; # delete cpp lines +$header =~ s/\n +([^\n\r]*)/\n$1/g; # remove starting space +$header =~ s/(?:\n ?\n)+/\n/g; # delete empty lines +$header =~ s! ((['"]) (?: \\. | .)*? \2) | # skip quoted strings + /\* .*? \*/ | # delete C comments + // [^\n\r]* # delete C++ comments just in case + ! $1 || ' ' # change comments to a single space + !xseg; # ignore white space, treat as single line + # evaluate result, repeat globally +$header =~ s/([^;])\n/$1/g; # join prototypes into single lines +$header =~ s/, +/,/g; +$header =~ s/ +/ /g; +$header =~ s/ +}/}/g; +$header =~ s/\n+//; + +$/ = "\n"; +my @lines = split ";\n", $header; + +our %retConv = ( + "int" => "int ", + "float" => "float32 ", + "double" => "float64 ", + "CBLAS_INDEX" => "int ", + "void" => "" +); + +foreach my $line (@lines) { + process($line); +} + +close($goblas); +`go fmt .`; + +sub process { + my $line = shift; + chomp $line; + if (not $line =~ m/^enum/) { + processProto($line); + } +} + +sub processProto { + my $proto = shift; + my ($func, $paramList) = split /[()]/, $proto; + (my $ret, $func) = split ' ', $func; + if ($done{$func} or $excludeComplex && $func =~ m/_[isd]?[zc]/ or $excludeAtlas && $func =~ m/^catlas_/) { + return + } + $done{$func} = 1; + my $GoRet = $retConv{$ret}; + my $complexType = $func; + $complexType =~ s/.*_[isd]?([zc]).*/$1/; + print $goblas "func (Implementation) ".Gofunc($func)."(".processParamToGo($func, $paramList, $complexType).") ".$GoRet."{\n"; + print $goblas processParamToChecks($func, $paramList); + print $goblas "\t"; + if ($ret ne 'void') { + chop($GoRet); + print $goblas "return ".$GoRet."("; + } + print $goblas "C.$func(".processParamToC($func, $paramList).")"; + if ($ret ne 'void') { + print $goblas ")"; + } + print $goblas "\n}\n"; +} + +sub Gofunc { + my $fnName = shift; + $fnName =~ s/_sub//; + my ($pack, $func, $tail) = split '_', $fnName; + if ($pack eq 'cblas') { + $pack = ""; + } else { + $pack = substr $pack, 1; + } + + return ucfirst $pack . ucfirst $func . ucfirst $tail if $tail; + return ucfirst $pack . ucfirst $func; +} + +sub processParamToGo { + my $func = shift; + my $paramList = shift; + my $complexType = shift; + my @processed; + my @params = split ',', $paramList; + my $skip = 0; + foreach my $param (@params) { + my @parts = split /[ *]/, $param; + my $var = lcfirst $parts[scalar @parts - 1]; + $param =~ m/^(?:const )?int/ && do { + push @processed, $var." int"; next; + }; + $param =~ m/^(?:const )?void/ && do { + my $type; + if ($var eq "alpha" || $var eq "beta") { + $type = " "; + } else { + $type = " []"; + } + if ($complexType eq 'c') { + push @processed, $var.$type."complex64"; next; + } elsif ($complexType eq 'z') { + push @processed, $var.$type."complex128"; next; + } else { + die "unexpected complex type for '$func' - '$complexType'"; + } + }; + $param =~ m/^(?:const )?char \*/ && do { + push @processed, $var." *byte"; next; + }; + $param =~ m/^(?:const )?float \*/ && do { + push @processed, $var." []float32"; next; + }; + $param =~ m/^(?:const )?double \*/ && do { + push @processed, $var." []float64"; next; + }; + $param =~ m/^(?:const )?float/ && do { + push @processed, $var." float32"; next; + }; + $param =~ m/^(?:const )?double/ && do { + push @processed, $var." float64"; next; + }; + $param =~ m/^const enum/ && do { + $var eq "order" && $skip++; + $var =~ /trans/ && do { + $var =~ s/trans([AB]?)/t$1/; + push @processed, $var." blas.Transpose"; next; + }; + $var eq "uplo" && do { + $var = "ul"; + push @processed, $var." blas.Uplo"; next; + }; + $var eq "diag" && do { + $var = "d"; + push @processed, $var." blas.Diag"; next; + }; + $var eq "side" && do { + $var = "s"; + push @processed, $var." blas.Side"; next; + }; + }; + } + die "missed Go parameters from '$func', '$paramList'" if scalar @processed+$skip != scalar @params; + return join ", ", @processed; +} + +sub processParamToChecks { + my $func = shift; + my $paramList = shift; + my @processed; + my @params = split ',', $paramList; + my %arrayArgs; + my %scalarArgs; + foreach my $param (@params) { + my @parts = split /[ *]/, $param; + my $var = lcfirst $parts[scalar @parts - 1]; + $param =~ m/^(?:const )?int \*[a-zA-Z]/ && do { + $scalarArgs{$var} = 1; next; + }; + $param =~ m/^(?:const )?void \*[a-zA-Z]/ && do { + if ($var ne "alpha" && $var ne "beta") { + $arrayArgs{$var} = 1; + } + next; + }; + $param =~ m/^(?:const )?(?:float|double) \*[a-zA-Z]/ && do { + $arrayArgs{$var} = 1; next; + }; + $param =~ m/^(?:const )?(?:int|float|double) [a-zA-Z]/ && do { + $scalarArgs{$var} = 1; next; + }; + $param =~ m/^const enum [a-zA-Z]/ && do { + $var eq "order" && do { + $scalarArgs{'o'} = 1; + }; + $var =~ /trans/ && do { + $var =~ s/trans([AB]?)/t$1/; + $scalarArgs{$var} = 1; + if ($func =~ m/cblas_[cz]h/) { + push @processed, "if $var != blas.NoTrans && $var != blas.ConjTrans { panic(\"blas: illegal transpose\") }"; next; + } elsif ($func =~ m/cblas_[cz]s/) { + push @processed, "if $var != blas.NoTrans && $var != blas.Trans { panic(\"blas: illegal transpose\") }"; next; + } else { + push @processed, "if $var != blas.NoTrans && $var != blas.Trans && $var != blas.ConjTrans { panic(\"blas: illegal transpose\") }"; next; + } + }; + $var eq "uplo" && do { + push @processed, "if ul != blas.Upper && ul != blas.Lower { panic(\"blas: illegal triangle\") }"; next; + }; + $var eq "diag" && do { + push @processed, "if d != blas.NonUnit && d != blas.Unit { panic(\"blas: illegal diagonal\") }"; next; + }; + $var eq "side" && do { + $scalarArgs{'s'} = 1; + push @processed, "if s != blas.Left && s != blas.Right { panic(\"blas: illegal side\") }"; next; + }; + }; + } + + # shape checks + foreach my $ref ('m', 'n', 'k', 'kL', 'kU') { + push @processed, "if $ref < 0 { panic(\"blas: $ref < 0\") }" if $scalarArgs{$ref}; + } + + if ($arrayArgs{'ap'}) { + push @processed, "if n*(n + 1)/2 > len(ap) { panic(\"blas: index of ap out of range\") }" + } + + push @processed, "if incX == 0 { panic(\"blas: zero x index increment\") }" if $scalarArgs{'incX'}; + push @processed, "if incY == 0 { panic(\"blas: zero y index increment\") }" if $scalarArgs{'incY'}; + if ($func =~ m/cblas_[sdcz]g[eb]mv/) { + push @processed, "var lenX, lenY int"; + push @processed, "if tA == blas.NoTrans { lenX, lenY = n, m } else { lenX, lenY = m, n }"; + push @processed, "if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) { panic(\"blas: x index out of range\") }"; + push @processed, "if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) { panic(\"blas: y index out of range\") }"; + } elsif ($scalarArgs{'m'}) { + push @processed, "if (incX > 0 && (m-1)*incX >= len(x)) || (incX < 0 && (1-m)*incX >= len(x)) { panic(\"blas: x index out of range\") }" if $scalarArgs{'incX'}; + push @processed, "if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic(\"blas: y index out of range\") }" if $scalarArgs{'incY'}; + } elsif ($func =~ m/cblas_[sdcz]s?scal/) { + push @processed, "if incX < 0 { return }"; + push @processed, "if incX > 0 && (n-1)*incX >= len(x) { panic(\"blas: x index out of range\") }"; + } elsif ($func =~ m/cblas_i[sdcz]amax/) { + push @processed, "if n == 0 || incX < 0 { return -1 }"; + push @processed, "if incX > 0 && (n-1)*incX >= len(x) { panic(\"blas: x index out of range\") }"; + } elsif ($func =~ m/cblas_[sdz][cz]?(?:asum|nrm2)/) { + push @processed, "if incX < 0 { return 0 }"; + push @processed, "if incX > 0 && (n-1)*incX >= len(x) { panic(\"blas: x index out of range\") }"; + } else { + push @processed, "if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic(\"blas: x index out of range\") }" if $scalarArgs{'incX'}; + push @processed, "if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic(\"blas: y index out of range\") }" if $scalarArgs{'incY'}; + } + + if ($arrayArgs{'a'} && $scalarArgs{'s'}) { + push @processed, "var k int"; + push @processed, "if s == blas.Left { k = m } else { k = n }"; + push @processed, "if lda*(k-1)+k > len(a) || lda < max(1, k) { panic(\"blas: index of a out of range\") }"; + push @processed, "if ldb*(m-1)+n > len(b) || ldb < max(1, n) { panic(\"blas: index of b out of range\") }"; + if ($arrayArgs{'c'}) { + push @processed, "if ldc*(m-1)+n > len(c) || ldc < max(1, n) { panic(\"blas: index of c out of range\") }"; + } + } + + if (not $func =~ m/(?:mm|r2?k)$/) { + if ($arrayArgs{'a'} && !$scalarArgs{'s'}) { + if (($scalarArgs{'kL'} && $scalarArgs{'kU'}) || $scalarArgs{'m'}) { + if ($scalarArgs{'kL'} && $scalarArgs{'kU'}) { + push @processed, "if lda*(m-1)+kL+kU+1 > len(a) || lda < kL+kU+1 { panic(\"blas: index of a out of range\") }"; + } else { + push @processed, "if lda*(m-1)+n > len(a) || lda < max(1, n) { panic(\"blas: index of a out of range\") }"; + } + } else { + if ($scalarArgs{'k'}) { + push @processed, "if lda*(n-1)+k+1 > len(a) || lda < k+1 { panic(\"blas: index of a out of range\") }"; + } else { + push @processed, "if lda*(n-1)+n > len(a) || lda < max(1, n) { panic(\"blas: index of a out of range\") }"; + } + } + } + } else { + if ($scalarArgs{'t'}) { + push @processed, "var row, col int"; + push @processed, "if t == blas.NoTrans { row, col = n, k } else { row, col = k, n }"; + foreach my $ref ('a', 'b') { + if ($arrayArgs{$ref}) { + push @processed, "if ld${ref}*(row-1)+col > len(${ref}) || ld${ref} < max(1, col) { panic(\"blas: index of ${ref} out of range\") }"; + } + } + if ($arrayArgs{'c'}) { + push @processed, "if ldc*(n-1)+n > len(c) || ldc < max(1, n) { panic(\"blas: index of c out of range\") }"; + } + } + if ($scalarArgs{'tA'} && $scalarArgs{'tB'}) { + push @processed, "var rowA, colA, rowB, colB int"; + push @processed, "if tA == blas.NoTrans { rowA, colA = m, k } else { rowA, colA = k, m }"; + push @processed, "if tB == blas.NoTrans { rowB, colB = k, n } else { rowB, colB = n, k }"; + push @processed, "if lda*(rowA-1)+colA > len(a) || lda < max(1, colA) { panic(\"blas: index of a out of range\") }"; + push @processed, "if ldb*(rowB-1)+colB > len(b) || ldb < max(1, colB) { panic(\"blas: index of b out of range\") }"; + push @processed, "if ldc*(m-1)+n > len(c) || ldc < max(1, n) { panic(\"blas: index of c out of range\") }"; + } + } + + my $checks = join "\n", @processed; + $checks .= "\n" if scalar @processed > 0; + return $checks +} + +sub processParamToC { + my $func = shift; + my $paramList = shift; + my @processed; + my @params = split ',', $paramList; + foreach my $param (@params) { + my @parts = split /[ *]/, $param; + my $var = lcfirst $parts[scalar @parts - 1]; + $param =~ m/^(?:const )?int \*[a-zA-Z]/ && do { + push @processed, "(*C.int)(&".$var.")"; next; + }; + $param =~ m/^(?:const )?void \*[a-zA-Z]/ && do { + my $type; + if ($var eq "alpha" || $var eq "beta") { + $type = ""; + } else { + $type = "[0]"; + } + push @processed, "unsafe.Pointer(&".$var.$type.")"; next; + }; + $param =~ m/^(?:const )?char \*[a-zA-Z]/ && do { + push @processed, "(*C.char)(&".$var.")"; next; + }; + $param =~ m/^(?:const )?float \*[a-zA-Z]/ && do { + push @processed, "(*C.float)(&".$var."[0])"; next; + }; + $param =~ m/^(?:const )?double \*[a-zA-Z]/ && do { + push @processed, "(*C.double)(&".$var."[0])"; next; + }; + $param =~ m/^(?:const )?int [a-zA-Z]/ && do { + push @processed, "C.int(".$var.")"; next; + }; + $param =~ m/^(?:const )float [a-zA-Z]/ && do { + push @processed, "C.float(".$var.")"; next; + }; + $param =~ m/^(?:const )double [a-zA-Z]/ && do { + push @processed, "C.double(".$var.")"; next; + }; + $param =~ m/^const enum [a-zA-Z]/ && do { + $var eq "order" && do { + push @processed, "C.enum_$parts[scalar @parts - 2](rowMajor)"; next; + }; + $var =~ /trans/ && do { + $var =~ s/trans([AB]?)/t$1/; + push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next; + }; + $var eq "uplo" && do { + $var = "ul"; + push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next; + }; + $var eq "diag" && do { + $var = "d"; + push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next; + }; + $var eq "side" && do { + $var = "s"; + push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next; + }; + }; + } + die "missed C parameters from '$func', '$paramList'" if scalar @processed != scalar @params; + return join ", ", @processed; +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level1doubleBench_auto_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level1doubleBench_auto_test.go new file mode 100644 index 0000000..326f70c --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level1doubleBench_auto_test.go @@ -0,0 +1,1685 @@ +// Copyright 2014 The Gonum Authors. All rights reserved. +// Use of this code is governed by a BSD-style +// license that can be found in the LICENSE file + +// This file is autogenerated by github.com/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go + +package cgo + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas" +) + +const ( + posInc1 = 5 + posInc2 = 3 + negInc1 = -3 + negInc2 = -4 + SMALL_SLICE = 10 + MEDIUM_SLICE = 1000 + LARGE_SLICE = 100000 + HUGE_SLICE = 10000000 +) + +func randomSlice(l, idx int) []float64 { + if idx < 0 { + idx = -idx + } + s := make([]float64, l*idx) + for i := range s { + s[i] = rand.Float64() + } + return s +} + +func benchmarkDdot(b *testing.B, n int, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Ddot(n, x, incX, y, incY) + } +} + +func BenchmarkDdotSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDnrm2(b *testing.B, n int, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dnrm2(n, x, incX) + } +} + +func BenchmarkDnrm2SmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2SmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2MediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2MediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2LargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2LargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2HugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2HugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +/* ------------------ */ +func benchmarkDasum(b *testing.B, n int, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dasum(n, x, incX) + } +} + +func BenchmarkDasumSmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumSmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumMediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumMediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumLargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumLargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumHugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumHugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +/* ------------------ */ +func benchmarkIdamax(b *testing.B, n int, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Idamax(n, x, incX) + } +} + +func BenchmarkIdamaxSmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxSmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxMediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxMediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxLargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxLargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxHugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxHugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +/* ------------------ */ +func benchmarkDswap(b *testing.B, n int, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dswap(n, x, incX, y, incY) + } +} + +func BenchmarkDswapSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDcopy(b *testing.B, n int, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dcopy(n, x, incX, y, incY) + } +} + +func BenchmarkDcopySmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopySmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopySmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopySmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDaxpy(b *testing.B, n int, alpha float64, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Daxpy(n, alpha, x, incX, y, incY) + } +} + +func BenchmarkDaxpySmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpySmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpySmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpySmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDrot(b *testing.B, n int, x []float64, incX int, y []float64, incY int, c, s float64) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drot(n, x, incX, y, incY, c, s) + } +} + +func BenchmarkDrotSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +/* ------------------ */ +func benchmarkDrotmOffDia(b *testing.B, n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drotm(n, x, incX, y, incY, p) + } +} + +func BenchmarkDrotmOffDiaSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +/* ------------------ */ +func benchmarkDrotmDia(b *testing.B, n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drotm(n, x, incX, y, incY, p) + } +} + +func BenchmarkDrotmDiaSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +/* ------------------ */ +func benchmarkDrotmResc(b *testing.B, n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drotm(n, x, incX, y, incY, p) + } +} + +func BenchmarkDrotmRescSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +/* ------------------ */ +func benchmarkDscal(b *testing.B, n int, alpha float64, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dscal(n, alpha, x, incX) + } +} + +func BenchmarkDscalSmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalSmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalMediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalMediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalLargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalLargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalHugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalHugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +/* ------------------ */ diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level1double_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level1double_test.go new file mode 100644 index 0000000..871c622 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level1double_test.go @@ -0,0 +1,57 @@ +package cgo + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +var impl Implementation + +func TestDasum(t *testing.T) { + testblas.DasumTest(t, impl) +} + +func TestDaxpy(t *testing.T) { + testblas.DaxpyTest(t, impl) +} + +func TestDdot(t *testing.T) { + testblas.DdotTest(t, impl) +} + +func TestDnrm2(t *testing.T) { + testblas.Dnrm2Test(t, impl) +} + +func TestIdamax(t *testing.T) { + testblas.IdamaxTest(t, impl) +} + +func TestDswap(t *testing.T) { + testblas.DswapTest(t, impl) +} + +func TestDcopy(t *testing.T) { + testblas.DcopyTest(t, impl) +} + +func TestDrotg(t *testing.T) { + testblas.DrotgTest(t, impl) +} + +func TestDrotmg(t *testing.T) { + testblas.DrotmgTest(t, impl) +} + +func TestDrot(t *testing.T) { + testblas.DrotTest(t, impl) +} + +func TestDrotm(t *testing.T) { + testblas.DrotmTest(t, impl) +} + +func TestDscal(t *testing.T) { + testblas.DscalTest(t, impl) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level2double_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level2double_test.go new file mode 100644 index 0000000..41d29fb --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level2double_test.go @@ -0,0 +1,75 @@ +package cgo + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func TestDgemv(t *testing.T) { + testblas.DgemvTest(t, impl) +} + +func TestDger(t *testing.T) { + testblas.DgerTest(t, impl) +} + +func TestDtbmv(t *testing.T) { + testblas.DtbmvTest(t, impl) +} + +func TestDtxmv(t *testing.T) { + testblas.DtxmvTest(t, impl) +} + +func TestDgbmv(t *testing.T) { + testblas.DgbmvTest(t, impl) +} + +func TestDtbsv(t *testing.T) { + testblas.DtbsvTest(t, impl) +} + +func TestDsbmv(t *testing.T) { + testblas.DsbmvTest(t, impl) +} + +func TestDtrsv(t *testing.T) { + testblas.DtrsvTest(t, impl) +} + +func TestDsyr(t *testing.T) { + testblas.DsyrTest(t, impl) +} + +func TestDsymv(t *testing.T) { + testblas.DsymvTest(t, impl) +} + +func TestDtrmv(t *testing.T) { + testblas.DtrmvTest(t, impl) +} + +func TestDsyr2(t *testing.T) { + testblas.Dsyr2Test(t, impl) +} + +func TestDspr2(t *testing.T) { + testblas.Dspr2Test(t, impl) +} + +func TestDspr(t *testing.T) { + testblas.DsprTest(t, impl) +} + +func TestDspmv(t *testing.T) { + testblas.DspmvTest(t, impl) +} + +func TestDtpsv(t *testing.T) { + testblas.DtpsvTest(t, impl) +} + +func TestDtmpv(t *testing.T) { + testblas.DtpmvTest(t, impl) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level3double_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level3double_test.go new file mode 100644 index 0000000..a35af51 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/cgo/level3double_test.go @@ -0,0 +1,31 @@ +package cgo + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func TestDgemm(t *testing.T) { + testblas.TestDgemm(t, impl) +} + +func TestDsymm(t *testing.T) { + testblas.DsymmTest(t, impl) +} + +func TestDtrsm(t *testing.T) { + testblas.DtrsmTest(t, impl) +} + +func TestDsyrk(t *testing.T) { + testblas.DsyrkTest(t, impl) +} + +func TestDsyr2k(t *testing.T) { + testblas.Dsyr2kTest(t, impl) +} + +func TestDtrmm(t *testing.T) { + testblas.DtrmmTest(t, impl) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/bench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/bench_test.go new file mode 100644 index 0000000..92cd0b8 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/bench_test.go @@ -0,0 +1,18 @@ +package native + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/testblas" +) + +const ( + Sm = testblas.SmallMat + Med = testblas.MediumMat + Lg = testblas.LargeMat + Hg = testblas.HugeMat +) + +const ( + T = blas.Trans + NT = blas.NoTrans +) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemm.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemm.go new file mode 100644 index 0000000..9131370 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemm.go @@ -0,0 +1,400 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package native + +import ( + "fmt" + "runtime" + "sync" + + "github.com/gonum/blas" + "github.com/gonum/internal/asm" +) + +const ( + blockSize = 64 // b x b matrix + minParBlock = 4 // minimum number of blocks needed to go parallel + buffMul = 4 // how big is the buffer relative to the number of workers +) + +// Dgemm computes +// C = beta * C + alpha * A * B. +// tA and tB specify whether A or B are transposed. A, B, and C are n×n dense +// matrices. +func (Implementation) Dgemm(tA, tB blas.Transpose, m, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { + var amat, bmat, cmat general + if tA == blas.Trans { + amat = general{ + data: a, + rows: k, + cols: m, + stride: lda, + } + } else { + amat = general{ + data: a, + rows: m, + cols: k, + stride: lda, + } + } + err := amat.check('a') + if err != nil { + panic(err.Error()) + } + if tB == blas.Trans { + bmat = general{ + data: b, + rows: n, + cols: k, + stride: ldb, + } + } else { + bmat = general{ + data: b, + rows: k, + cols: n, + stride: ldb, + } + } + + err = bmat.check('b') + if err != nil { + panic(err.Error()) + } + cmat = general{ + data: c, + rows: m, + cols: n, + stride: ldc, + } + err = cmat.check('c') + if err != nil { + panic(err.Error()) + } + if tA != blas.Trans && tA != blas.NoTrans { + panic(badTranspose) + } + if tB != blas.Trans && tB != blas.NoTrans { + panic(badTranspose) + } + + // scale c + if beta != 1 { + if beta == 0 { + for i := 0; i < m; i++ { + ctmp := cmat.data[i*cmat.stride : i*cmat.stride+cmat.cols] + for j := range ctmp { + ctmp[j] = 0 + } + } + } else { + for i := 0; i < m; i++ { + ctmp := cmat.data[i*cmat.stride : i*cmat.stride+cmat.cols] + for j := range ctmp { + ctmp[j] *= beta + } + } + } + } + + dgemmParallel(tA, tB, amat, bmat, cmat, alpha) +} + +func dgemmParallel(tA, tB blas.Transpose, a, b, c general, alpha float64) { + // dgemmParallel computes a parallel matrix multiplication by partitioning + // a and b into sub-blocks, and updating c with the multiplication of the sub-block + // In all cases, + // A = [ A_11 A_12 ... A_1j + // A_21 A_22 ... A_2j + // ... + // A_i1 A_i2 ... A_ij] + // + // and same for B. All of the submatrix sizes are blockSize*blockSize except + // at the edges. + // In all cases, there is one dimension for each matrix along which + // C must be updated sequentially. + // Cij = \sum_k Aik Bki, (A * B) + // Cij = \sum_k Aki Bkj, (A^T * B) + // Cij = \sum_k Aik Bjk, (A * B^T) + // Cij = \sum_k Aki Bjk, (A^T * B^T) + // + // This code computes one {i, j} block sequentially along the k dimension, + // and computes all of the {i, j} blocks concurrently. This + // partitioning allows Cij to be updated in-place without race-conditions. + // Instead of launching a goroutine for each possible concurrent computation, + // a number of worker goroutines are created and channels are used to pass + // available and completed cases. + // + // http://alexkr.com/docs/matrixmult.pdf is a good reference on matrix-matrix + // multiplies, though this code does not copy matrices to attempt to eliminate + // cache misses. + + aTrans := tA == blas.Trans + bTrans := tB == blas.Trans + + maxKLen, parBlocks := computeNumBlocks(a, b, aTrans, bTrans) + if parBlocks < minParBlock { + // The matrix multiplication is small in the dimensions where it can be + // computed concurrently. Just do it in serial. + dgemmSerial(tA, tB, a, b, c, alpha) + return + } + + nWorkers := runtime.GOMAXPROCS(0) + if parBlocks < nWorkers { + nWorkers = parBlocks + } + // There is a tradeoff between the workers having to wait for work + // and a large buffer making operations slow. + buf := buffMul * nWorkers + if buf > parBlocks { + buf = parBlocks + } + + sendChan := make(chan subMul, buf) + + // Launch workers. A worker receives an {i, j} submatrix of c, and computes + // A_ik B_ki (or the transposed version) storing the result in c_ij. When the + // channel is finally closed, it signals to the waitgroup that it has finished + // computing. + var wg sync.WaitGroup + for i := 0; i < nWorkers; i++ { + wg.Add(1) + go func() { + defer wg.Done() + // Make local copies of otherwise global variables to reduce shared memory. + // This has a noticable effect on benchmarks in some cases. + alpha := alpha + aTrans := aTrans + bTrans := bTrans + crows := c.rows + ccols := c.cols + for sub := range sendChan { + i := sub.i + j := sub.j + leni := blockSize + if i+leni > crows { + leni = crows - i + } + lenj := blockSize + if j+lenj > ccols { + lenj = ccols - j + } + cSub := c.view(i, j, leni, lenj) + + // Compute A_ik B_kj for all k + for k := 0; k < maxKLen; k += blockSize { + lenk := blockSize + if k+lenk > maxKLen { + lenk = maxKLen - k + } + var aSub, bSub general + if aTrans { + aSub = a.view(k, i, lenk, leni) + } else { + aSub = a.view(i, k, leni, lenk) + } + if bTrans { + bSub = b.view(j, k, lenj, lenk) + } else { + bSub = b.view(k, j, lenk, lenj) + } + + dgemmSerial(tA, tB, aSub, bSub, cSub, alpha) + } + } + }() + } + + // Send out all of the {i, j} subblocks for computation. + for i := 0; i < c.rows; i += blockSize { + for j := 0; j < c.cols; j += blockSize { + sendChan <- subMul{ + i: i, + j: j, + } + } + } + close(sendChan) + wg.Wait() +} + +type subMul struct { + i, j int // index of block +} + +// computeNumBlocks says how many blocks there are to compute. maxKLen says the length of the +// k dimension, parBlocks is the number of blocks that could be computed in parallel +// (the submatrices in i and j). expect is the full number of blocks that will be computed. +func computeNumBlocks(a, b general, aTrans, bTrans bool) (maxKLen, parBlocks int) { + aRowBlocks := a.rows / blockSize + if a.rows%blockSize != 0 { + aRowBlocks++ + } + aColBlocks := a.cols / blockSize + if a.cols%blockSize != 0 { + aColBlocks++ + } + bRowBlocks := b.rows / blockSize + if b.rows%blockSize != 0 { + bRowBlocks++ + } + bColBlocks := b.cols / blockSize + if b.cols%blockSize != 0 { + bColBlocks++ + } + + switch { + case !aTrans && !bTrans: + // Cij = \sum_k Aik Bki + maxKLen = a.cols + parBlocks = aRowBlocks * bColBlocks + case aTrans && !bTrans: + // Cij = \sum_k Aki Bkj + maxKLen = a.rows + parBlocks = aColBlocks * bColBlocks + case !aTrans && bTrans: + // Cij = \sum_k Aik Bjk + maxKLen = a.cols + parBlocks = aRowBlocks * bRowBlocks + case aTrans && bTrans: + // Cij = \sum_k Aki Bjk + maxKLen = a.rows + parBlocks = aColBlocks * bRowBlocks + } + return +} + +// dgemmSerial is serial matrix multiply +func dgemmSerial(tA, tB blas.Transpose, a, b, c general, alpha float64) { + switch { + case tA == blas.NoTrans && tB == blas.NoTrans: + dgemmSerialNotNot(a, b, c, alpha) + return + case tA == blas.Trans && tB == blas.NoTrans: + dgemmSerialTransNot(a, b, c, alpha) + return + case tA == blas.NoTrans && tB == blas.Trans: + dgemmSerialNotTrans(a, b, c, alpha) + return + case tA == blas.Trans && tB == blas.Trans: + dgemmSerialTransTrans(a, b, c, alpha) + return + default: + panic("unreachable") + } +} + +// dgemmSerial where neither a nor b are transposed +func dgemmSerialNotNot(a, b, c general, alpha float64) { + if debug { + if a.cols != b.rows { + panic("inner dimension mismatch") + } + if a.rows != c.rows { + panic("outer dimension mismatch") + } + if b.cols != c.cols { + panic("outer dimension mismatch") + } + } + + // This style is used instead of the literal [i*stride +j]) is used because + // approximately 5 times faster as of go 1.3. + for i := 0; i < a.rows; i++ { + ctmp := c.data[i*c.stride : i*c.stride+c.cols] + for l, v := range a.data[i*a.stride : i*a.stride+a.cols] { + tmp := alpha * v + if tmp != 0 { + asm.DaxpyUnitary(tmp, b.data[l*b.stride:l*b.stride+b.cols], ctmp, ctmp) + } + } + } +} + +// dgemmSerial where neither a is transposed and b is not +func dgemmSerialTransNot(a, b, c general, alpha float64) { + if debug { + if a.rows != b.rows { + fmt.Println(a.rows, b.rows) + panic("inner dimension mismatch") + } + if a.cols != c.rows { + panic("outer dimension mismatch") + } + if b.cols != c.cols { + panic("outer dimension mismatch") + } + } + + // This style is used instead of the literal [i*stride +j]) is used because + // approximately 5 times faster as of go 1.3. + for l := 0; l < a.rows; l++ { + btmp := b.data[l*b.stride : l*b.stride+b.cols] + for i, v := range a.data[l*a.stride : l*a.stride+a.cols] { + tmp := alpha * v + ctmp := c.data[i*c.stride : i*c.stride+c.cols] + if tmp != 0 { + asm.DaxpyUnitary(tmp, btmp, ctmp, ctmp) + } + } + } +} + +// dgemmSerial where neither a is not transposed and b is +func dgemmSerialNotTrans(a, b, c general, alpha float64) { + if debug { + if a.cols != b.cols { + panic("inner dimension mismatch") + } + if a.rows != c.rows { + panic("outer dimension mismatch") + } + if b.rows != c.cols { + panic("outer dimension mismatch") + } + } + + // This style is used instead of the literal [i*stride +j]) is used because + // approximately 5 times faster as of go 1.3. + for i := 0; i < a.rows; i++ { + atmp := a.data[i*a.stride : i*a.stride+a.cols] + ctmp := c.data[i*c.stride : i*c.stride+c.cols] + for j := 0; j < b.rows; j++ { + ctmp[j] += alpha * asm.DdotUnitary(atmp, b.data[j*b.stride:j*b.stride+b.cols]) + } + } + +} + +// dgemmSerial where both are transposed +func dgemmSerialTransTrans(a, b, c general, alpha float64) { + if debug { + if a.rows != b.cols { + panic("inner dimension mismatch") + } + if a.cols != c.rows { + panic("outer dimension mismatch") + } + if b.rows != c.cols { + panic("outer dimension mismatch") + } + } + + // This style is used instead of the literal [i*stride +j]) is used because + // approximately 5 times faster as of go 1.3. + for l := 0; l < a.rows; l++ { + for i, v := range a.data[l*a.stride : l*a.stride+a.cols] { + ctmp := c.data[i*c.stride : i*c.stride+c.cols] + if v != 0 { + tmp := alpha * v + if tmp != 0 { + asm.DaxpyInc(tmp, b.data[l:], ctmp, uintptr(b.rows), uintptr(b.stride), 1, 0, 0) + } + } + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemmbench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemmbench_test.go new file mode 100644 index 0000000..d77bf53 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemmbench_test.go @@ -0,0 +1,47 @@ +package native + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func BenchmarkDgemmSmSmSm(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Sm, Sm, Sm, NT, NT) +} + +func BenchmarkDgemmMedMedMed(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, NT, NT) +} + +func BenchmarkDgemmMedLgMed(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Lg, Med, NT, NT) +} + +func BenchmarkDgemmLgLgLg(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Lg, Lg, Lg, NT, NT) +} + +func BenchmarkDgemmLgSmLg(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Lg, Sm, Lg, NT, NT) +} + +func BenchmarkDgemmLgLgSm(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Lg, Lg, Sm, NT, NT) +} + +func BenchmarkDgemmHgHgSm(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Hg, Hg, Sm, NT, NT) +} + +func BenchmarkDgemmMedMedMedTNT(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, T, NT) +} + +func BenchmarkDgemmMedMedMedNTT(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, NT, T) +} + +func BenchmarkDgemmMedMedMedTT(b *testing.B) { + testblas.DgemmBenchmark(b, impl, Med, Med, Med, T, T) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemvbench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemvbench_test.go new file mode 100644 index 0000000..21e7074 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgemvbench_test.go @@ -0,0 +1,87 @@ +package native + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func BenchmarkDgemvSmSmNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Sm, 1, 1) +} + +func BenchmarkDgemvSmSmNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Sm, 2, 3) +} + +func BenchmarkDgemvSmSmTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Sm, 1, 1) +} + +func BenchmarkDgemvSmSmTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Sm, 2, 3) +} + +func BenchmarkDgemvMedMedNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Med, Med, 1, 1) +} + +func BenchmarkDgemvMedMedNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Med, Med, 2, 3) +} + +func BenchmarkDgemvMedMedTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Med, Med, 1, 1) +} + +func BenchmarkDgemvMedMedTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Med, Med, 2, 3) +} + +func BenchmarkDgemvLgLgNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Lg, 1, 1) +} + +func BenchmarkDgemvLgLgNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Lg, 2, 3) +} + +func BenchmarkDgemvLgLgTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Lg, 1, 1) +} + +func BenchmarkDgemvLgLgTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Lg, 2, 3) +} + +func BenchmarkDgemvLgSmNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Sm, 1, 1) +} + +func BenchmarkDgemvLgSmNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Lg, Sm, 2, 3) +} + +func BenchmarkDgemvLgSmTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Sm, 1, 1) +} + +func BenchmarkDgemvLgSmTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Lg, Sm, 2, 3) +} + +func BenchmarkDgemvSmLgNoTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Lg, 1, 1) +} + +func BenchmarkDgemvSmLgNoTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, NT, Sm, Lg, 2, 3) +} + +func BenchmarkDgemvSmLgTransInc1(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Lg, 1, 1) +} + +func BenchmarkDgemvSmLgTransIncN(b *testing.B) { + testblas.DgemvBenchmark(b, impl, T, Sm, Lg, 2, 3) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgerbench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgerbench_test.go new file mode 100644 index 0000000..b4d7b3c --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/dgerbench_test.go @@ -0,0 +1,47 @@ +package native + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func BenchmarkDgerSmSmInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Sm, 1, 1) +} + +func BenchmarkDgerSmSmIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Sm, 2, 3) +} + +func BenchmarkDgerMedMedInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Med, Med, 1, 1) +} + +func BenchmarkDgerMedMedIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Med, Med, 2, 3) +} + +func BenchmarkDgerLgLgInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Lg, 1, 1) +} + +func BenchmarkDgerLgLgIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Lg, 2, 3) +} + +func BenchmarkDgerLgSmInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Sm, 1, 1) +} + +func BenchmarkDgerLgSmIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Lg, Sm, 2, 3) +} + +func BenchmarkDgerSmLgInc1(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Lg, 1, 1) +} + +func BenchmarkDgerSmLgIncN(b *testing.B) { + testblas.DgerBenchmark(b, impl, Sm, Lg, 2, 3) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/doc.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/doc.go new file mode 100644 index 0000000..68e591b --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/doc.go @@ -0,0 +1,82 @@ +/* +Package native is a Go implementation of the BLAS API. This implementation +panics when the input arguments are invalid as per the standard, for example +if a vector increment is zero. Please note that the treatment of NaN values +is not specified, and differs among the BLAS implementations. +github.com/gonum/blas/blas64 provides helpful wrapper functions to the BLAS +interface. The rest of this text describes the layout of the data for the input types. + +Please note that in the function documentation, x[i] refers to the i^th element +of the vector, which will be different from the i^th element of the slice if +incX != 1. + +See http://www.netlib.org/lapack/explore-html/d4/de1/_l_i_c_e_n_s_e_source.html +for more license information. + +Vector arguments are effectively strided slices. They have two input arguments, +a number of elements, n, and an increment, incX. The increment specifies the +distance between elements of the vector. The actual Go slice may be longer +than necessary. +The increment may be positive or negative, except in functions with only +a single vector argument where the increment may only be positive. If the increment +is negative, s[0] is the last element in the slice. Note that this is not the same +as counting backward from the end of the slice, as len(s) may be longer than +necessary. So, for example, if n = 5 and incX = 3, the elements of s are + [0 * * 1 * * 2 * * 3 * * 4 * * * ...] +where ∗ elements are never accessed. If incX = -3, the same elements are +accessed, just in reverse order (4, 3, 2, 1, 0). + +Dense matrices are specified by a number of rows, a number of columns, and a stride. +The stride specifies the number of entries in the slice between the first element +of successive rows. The stride must be at least as large as the number of columns +but may be longer. + [a00 ... a0n a0* ... a1stride-1 a21 ... amn am* ... amstride-1] +Thus, dense[i*ld + j] refers to the {i, j}th element of the matrix. + +Symmetric and triangular matrices (non-packed) are stored identically to Dense, +except that only elements in one triangle of the matrix are accessed. + +Packed symmetric and packed triangular matrices are laid out with the entries +condensed such that all of the unreferenced elements are removed. So, the upper triangular +matrix + [ + 1 2 3 + 0 4 5 + 0 0 6 + ] +and the lower-triangular matrix + [ + 1 0 0 + 2 3 0 + 4 5 6 + ] +will both be compacted as [1 2 3 4 5 6]. The (i, j) element of the original +dense matrix can be found at element i*n - (i-1)*i/2 + j for upper triangular, +and at element i * (i+1) /2 + j for lower triangular. + +Banded matrices are laid out in a compact format, constructed by removing the +zeros in the rows and aligning the diagonals. For example, the matrix + [ + 1 2 3 0 0 0 + 4 5 6 7 0 0 + 0 8 9 10 11 0 + 0 0 12 13 14 15 + 0 0 0 16 17 18 + 0 0 0 0 19 20 + ] + +implicitly becomes (∗ entries are never accessed) + [ + * 1 2 3 + 4 5 6 7 + 8 9 10 11 + 12 13 14 15 + 16 17 18 * + 19 20 * * + ] +which is given to the BLAS routine is [∗ 1 2 3 4 ...]. + +See http://www.crest.iu.edu/research/mtl/reference/html/banded.html +for more information +*/ +package native diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/general.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/general.go new file mode 100644 index 0000000..90ea0e2 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/general.go @@ -0,0 +1,159 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package native + +import ( + "errors" + "fmt" + "math" +) + +const ( + debug = false +) + +func newGeneral(r, c int) general { + return general{ + data: make([]float64, r*c), + rows: r, + cols: c, + stride: c, + } +} + +type general struct { + data []float64 + rows, cols int + stride int +} + +// adds element-wise into receiver. rows and columns must match +func (g general) add(h general) { + if debug { + if g.rows != h.rows { + panic("blas: row size mismatch") + } + if g.cols != h.cols { + panic("blas: col size mismatch") + } + } + for i := 0; i < g.rows; i++ { + gtmp := g.data[i*g.stride : i*g.stride+g.cols] + for j, v := range h.data[i*h.stride : i*h.stride+h.cols] { + gtmp[j] += v + } + } +} + +// at returns the value at the ith row and jth column. For speed reasons, the +// rows and columns are not bounds checked. +func (g general) at(i, j int) float64 { + if debug { + if i < 0 || i >= g.rows { + panic("blas: row out of bounds") + } + if j < 0 || j >= g.cols { + panic("blas: col out of bounds") + } + } + return g.data[i*g.stride+j] +} + +func (g general) check(c byte) error { + if g.rows < 0 { + return errors.New("blas: rows < 0") + } + if g.cols < 0 { + return errors.New("blas: cols < 0") + } + if g.stride < 1 { + return errors.New("blas: stride < 1") + } + if g.stride < g.cols { + return errors.New("blas: illegal stride") + } + if (g.rows-1)*g.stride+g.cols > len(g.data) { + return fmt.Errorf("blas: index of %c out of range", c) + } + return nil +} + +func (g general) clone() general { + data := make([]float64, len(g.data)) + copy(data, g.data) + return general{ + data: data, + rows: g.rows, + cols: g.cols, + stride: g.stride, + } +} + +// assumes they are the same size +func (g general) copy(h general) { + if debug { + if g.rows != h.rows { + panic("blas: row mismatch") + } + if g.cols != h.cols { + panic("blas: col mismatch") + } + } + for k := 0; k < g.rows; k++ { + copy(g.data[k*g.stride:(k+1)*g.stride], h.data[k*h.stride:(k+1)*h.stride]) + } +} + +func (g general) equal(a general) bool { + if g.rows != a.rows || g.cols != a.cols || g.stride != a.stride { + return false + } + for i, v := range g.data { + if a.data[i] != v { + return false + } + } + return true +} + +/* +// print is to aid debugging. Commented out to avoid fmt import +func (g general) print() { + fmt.Println("r = ", g.rows, "c = ", g.cols, "stride: ", g.stride) + for i := 0; i < g.rows; i++ { + fmt.Println(g.data[i*g.stride : (i+1)*g.stride]) + } + +} +*/ + +func (g general) view(i, j, r, c int) general { + if debug { + if i < 0 || i+r > g.rows { + panic("blas: row out of bounds") + } + if j < 0 || j+c > g.cols { + panic("blas: col out of bounds") + } + } + return general{ + data: g.data[i*g.stride+j : (i+r-1)*g.stride+j+c], + rows: r, + cols: c, + stride: g.stride, + } +} + +func (g general) equalWithinAbs(a general, tol float64) bool { + if g.rows != a.rows || g.cols != a.cols || g.stride != a.stride { + return false + } + for i, v := range g.data { + if math.Abs(a.data[i]-v) > tol { + return false + } + } + return true +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1double.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1double.go new file mode 100644 index 0000000..27c938f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1double.go @@ -0,0 +1,600 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package native + +import ( + "math" + + "github.com/gonum/blas" + "github.com/gonum/internal/asm" +) + +type Implementation struct{} + +var _ blas.Float64Level1 = Implementation{} + +const ( + negativeN = "blas: n < 0" + zeroIncX = "blas: zero x index increment" + zeroIncY = "blas: zero y index increment" + badLenX = "blas: x index out of range" + badLenY = "blas: y index out of range" +) + +// Ddot computes the dot product of the two vectors +// \sum_i x[i]*y[i] +func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int) float64 { + if n < 0 { + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + if incX == 1 && incY == 1 { + if len(x) < n { + panic(badLenX) + } + if len(y) < n { + panic(badLenY) + } + return asm.DdotUnitary(x[:n], y) + } + var ix, iy int + if incX < 0 { + ix = (-n + 1) * incX + } + if incY < 0 { + iy = (-n + 1) * incY + } + if ix >= len(x) || ix+(n-1)*incX >= len(x) { + panic(badLenX) + } + if iy >= len(y) || iy+(n-1)*incY >= len(y) { + panic(badLenY) + } + return asm.DdotInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) +} + +// Dnrm2 computes the Euclidean norm of a vector, +// sqrt(\sum_i x[i] * x[i]). +// This function returns 0 if incX is negative. +func (Implementation) Dnrm2(n int, x []float64, incX int) float64 { + if incX < 1 { + if incX == 0 { + panic(zeroIncX) + } + return 0 + } + if n < 2 { + if n == 1 { + return math.Abs(x[0]) + } + if n == 0 { + return 0 + } + if n < 1 { + panic(negativeN) + } + } + scale := 0.0 + sumSquares := 1.0 + if incX == 1 { + x = x[:n] + for _, v := range x { + absxi := math.Abs(v) + if scale < absxi { + sumSquares = 1 + sumSquares*(scale/absxi)*(scale/absxi) + scale = absxi + } else { + sumSquares = sumSquares + (absxi/scale)*(absxi/scale) + } + } + return scale * math.Sqrt(sumSquares) + } + for ix := 0; ix < n*incX; ix += incX { + val := x[ix] + if val == 0 { + continue + } + absxi := math.Abs(val) + if scale < absxi { + sumSquares = 1 + sumSquares*(scale/absxi)*(scale/absxi) + scale = absxi + } else { + sumSquares = sumSquares + (absxi/scale)*(absxi/scale) + } + } + return scale * math.Sqrt(sumSquares) +} + +// Dasum computes the sum of the absolute values of the elements of x. +// \sum_i |x[i]| +// Dasum returns 0 if incX is negative. +func (Implementation) Dasum(n int, x []float64, incX int) float64 { + var sum float64 + if n < 0 { + panic(negativeN) + } + if incX < 1 { + if incX == 0 { + panic(zeroIncX) + } + return 0 + } + if incX == 1 { + x = x[:n] + for _, v := range x { + sum += math.Abs(v) + } + return sum + } + for i := 0; i < n; i++ { + sum += math.Abs(x[i*incX]) + } + return sum +} + +// Idamax returns the index of the largest element of x. If there are multiple +// such indices the earliest is returned. Idamax returns -1 if incX is negative or if +// n == 0. +func (Implementation) Idamax(n int, x []float64, incX int) int { + if incX < 1 { + if incX == 0 { + panic(zeroIncX) + } + return -1 + } + if n < 2 { + if n == 1 { + return 0 + } + if n == 0 { + return -1 // Netlib returns invalid index when n == 0 + } + if n < 1 { + panic(negativeN) + } + } + idx := 0 + max := math.Abs(x[0]) + if incX == 1 { + for i, v := range x { + absV := math.Abs(v) + if absV > max { + max = absV + idx = i + } + } + } + ix := incX + for i := 1; i < n; i++ { + v := x[ix] + absV := math.Abs(v) + if absV > max { + max = absV + idx = i + } + ix += incX + } + return idx +} + +// Dswap exchanges the elements of two vectors. +// x[i], y[i] = y[i], x[i] for all i +func (Implementation) Dswap(n int, x []float64, incX int, y []float64, incY int) { + if n < 1 { + if n == 0 { + return + } + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + if incX == 1 && incY == 1 { + x = x[:n] + for i, v := range x { + x[i], y[i] = y[i], v + } + return + } + var ix, iy int + if incX < 0 { + ix = (-n + 1) * incX + } + if incY < 0 { + iy = (-n + 1) * incY + } + for i := 0; i < n; i++ { + x[ix], y[iy] = y[iy], x[ix] + ix += incX + iy += incY + } +} + +// Dcopy copies the elements of x into the elements of y. +// y[i] = x[i] for all i +func (Implementation) Dcopy(n int, x []float64, incX int, y []float64, incY int) { + if n < 1 { + if n == 0 { + return + } + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + if incX == 1 && incY == 1 { + copy(y[:n], x[:n]) + return + } + var ix, iy int + if incX < 0 { + ix = (-n + 1) * incX + } + if incY < 0 { + iy = (-n + 1) * incY + } + for i := 0; i < n; i++ { + y[iy] = x[ix] + ix += incX + iy += incY + } +} + +// Daxpy adds alpha times x to y +// y[i] += alpha * x[i] for all i +func (Implementation) Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) { + if n < 1 { + if n == 0 { + return + } + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + if alpha == 0 { + return + } + if incX == 1 && incY == 1 { + if len(x) < n { + panic(badLenX) + } + if len(y) < n { + panic(badLenY) + } + asm.DaxpyUnitary(alpha, x[:n], y, y) + return + } + var ix, iy int + if incX < 0 { + ix = (-n + 1) * incX + } + if incY < 0 { + iy = (-n + 1) * incY + } + if ix >= len(x) || ix+(n-1)*incX >= len(x) { + panic(badLenX) + } + if iy >= len(y) || iy+(n-1)*incY >= len(y) { + panic(badLenY) + } + asm.DaxpyInc(alpha, x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) +} + +// Drotg computes the plane rotation +// _ _ _ _ _ _ +// | c s | | a | | r | +// | -s c | * | b | = | 0 | +// ‾ ‾ ‾ ‾ ‾ ‾ +// where +// r = ±(a^2 + b^2) +// c = a/r, the cosine of the plane rotation +// s = b/r, the sine of the plane rotation +// +// NOTE: There is a discrepancy between the refence implementation and the BLAS +// technical manual regarding the sign for r when a or b are zero. +// Drotg agrees with the definition in the manual and other +// common BLAS implementations. +func (Implementation) Drotg(a, b float64) (c, s, r, z float64) { + if b == 0 && a == 0 { + return 1, 0, a, 0 + } + absA := math.Abs(a) + absB := math.Abs(b) + aGTb := absA > absB + r = math.Hypot(a, b) + if aGTb { + r = math.Copysign(r, a) + } else { + r = math.Copysign(r, b) + } + c = a / r + s = b / r + if aGTb { + z = s + } else if c != 0 { // r == 0 case handled above + z = 1 / c + } else { + z = 1 + } + return +} + +// Drotmg computes the modified Givens rotation. See +// http://www.netlib.org/lapack/explore-html/df/deb/drotmg_8f.html +// for more details. +func (Implementation) Drotmg(d1, d2, x1, y1 float64) (p blas.DrotmParams, rd1, rd2, rx1 float64) { + var p1, p2, q1, q2, u float64 + + gam := 4096.0 + gamsq := 16777216.0 + rgamsq := 5.9604645e-8 + + if d1 < 0 { + p.Flag = blas.Rescaling + return + } + + p2 = d2 * y1 + if p2 == 0 { + p.Flag = blas.Identity + rd1 = d1 + rd2 = d2 + rx1 = x1 + return + } + p1 = d1 * x1 + q2 = p2 * y1 + q1 = p1 * x1 + + absQ1 := math.Abs(q1) + absQ2 := math.Abs(q2) + + if absQ1 < absQ2 && q2 < 0 { + p.Flag = blas.Rescaling + return + } + + if d1 == 0 { + p.Flag = blas.Diagonal + p.H[0] = p1 / p2 + p.H[3] = x1 / y1 + u = 1 + p.H[0]*p.H[3] + rd1, rd2 = d2/u, d1/u + rx1 = y1 / u + return + } + + // Now we know that d1 != 0, and d2 != 0. If d2 == 0, it would be caught + // when p2 == 0, and if d1 == 0, then it is caught above + + if absQ1 > absQ2 { + p.H[1] = -y1 / x1 + p.H[2] = p2 / p1 + u = 1 - p.H[2]*p.H[1] + rd1 = d1 + rd2 = d2 + rx1 = x1 + p.Flag = blas.OffDiagonal + // u must be greater than zero because |q1| > |q2|, so check from netlib + // is unnecessary + // This is left in for ease of comparison with complex routines + //if u > 0 { + rd1 /= u + rd2 /= u + rx1 *= u + //} + } else { + p.Flag = blas.Diagonal + p.H[0] = p1 / p2 + p.H[3] = x1 / y1 + u = 1 + p.H[0]*p.H[3] + rd1 = d2 / u + rd2 = d1 / u + rx1 = y1 * u + } + + for rd1 <= rgamsq || rd1 >= gamsq { + if p.Flag == blas.OffDiagonal { + p.H[0] = 1 + p.H[3] = 1 + p.Flag = blas.Rescaling + } else if p.Flag == blas.Diagonal { + p.H[1] = -1 + p.H[2] = 1 + p.Flag = blas.Rescaling + } + if rd1 <= rgamsq { + rd1 *= gam * gam + rx1 /= gam + p.H[0] /= gam + p.H[2] /= gam + } else { + rd1 /= gam * gam + rx1 *= gam + p.H[0] *= gam + p.H[2] *= gam + } + } + + for math.Abs(rd2) <= rgamsq || math.Abs(rd2) >= gamsq { + if p.Flag == blas.OffDiagonal { + p.H[0] = 1 + p.H[3] = 1 + p.Flag = blas.Rescaling + } else if p.Flag == blas.Diagonal { + p.H[1] = -1 + p.H[2] = 1 + p.Flag = blas.Rescaling + } + if math.Abs(rd2) <= rgamsq { + rd2 *= gam * gam + p.H[1] /= gam + p.H[3] /= gam + } else { + rd2 /= gam * gam + p.H[1] *= gam + p.H[3] *= gam + } + } + return +} + +// Drot applies a plane transformation. +// x[i] = c * x[i] + s * y[i] +// y[i] = c * y[i] - s * x[i] +func (Implementation) Drot(n int, x []float64, incX int, y []float64, incY int, c float64, s float64) { + if n < 1 { + if n == 0 { + return + } + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + + if incX == 1 && incY == 1 { + x = x[:n] + for i, vx := range x { + vy := y[i] + x[i], y[i] = c*vx+s*vy, c*vy-s*vx + } + return + } + var ix, iy int + if incX < 0 { + ix = (-n + 1) * incX + } + if incY < 0 { + iy = (-n + 1) * incY + } + for i := 0; i < n; i++ { + vx := x[ix] + vy := y[iy] + x[ix], y[iy] = c*vx+s*vy, c*vy-s*vx + ix += incX + iy += incY + } +} + +// Drotm applies the modified Givens rotation to the 2⨉n matrix. +func (Implementation) Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + if n <= 0 { + if n == 0 { + return + } + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + + var h11, h12, h21, h22 float64 + var ix, iy int + switch p.Flag { + case blas.Identity: + return + case blas.Rescaling: + h11 = p.H[0] + h12 = p.H[2] + h21 = p.H[1] + h22 = p.H[3] + case blas.OffDiagonal: + h11 = 1 + h12 = p.H[2] + h21 = p.H[1] + h22 = 1 + case blas.Diagonal: + h11 = p.H[0] + h12 = 1 + h21 = -1 + h22 = p.H[3] + } + if incX < 0 { + ix = (-n + 1) * incX + } + if incY < 0 { + iy = (-n + 1) * incY + } + if incX == 1 && incY == 1 { + x = x[:n] + for i, vx := range x { + vy := y[i] + x[i], y[i] = vx*h11+vy*h12, vx*h21+vy*h22 + } + return + } + for i := 0; i < n; i++ { + vx := x[ix] + vy := y[iy] + x[ix], y[iy] = vx*h11+vy*h12, vx*h21+vy*h22 + ix += incX + iy += incY + } + return +} + +// Dscal scales x by alpha. +// x[i] *= alpha +// Dscal has no effect if incX < 0. +func (Implementation) Dscal(n int, alpha float64, x []float64, incX int) { + if incX < 1 { + if incX == 0 { + panic(zeroIncX) + } + return + } + if n < 1 { + if n == 0 { + return + } + if n < 1 { + panic(negativeN) + } + } + if alpha == 0 { + if incX == 1 { + x = x[:n] + for i := range x { + x[i] = 0 + } + } + for ix := 0; ix < n*incX; ix += incX { + x[ix] = 0 + } + } + if incX == 1 { + x = x[:n] + for i := range x { + x[i] *= alpha + } + return + } + for ix := 0; ix < n*incX; ix += incX { + x[ix] *= alpha + } + return +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1doubleBench_auto_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1doubleBench_auto_test.go new file mode 100644 index 0000000..1cabfda --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1doubleBench_auto_test.go @@ -0,0 +1,1685 @@ +// Copyright 2014 The Gonum Authors. All rights reserved. +// Use of this code is governed by a BSD-style +// license that can be found in the LICENSE file + +// This file is autogenerated by github.com/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go + +package native + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas" +) + +const ( + posInc1 = 5 + posInc2 = 3 + negInc1 = -3 + negInc2 = -4 + SMALL_SLICE = 10 + MEDIUM_SLICE = 1000 + LARGE_SLICE = 100000 + HUGE_SLICE = 10000000 +) + +func randomSlice(l, idx int) []float64 { + if idx < 0 { + idx = -idx + } + s := make([]float64, l*idx) + for i := range s { + s[i] = rand.Float64() + } + return s +} + +func benchmarkDdot(b *testing.B, n int, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Ddot(n, x, incX, y, incY) + } +} + +func BenchmarkDdotSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +func BenchmarkDdotHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDdot(b, n, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDnrm2(b *testing.B, n int, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dnrm2(n, x, incX) + } +} + +func BenchmarkDnrm2SmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2SmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2MediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2MediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2LargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2LargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2HugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +func BenchmarkDnrm2HugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDnrm2(b, n, x, incX) +} + +/* ------------------ */ +func benchmarkDasum(b *testing.B, n int, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dasum(n, x, incX) + } +} + +func BenchmarkDasumSmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumSmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumMediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumMediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumLargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumLargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumHugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +func BenchmarkDasumHugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkDasum(b, n, x, incX) +} + +/* ------------------ */ +func benchmarkIdamax(b *testing.B, n int, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Idamax(n, x, incX) + } +} + +func BenchmarkIdamaxSmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxSmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxMediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxMediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxLargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxLargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxHugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +func BenchmarkIdamaxHugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + + benchmarkIdamax(b, n, x, incX) +} + +/* ------------------ */ +func benchmarkDswap(b *testing.B, n int, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dswap(n, x, incX, y, incY) + } +} + +func BenchmarkDswapSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +func BenchmarkDswapHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDswap(b, n, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDcopy(b *testing.B, n int, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dcopy(n, x, incX, y, incY) + } +} + +func BenchmarkDcopySmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopySmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopySmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopySmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +func BenchmarkDcopyHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + + benchmarkDcopy(b, n, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDaxpy(b *testing.B, n int, alpha float64, x []float64, incX int, y []float64, incY int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Daxpy(n, alpha, x, incX, y, incY) + } +} + +func BenchmarkDaxpySmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpySmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpySmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpySmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +func BenchmarkDaxpyHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + alpha := 2.4 + benchmarkDaxpy(b, n, alpha, x, incX, y, incY) +} + +/* ------------------ */ +func benchmarkDrot(b *testing.B, n int, x []float64, incX int, y []float64, incY int, c, s float64) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drot(n, x, incX, y, incY, c, s) + } +} + +func BenchmarkDrotSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +func BenchmarkDrotHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + c := 0.89725836967 + s := 0.44150585279 + benchmarkDrot(b, n, x, incX, y, incY, c, s) +} + +/* ------------------ */ +func benchmarkDrotmOffDia(b *testing.B, n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drotm(n, x, incX, y, incY, p) + } +} + +func BenchmarkDrotmOffDiaSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmOffDiaHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375, 0}} + benchmarkDrotmOffDia(b, n, x, incX, y, incY, p) +} + +/* ------------------ */ +func benchmarkDrotmDia(b *testing.B, n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drotm(n, x, incX, y, incY, p) + } +} + +func BenchmarkDrotmDiaSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmDiaHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}} + benchmarkDrotmDia(b, n, x, incX, y, incY, p) +} + +/* ------------------ */ +func benchmarkDrotmResc(b *testing.B, n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Drotm(n, x, incX, y, incY, p) + } +} + +func BenchmarkDrotmRescSmallBothUnitary(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescSmallIncUni(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescSmallUniInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescSmallBothInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumBothUnitary(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumIncUni(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumUniInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescMediumBothInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeBothUnitary(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeIncUni(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeUniInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescLargeBothInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeBothUnitary(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeIncUni(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := 1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeUniInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +func BenchmarkDrotmRescHugeBothInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + incY := negInc1 + y := randomSlice(n, incY) + p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}} + benchmarkDrotmResc(b, n, x, incX, y, incY, p) +} + +/* ------------------ */ +func benchmarkDscal(b *testing.B, n int, alpha float64, x []float64, incX int) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + impl.Dscal(n, alpha, x, incX) + } +} + +func BenchmarkDscalSmallUnitaryInc(b *testing.B) { + n := SMALL_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalSmallPosInc(b *testing.B) { + n := SMALL_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalMediumUnitaryInc(b *testing.B) { + n := MEDIUM_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalMediumPosInc(b *testing.B) { + n := MEDIUM_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalLargeUnitaryInc(b *testing.B) { + n := LARGE_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalLargePosInc(b *testing.B) { + n := LARGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalHugeUnitaryInc(b *testing.B) { + n := HUGE_SLICE + incX := 1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +func BenchmarkDscalHugePosInc(b *testing.B) { + n := HUGE_SLICE + incX := posInc1 + x := randomSlice(n, incX) + alpha := 2.4 + benchmarkDscal(b, n, alpha, x, incX) +} + +/* ------------------ */ diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1double_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1double_test.go new file mode 100644 index 0000000..5b4ce97 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level1double_test.go @@ -0,0 +1,57 @@ +package native + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +var impl Implementation + +func TestDasum(t *testing.T) { + testblas.DasumTest(t, impl) +} + +func TestDaxpy(t *testing.T) { + testblas.DaxpyTest(t, impl) +} + +func TestDdot(t *testing.T) { + testblas.DdotTest(t, impl) +} + +func TestDnrm2(t *testing.T) { + testblas.Dnrm2Test(t, impl) +} + +func TestIdamax(t *testing.T) { + testblas.IdamaxTest(t, impl) +} + +func TestDswap(t *testing.T) { + testblas.DswapTest(t, impl) +} + +func TestDcopy(t *testing.T) { + testblas.DcopyTest(t, impl) +} + +func TestDrotg(t *testing.T) { + testblas.DrotgTest(t, impl) +} + +func TestDrotmg(t *testing.T) { + testblas.DrotmgTest(t, impl) +} + +func TestDrot(t *testing.T) { + testblas.DrotTest(t, impl) +} + +func TestDrotm(t *testing.T) { + testblas.DrotmTest(t, impl) +} + +func TestDscal(t *testing.T) { + testblas.DscalTest(t, impl) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level2double.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level2double.go new file mode 100644 index 0000000..77b82e5 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level2double.go @@ -0,0 +1,2194 @@ +package native + +import ( + "github.com/gonum/blas" + "github.com/gonum/internal/asm" +) + +var _ blas.Float64Level2 = Implementation{} + +const ( + mLT0 = "blas: m < 0" + nLT0 = "blas: n < 0" + kLT0 = "blas: k < 0" + kLLT0 = "blas: kL < 0" + kULT0 = "blas: kU < 0" + + badUplo = "blas: illegal triangle" + badTranspose = "blas: illegal transpose" + badDiag = "blas: illegal diagonal" + badSide = "blas: illegal side" + + badLdA = "blas: index of a out of range" + badLdB = "blas: index of b out of range" + badLdC = "blas: index of c out of range" +) + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +func min(a, b int) int { + if a > b { + return b + } + return a +} + +// Dgemv computes +// y = alpha * a * x + beta * y if tA = blas.NoTrans +// y = alpha * A^T * x + beta * y if tA = blas.Trans or blas.ConjTrans +// where A is an m×n dense matrix, x and y are vectors, and alpha is a scalar. +func (Implementation) Dgemv(tA blas.Transpose, m, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if m < 0 { + panic(mLT0) + } + if n < 0 { + panic(nLT0) + } + if lda < max(1, n) { + panic(badLdA) + } + + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + + // Quick return if possible + if m == 0 || n == 0 || (alpha == 0 && beta == 1) { + return + } + + // Set up indexes + lenX := m + lenY := n + if tA == blas.NoTrans { + lenX = n + lenY = m + } + var kx, ky int + if incX > 0 { + kx = 0 + } else { + kx = -(lenX - 1) * incX + } + if incY > 0 { + ky = 0 + } else { + ky = -(lenY - 1) * incY + } + + // First form y := beta * y + if incY > 0 { + Implementation{}.Dscal(lenY, beta, y, incY) + } else { + Implementation{}.Dscal(lenY, beta, y, -incY) + } + + if alpha == 0 { + return + } + + // Form y := alpha * A * x + y + if tA == blas.NoTrans { + if incX == 1 { + for i := 0; i < m; i++ { + y[i] += alpha * asm.DdotUnitary(a[lda*i:lda*i+n], x) + } + return + } + iy := ky + for i := 0; i < m; i++ { + y[iy] += alpha * asm.DdotInc(x, a[lda*i:lda*i+n], uintptr(n), uintptr(incX), 1, uintptr(kx), 0) + iy += incY + } + return + } + // Cases where a is not transposed. + if incX == 1 { + for i := 0; i < m; i++ { + tmp := alpha * x[i] + if tmp != 0 { + asm.DaxpyUnitary(tmp, a[lda*i:lda*i+n], y, y) + } + } + return + } + ix := kx + for i := 0; i < m; i++ { + tmp := alpha * x[ix] + if tmp != 0 { + asm.DaxpyInc(tmp, a[lda*i:lda*i+n], y, uintptr(n), 1, uintptr(incY), 0, uintptr(ky)) + } + ix += incX + } +} + +// Dger performs the rank-one operation +// A += alpha * x * y^T +// where A is an m×n dense matrix, x and y are vectors, and alpha is a scalar. +func (Implementation) Dger(m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { + // Check inputs + if m < 0 { + panic("m < 0") + } + if n < 0 { + panic(negativeN) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + if lda < max(1, n) { + panic(badLdA) + } + + // Quick return if possible + if m == 0 || n == 0 || alpha == 0 { + return + } + + var ky, kx int + if incY > 0 { + ky = 0 + } else { + ky = -(n - 1) * incY + } + + if incX > 0 { + kx = 0 + } else { + kx = -(m - 1) * incX + } + + if incX == 1 && incY == 1 { + x = x[:m] + y = y[:n] + for i, xv := range x { + tmp := alpha * xv + if tmp != 0 { + atmp := a[i*lda : i*lda+n] + asm.DaxpyUnitary(tmp, y, atmp, atmp) + } + } + return + } + + ix := kx + for i := 0; i < m; i++ { + tmp := alpha * x[ix] + if tmp != 0 { + asm.DaxpyInc(tmp, y, a[i*lda:i*lda+n], uintptr(n), uintptr(incY), 1, uintptr(ky), 0) + } + ix += incX + } +} + +// Dgbmv computes +// y = alpha * A * x + beta * y if tA == blas.NoTrans +// y = alpha * A^T * x + beta * y if tA == blas.Trans +// where a is an m×n band matrix kL subdiagonals and kU super-diagonals, and +// m and n refer to the size of the full dense matrix it represents. +// x and y are vectors, and alpha and beta are scalars. +func (Implementation) Dgbmv(tA blas.Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if m < 0 { + panic(mLT0) + } + if n < 0 { + panic(nLT0) + } + if kL < 0 { + panic(kLLT0) + } + if kL < 0 { + panic(kULT0) + } + if lda < kL+kU+1 { + panic(badLdA) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + + // Quick return if possible + if m == 0 || n == 0 || (alpha == 0 && beta == 1) { + return + } + + // Set up indexes + lenX := m + lenY := n + if tA == blas.NoTrans { + lenX = n + lenY = m + } + var kx, ky int + if incX > 0 { + kx = 0 + } else { + kx = -(lenX - 1) * incX + } + if incY > 0 { + ky = 0 + } else { + ky = -(lenY - 1) * incY + } + + // First form y := beta * y + if incY > 0 { + Implementation{}.Dscal(lenY, beta, y, incY) + } else { + Implementation{}.Dscal(lenY, beta, y, -incY) + } + + if alpha == 0 { + return + } + + // i and j are indices of the compacted banded matrix. + // off is the offset into the dense matrix (off + j = densej) + ld := min(m, n) + nCol := kU + 1 + kL + if tA == blas.NoTrans { + iy := ky + if incX == 1 { + for i := 0; i < m; i++ { + l := max(0, kL-i) + u := min(nCol, ld+kL-i) + off := max(0, i-kL) + atmp := a[i*lda+l : i*lda+u] + xtmp := x[off : off+u-l] + var sum float64 + for j, v := range atmp { + sum += xtmp[j] * v + } + y[iy] += sum * alpha + iy += incY + } + return + } + for i := 0; i < m; i++ { + l := max(0, kL-i) + u := min(nCol, ld+kL-i) + off := max(0, i-kL) + atmp := a[i*lda+l : i*lda+u] + jx := kx + var sum float64 + for _, v := range atmp { + sum += x[off*incX+jx] * v + jx += incX + } + y[iy] += sum * alpha + iy += incY + } + return + } + if incX == 1 { + for i := 0; i < m; i++ { + l := max(0, kL-i) + u := min(nCol, ld+kL-i) + off := max(0, i-kL) + atmp := a[i*lda+l : i*lda+u] + tmp := alpha * x[i] + jy := ky + for _, v := range atmp { + y[jy+off*incY] += tmp * v + jy += incY + } + } + return + } + ix := kx + for i := 0; i < m; i++ { + l := max(0, kL-i) + u := min(nCol, ld+kL-i) + off := max(0, i-kL) + atmp := a[i*lda+l : i*lda+u] + tmp := alpha * x[ix] + jy := ky + for _, v := range atmp { + y[jy+off*incY] += tmp * v + jy += incY + } + ix += incX + } +} + +// Dtrmv computes +// x = A * x if tA == blas.NoTrans +// x = A^T * x if tA == blas.Trans +// A is an n×n Triangular matrix and x is a vector. +func (Implementation) Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if n < 0 { + panic(nLT0) + } + if lda < n { + panic(badLdA) + } + if incX == 0 { + panic(zeroIncX) + } + if n == 0 { + return + } + nonUnit := d != blas.Unit + if n == 1 { + x[0] *= a[0] + return + } + var kx int + if incX <= 0 { + kx = -(n - 1) * incX + } + if tA == blas.NoTrans { + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + var tmp float64 + if nonUnit { + tmp = a[i*lda+i] * x[i] + } else { + tmp = x[i] + } + xtmp := x[i+1:] + for j, v := range a[i*lda+i+1 : i*lda+n] { + tmp += v * xtmp[j] + } + x[i] = tmp + } + return + } + ix := kx + for i := 0; i < n; i++ { + var tmp float64 + if nonUnit { + tmp = a[i*lda+i] * x[ix] + } else { + tmp = x[ix] + } + jx := ix + incX + for _, v := range a[i*lda+i+1 : i*lda+n] { + tmp += v * x[jx] + jx += incX + } + x[ix] = tmp + ix += incX + } + return + } + if incX == 1 { + for i := n - 1; i >= 0; i-- { + var tmp float64 + if nonUnit { + tmp += a[i*lda+i] * x[i] + } else { + tmp = x[i] + } + for j, v := range a[i*lda : i*lda+i] { + tmp += v * x[j] + } + x[i] = tmp + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + var tmp float64 + if nonUnit { + tmp += a[i*lda+i] * x[ix] + } else { + tmp = x[ix] + } + jx := kx + for _, v := range a[i*lda : i*lda+i] { + tmp += v * x[jx] + jx += incX + } + x[ix] = tmp + ix -= incX + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + if incX == 1 { + for i := n - 1; i >= 0; i-- { + xi := x[i] + atmp := a[i*lda+i+1 : i*lda+n] + xtmp := x[i+1 : n] + for j, v := range atmp { + xtmp[j] += xi * v + } + if nonUnit { + x[i] *= a[i*lda+i] + } + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + xi := x[ix] + jx := kx + (i+1)*incX + atmp := a[i*lda+i+1 : i*lda+n] + for _, v := range atmp { + x[jx] += xi * v + jx += incX + } + if nonUnit { + x[ix] *= a[i*lda+i] + } + ix -= incX + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + xi := x[i] + atmp := a[i*lda : i*lda+i] + for j, v := range atmp { + x[j] += xi * v + } + if nonUnit { + x[i] *= a[i*lda+i] + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + xi := x[ix] + jx := kx + atmp := a[i*lda : i*lda+i] + for _, v := range atmp { + x[jx] += xi * v + jx += incX + } + if nonUnit { + x[ix] *= a[i*lda+i] + } + ix += incX + } +} + +// Dtrsv solves +// A * x = b if tA == blas.NoTrans +// A^T * x = b if tA == blas.Trans +// A is an n×n triangular matrix and x is a vector. +// At entry to the function, x contains the values of b, and the result is +// stored in place into x. +// +// No test for singularity or near-singularity is included in this +// routine. Such tests must be performed before calling this routine. +func (Implementation) Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) { + // Test the input parameters + // Verify inputs + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if n < 0 { + panic(nLT0) + } + if lda > n && lda > 1 { + panic("blas: lda must be less than max(1,n)") + } + if incX == 0 { + panic(zeroIncX) + } + // Quick return if possible + if n == 0 { + return + } + if n == 1 { + if d == blas.NonUnit { + x[0] /= a[0] + } + return + } + + var kx int + if incX < 0 { + kx = -(n - 1) * incX + } + nonUnit := d == blas.NonUnit + if tA == blas.NoTrans { + if ul == blas.Upper { + if incX == 1 { + for i := n - 1; i >= 0; i-- { + var sum float64 + atmp := a[i*lda+i+1 : i*lda+n] + for j, v := range atmp { + jv := i + j + 1 + sum += x[jv] * v + } + x[i] -= sum + if nonUnit { + x[i] /= a[i*lda+i] + } + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + var sum float64 + jx := ix + incX + atmp := a[i*lda+i+1 : i*lda+n] + for _, v := range atmp { + sum += x[jx] * v + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= a[i*lda+i] + } + ix -= incX + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + var sum float64 + atmp := a[i*lda : i*lda+i] + for j, v := range atmp { + sum += x[j] * v + } + x[i] -= sum + if nonUnit { + x[i] /= a[i*lda+i] + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + jx := kx + var sum float64 + atmp := a[i*lda : i*lda+i] + for _, v := range atmp { + sum += x[jx] * v + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= a[i*lda+i] + } + ix += incX + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + if nonUnit { + x[i] /= a[i*lda+i] + } + xi := x[i] + atmp := a[i*lda+i+1 : i*lda+n] + for j, v := range atmp { + jv := j + i + 1 + x[jv] -= v * xi + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + if nonUnit { + x[ix] /= a[i*lda+i] + } + xi := x[ix] + jx := kx + (i+1)*incX + atmp := a[i*lda+i+1 : i*lda+n] + for _, v := range atmp { + x[jx] -= v * xi + jx += incX + } + ix += incX + } + return + } + if incX == 1 { + for i := n - 1; i >= 0; i-- { + if nonUnit { + x[i] /= a[i*lda+i] + } + xi := x[i] + atmp := a[i*lda : i*lda+i] + for j, v := range atmp { + x[j] -= v * xi + } + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + if nonUnit { + x[ix] /= a[i*lda+i] + } + xi := x[ix] + jx := kx + atmp := a[i*lda : i*lda+i] + for _, v := range atmp { + x[jx] -= v * xi + jx += incX + } + ix -= incX + } +} + +// Dsymv computes +// y = alpha * A * x + beta * y, +// where a is an n×n symmetric matrix, x and y are vectors, and alpha and +// beta are scalars. +func (Implementation) Dsymv(ul blas.Uplo, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + // Check inputs + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(negativeN) + } + if lda > 1 && lda > n { + panic(badLdA) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + // Quick return if possible + if n == 0 || (alpha == 0 && beta == 1) { + return + } + + // Set up start points + var kx, ky int + if incX > 0 { + kx = 0 + } else { + kx = -(n - 1) * incX + } + if incY > 0 { + ky = 0 + } else { + ky = -(n - 1) * incY + } + + // Form y = beta * y + if beta != 1 { + if incY > 0 { + Implementation{}.Dscal(n, beta, y, incY) + } else { + Implementation{}.Dscal(n, beta, y, -incY) + } + } + + if alpha == 0 { + return + } + + if n == 1 { + y[0] += alpha * a[0] * x[0] + return + } + + if ul == blas.Upper { + if incX == 1 { + iy := ky + for i := 0; i < n; i++ { + xv := x[i] * alpha + sum := x[i] * a[i*lda+i] + jy := ky + (i+1)*incY + atmp := a[i*lda+i+1 : i*lda+n] + for j, v := range atmp { + jp := j + i + 1 + sum += x[jp] * v + y[jy] += xv * v + jy += incY + } + y[iy] += alpha * sum + iy += incY + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + xv := x[ix] * alpha + sum := x[ix] * a[i*lda+i] + jx := kx + (i+1)*incX + jy := ky + (i+1)*incY + atmp := a[i*lda+i+1 : i*lda+n] + for _, v := range atmp { + sum += x[jx] * v + y[jy] += xv * v + jx += incX + jy += incY + } + y[iy] += alpha * sum + ix += incX + iy += incY + } + return + } + // Cases where a is lower triangular. + if incX == 1 { + iy := ky + for i := 0; i < n; i++ { + jy := ky + xv := alpha * x[i] + atmp := a[i*lda : i*lda+i] + var sum float64 + for j, v := range atmp { + sum += x[j] * v + y[jy] += xv * v + jy += incY + } + sum += x[i] * a[i*lda+i] + sum *= alpha + y[iy] += sum + iy += incY + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + jx := kx + jy := ky + xv := alpha * x[ix] + atmp := a[i*lda : i*lda+i] + var sum float64 + for _, v := range atmp { + sum += x[jx] * v + y[jy] += xv * v + jx += incX + jy += incY + } + sum += x[ix] * a[i*lda+i] + sum *= alpha + y[iy] += sum + ix += incX + iy += incY + } +} + +// Dtbmv computes +// x = A * x if tA == blas.NoTrans +// x = A^T * x if tA == blas.Trans +// where A is an n×n triangular banded matrix with k diagonals, and x is a vector. +func (Implementation) Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if n < 0 { + panic(nLT0) + } + if k < 0 { + panic(kLT0) + } + if lda < k+1 { + panic("blas: lda must be less than max(1,n)") + } + if incX == 0 { + panic(zeroIncX) + } + if n == 0 { + return + } + var kx int + if incX <= 0 { + kx = -(n - 1) * incX + } else if incX != 1 { + kx = 0 + } + _ = kx + + nonunit := d != blas.Unit + + if tA == blas.NoTrans { + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + u := min(1+k, n-i) + var sum float64 + atmp := a[i*lda:] + xtmp := x[i:] + for j := 1; j < u; j++ { + sum += xtmp[j] * atmp[j] + } + if nonunit { + sum += xtmp[0] * atmp[0] + } else { + sum += xtmp[0] + } + x[i] = sum + } + return + } + ix := kx + for i := 0; i < n; i++ { + u := min(1+k, n-i) + var sum float64 + atmp := a[i*lda:] + jx := incX + for j := 1; j < u; j++ { + sum += x[ix+jx] * atmp[j] + jx += incX + } + if nonunit { + sum += x[ix] * atmp[0] + } else { + sum += x[ix] + } + x[ix] = sum + ix += incX + } + return + } + if incX == 1 { + for i := n - 1; i >= 0; i-- { + l := max(0, k-i) + atmp := a[i*lda:] + var sum float64 + for j := l; j < k; j++ { + sum += x[i-k+j] * atmp[j] + } + if nonunit { + sum += x[i] * atmp[k] + } else { + sum += x[i] + } + x[i] = sum + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + l := max(0, k-i) + atmp := a[i*lda:] + var sum float64 + jx := l * incX + for j := l; j < k; j++ { + sum += x[ix-k*incX+jx] * atmp[j] + jx += incX + } + if nonunit { + sum += x[ix] * atmp[k] + } else { + sum += x[ix] + } + x[ix] = sum + ix -= incX + } + return + } + if ul == blas.Upper { + if incX == 1 { + for i := n - 1; i >= 0; i-- { + u := k + 1 + if i < u { + u = i + 1 + } + var sum float64 + for j := 1; j < u; j++ { + sum += x[i-j] * a[(i-j)*lda+j] + } + if nonunit { + sum += x[i] * a[i*lda] + } else { + sum += x[i] + } + x[i] = sum + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + u := k + 1 + if i < u { + u = i + 1 + } + var sum float64 + jx := incX + for j := 1; j < u; j++ { + sum += x[ix-jx] * a[(i-j)*lda+j] + jx += incX + } + if nonunit { + sum += x[ix] * a[i*lda] + } else { + sum += x[ix] + } + x[ix] = sum + ix -= incX + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + u := k + if i+k >= n { + u = n - i - 1 + } + var sum float64 + for j := 0; j < u; j++ { + sum += x[i+j+1] * a[(i+j+1)*lda+k-j-1] + } + if nonunit { + sum += x[i] * a[i*lda+k] + } else { + sum += x[i] + } + x[i] = sum + } + return + } + ix := kx + for i := 0; i < n; i++ { + u := k + if i+k >= n { + u = n - i - 1 + } + var ( + sum float64 + jx int + ) + for j := 0; j < u; j++ { + sum += x[ix+jx+incX] * a[(i+j+1)*lda+k-j-1] + jx += incX + } + if nonunit { + sum += x[ix] * a[i*lda+k] + } else { + sum += x[ix] + } + x[ix] = sum + ix += incX + } +} + +// Dtpmv computes +// x = A * x if tA == blas.NoTrans +// x = A^T * x if tA == blas.Trans +// where A is an n×n unit triangular matrix in packed format, and x is a vector. +func (Implementation) Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) { + // Verify inputs + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if n < 0 { + panic(nLT0) + } + if len(ap) < (n*(n+1))/2 { + panic("blas: index of ap out of range") + } + if incX == 0 { + panic(zeroIncX) + } + if n == 0 { + return + } + var kx int + if incX <= 0 { + kx = -(n - 1) * incX + } + + nonUnit := d == blas.NonUnit + var offset int // Offset is the index of (i,i) + if tA == blas.NoTrans { + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + xi := x[i] + if nonUnit { + xi *= ap[offset] + } + atmp := ap[offset+1 : offset+n-i] + xtmp := x[i+1:] + for j, v := range atmp { + xi += v * xtmp[j] + } + x[i] = xi + offset += n - i + } + return + } + ix := kx + for i := 0; i < n; i++ { + xix := x[ix] + if nonUnit { + xix *= ap[offset] + } + atmp := ap[offset+1 : offset+n-i] + jx := kx + (i+1)*incX + for _, v := range atmp { + xix += v * x[jx] + jx += incX + } + x[ix] = xix + offset += n - i + ix += incX + } + return + } + if incX == 1 { + offset = n*(n+1)/2 - 1 + for i := n - 1; i >= 0; i-- { + xi := x[i] + if nonUnit { + xi *= ap[offset] + } + atmp := ap[offset-i : offset] + for j, v := range atmp { + xi += v * x[j] + } + x[i] = xi + offset -= i + 1 + } + return + } + ix := kx + (n-1)*incX + offset = n*(n+1)/2 - 1 + for i := n - 1; i >= 0; i-- { + xix := x[ix] + if nonUnit { + xix *= ap[offset] + } + atmp := ap[offset-i : offset] + jx := kx + for _, v := range atmp { + xix += v * x[jx] + jx += incX + } + x[ix] = xix + offset -= i + 1 + ix -= incX + } + return + } + // Cases where ap is transposed. + if ul == blas.Upper { + if incX == 1 { + offset = n*(n+1)/2 - 1 + for i := n - 1; i >= 0; i-- { + xi := x[i] + atmp := ap[offset+1 : offset+n-i] + xtmp := x[i+1:] + for j, v := range atmp { + xtmp[j] += v * xi + } + if nonUnit { + x[i] *= ap[offset] + } + offset -= n - i + 1 + } + return + } + ix := kx + (n-1)*incX + offset = n*(n+1)/2 - 1 + for i := n - 1; i >= 0; i-- { + xix := x[ix] + jx := kx + (i+1)*incX + atmp := ap[offset+1 : offset+n-i] + for _, v := range atmp { + x[jx] += v * xix + jx += incX + } + if nonUnit { + x[ix] *= ap[offset] + } + offset -= n - i + 1 + ix -= incX + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + xi := x[i] + atmp := ap[offset-i : offset] + for j, v := range atmp { + x[j] += v * xi + } + if nonUnit { + x[i] *= ap[offset] + } + offset += i + 2 + } + return + } + ix := kx + for i := 0; i < n; i++ { + xix := x[ix] + jx := kx + atmp := ap[offset-i : offset] + for _, v := range atmp { + x[jx] += v * xix + jx += incX + } + if nonUnit { + x[ix] *= ap[offset] + } + ix += incX + offset += i + 2 + } +} + +// Dtbsv solves +// A * x = b +// where A is an n×n triangular banded matrix with k diagonals in packed format, +// and x is a vector. +// At entry to the function, x contains the values of b, and the result is +// stored in place into x. +// +// No test for singularity or near-singularity is included in this +// routine. Such tests must be performed before calling this routine. +func (Implementation) Dtbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if n < 0 { + panic(nLT0) + } + if lda < k+1 { + panic(badLdA) + } + if incX == 0 { + panic(zeroIncX) + } + if n == 0 { + return + } + var kx int + if incX < 0 { + kx = -(n - 1) * incX + } else { + kx = 0 + } + nonUnit := d == blas.NonUnit + // Form x = A^-1 x. + // Several cases below use subslices for speed improvement. + // The incX != 1 cases usually do not because incX may be negative. + if tA == blas.NoTrans { + if ul == blas.Upper { + if incX == 1 { + for i := n - 1; i >= 0; i-- { + bands := k + if i+bands >= n { + bands = n - i - 1 + } + atmp := a[i*lda+1:] + xtmp := x[i+1 : i+bands+1] + var sum float64 + for j, v := range xtmp { + sum += v * atmp[j] + } + x[i] -= sum + if nonUnit { + x[i] /= a[i*lda] + } + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + max := k + 1 + if i+max > n { + max = n - i + } + atmp := a[i*lda:] + var ( + jx int + sum float64 + ) + for j := 1; j < max; j++ { + jx += incX + sum += x[ix+jx] * atmp[j] + } + x[ix] -= sum + if nonUnit { + x[ix] /= atmp[0] + } + ix -= incX + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + bands := k + if i-k < 0 { + bands = i + } + atmp := a[i*lda+k-bands:] + xtmp := x[i-bands : i] + var sum float64 + for j, v := range xtmp { + sum += v * atmp[j] + } + x[i] -= sum + if nonUnit { + x[i] /= atmp[bands] + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + bands := k + if i-k < 0 { + bands = i + } + atmp := a[i*lda+k-bands:] + var ( + sum float64 + jx int + ) + for j := 0; j < bands; j++ { + sum += x[ix-bands*incX+jx] * atmp[j] + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= atmp[bands] + } + ix += incX + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + bands := k + if i-k < 0 { + bands = i + } + var sum float64 + for j := 0; j < bands; j++ { + sum += x[i-bands+j] * a[(i-bands+j)*lda+bands-j] + } + x[i] -= sum + if nonUnit { + x[i] /= a[i*lda] + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + bands := k + if i-k < 0 { + bands = i + } + var ( + sum float64 + jx int + ) + for j := 0; j < bands; j++ { + sum += x[ix-bands*incX+jx] * a[(i-bands+j)*lda+bands-j] + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= a[i*lda] + } + ix += incX + } + return + } + if incX == 1 { + for i := n - 1; i >= 0; i-- { + bands := k + if i+bands >= n { + bands = n - i - 1 + } + var sum float64 + xtmp := x[i+1 : i+1+bands] + for j, v := range xtmp { + sum += v * a[(i+j+1)*lda+k-j-1] + } + x[i] -= sum + if nonUnit { + x[i] /= a[i*lda+k] + } + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + bands := k + if i+bands >= n { + bands = n - i - 1 + } + var ( + sum float64 + jx int + ) + for j := 0; j < bands; j++ { + sum += x[ix+jx+incX] * a[(i+j+1)*lda+k-j-1] + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= a[i*lda+k] + } + ix -= incX + } +} + +// Dsbmv performs +// y = alpha * A * x + beta * y +// where A is an n×n symmetric banded matrix, x and y are vectors, and alpha +// and beta are scalars. +func (Implementation) Dsbmv(ul blas.Uplo, n, k int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(nLT0) + } + + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + + // Quick return if possible + if n == 0 || (alpha == 0 && beta == 1) { + return + } + + // Set up indexes + lenX := n + lenY := n + var kx, ky int + if incX > 0 { + kx = 0 + } else { + kx = -(lenX - 1) * incX + } + if incY > 0 { + ky = 0 + } else { + ky = -(lenY - 1) * incY + } + + // First form y := beta * y + if incY > 0 { + Implementation{}.Dscal(lenY, beta, y, incY) + } else { + Implementation{}.Dscal(lenY, beta, y, -incY) + } + + if alpha == 0 { + return + } + + if ul == blas.Upper { + if incX == 1 { + iy := ky + for i := 0; i < n; i++ { + atmp := a[i*lda:] + tmp := alpha * x[i] + sum := tmp * atmp[0] + u := min(k, n-i-1) + jy := incY + for j := 1; j <= u; j++ { + v := atmp[j] + sum += alpha * x[i+j] * v + y[iy+jy] += tmp * v + jy += incY + } + y[iy] += sum + iy += incY + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + atmp := a[i*lda:] + tmp := alpha * x[ix] + sum := tmp * atmp[0] + u := min(k, n-i-1) + jx := incX + jy := incY + for j := 1; j <= u; j++ { + v := atmp[j] + sum += alpha * x[ix+jx] * v + y[iy+jy] += tmp * v + jx += incX + jy += incY + } + y[iy] += sum + ix += incX + iy += incY + } + return + } + + // Casses where a has bands below the diagonal. + if incX == 1 { + iy := ky + for i := 0; i < n; i++ { + l := max(0, k-i) + tmp := alpha * x[i] + jy := l * incY + atmp := a[i*lda:] + for j := l; j < k; j++ { + v := atmp[j] + y[iy] += alpha * v * x[i-k+j] + y[iy-k*incY+jy] += tmp * v + jy += incY + } + y[iy] += tmp * atmp[k] + iy += incY + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + l := max(0, k-i) + tmp := alpha * x[ix] + jx := l * incX + jy := l * incY + atmp := a[i*lda:] + for j := l; j < k; j++ { + v := atmp[j] + y[iy] += alpha * v * x[ix-k*incX+jx] + y[iy-k*incY+jy] += tmp * v + jx += incX + jy += incY + } + y[iy] += tmp * atmp[k] + ix += incX + iy += incY + } + return +} + +// Dsyr performs the rank-one update +// a += alpha * x * x^T +// where a is an n×n symmetric matrix, and x is a vector. +func (Implementation) Dsyr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(nLT0) + } + if incX == 0 { + panic(zeroIncX) + } + if lda < n { + panic(badLdA) + } + if alpha == 0 || n == 0 { + return + } + + lenX := n + var kx int + if incX > 0 { + kx = 0 + } else { + kx = -(lenX - 1) * incX + } + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + tmp := x[i] * alpha + if tmp != 0 { + atmp := a[i*lda+i : i*lda+n] + xtmp := x[i:n] + for j, v := range xtmp { + atmp[j] += v * tmp + } + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + tmp := x[ix] * alpha + if tmp != 0 { + jx := ix + atmp := a[i*lda:] + for j := i; j < n; j++ { + atmp[j] += x[jx] * tmp + jx += incX + } + } + ix += incX + } + return + } + // Cases where a is lower triangular. + if incX == 1 { + for i := 0; i < n; i++ { + tmp := x[i] * alpha + if tmp != 0 { + atmp := a[i*lda:] + xtmp := x[:i+1] + for j, v := range xtmp { + atmp[j] += tmp * v + } + } + } + return + } + ix := kx + for i := 0; i < n; i++ { + tmp := x[ix] * alpha + if tmp != 0 { + atmp := a[i*lda:] + jx := kx + for j := 0; j < i+1; j++ { + atmp[j] += tmp * x[jx] + jx += incX + } + } + ix += incX + } +} + +// Dsyr2 performs the symmetric rank-two update +// A += alpha * x * y^T + alpha * y * x^T +// where A is a symmetric n×n matrix, x and y are vectors, and alpha is a scalar. +func (Implementation) Dsyr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(nLT0) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + if alpha == 0 { + return + } + + var ky, kx int + if incY > 0 { + ky = 0 + } else { + ky = -(n - 1) * incY + } + if incX > 0 { + kx = 0 + } else { + kx = -(n - 1) * incX + } + if ul == blas.Upper { + if incX == 1 && incY == 1 { + for i := 0; i < n; i++ { + xi := x[i] + yi := y[i] + atmp := a[i*lda:] + for j := i; j < n; j++ { + atmp[j] += alpha * (xi*y[j] + x[j]*yi) + } + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + jx := kx + i*incX + jy := ky + i*incY + xi := x[ix] + yi := y[iy] + atmp := a[i*lda:] + for j := i; j < n; j++ { + atmp[j] += alpha * (xi*y[jy] + x[jx]*yi) + jx += incX + jy += incY + } + ix += incX + iy += incY + } + return + } + if incX == 1 && incY == 1 { + for i := 0; i < n; i++ { + xi := x[i] + yi := y[i] + atmp := a[i*lda:] + for j := 0; j <= i; j++ { + atmp[j] += alpha * (xi*y[j] + x[j]*yi) + } + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + jx := kx + jy := ky + xi := x[ix] + yi := y[iy] + atmp := a[i*lda:] + for j := 0; j <= i; j++ { + atmp[j] += alpha * (xi*y[jy] + x[jx]*yi) + jx += incX + jy += incY + } + ix += incX + iy += incY + } + return +} + +// Dtpsv solves +// A * x = b if tA == blas.NoTrans +// A^T * x = b if tA == blas.Trans +// where A is an n×n triangular matrix in packed format and x is a vector. +// At entry to the function, x contains the values of b, and the result is +// stored in place into x. +// +// No test for singularity or near-singularity is included in this +// routine. Such tests must be performed before calling this routine. +func (Implementation) Dtpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, x []float64, incX int) { + // Verify inputs + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if n < 0 { + panic(nLT0) + } + if len(a) < (n*(n+1))/2 { + panic("blas: not enough data in ap") + } + if incX == 0 { + panic(zeroIncX) + } + if n == 0 { + return + } + var kx int + if incX <= 0 { + kx = -(n - 1) * incX + } + + nonUnit := d == blas.NonUnit + var offset int // Offset is the index of (i,i) + if tA == blas.NoTrans { + if ul == blas.Upper { + offset = n*(n+1)/2 - 1 + if incX == 1 { + for i := n - 1; i >= 0; i-- { + atmp := a[offset+1 : offset+n-i] + xtmp := x[i+1:] + var sum float64 + for j, v := range atmp { + sum += v * xtmp[j] + } + x[i] -= sum + if nonUnit { + x[i] /= a[offset] + } + offset -= n - i + 1 + } + return + } + ix := kx + (n-1)*incX + for i := n - 1; i >= 0; i-- { + atmp := a[offset+1 : offset+n-i] + jx := kx + (i+1)*incX + var sum float64 + for _, v := range atmp { + sum += v * x[jx] + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= a[offset] + } + ix -= incX + offset -= n - i + 1 + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + atmp := a[offset-i : offset] + var sum float64 + for j, v := range atmp { + sum += v * x[j] + } + x[i] -= sum + if nonUnit { + x[i] /= a[offset] + } + offset += i + 2 + } + return + } + ix := kx + for i := 0; i < n; i++ { + jx := kx + atmp := a[offset-i : offset] + var sum float64 + for _, v := range atmp { + sum += v * x[jx] + jx += incX + } + x[ix] -= sum + if nonUnit { + x[ix] /= a[offset] + } + ix += incX + offset += i + 2 + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + if nonUnit { + x[i] /= a[offset] + } + xi := x[i] + atmp := a[offset+1 : offset+n-i] + xtmp := x[i+1:] + for j, v := range atmp { + xtmp[j] -= v * xi + } + offset += n - i + } + return + } + ix := kx + for i := 0; i < n; i++ { + if nonUnit { + x[ix] /= a[offset] + } + xix := x[ix] + atmp := a[offset+1 : offset+n-i] + jx := kx + (i+1)*incX + for _, v := range atmp { + x[jx] -= v * xix + jx += incX + } + ix += incX + offset += n - i + } + return + } + if incX == 1 { + offset = n*(n+1)/2 - 1 + for i := n - 1; i >= 0; i-- { + if nonUnit { + x[i] /= a[offset] + } + xi := x[i] + atmp := a[offset-i : offset] + for j, v := range atmp { + x[j] -= v * xi + } + offset -= i + 1 + } + return + } + ix := kx + (n-1)*incX + offset = n*(n+1)/2 - 1 + for i := n - 1; i >= 0; i-- { + if nonUnit { + x[ix] /= a[offset] + } + xix := x[ix] + atmp := a[offset-i : offset] + jx := kx + for _, v := range atmp { + x[jx] -= v * xix + jx += incX + } + ix -= incX + offset -= i + 1 + } +} + +// Dspmv performs +// y = alpha * A * x + beta * y, +// where A is an n×n symmetric matrix in packed format, x and y are vectors +// and alpha and beta are scalars. +func (Implementation) Dspmv(ul blas.Uplo, n int, alpha float64, a []float64, x []float64, incX int, beta float64, y []float64, incY int) { + // Verify inputs + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(nLT0) + } + if len(a) < (n*(n+1))/2 { + panic("blas: not enough data in a") + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + // Quick return if possible + if n == 0 || (alpha == 0 && beta == 1) { + return + } + + // Set up start points + var kx, ky int + if incX > 0 { + kx = 0 + } else { + kx = -(n - 1) * incX + } + if incY > 0 { + ky = 0 + } else { + ky = -(n - 1) * incY + } + + // Form y = beta * y + if beta != 1 { + if incY > 0 { + Implementation{}.Dscal(n, beta, y, incY) + } else { + Implementation{}.Dscal(n, beta, y, -incY) + } + } + + if alpha == 0 { + return + } + + if n == 1 { + y[0] += alpha * a[0] * x[0] + return + } + var offset int // Offset is the index of (i,i). + if ul == blas.Upper { + if incX == 1 { + iy := ky + for i := 0; i < n; i++ { + xv := x[i] * alpha + sum := a[offset] * x[i] + atmp := a[offset+1 : offset+n-i] + xtmp := x[i+1:] + jy := ky + (i+1)*incY + for j, v := range atmp { + sum += v * xtmp[j] + y[jy] += v * xv + jy += incY + } + y[iy] += alpha * sum + iy += incY + offset += n - i + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + xv := x[ix] * alpha + sum := a[offset] * x[ix] + atmp := a[offset+1 : offset+n-i] + jx := kx + (i+1)*incX + jy := ky + (i+1)*incY + for _, v := range atmp { + sum += v * x[jx] + y[jy] += v * xv + jx += incX + jy += incY + } + y[iy] += alpha * sum + ix += incX + iy += incY + offset += n - i + } + return + } + if incX == 1 { + iy := ky + for i := 0; i < n; i++ { + xv := x[i] * alpha + atmp := a[offset-i : offset] + jy := ky + var sum float64 + for j, v := range atmp { + sum += v * x[j] + y[jy] += v * xv + jy += incY + } + sum += a[offset] * x[i] + y[iy] += alpha * sum + iy += incY + offset += i + 2 + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + xv := x[ix] * alpha + atmp := a[offset-i : offset] + jx := kx + jy := ky + var sum float64 + for _, v := range atmp { + sum += v * x[jx] + y[jy] += v * xv + jx += incX + jy += incY + } + + sum += a[offset] * x[ix] + y[iy] += alpha * sum + ix += incX + iy += incY + offset += i + 2 + } +} + +// Dspr computes the rank-one operation +// a += alpha * x * x^T +// where a is an n×n symmetric matrix in packed format, x is a vector, and +// alpha is a scalar. +func (Implementation) Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(nLT0) + } + if incX == 0 { + panic(zeroIncX) + } + if len(a) < (n*(n+1))/2 { + panic("blas: not enough data in a") + } + if alpha == 0 || n == 0 { + return + } + lenX := n + var kx int + if incX > 0 { + kx = 0 + } else { + kx = -(lenX - 1) * incX + } + var offset int // Offset is the index of (i,i). + if ul == blas.Upper { + if incX == 1 { + for i := 0; i < n; i++ { + atmp := a[offset:] + xv := alpha * x[i] + xtmp := x[i:n] + for j, v := range xtmp { + atmp[j] += xv * v + } + offset += n - i + } + return + } + ix := kx + for i := 0; i < n; i++ { + jx := kx + i*incX + atmp := a[offset:] + xv := alpha * x[ix] + for j := 0; j < n-i; j++ { + atmp[j] += xv * x[jx] + jx += incX + } + ix += incX + offset += n - i + } + return + } + if incX == 1 { + for i := 0; i < n; i++ { + atmp := a[offset-i:] + xv := alpha * x[i] + xtmp := x[:i+1] + for j, v := range xtmp { + atmp[j] += xv * v + } + offset += i + 2 + } + return + } + ix := kx + for i := 0; i < n; i++ { + jx := kx + atmp := a[offset-i:] + xv := alpha * x[ix] + for j := 0; j <= i; j++ { + atmp[j] += xv * x[jx] + jx += incX + } + ix += incX + offset += i + 2 + } +} + +// Dspr2 performs the symmetric rank-2 update +// a += alpha * x * y^T + alpha * y * x^T +// where a is an n×n symmetric matirx in packed format and x and y are vectors. +func (Implementation) Dspr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if n < 0 { + panic(nLT0) + } + if incX == 0 { + panic(zeroIncX) + } + if incY == 0 { + panic(zeroIncY) + } + + if len(a) < (n*(n+1))/2 { + panic("goblas: not enough data in a") + } + if alpha == 0 { + return + } + var ky, kx int + if incY > 0 { + ky = 0 + } else { + ky = -(n - 1) * incY + } + if incX > 0 { + kx = 0 + } else { + kx = -(n - 1) * incX + } + var offset int // Offset is the index of (i,i). + if ul == blas.Upper { + if incX == 1 && incY == 1 { + for i := 0; i < n; i++ { + atmp := a[offset:] + xi := x[i] + yi := y[i] + xtmp := x[i:n] + ytmp := y[i:n] + for j, v := range xtmp { + atmp[j] += alpha * (xi*ytmp[j] + v*yi) + } + offset += n - i + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + jx := kx + i*incX + jy := ky + i*incY + atmp := a[offset:] + xi := x[ix] + yi := y[iy] + for j := 0; j < n-i; j++ { + atmp[j] += alpha * (xi*y[jy] + x[jx]*yi) + jx += incX + jy += incY + } + ix += incX + iy += incY + offset += n - i + } + return + } + if incX == 1 && incY == 1 { + for i := 0; i < n; i++ { + atmp := a[offset-i:] + xi := x[i] + yi := y[i] + xtmp := x[:i+1] + for j, v := range xtmp { + atmp[j] += alpha * (xi*y[j] + v*yi) + } + offset += i + 2 + } + return + } + ix := kx + iy := ky + for i := 0; i < n; i++ { + jx := kx + jy := ky + atmp := a[offset-i:] + for j := 0; j <= i; j++ { + atmp[j] += alpha * (x[ix]*y[jy] + x[jx]*y[iy]) + jx += incX + jy += incY + } + ix += incX + iy += incY + offset += i + 2 + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level2double_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level2double_test.go new file mode 100644 index 0000000..98447e0 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level2double_test.go @@ -0,0 +1,75 @@ +package native + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func TestDgemv(t *testing.T) { + testblas.DgemvTest(t, impl) +} + +func TestDger(t *testing.T) { + testblas.DgerTest(t, impl) +} + +func TestDtxmv(t *testing.T) { + testblas.DtxmvTest(t, impl) +} + +func TestDgbmv(t *testing.T) { + testblas.DgbmvTest(t, impl) +} + +func TestDtbsv(t *testing.T) { + testblas.DtbsvTest(t, impl) +} + +func TestDsbmv(t *testing.T) { + testblas.DsbmvTest(t, impl) +} + +func TestDtbmv(t *testing.T) { + testblas.DtbmvTest(t, impl) +} + +func TestDtrsv(t *testing.T) { + testblas.DtrsvTest(t, impl) +} + +func TestDtrmv(t *testing.T) { + testblas.DtrmvTest(t, impl) +} + +func TestDsymv(t *testing.T) { + testblas.DsymvTest(t, impl) +} + +func TestDsyr(t *testing.T) { + testblas.DsyrTest(t, impl) +} + +func TestDsyr2(t *testing.T) { + testblas.Dsyr2Test(t, impl) +} + +func TestDspr2(t *testing.T) { + testblas.Dspr2Test(t, impl) +} + +func TestDspr(t *testing.T) { + testblas.DsprTest(t, impl) +} + +func TestDspmv(t *testing.T) { + testblas.DspmvTest(t, impl) +} + +func TestDtpsv(t *testing.T) { + testblas.DtpsvTest(t, impl) +} + +func TestDtpmv(t *testing.T) { + testblas.DtpmvTest(t, impl) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level3double.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level3double.go new file mode 100644 index 0000000..ddac471 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level3double.go @@ -0,0 +1,815 @@ +package native + +import ( + "github.com/gonum/blas" + "github.com/gonum/internal/asm" +) + +var _ blas.Float64Level3 = Implementation{} + +// Dtrsm solves +// A * X = alpha * B if tA == blas.NoTrans, side == blas.Left +// A^T * X = alpha * B if tA == blas.Trans, side == blas.Left +// X * A = alpha * B if tA == blas.NoTrans, side == blas.Right +// X * A^T = alpha * B if tA == blas.Trans, side == blas.Right +// where A is an n×n triangular matrix, x is an m×n matrix, and alpha is a +// scalar. +// +// At entry to the function, X contains the values of B, and the result is +// stored in place into X. +// +// No check is made that A is invertible. +func (Implementation) Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) { + if s != blas.Left && s != blas.Right { + panic(badSide) + } + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if m < 0 { + panic(mLT0) + } + if n < 0 { + panic(nLT0) + } + if ldb < n { + panic(badLdB) + } + if s == blas.Left { + if lda < m { + panic(badLdA) + } + } else { + if lda < n { + panic(badLdA) + } + } + + if m == 0 || n == 0 { + return + } + + if alpha == 0 { + for i := 0; i < m; i++ { + btmp := b[i*ldb : i*ldb+n] + for j := range btmp { + btmp[j] = 0 + } + } + return + } + nonUnit := d == blas.NonUnit + if s == blas.Left { + if tA == blas.NoTrans { + if ul == blas.Upper { + for i := m - 1; i >= 0; i-- { + btmp := b[i*ldb : i*ldb+n] + if alpha != 1 { + for j := range btmp { + btmp[j] *= alpha + } + } + for ka, va := range a[i*lda+i+1 : i*lda+m] { + k := ka + i + 1 + if va != 0 { + asm.DaxpyUnitary(-va, b[k*ldb:k*ldb+n], btmp, btmp) + } + } + if nonUnit { + tmp := 1 / a[i*lda+i] + for j := 0; j < n; j++ { + btmp[j] *= tmp + } + } + } + return + } + for i := 0; i < m; i++ { + btmp := b[i*ldb : i*ldb+n] + if alpha != 1 { + for j := 0; j < n; j++ { + btmp[j] *= alpha + } + } + for k, va := range a[i*lda : i*lda+i] { + if va != 0 { + asm.DaxpyUnitary(-va, b[k*ldb:k*ldb+n], btmp, btmp) + } + } + if nonUnit { + tmp := 1 / a[i*lda+i] + for j := 0; j < n; j++ { + btmp[j] *= tmp + } + } + } + return + } + // Cases where a is transposed + if ul == blas.Upper { + for k := 0; k < m; k++ { + btmpk := b[k*ldb : k*ldb+n] + if nonUnit { + tmp := 1 / a[k*lda+k] + for j := 0; j < n; j++ { + btmpk[j] *= tmp + } + } + for ia, va := range a[k*lda+k+1 : k*lda+m] { + i := ia + k + 1 + if va != 0 { + btmp := b[i*ldb : i*ldb+n] + asm.DaxpyUnitary(-va, btmpk, btmp, btmp) + } + } + if alpha != 1 { + for j := 0; j < n; j++ { + btmpk[j] *= alpha + } + } + } + return + } + for k := m - 1; k >= 0; k-- { + btmpk := b[k*ldb : k*ldb+n] + if nonUnit { + tmp := 1 / a[k*lda+k] + for j := 0; j < n; j++ { + btmpk[j] *= tmp + } + } + for i, va := range a[k*lda : k*lda+k] { + if va != 0 { + btmp := b[i*ldb : i*ldb+n] + asm.DaxpyUnitary(-va, btmpk, btmp, btmp) + } + } + if alpha != 1 { + for j := 0; j < n; j++ { + btmpk[j] *= alpha + } + } + } + return + } + // Cases where a is to the right of X. + if tA == blas.NoTrans { + if ul == blas.Upper { + for i := 0; i < m; i++ { + btmp := b[i*ldb : i*ldb+n] + if alpha != 1 { + for j := 0; j < n; j++ { + btmp[j] *= alpha + } + } + for k, vb := range btmp { + if vb != 0 { + if btmp[k] != 0 { + if nonUnit { + btmp[k] /= a[k*lda+k] + } + btmpk := btmp[k+1 : n] + asm.DaxpyUnitary(-btmp[k], a[k*lda+k+1:k*lda+n], btmpk, btmpk) + } + } + } + } + return + } + for i := 0; i < m; i++ { + btmp := b[i*lda : i*lda+n] + if alpha != 1 { + for j := 0; j < n; j++ { + btmp[j] *= alpha + } + } + for k := n - 1; k >= 0; k-- { + if btmp[k] != 0 { + if nonUnit { + btmp[k] /= a[k*lda+k] + } + asm.DaxpyUnitary(-btmp[k], a[k*lda:k*lda+k], btmp, btmp) + } + } + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + for i := 0; i < m; i++ { + btmp := b[i*lda : i*lda+n] + for j := n - 1; j >= 0; j-- { + tmp := alpha*btmp[j] - asm.DdotUnitary(a[j*lda+j+1:j*lda+n], btmp[j+1:]) + if nonUnit { + tmp /= a[j*lda+j] + } + btmp[j] = tmp + } + } + return + } + for i := 0; i < m; i++ { + btmp := b[i*lda : i*lda+n] + for j := 0; j < n; j++ { + tmp := alpha*btmp[j] - asm.DdotUnitary(a[j*lda:j*lda+j], btmp) + if nonUnit { + tmp /= a[j*lda+j] + } + btmp[j] = tmp + } + } +} + +// Dsymm performs one of +// C = alpha * A * B + beta * C if side == blas.Left +// C = alpha * B * A + beta * C if side == blas.Right +// where A is an n×n symmetric matrix, B and C are m×n matrices, and alpha +// is a scalar. +func (Implementation) Dsymm(s blas.Side, ul blas.Uplo, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { + if s != blas.Right && s != blas.Left { + panic("goblas: bad side") + } + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if m < 0 { + panic(mLT0) + } + if n < 0 { + panic(nLT0) + } + if (lda < m && s == blas.Left) || (lda < n && s == blas.Right) { + panic(badLdA) + } + if ldb < n { + panic(badLdB) + } + if ldc < n { + panic(badLdC) + } + if m == 0 || n == 0 { + return + } + if alpha == 0 && beta == 1 { + return + } + if alpha == 0 { + if beta == 0 { + for i := 0; i < m; i++ { + ctmp := c[i*ldc : i*ldc+n] + for j := range ctmp { + ctmp[j] = 0 + } + } + return + } + for i := 0; i < m; i++ { + ctmp := c[i*ldc : i*ldc+n] + for j := 0; j < n; j++ { + ctmp[j] *= beta + } + } + return + } + + isUpper := ul == blas.Upper + if s == blas.Left { + for i := 0; i < m; i++ { + atmp := alpha * a[i*lda+i] + btmp := b[i*ldb : i*ldb+n] + ctmp := c[i*ldc : i*ldc+n] + for j, v := range btmp { + ctmp[j] *= beta + ctmp[j] += atmp * v + } + + for k := 0; k < i; k++ { + var atmp float64 + if isUpper { + atmp = a[k*lda+i] + } else { + atmp = a[i*lda+k] + } + atmp *= alpha + ctmp := c[i*ldc : i*ldc+n] + asm.DaxpyUnitary(atmp, b[k*ldb:k*ldb+n], ctmp, ctmp) + } + for k := i + 1; k < m; k++ { + var atmp float64 + if isUpper { + atmp = a[i*lda+k] + } else { + atmp = a[k*lda+i] + } + atmp *= alpha + ctmp := c[i*ldc : i*ldc+n] + asm.DaxpyUnitary(atmp, b[k*ldb:k*ldb+n], ctmp, ctmp) + } + } + return + } + if isUpper { + for i := 0; i < m; i++ { + for j := n - 1; j >= 0; j-- { + tmp := alpha * b[i*ldb+j] + var tmp2 float64 + atmp := a[j*lda+j+1 : j*lda+n] + btmp := b[i*ldb+j+1 : i*ldb+n] + ctmp := c[i*ldc+j+1 : i*ldc+n] + for k, v := range atmp { + ctmp[k] += tmp * v + tmp2 += btmp[k] * v + } + c[i*ldc+j] *= beta + c[i*ldc+j] += tmp*a[j*lda+j] + alpha*tmp2 + } + } + return + } + for i := 0; i < m; i++ { + for j := 0; j < n; j++ { + tmp := alpha * b[i*ldb+j] + var tmp2 float64 + atmp := a[j*lda : j*lda+j] + btmp := b[i*ldb : i*ldb+j] + ctmp := c[i*ldc : i*ldc+j] + for k, v := range atmp { + ctmp[k] += tmp * v + tmp2 += btmp[k] * v + } + c[i*ldc+j] *= beta + c[i*ldc+j] += tmp*a[j*lda+j] + alpha*tmp2 + } + } +} + +// Dsyrk performs the symmetric rank-k operation +// C = alpha * A * A^T + beta*C +// C is an n×n symmetric matrix. A is an n×k matrix if tA == blas.NoTrans, and +// a k×n matrix otherwise. alpha and beta are scalars. +func (Implementation) Dsyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.Trans && tA != blas.NoTrans && tA != blas.ConjTrans { + panic(badTranspose) + } + if n < 0 { + panic(nLT0) + } + if k < 0 { + panic(kLT0) + } + if ldc < n { + panic(badLdC) + } + if tA == blas.Trans { + if lda < n { + panic(badLdA) + } + } else { + if lda < k { + panic(badLdA) + } + } + if alpha == 0 { + if beta == 0 { + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + for j := range ctmp { + ctmp[j] = 0 + } + } + return + } + for i := 0; i < n; i++ { + ctmp := c[i*ldc : i*ldc+i+1] + for j := range ctmp { + ctmp[j] = 0 + } + } + return + } + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + for j := range ctmp { + ctmp[j] *= beta + } + } + return + } + for i := 0; i < n; i++ { + ctmp := c[i*ldc : i*ldc+i+1] + for j := range ctmp { + ctmp[j] *= beta + } + } + return + } + if tA == blas.NoTrans { + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + atmp := a[i*lda : i*lda+k] + for jc, vc := range ctmp { + j := jc + i + ctmp[jc] = vc*beta + alpha*asm.DdotUnitary(atmp, a[j*lda:j*lda+k]) + } + } + return + } + for i := 0; i < n; i++ { + atmp := a[i*lda : i*lda+k] + for j, vc := range c[i*ldc : i*ldc+i+1] { + c[i*ldc+j] = vc*beta + alpha*asm.DdotUnitary(a[j*lda:j*lda+k], atmp) + } + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + if beta != 1 { + for j := range ctmp { + ctmp[j] *= beta + } + } + for l := 0; l < k; l++ { + tmp := alpha * a[l*lda+i] + if tmp != 0 { + asm.DaxpyUnitary(tmp, a[l*lda+i:l*lda+n], ctmp, ctmp) + } + } + } + return + } + for i := 0; i < n; i++ { + ctmp := c[i*ldc : i*ldc+i+1] + if beta != 0 { + for j := range ctmp { + ctmp[j] *= beta + } + } + for l := 0; l < k; l++ { + tmp := alpha * a[l*lda+i] + if tmp != 0 { + asm.DaxpyUnitary(tmp, a[l*lda:l*lda+i+1], ctmp, ctmp) + } + } + } +} + +// Dsyr2k performs the symmetric rank 2k operation +// C = alpha * A * B^T + alpha * B * A^T + beta * C +// where C is an n×n symmetric matrix. A and B are n×k matrices if +// tA == NoTrans and k×n otherwise. alpha and beta are scalars. +func (Implementation) Dsyr2k(ul blas.Uplo, tA blas.Transpose, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.Trans && tA != blas.NoTrans && tA != blas.ConjTrans { + panic(badTranspose) + } + if n < 0 { + panic(nLT0) + } + if k < 0 { + panic(kLT0) + } + if ldc < n { + panic(badLdC) + } + if tA == blas.Trans { + if lda < n { + panic(badLdA) + } + if ldb < n { + panic(badLdB) + } + } else { + if lda < k { + panic(badLdA) + } + if ldb < k { + panic(badLdB) + } + } + if alpha == 0 { + if beta == 0 { + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + for j := range ctmp { + ctmp[j] = 0 + } + } + return + } + for i := 0; i < n; i++ { + ctmp := c[i*ldc : i*ldc+i+1] + for j := range ctmp { + ctmp[j] = 0 + } + } + return + } + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + for j := range ctmp { + ctmp[j] *= beta + } + } + return + } + for i := 0; i < n; i++ { + ctmp := c[i*ldc : i*ldc+i+1] + for j := range ctmp { + ctmp[j] *= beta + } + } + return + } + if tA == blas.NoTrans { + if ul == blas.Upper { + for i := 0; i < n; i++ { + atmp := a[i*lda : i*lda+k] + btmp := b[i*lda : i*lda+k] + ctmp := c[i*ldc+i : i*ldc+n] + for jc := range ctmp { + j := i + jc + var tmp1, tmp2 float64 + binner := b[j*ldb : j*ldb+k] + for l, v := range a[j*lda : j*lda+k] { + tmp1 += v * btmp[l] + tmp2 += atmp[l] * binner[l] + } + ctmp[jc] *= beta + ctmp[jc] += alpha * (tmp1 + tmp2) + } + } + return + } + for i := 0; i < n; i++ { + atmp := a[i*lda : i*lda+k] + btmp := b[i*lda : i*lda+k] + ctmp := c[i*ldc : i*ldc+i+1] + for j := 0; j <= i; j++ { + var tmp1, tmp2 float64 + binner := b[j*ldb : j*ldb+k] + for l, v := range a[j*lda : j*lda+k] { + tmp1 += v * btmp[l] + tmp2 += atmp[l] * binner[l] + } + ctmp[j] *= beta + ctmp[j] += alpha * (tmp1 + tmp2) + } + } + return + } + if ul == blas.Upper { + for i := 0; i < n; i++ { + ctmp := c[i*ldc+i : i*ldc+n] + if beta != 1 { + for j := range ctmp { + ctmp[j] *= beta + } + } + for l := 0; l < k; l++ { + tmp1 := alpha * b[l*lda+i] + tmp2 := alpha * a[l*lda+i] + btmp := b[l*ldb+i : l*ldb+n] + if tmp1 != 0 || tmp2 != 0 { + for j, v := range a[l*lda+i : l*lda+n] { + ctmp[j] += v*tmp1 + btmp[j]*tmp2 + } + } + } + } + return + } + for i := 0; i < n; i++ { + ctmp := c[i*ldc : i*ldc+i+1] + if beta != 1 { + for j := range ctmp { + ctmp[j] *= beta + } + } + for l := 0; l < k; l++ { + tmp1 := alpha * b[l*lda+i] + tmp2 := alpha * a[l*lda+i] + btmp := b[l*ldb : l*ldb+i+1] + if tmp1 != 0 || tmp2 != 0 { + for j, v := range a[l*lda : l*lda+i+1] { + ctmp[j] += v*tmp1 + btmp[j]*tmp2 + } + } + } + } +} + +// Dtrmm performs +// B = alpha * A * B if tA == blas.NoTrans and side == blas.Left +// B = alpha * A^T * B if tA == blas.Trans and side == blas.Left +// B = alpha * B * A if tA == blas.NoTrans and side == blas.Right +// B = alpha * B * A^T if tA == blas.Trans and side == blas.Right +// where A is an n×n triangular matrix, and B is an m×n matrix. +func (Implementation) Dtrmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) { + if s != blas.Left && s != blas.Right { + panic(badSide) + } + if ul != blas.Lower && ul != blas.Upper { + panic(badUplo) + } + if tA != blas.NoTrans && tA != blas.Trans && tA != blas.ConjTrans { + panic(badTranspose) + } + if d != blas.NonUnit && d != blas.Unit { + panic(badDiag) + } + if m < 0 { + panic(mLT0) + } + if n < 0 { + panic(nLT0) + } + if ldb < n { + panic(badLdB) + } + if s == blas.Left { + if lda < m { + panic(badLdA) + } + } else { + if lda < n { + panic(badLdA) + } + } + if alpha == 0 { + for i := 0; i < m; i++ { + btmp := b[i*ldb : i*ldb+n] + for j := range btmp { + btmp[j] = 0 + } + } + return + } + + nonUnit := d == blas.NonUnit + if s == blas.Left { + if tA == blas.NoTrans { + if ul == blas.Upper { + for i := 0; i < m; i++ { + tmp := alpha + if nonUnit { + tmp *= a[i*lda+i] + } + btmp := b[i*ldb : i*ldb+n] + for j := range btmp { + btmp[j] *= tmp + } + for ka, va := range a[i*lda+i+1 : i*lda+m] { + k := ka + i + 1 + tmp := alpha * va + if tmp != 0 { + asm.DaxpyUnitary(tmp, b[k*ldb:k*ldb+n], btmp, btmp) + } + } + } + return + } + for i := m - 1; i >= 0; i-- { + tmp := alpha + if nonUnit { + tmp *= a[i*lda+i] + } + btmp := b[i*ldb : i*ldb+n] + for j := range btmp { + btmp[j] *= tmp + } + for k, va := range a[i*lda : i*lda+i] { + tmp := alpha * va + if tmp != 0 { + asm.DaxpyUnitary(tmp, b[k*ldb:k*ldb+n], btmp, btmp) + } + } + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + for k := m - 1; k >= 0; k-- { + btmpk := b[k*ldb : k*ldb+n] + for ia, va := range a[k*lda+k+1 : k*lda+m] { + i := ia + k + 1 + btmp := b[i*ldb : i*ldb+n] + tmp := alpha * va + if tmp != 0 { + asm.DaxpyUnitary(tmp, btmpk, btmp, btmp) + } + } + tmp := alpha + if nonUnit { + tmp *= a[k*lda+k] + } + if tmp != 1 { + for j := 0; j < n; j++ { + btmpk[j] *= tmp + } + } + } + return + } + for k := 0; k < m; k++ { + btmpk := b[k*ldb : k*ldb+n] + for i, va := range a[k*lda : k*lda+k] { + btmp := b[i*ldb : i*ldb+n] + tmp := alpha * va + if tmp != 0 { + asm.DaxpyUnitary(tmp, btmpk, btmp, btmp) + } + } + tmp := alpha + if nonUnit { + tmp *= a[k*lda+k] + } + if tmp != 1 { + for j := 0; j < n; j++ { + btmpk[j] *= tmp + } + } + } + return + } + // Cases where a is on the right + if tA == blas.NoTrans { + if ul == blas.Upper { + for i := 0; i < m; i++ { + btmp := b[i*ldb : i*ldb+n] + for k := n - 1; k >= 0; k-- { + tmp := alpha * btmp[k] + if tmp != 0 { + btmp[k] = tmp + if nonUnit { + btmp[k] *= a[k*lda+k] + } + for ja, v := range a[k*lda+k+1 : k*lda+n] { + j := ja + k + 1 + btmp[j] += tmp * v + } + } + } + } + return + } + for i := 0; i < m; i++ { + btmp := b[i*ldb : i*ldb+n] + for k := 0; k < n; k++ { + tmp := alpha * btmp[k] + if tmp != 0 { + btmp[k] = tmp + if nonUnit { + btmp[k] *= a[k*lda+k] + } + asm.DaxpyUnitary(tmp, a[k*lda:k*lda+k], btmp, btmp) + } + } + } + return + } + // Cases where a is transposed. + if ul == blas.Upper { + for i := 0; i < m; i++ { + btmp := b[i*lda : i*lda+n] + for j, vb := range btmp { + tmp := vb + if nonUnit { + tmp *= a[j*lda+j] + } + tmp += asm.DdotUnitary(a[j*lda+j+1:j*lda+n], btmp[j+1:n]) + btmp[j] = alpha * tmp + } + } + return + } + for i := 0; i < m; i++ { + btmp := b[i*lda : i*lda+n] + for j := n - 1; j >= 0; j-- { + tmp := btmp[j] + if nonUnit { + tmp *= a[j*lda+j] + } + tmp += asm.DdotUnitary(a[j*lda:j*lda+j], btmp[:j]) + btmp[j] = alpha * tmp + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level3double_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level3double_test.go new file mode 100644 index 0000000..ce7e108 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/level3double_test.go @@ -0,0 +1,31 @@ +package native + +import ( + "testing" + + "github.com/gonum/blas/testblas" +) + +func TestDgemm(t *testing.T) { + testblas.TestDgemm(t, impl) +} + +func TestDsymm(t *testing.T) { + testblas.DsymmTest(t, impl) +} + +func TestDtrsm(t *testing.T) { + testblas.DtrsmTest(t, impl) +} + +func TestDsyrk(t *testing.T) { + testblas.DsyrkTest(t, impl) +} + +func TestDsyr2k(t *testing.T) { + testblas.Dsyr2kTest(t, impl) +} + +func TestDtrmm(t *testing.T) { + testblas.DtrmmTest(t, impl) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/pardgemm_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/pardgemm_test.go new file mode 100644 index 0000000..a26825a --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/native/pardgemm_test.go @@ -0,0 +1,178 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package native + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas" +) + +func TestDgemmParallel(t *testing.T) { + for i, test := range []struct { + m int + n int + k int + alpha float64 + tA blas.Transpose + tB blas.Transpose + }{ + { + m: 3, + n: 4, + k: 2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: blockSize*2 + 5, + n: 3, + k: 2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: 3, + n: blockSize * 2, + k: 2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: 2, + n: 3, + k: blockSize*3 - 2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: blockSize * minParBlock, + n: 3, + k: 2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: 3, + n: blockSize * minParBlock, + k: 2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: 2, + n: 3, + k: blockSize * minParBlock, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: blockSize*minParBlock + 1, + n: blockSize * minParBlock, + k: 3, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: 3, + n: blockSize*minParBlock + 2, + k: blockSize * 3, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: blockSize * minParBlock, + n: 3, + k: blockSize * minParBlock, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: blockSize * minParBlock, + n: blockSize * minParBlock, + k: blockSize * 3, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + { + m: blockSize + blockSize/2, + n: blockSize + blockSize/2, + k: blockSize + blockSize/2, + alpha: 2.5, + tA: blas.NoTrans, + tB: blas.NoTrans, + }, + } { + testMatchParallelSerial(t, i, blas.NoTrans, blas.NoTrans, test.m, test.n, test.k, test.alpha) + testMatchParallelSerial(t, i, blas.Trans, blas.NoTrans, test.m, test.n, test.k, test.alpha) + testMatchParallelSerial(t, i, blas.NoTrans, blas.Trans, test.m, test.n, test.k, test.alpha) + testMatchParallelSerial(t, i, blas.Trans, blas.Trans, test.m, test.n, test.k, test.alpha) + } +} + +func testMatchParallelSerial(t *testing.T, i int, tA, tB blas.Transpose, m, n, k int, alpha float64) { + var ( + rowA, colA int + rowB, colB int + ) + if tA == blas.NoTrans { + rowA = m + colA = k + } else { + rowA = k + colA = m + } + if tB == blas.NoTrans { + rowB = k + colB = n + } else { + rowB = n + colB = k + } + a := randmat(rowA, colA, colA) + b := randmat(rowB, colB, colB) + c := randmat(m, n, n) + + aClone := a.clone() + bClone := b.clone() + cClone := c.clone() + + dgemmSerial(tA, tB, a, b, cClone, alpha) + dgemmParallel(tA, tB, a, b, c, alpha) + if !a.equal(aClone) { + t.Errorf("Case %v: a changed during call to dgemmParallel", i) + } + if !b.equal(bClone) { + t.Errorf("Case %v: b changed during call to dgemmParallel", i) + } + if !c.equalWithinAbs(cClone, 1e-12) { + t.Errorf("Case %v: answer not equal parallel and serial", i) + } +} + +func randmat(r, c, stride int) general { + data := make([]float64, r*stride+c) + for i := range data { + data[i] = rand.Float64() + } + return general{ + data: data, + rows: r, + cols: c, + stride: stride, + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go new file mode 100644 index 0000000..30fcfa4 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go @@ -0,0 +1,284 @@ +// Copyright 2014 The Gonum Authors. All rights reserved. +// Use of this code is governed by a BSD-style +// license that can be found in the LICENSE file + +// Script for automatic code generation of the benchmark routines +package main + +import ( + "fmt" + "os" + "path/filepath" + "strconv" +) + +var gopath string + +var copyrightnotice = []byte(`// Copyright 2014 The Gonum Authors. All rights reserved. +// Use of this code is governed by a BSD-style +// license that can be found in the LICENSE file`) + +var autogen = []byte(`// This file is autogenerated by github.com/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go`) + +var imports = []byte(`import( + "math/rand" + "testing" + + "github.com/gonum/blas" +)`) + +var randomSliceFunction = []byte(`func randomSlice(l, idx int) ([]float64) { + if idx < 0{ + idx = -idx + } + s := make([]float64, l * idx) + for i := range s { + s[i] = rand.Float64() + } + return s +}`) + +const ( + posInc1 = 5 + posInc2 = 3 + negInc1 = -3 + negInc2 = -4 +) + +var level1Sizes = []struct { + lower string + upper string + camel string + size int +}{ + { + lower: "small", + upper: "SMALL_SLICE", + camel: "Small", + size: 10, + }, + { + lower: "medium", + upper: "MEDIUM_SLICE", + camel: "Medium", + size: 1000, + }, + { + lower: "large", + upper: "LARGE_SLICE", + camel: "Large", + size: 100000, + }, + { + lower: "huge", + upper: "HUGE_SLICE", + camel: "Huge", + size: 10000000, + }, +} + +type level1functionStruct struct { + camel string + sig string + call string + extraSetup string + oneInput bool + extraName string // if have a couple different cases for the same function +} + +var level1Functions = []level1functionStruct{ + { + camel: "Ddot", + sig: "n int, x []float64, incX int, y []float64, incY int", + call: "n, x, incX, y, incY", + oneInput: false, + }, + { + camel: "Dnrm2", + sig: "n int, x []float64, incX int", + call: "n, x, incX", + oneInput: true, + }, + { + camel: "Dasum", + sig: "n int, x []float64, incX int", + call: "n, x, incX", + oneInput: true, + }, + { + camel: "Idamax", + sig: "n int, x []float64, incX int", + call: "n, x, incX", + oneInput: true, + }, + { + camel: "Dswap", + sig: "n int, x []float64, incX int, y []float64, incY int", + call: "n, x, incX, y, incY", + oneInput: false, + }, + { + camel: "Dcopy", + sig: "n int, x []float64, incX int, y []float64, incY int", + call: "n, x, incX, y, incY", + oneInput: false, + }, + { + camel: "Daxpy", + sig: "n int, alpha float64, x []float64, incX int, y []float64, incY int", + call: "n, alpha, x, incX, y, incY", + extraSetup: "alpha := 2.4", + oneInput: false, + }, + { + camel: "Drot", + sig: "n int, x []float64, incX int, y []float64, incY int, c, s float64", + call: "n, x, incX, y, incY, c, s", + extraSetup: "c := 0.89725836967\ns:= 0.44150585279", + oneInput: false, + }, + { + camel: "Drotm", + sig: "n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams", + call: "n, x, incX, y, incY, p", + extraSetup: "p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{0, -0.625, 0.9375,0}}", + oneInput: false, + extraName: "OffDia", + }, + { + camel: "Drotm", + sig: "n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams", + call: "n, x, incX, y, incY, p", + extraSetup: "p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{5.0 / 12, 0, 0, 0.625}}", + oneInput: false, + extraName: "Dia", + }, + { + camel: "Drotm", + sig: "n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams", + call: "n, x, incX, y, incY, p", + extraSetup: "p := blas.DrotmParams{Flag: blas.OffDiagonal, H: [4]float64{4096, -3584, 1792, 4096}}", + oneInput: false, + extraName: "Resc", + }, + { + camel: "Dscal", + sig: "n int, alpha float64, x []float64, incX int", + call: "n, alpha, x, incX", + extraSetup: "alpha := 2.4", + oneInput: true, + }, +} + +func init() { + gopath = os.Getenv("GOPATH") + if gopath == "" { + panic("gopath not set") + } +} + +func main() { + blasPath := filepath.Join(gopath, "src", "github.com", "gonum", "blas") + + pkgs := []struct{ name string }{{name: "native"}, {name: "cgo"}} + + for _, pkg := range pkgs { + err := level1(filepath.Join(blasPath, pkg.name), pkg.name) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + } +} + +func printHeader(f *os.File, name string) error { + if _, err := f.Write([]byte(copyrightnotice)); err != nil { + return err + } + f.WriteString("\n\n") + f.Write(autogen) + f.WriteString("\n\n") + f.WriteString("package " + name) + f.WriteString("\n\n") + f.Write(imports) + f.WriteString("\n\n") + return nil +} + +// Generate the benchmark scripts for level1 +func level1(benchPath string, pkgname string) error { + // Generate level 1 benchmarks + level1Filepath := filepath.Join(benchPath, "level1doubleBench_auto_test.go") + f, err := os.Create(level1Filepath) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + defer f.Close() + printHeader(f, pkgname) + + // Print all of the constants + f.WriteString("const (\n") + f.WriteString("\tposInc1 = " + strconv.Itoa(posInc1) + "\n") + f.WriteString("\tposInc2 = " + strconv.Itoa(posInc2) + "\n") + f.WriteString("\tnegInc1 = " + strconv.Itoa(negInc1) + "\n") + f.WriteString("\tnegInc2 = " + strconv.Itoa(negInc2) + "\n") + for _, con := range level1Sizes { + f.WriteString("\t" + con.upper + " = " + strconv.Itoa(con.size) + "\n") + } + f.WriteString(")\n") + f.WriteString("\n") + + // Write the randomSlice function + f.Write(randomSliceFunction) + f.WriteString("\n\n") + + // Start writing the benchmarks + for _, fun := range level1Functions { + writeLevel1Benchmark(fun, f) + f.WriteString("\n/* ------------------ */ \n") + } + + return nil +} + +func writeLevel1Benchmark(fun level1functionStruct, f *os.File) { + // First, write the base benchmark file + f.WriteString("func benchmark" + fun.camel + fun.extraName + "(b *testing.B, ") + f.WriteString(fun.sig) + f.WriteString(") {\n") + + f.WriteString("b.ResetTimer()\n") + f.WriteString("for i := 0; i < b.N; i++{\n") + f.WriteString("\timpl." + fun.camel + "(") + + f.WriteString(fun.call) + f.WriteString(")\n}\n}\n") + f.WriteString("\n") + + // Write all of the benchmarks to call it + for _, sz := range level1Sizes { + lambda := func(incX, incY, name string, twoInput bool) { + f.WriteString("func Benchmark" + fun.camel + fun.extraName + sz.camel + name + "(b *testing.B){\n") + f.WriteString("n := " + sz.upper + "\n") + f.WriteString("incX := " + incX + "\n") + f.WriteString("x := randomSlice(n, incX)\n") + if twoInput { + f.WriteString("incY := " + incY + "\n") + f.WriteString("y := randomSlice(n, incY)\n") + } + f.WriteString(fun.extraSetup + "\n") + f.WriteString("benchmark" + fun.camel + fun.extraName + "(b, " + fun.call + ")\n") + f.WriteString("}\n\n") + } + if fun.oneInput { + lambda("1", "", "UnitaryInc", false) + lambda("posInc1", "", "PosInc", false) + } else { + lambda("1", "1", "BothUnitary", true) + lambda("posInc1", "1", "IncUni", true) + lambda("1", "negInc1", "UniInc", true) + lambda("posInc1", "negInc1", "BothInc", true) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/benchsize.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/benchsize.go new file mode 100644 index 0000000..41d132b --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/benchsize.go @@ -0,0 +1,8 @@ +package testblas + +const ( + SmallMat = 10 + MediumMat = 100 + LargeMat = 1000 + HugeMat = 10000 +) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/common.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/common.go new file mode 100644 index 0000000..0db9d32 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/common.go @@ -0,0 +1,234 @@ +package testblas + +import ( + "math" + "testing" + + "github.com/gonum/blas" +) + +// throwPanic will throw unexpected panics if true, or will just report them as errors if false +const throwPanic = true + +func dTolEqual(a, b float64) bool { + if math.IsNaN(a) && math.IsNaN(b) { + return true + } + m := math.Max(math.Abs(a), math.Abs(b)) + if m > 1 { + a /= m + b /= m + } + if math.Abs(a-b) < 1e-14 { + return true + } + return false +} + +func dSliceTolEqual(a, b []float64) bool { + if len(a) != len(b) { + return false + } + for i := range a { + if !dTolEqual(a[i], b[i]) { + return false + } + } + return true +} + +func dStridedSliceTolEqual(n int, a []float64, inca int, b []float64, incb int) bool { + ia := 0 + ib := 0 + if inca <= 0 { + ia = -(n - 1) * inca + } + if incb <= 0 { + ib = -(n - 1) * incb + } + for i := 0; i < n; i++ { + if !dTolEqual(a[ia], b[ib]) { + return false + } + ia += inca + ib += incb + } + return true +} + +func dSliceEqual(a, b []float64) bool { + if len(a) != len(b) { + return false + } + for i := range a { + if !(a[i] == b[i]) { + return false + } + } + return true +} + +func dCopyTwoTmp(x, xTmp, y, yTmp []float64) { + if len(x) != len(xTmp) { + panic("x size mismatch") + } + if len(y) != len(yTmp) { + panic("y size mismatch") + } + for i, val := range x { + xTmp[i] = val + } + for i, val := range y { + yTmp[i] = val + } +} + +// returns true if the function panics +func panics(f func()) (b bool) { + defer func() { + err := recover() + if err != nil { + b = true + } + }() + f() + return +} + +func testpanics(f func(), name string, t *testing.T) { + b := panics(f) + if !b { + t.Errorf("%v should panic and does not", name) + } +} + +func sliceOfSliceCopy(a [][]float64) [][]float64 { + n := make([][]float64, len(a)) + for i := range a { + n[i] = make([]float64, len(a[i])) + copy(n[i], a[i]) + } + return n +} + +func sliceCopy(a []float64) []float64 { + n := make([]float64, len(a)) + copy(n, a) + return n +} + +func flatten(a [][]float64) []float64 { + if len(a) == 0 { + return nil + } + m := len(a) + n := len(a[0]) + s := make([]float64, m*n) + for i := 0; i < m; i++ { + for j := 0; j < n; j++ { + s[i*n+j] = a[i][j] + } + } + return s +} + +func unflatten(a []float64, m, n int) [][]float64 { + s := make([][]float64, m) + for i := 0; i < m; i++ { + s[i] = make([]float64, n) + for j := 0; j < n; j++ { + s[i][j] = a[i*n+j] + } + } + return s +} + +// flattenTriangular turns the upper or lower triangle of a dense slice of slice +// into a single slice with packed storage. a must be a square matrix. +func flattenTriangular(a [][]float64, ul blas.Uplo) []float64 { + m := len(a) + aFlat := make([]float64, m*(m+1)/2) + var k int + if ul == blas.Upper { + for i := 0; i < m; i++ { + k += copy(aFlat[k:], a[i][i:]) + } + return aFlat + } + for i := 0; i < m; i++ { + k += copy(aFlat[k:], a[i][:i+1]) + } + return aFlat +} + +// flattenBanded turns a dense banded slice of slice into the compact banded matrix format +func flattenBanded(a [][]float64, ku, kl int) []float64 { + m := len(a) + n := len(a[0]) + if ku < 0 || kl < 0 { + panic("testblas: negative band length") + } + nRows := m + nCols := (ku + kl + 1) + aflat := make([]float64, nRows*nCols) + for i := range aflat { + aflat[i] = math.NaN() + } + // loop over the rows, and then the bands + // elements in the ith row stay in the ith row + // order in bands is kept + for i := 0; i < nRows; i++ { + min := -kl + if i-kl < 0 { + min = -i + } + max := ku + if i+ku >= n { + max = n - i - 1 + } + for j := min; j <= max; j++ { + col := kl + j + aflat[i*nCols+col] = a[i][i+j] + } + } + return aflat +} + +// makeIncremented takes a slice with inc == 1 and makes an incremented version +// and adds extra values on the end +func makeIncremented(x []float64, inc int, extra int) []float64 { + if inc == 0 { + panic("zero inc") + } + absinc := inc + if absinc < 0 { + absinc = -inc + } + xcopy := make([]float64, len(x)) + if inc > 0 { + copy(xcopy, x) + } else { + for i := 0; i < len(x); i++ { + xcopy[i] = x[len(x)-i-1] + } + } + + // don't use NaN because it makes comparison hard + // Do use a weird unique value for easier debugging + counter := 100.0 + var xnew []float64 + for i, v := range xcopy { + xnew = append(xnew, v) + if i != len(x)-1 { + for j := 0; j < absinc-1; j++ { + xnew = append(xnew, counter) + counter++ + } + } + } + for i := 0; i < extra; i++ { + xnew = append(xnew, counter) + counter++ + } + return xnew +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/common_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/common_test.go new file mode 100644 index 0000000..3dcbe51 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/common_test.go @@ -0,0 +1,187 @@ +package testblas + +import ( + "math" + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +func TestFlattenBanded(t *testing.T) { + for i, test := range []struct { + dense [][]float64 + ku int + kl int + condensed [][]float64 + }{ + { + dense: [][]float64{{3}}, + ku: 0, + kl: 0, + condensed: [][]float64{{3}}, + }, + { + dense: [][]float64{ + {3, 4, 0}, + }, + ku: 1, + kl: 0, + condensed: [][]float64{ + {3, 4}, + }, + }, + { + dense: [][]float64{ + {3, 4, 0, 0, 0}, + }, + ku: 1, + kl: 0, + condensed: [][]float64{ + {3, 4}, + }, + }, + { + dense: [][]float64{ + {3, 4, 0}, + {0, 5, 8}, + {0, 0, 2}, + {0, 0, 0}, + {0, 0, 0}, + }, + ku: 1, + kl: 0, + condensed: [][]float64{ + {3, 4}, + {5, 8}, + {2, math.NaN()}, + {math.NaN(), math.NaN()}, + {math.NaN(), math.NaN()}, + }, + }, + { + dense: [][]float64{ + {3, 4, 6}, + {0, 5, 8}, + {0, 0, 2}, + {0, 0, 0}, + {0, 0, 0}, + }, + ku: 2, + kl: 0, + condensed: [][]float64{ + {3, 4, 6}, + {5, 8, math.NaN()}, + {2, math.NaN(), math.NaN()}, + {math.NaN(), math.NaN(), math.NaN()}, + {math.NaN(), math.NaN(), math.NaN()}, + }, + }, + { + dense: [][]float64{ + {3, 4, 6}, + {1, 5, 8}, + {0, 6, 2}, + {0, 0, 7}, + {0, 0, 0}, + }, + ku: 2, + kl: 1, + condensed: [][]float64{ + {math.NaN(), 3, 4, 6}, + {1, 5, 8, math.NaN()}, + {6, 2, math.NaN(), math.NaN()}, + {7, math.NaN(), math.NaN(), math.NaN()}, + {math.NaN(), math.NaN(), math.NaN(), math.NaN()}, + }, + }, + { + dense: [][]float64{ + {1, 2, 0}, + {3, 4, 5}, + {6, 7, 8}, + {0, 9, 10}, + {0, 0, 11}, + }, + ku: 1, + kl: 2, + condensed: [][]float64{ + {math.NaN(), math.NaN(), 1, 2}, + {math.NaN(), 3, 4, 5}, + {6, 7, 8, math.NaN()}, + {9, 10, math.NaN(), math.NaN()}, + {11, math.NaN(), math.NaN(), math.NaN()}, + }, + }, + { + dense: [][]float64{ + {1, 0, 0}, + {3, 4, 0}, + {6, 7, 8}, + {0, 9, 10}, + {0, 0, 11}, + }, + ku: 0, + kl: 2, + condensed: [][]float64{ + {math.NaN(), math.NaN(), 1}, + {math.NaN(), 3, 4}, + {6, 7, 8}, + {9, 10, math.NaN()}, + {11, math.NaN(), math.NaN()}, + }, + }, + { + dense: [][]float64{ + {1, 0, 0, 0, 0}, + {3, 4, 0, 0, 0}, + {1, 3, 5, 0, 0}, + }, + ku: 0, + kl: 2, + condensed: [][]float64{ + {math.NaN(), math.NaN(), 1}, + {math.NaN(), 3, 4}, + {1, 3, 5}, + }, + }, + } { + condensed := flattenBanded(test.dense, test.ku, test.kl) + correct := flatten(test.condensed) + if !floats.Same(condensed, correct) { + t.Errorf("Case %v mismatch. Want %v, got %v.", i, correct, condensed) + } + } +} + +func TestFlattenTriangular(t *testing.T) { + for i, test := range []struct { + a [][]float64 + ans []float64 + ul blas.Uplo + }{ + { + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + ul: blas.Upper, + ans: []float64{1, 2, 3, 4, 5, 6}, + }, + { + a: [][]float64{ + {1, 0, 0}, + {2, 3, 0}, + {4, 5, 6}, + }, + ul: blas.Lower, + ans: []float64{1, 2, 3, 4, 5, 6}, + }, + } { + a := flattenTriangular(test.a, test.ul) + if !floats.Equal(a, test.ans) { + t.Errorf("Case %v. Want %v, got %v.", i, test.ans, a) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgbmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgbmv.go new file mode 100644 index 0000000..8729b5b --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgbmv.go @@ -0,0 +1,94 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dgbmver interface { + Dgbmv(tA blas.Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) +} + +func DgbmvTest(t *testing.T, blasser Dgbmver) { + for i, test := range []struct { + tA blas.Transpose + m, n int + kL, kU int + alpha float64 + a [][]float64 + lda int + x []float64 + beta float64 + y []float64 + ans []float64 + }{ + { + tA: blas.NoTrans, + m: 9, + n: 6, + lda: 4, + kL: 2, + kU: 1, + alpha: 3.0, + beta: 2.0, + a: [][]float64{ + {5, 3, 0, 0, 0, 0}, + {-1, 2, 9, 0, 0, 0}, + {4, 8, 3, 6, 0, 0}, + {0, -1, 8, 2, 1, 0}, + {0, 0, 9, 9, 9, 5}, + {0, 0, 0, 2, -3, 2}, + {0, 0, 0, 0, 1, 5}, + {0, 0, 0, 0, 0, 6}, + {0, 0, 0, 0, 0, 0}, + }, + x: []float64{1, 2, 3, 4, 5, 6}, + y: []float64{-1, -2, -3, -4, -5, -6, -7, -8, -9}, + ans: []float64{31, 86, 153, 97, 404, 3, 91, 92, -18}, + }, + { + tA: blas.Trans, + m: 9, + n: 6, + lda: 4, + kL: 2, + kU: 1, + alpha: 3.0, + beta: 2.0, + a: [][]float64{ + {5, 3, 0, 0, 0, 0}, + {-1, 2, 9, 0, 0, 0}, + {4, 8, 3, 6, 0, 0}, + {0, -1, 8, 2, 1, 0}, + {0, 0, 9, 9, 9, 5}, + {0, 0, 0, 2, -3, 2}, + {0, 0, 0, 0, 1, 5}, + {0, 0, 0, 0, 0, 6}, + {0, 0, 0, 0, 0, 0}, + }, + x: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, + y: []float64{-1, -2, -3, -4, -5, -6}, + ans: []float64{43, 77, 306, 241, 104, 348}, + }, + } { + extra := 3 + aFlat := flattenBanded(test.a, test.kU, test.kL) + incTest := func(incX, incY, extra int) { + xnew := makeIncremented(test.x, incX, extra) + ynew := makeIncremented(test.y, incY, extra) + ans := makeIncremented(test.ans, incY, extra) + blasser.Dgbmv(test.tA, test.m, test.n, test.kL, test.kU, test.alpha, aFlat, test.lda, xnew, incX, test.beta, ynew, incY) + if !dSliceTolEqual(ans, ynew) { + t.Errorf("Case %v: Want %v, got %v", i, ans, ynew) + } + } + incTest(1, 1, extra) + incTest(1, 3, extra) + incTest(1, -3, extra) + incTest(2, 3, extra) + incTest(2, -3, extra) + incTest(3, 2, extra) + incTest(-3, 2, extra) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemm.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemm.go new file mode 100644 index 0000000..4519d7e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemm.go @@ -0,0 +1,252 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dgemmer interface { + Dgemm(tA, tB blas.Transpose, m, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) +} + +type DgemmCase struct { + isATrans bool + m, n, k int + alpha, beta float64 + a [][]float64 + aTrans [][]float64 // transpose of a + b [][]float64 + c [][]float64 + ans [][]float64 +} + +var DgemmCases = []DgemmCase{ + + { + m: 4, + n: 3, + k: 2, + isATrans: false, + alpha: 2, + beta: 0.5, + a: [][]float64{ + {1, 2}, + {4, 5}, + {7, 8}, + {10, 11}, + }, + b: [][]float64{ + {1, 5, 6}, + {5, -8, 8}, + }, + c: [][]float64{ + {4, 8, -9}, + {12, 16, -8}, + {1, 5, 15}, + {-3, -4, 7}, + }, + ans: [][]float64{ + {24, -18, 39.5}, + {64, -32, 124}, + {94.5, -55.5, 219.5}, + {128.5, -78, 299.5}, + }, + }, + { + m: 4, + n: 2, + k: 3, + isATrans: false, + alpha: 2, + beta: 0.5, + a: [][]float64{ + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9}, + {10, 11, 12}, + }, + b: [][]float64{ + {1, 5}, + {5, -8}, + {6, 2}, + }, + c: [][]float64{ + {4, 8}, + {12, 16}, + {1, 5}, + {-3, -4}, + }, + ans: [][]float64{ + {60, -6}, + {136, -8}, + {202.5, -19.5}, + {272.5, -30}, + }, + }, + { + m: 3, + n: 2, + k: 4, + isATrans: false, + alpha: 2, + beta: 0.5, + a: [][]float64{ + {1, 2, 3, 4}, + {4, 5, 6, 7}, + {8, 9, 10, 11}, + }, + b: [][]float64{ + {1, 5}, + {5, -8}, + {6, 2}, + {8, 10}, + }, + c: [][]float64{ + {4, 8}, + {12, 16}, + {9, -10}, + }, + ans: [][]float64{ + {124, 74}, + {248, 132}, + {406.5, 191}, + }, + }, + { + m: 3, + n: 4, + k: 2, + isATrans: false, + alpha: 2, + beta: 0.5, + a: [][]float64{ + {1, 2}, + {4, 5}, + {8, 9}, + }, + b: [][]float64{ + {1, 5, 2, 1}, + {5, -8, 2, 1}, + }, + c: [][]float64{ + {4, 8, 2, 2}, + {12, 16, 8, 9}, + {9, -10, 10, 10}, + }, + ans: [][]float64{ + {24, -18, 13, 7}, + {64, -32, 40, 22.5}, + {110.5, -69, 73, 39}, + }, + }, + { + m: 2, + n: 4, + k: 3, + isATrans: false, + alpha: 2, + beta: 0.5, + a: [][]float64{ + {1, 2, 3}, + {4, 5, 6}, + }, + b: [][]float64{ + {1, 5, 8, 8}, + {5, -8, 9, 10}, + {6, 2, -3, 2}, + }, + c: [][]float64{ + {4, 8, 7, 8}, + {12, 16, -2, 6}, + }, + ans: [][]float64{ + {60, -6, 37.5, 72}, + {136, -8, 117, 191}, + }, + }, + { + m: 2, + n: 3, + k: 4, + isATrans: false, + alpha: 2, + beta: 0.5, + a: [][]float64{ + {1, 2, 3, 4}, + {4, 5, 6, 7}, + }, + b: [][]float64{ + {1, 5, 8}, + {5, -8, 9}, + {6, 2, -3}, + {8, 10, 2}, + }, + c: [][]float64{ + {4, 8, 1}, + {12, 16, 6}, + }, + ans: [][]float64{ + {124, 74, 50.5}, + {248, 132, 149}, + }, + }, +} + +// assumes [][]float64 is actually a matrix +func transpose(a [][]float64) [][]float64 { + b := make([][]float64, len(a[0])) + for i := range b { + b[i] = make([]float64, len(a)) + for j := range b[i] { + b[i][j] = a[j][i] + } + } + return b +} + +func TestDgemm(t *testing.T, blasser Dgemmer) { + for i, test := range DgemmCases { + // Test that it passes row major + dgemmcomp(i, "RowMajorNoTrans", t, blasser, blas.NoTrans, blas.NoTrans, + test.m, test.n, test.k, test.alpha, test.beta, test.a, test.b, test.c, test.ans) + // Try with A transposed + dgemmcomp(i, "RowMajorTransA", t, blasser, blas.Trans, blas.NoTrans, + test.m, test.n, test.k, test.alpha, test.beta, transpose(test.a), test.b, test.c, test.ans) + // Try with B transposed + dgemmcomp(i, "RowMajorTransB", t, blasser, blas.NoTrans, blas.Trans, + test.m, test.n, test.k, test.alpha, test.beta, test.a, transpose(test.b), test.c, test.ans) + // Try with both transposed + dgemmcomp(i, "RowMajorTransBoth", t, blasser, blas.Trans, blas.Trans, + test.m, test.n, test.k, test.alpha, test.beta, transpose(test.a), transpose(test.b), test.c, test.ans) + } +} + +func dgemmcomp(i int, name string, t *testing.T, blasser Dgemmer, tA, tB blas.Transpose, m, n, k int, + alpha, beta float64, a [][]float64, b [][]float64, c [][]float64, ans [][]float64) { + + aFlat := flatten(a) + aCopy := flatten(a) + bFlat := flatten(b) + bCopy := flatten(b) + cFlat := flatten(c) + ansFlat := flatten(ans) + lda := len(a[0]) + ldb := len(b[0]) + ldc := len(c[0]) + + // Compute the matrix multiplication + blasser.Dgemm(tA, tB, m, n, k, alpha, aFlat, lda, bFlat, ldb, beta, cFlat, ldc) + + if !dSliceEqual(aFlat, aCopy) { + t.Errorf("Test %v case %v: a changed during call to Dgemm", i, name) + } + if !dSliceEqual(bFlat, bCopy) { + t.Errorf("Test %v case %v: b changed during call to Dgemm", i, name) + } + + if !dSliceTolEqual(ansFlat, cFlat) { + t.Errorf("Test %v case %v: answer mismatch. Expected %v, Found %v", i, name, ansFlat, cFlat) + } + // TODO: Need to add a sub-slice test where don't use up full matrix +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemmbench.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemmbench.go new file mode 100644 index 0000000..d54b747 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemmbench.go @@ -0,0 +1,39 @@ +package testblas + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas" +) + +func DgemmBenchmark(b *testing.B, dgemm Dgemmer, m, n, k int, tA, tB blas.Transpose) { + a := make([]float64, m*k) + for i := range a { + a[i] = rand.Float64() + } + bv := make([]float64, k*n) + for i := range bv { + bv[i] = rand.Float64() + } + c := make([]float64, m*n) + for i := range c { + c[i] = rand.Float64() + } + var lda, ldb int + if tA == blas.Trans { + lda = m + } else { + lda = k + } + if tB == blas.Trans { + ldb = k + } else { + ldb = n + } + ldc := n + b.ResetTimer() + for i := 0; i < b.N; i++ { + dgemm.Dgemm(tA, tB, m, n, k, 3.0, a, lda, bv, ldb, 1.0, c, ldc) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemv.go new file mode 100644 index 0000000..c192827 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dgemv.go @@ -0,0 +1,600 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type DgemvCase struct { + Name string + m int + n int + A [][]float64 + tA blas.Transpose + x []float64 + incX int + y []float64 + incY int + xCopy []float64 + yCopy []float64 + + Subcases []DgemvSubcase +} + +type DgemvSubcase struct { + mulXNeg1 bool + mulYNeg1 bool + alpha float64 + beta float64 + ans []float64 +} + +var DgemvCases = []DgemvCase{ + { + Name: "M_gt_N_Inc1_NoTrans", + tA: blas.NoTrans, + m: 5, + n: 3, + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + {1, 1, 2}, + {9, 2, 5}, + }, + incX: 1, + incY: 1, + x: []float64{1, 2, 3}, + y: []float64{7, 8, 9, 10, 11}, + + Subcases: []DgemvSubcase{ + { + alpha: 0, + beta: 0, + ans: []float64{0, 0, 0, 0, 0}, + }, + { + alpha: 0, + beta: 1, + ans: []float64{7, 8, 9, 10, 11}, + }, + { + alpha: 1, + beta: 0, + ans: []float64{40.8, 43.9, 33, 9, 28}, + }, + { + alpha: 8, + beta: -6, + ans: []float64{284.4, 303.2, 210, 12, 158}, + }, + }, + }, + { + Name: "M_gt_N_Inc1_Trans", + tA: blas.Trans, + m: 5, + n: 3, + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + {1, 1, 2}, + {9, 2, 5}, + }, + incX: 1, + incY: 1, + x: []float64{1, 2, 3, -4, 5}, + y: []float64{7, 8, 9}, + + Subcases: []DgemvSubcase{ + { + alpha: 0, + beta: 0, + ans: []float64{0, 0, 0}, + }, + { + alpha: 0, + beta: 1, + ans: []float64{7, 8, 9}, + }, + { + alpha: 1, + beta: 0, + ans: []float64{94.3, 40.2, 52.3}, + }, + { + alpha: 8, + beta: -6, + ans: []float64{712.4, 273.6, 364.4}, + }, + }, + }, + { + Name: "M_eq_N_Inc1_NoTrans", + tA: blas.NoTrans, + m: 3, + n: 3, + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + }, + incX: 1, + incY: 1, + x: []float64{1, 2, 3}, + y: []float64{7, 2, 2}, + + Subcases: []DgemvSubcase{ + { + alpha: 0, + beta: 0, + ans: []float64{0, 0, 0}, + }, + { + alpha: 0, + beta: 1, + ans: []float64{7, 2, 2}, + }, + { + alpha: 1, + beta: 0, + ans: []float64{40.8, 43.9, 33}, + }, + { + alpha: 8, + beta: -6, + ans: []float64{40.8*8 - 6*7, 43.9*8 - 6*2, 33*8 - 6*2}, + }, + }, + }, + { + Name: "M_eq_N_Inc1_Trans", + tA: blas.Trans, + m: 3, + n: 3, + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + }, + incX: 1, + incY: 1, + x: []float64{1, 2, 3}, + y: []float64{7, 2, 2}, + + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{384.4, 261.6, 270.4}, + }, + }, + }, + { + Name: "M_lt_N_Inc1_NoTrans", + tA: blas.NoTrans, + m: 3, + n: 5, + A: [][]float64{ + {4.1, 6.2, 8.1, 10, 7}, + {9.6, 3.5, 9.1, -2, 9}, + {10, 7, 3, 1, -5}, + }, + incX: 1, + incY: 1, + x: []float64{1, 2, 3, -7.6, 8.1}, + y: []float64{7, 2, 2}, + + Subcases: []DgemvSubcase{ + { + alpha: 0, + beta: 0, + ans: []float64{0, 0, 0}, + }, + { + alpha: 0, + beta: 1, + ans: []float64{7, 2, 2}, + }, + { + alpha: 1, + beta: 0, + ans: []float64{21.5, 132, -15.1}, + }, + + { + alpha: 8, + beta: -6, + ans: []float64{21.5*8 - 6*7, 132*8 - 6*2, -15.1*8 - 6*2}, + }, + }, + }, + { + Name: "M_lt_N_Inc1_Trans", + tA: blas.Trans, + m: 3, + n: 5, + A: [][]float64{ + {4.1, 6.2, 8.1, 10, 7}, + {9.6, 3.5, 9.1, -2, 9}, + {10, 7, 3, 1, -5}, + }, + incX: 1, + incY: 1, + x: []float64{1, 2, 3}, + y: []float64{7, 2, 2, -3, 5}, + + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{384.4, 261.6, 270.4, 90, 50}, + }, + }, + }, + { + Name: "M_gt_N_IncNot1_NoTrans", + tA: blas.NoTrans, + m: 5, + n: 3, + + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + {1, 1, 2}, + {9, 2, 5}, + }, + incX: 2, + incY: 3, + x: []float64{1, 15, 2, 150, 3}, + y: []float64{7, 2, 6, 8, -4, -5, 9, 1, 1, 10, 19, 22, 11}, + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{284.4, 2, 6, 303.2, -4, -5, 210, 1, 1, 12, 19, 22, 158}, + }, + { + mulXNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{220.4, 2, 6, 311.2, -4, -5, 322, 1, 1, -4, 19, 22, 222}, + }, + { + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{182, 2, 6, 24, -4, -5, 210, 1, 1, 291.2, 19, 22, 260.4}, + }, + { + mulXNeg1: true, + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{246, 2, 6, 8, -4, -5, 322, 1, 1, 299.2, 19, 22, 196.4}, + }, + }, + }, + { + Name: "M_gt_N_IncNot1_Trans", + tA: blas.Trans, + m: 5, + n: 3, + + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + {1, 1, 2}, + {9, 2, 5}, + }, + incX: 2, + incY: 3, + x: []float64{1, 15, 2, 150, 3, 8, -3, 6, 5}, + y: []float64{7, 2, 6, 8, -4, -5, 9}, + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{720.4, 2, 6, 281.6, -4, -5, 380.4}, + }, + { + mulXNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{219.6, 2, 6, 316, -4, -5, 195.6}, + }, + { + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{392.4, 2, 6, 281.6, -4, -5, 708.4}, + }, + { + mulXNeg1: true, + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{207.6, 2, 6, 316, -4, -5, 207.6}, + }, + }, + }, + { + Name: "M_eq_N_IncNot1_NoTrans", + tA: blas.NoTrans, + m: 3, + n: 3, + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + }, + incX: 2, + incY: 3, + x: []float64{1, 15, 2, 150, 3}, + y: []float64{7, 2, 6, 8, -4, -5, 9}, + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{284.4, 2, 6, 303.2, -4, -5, 210}, + }, + { + mulXNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{220.4, 2, 6, 311.2, -4, -5, 322}, + }, + { + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{222, 2, 6, 303.2, -4, -5, 272.4}, + }, + { + mulXNeg1: true, + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{334, 2, 6, 311.2, -4, -5, 208.4}, + }, + }, + }, + { + Name: "M_eq_N_IncNot1_Trans", + tA: blas.Trans, + m: 3, + n: 3, + A: [][]float64{ + {4.1, 6.2, 8.1}, + {9.6, 3.5, 9.1}, + {10, 7, 3}, + }, + incX: 2, + incY: 3, + x: []float64{1, 15, 2, 150, 3}, + y: []float64{7, 2, 6, 8, -4, -5, 9}, + + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{384.4, 2, 6, 225.6, -4, -5, 228.4}, + }, + { + mulXNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{290, 2, 6, 212.8, -4, -5, 310}, + }, + { + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{240.4, 2, 6, 225.6, -4, -5, 372.4}, + }, + { + mulXNeg1: true, + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{322, 2, 6, 212.8, -4, -5, 278}, + }, + }, + }, + { + Name: "M_lt_N_IncNot1_NoTrans", + tA: blas.NoTrans, + m: 3, + n: 5, + A: [][]float64{ + {4.1, 6.2, 8.1, 10, 11}, + {9.6, 3.5, 9.1, -3, -2}, + {10, 7, 3, -7, -4}, + }, + incX: 2, + incY: 3, + x: []float64{1, 15, 2, 150, 3, -2, -4, 8, -9}, + y: []float64{7, 2, 6, 8, -4, -5, 9}, + + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{-827.6, 2, 6, 543.2, -4, -5, 722}, + }, + { + mulXNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{-93.2, 2, 6, -696.8, -4, -5, -1070}, + }, + { + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{734, 2, 6, 543.2, -4, -5, -839.6}, + }, + { + mulXNeg1: true, + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{-1058, 2, 6, -696.8, -4, -5, -105.2}, + }, + }, + }, + { + Name: "M_lt_N_IncNot1_Trans", + tA: blas.Trans, + m: 3, + n: 5, + A: [][]float64{ + {4.1, 6.2, 8.1, 10, 11}, + {9.6, 3.5, 9.1, -3, -2}, + {10, 7, 3, -7, -4}, + }, + incX: 2, + incY: 3, + x: []float64{1, 15, 2, 150, 3}, + y: []float64{7, 2, 6, 8, -4, -5, 9, -4, -1, -9, 1, 1, 2}, + + Subcases: []DgemvSubcase{ + { + alpha: 8, + beta: -6, + ans: []float64{384.4, 2, 6, 225.6, -4, -5, 228.4, -4, -1, -82, 1, 1, -52}, + }, + { + mulXNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{290, 2, 6, 212.8, -4, -5, 310, -4, -1, 190, 1, 1, 188}, + }, + { + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{-82, 2, 6, -184, -4, -5, 228.4, -4, -1, 327.6, 1, 1, 414.4}, + }, + { + mulXNeg1: true, + mulYNeg1: true, + alpha: 8, + beta: -6, + ans: []float64{158, 2, 6, 88, -4, -5, 310, -4, -1, 314.8, 1, 1, 320}, + }, + }, + }, + + // TODO: A can be longer than mxn. Add cases where it is longer + // TODO: x and y can also be longer. Add tests for these + // TODO: Add tests for dimension mismatch + // TODO: Add places with a "submatrix view", where lda != m +} + +type Dgemver interface { + Dgemv(tA blas.Transpose, m, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) +} + +func DgemvTest(t *testing.T, blasser Dgemver) { + for _, test := range DgemvCases { + for i, cas := range test.Subcases { + // Test that it passes with row-major + dgemvcomp(t, test, cas, i, blasser) + + // Test the bad inputs + dgemvbad(t, test, cas, i, blasser) + } + } +} + +func dgemvcomp(t *testing.T, test DgemvCase, cas DgemvSubcase, i int, blasser Dgemver) { + x := sliceCopy(test.x) + y := sliceCopy(test.y) + a := sliceOfSliceCopy(test.A) + aFlat := flatten(a) + + lda := test.n + + incX := test.incX + if cas.mulXNeg1 { + incX *= -1 + } + incY := test.incY + if cas.mulYNeg1 { + incY *= -1 + } + + f := func() { + blasser.Dgemv(test.tA, test.m, test.n, cas.alpha, aFlat, lda, x, incX, cas.beta, y, incY) + } + if panics(f) { + t.Errorf("Test %v case %v: unexpected panic", test.Name, i) + if throwPanic { + blasser.Dgemv(test.tA, test.m, test.n, cas.alpha, aFlat, lda, x, incX, cas.beta, y, incY) + } + return + } + // Check that x and a are unchanged + if !dSliceEqual(x, test.x) { + t.Errorf("Test %v, case %v: x modified during call", test.Name, i) + } + aFlat2 := flatten(sliceOfSliceCopy(test.A)) + if !dSliceEqual(aFlat2, aFlat) { + t.Errorf("Test %v, case %v: a modified during call", test.Name, i) + } + + // Check that the answer matches + if !dSliceTolEqual(cas.ans, y) { + t.Errorf("Test %v, case %v: answer mismatch: Expected %v, Found %v", test.Name, i, cas.ans, y) + } +} + +func dgemvbad(t *testing.T, test DgemvCase, cas DgemvSubcase, i int, blasser Dgemver) { + x := sliceCopy(test.x) + y := sliceCopy(test.y) + a := sliceOfSliceCopy(test.A) + aFlatRow := flatten(a) + ldaRow := test.n + + f := func() { + blasser.Dgemv(312, test.m, test.n, cas.alpha, aFlatRow, ldaRow, x, test.incX, cas.beta, y, test.incY) + } + if !panics(f) { + t.Errorf("Test %v case %v: no panic for bad transpose", test.Name, i) + } + f = func() { + blasser.Dgemv(test.tA, -2, test.n, cas.alpha, aFlatRow, ldaRow, x, test.incX, cas.beta, y, test.incY) + } + if !panics(f) { + t.Errorf("Test %v case %v: no panic for m negative", test.Name, i) + } + f = func() { + blasser.Dgemv(test.tA, test.m, -4, cas.alpha, aFlatRow, ldaRow, x, test.incX, cas.beta, y, test.incY) + } + if !panics(f) { + t.Errorf("Test %v case %v: no panic for n negative", test.Name, i) + } + f = func() { + blasser.Dgemv(test.tA, test.m, test.n, cas.alpha, aFlatRow, ldaRow, x, 0, cas.beta, y, test.incY) + } + if !panics(f) { + t.Errorf("Test %v case %v: no panic for incX zero", test.Name, i) + } + f = func() { + blasser.Dgemv(test.tA, test.m, test.n, cas.alpha, aFlatRow, ldaRow, x, test.incX, cas.beta, y, 0) + } + if !panics(f) { + t.Errorf("Test %v case %v: no panic for incY zero", test.Name, i) + } + f = func() { + blasser.Dgemv(test.tA, test.m, test.n, cas.alpha, aFlatRow, ldaRow-1, x, test.incX, cas.beta, y, test.incY) + } + if !panics(f) { + t.Errorf("Test %v case %v: no panic for lda too small row major", test.Name, i) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dger.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dger.go new file mode 100644 index 0000000..c7c8796 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dger.go @@ -0,0 +1,164 @@ +package testblas + +import "testing" + +type Dgerer interface { + Dger(m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) +} + +func DgerTest(t *testing.T, blasser Dgerer) { + for _, test := range []struct { + name string + a [][]float64 + m int + n int + x []float64 + y []float64 + incX int + incY int + ansAlphaEq1 []float64 + + trueAns [][]float64 + }{ + { + name: "M gt N inc 1", + m: 5, + n: 3, + a: [][]float64{ + {1.3, 2.4, 3.5}, + {2.6, 2.8, 3.3}, + {-1.3, -4.3, -9.7}, + {8, 9, -10}, + {-12, -14, -6}, + }, + x: []float64{-2, -3, 0, 1, 2}, + y: []float64{-1.1, 5, 0}, + incX: 1, + incY: 1, + trueAns: [][]float64{{3.5, -7.6, 3.5}, {5.9, -12.2, 3.3}, {-1.3, -4.3, -9.7}, {6.9, 14, -10}, {-14.2, -4, -6}}, + }, + { + name: "M eq N inc 1", + m: 3, + n: 3, + a: [][]float64{ + {1.3, 2.4, 3.5}, + {2.6, 2.8, 3.3}, + {-1.3, -4.3, -9.7}, + }, + x: []float64{-2, -3, 0}, + y: []float64{-1.1, 5, 0}, + incX: 1, + incY: 1, + trueAns: [][]float64{{3.5, -7.6, 3.5}, {5.9, -12.2, 3.3}, {-1.3, -4.3, -9.7}}, + }, + + { + name: "M lt N inc 1", + m: 3, + n: 6, + a: [][]float64{ + {1.3, 2.4, 3.5, 4.8, 1.11, -9}, + {2.6, 2.8, 3.3, -3.4, 6.2, -8.7}, + {-1.3, -4.3, -9.7, -3.1, 8.9, 8.9}, + }, + x: []float64{-2, -3, 0}, + y: []float64{-1.1, 5, 0, 9, 19, 22}, + incX: 1, + incY: 1, + trueAns: [][]float64{{3.5, -7.6, 3.5, -13.2, -36.89, -53}, {5.9, -12.2, 3.3, -30.4, -50.8, -74.7}, {-1.3, -4.3, -9.7, -3.1, 8.9, 8.9}}, + }, + { + name: "M gt N inc not 1", + m: 5, + n: 3, + a: [][]float64{ + {1.3, 2.4, 3.5}, + {2.6, 2.8, 3.3}, + {-1.3, -4.3, -9.7}, + {8, 9, -10}, + {-12, -14, -6}, + }, + x: []float64{-2, -3, 0, 1, 2, 6, 0, 9, 7}, + y: []float64{-1.1, 5, 0, 8, 7, -5, 7}, + incX: 2, + incY: 3, + trueAns: [][]float64{{3.5, -13.6, -10.5}, {2.6, 2.8, 3.3}, {-3.5, 11.7, 4.3}, {8, 9, -10}, {-19.700000000000003, 42, 43}}, + }, + { + name: "M eq N inc not 1", + m: 3, + n: 3, + a: [][]float64{ + {1.3, 2.4, 3.5}, + {2.6, 2.8, 3.3}, + {-1.3, -4.3, -9.7}, + }, + x: []float64{-2, -3, 0, 8, 7, -9, 7, -6, 12, 6, 6, 6, -11}, + y: []float64{-1.1, 5, 0, 0, 9, 8, 6}, + incX: 4, + incY: 3, + trueAns: [][]float64{{3.5, 2.4, -8.5}, {-5.1, 2.8, 45.3}, {-14.5, -4.3, 62.3}}, + }, + { + name: "M lt N inc not 1", + m: 3, + n: 6, + a: [][]float64{ + {1.3, 2.4, 3.5, 4.8, 1.11, -9}, + {2.6, 2.8, 3.3, -3.4, 6.2, -8.7}, + {-1.3, -4.3, -9.7, -3.1, 8.9, 8.9}, + }, + x: []float64{-2, -3, 0, 0, 8, 0, 9, -3}, + y: []float64{-1.1, 5, 0, 9, 19, 22, 11, -8.11, -9.22, 9.87, 7}, + incX: 3, + incY: 2, + trueAns: [][]float64{{3.5, 2.4, -34.5, -17.2, 19.55, -23}, {2.6, 2.8, 3.3, -3.4, 6.2, -8.7}, {-11.2, -4.3, 161.3, 95.9, -74.08, 71.9}}, + }, + } { + // TODO: Add tests where a is longer + // TODO: Add panic tests + // TODO: Add negative increment tests + + x := sliceCopy(test.x) + y := sliceCopy(test.y) + + a := sliceOfSliceCopy(test.a) + + // Test with row major + alpha := 1.0 + aFlat := flatten(a) + blasser.Dger(test.m, test.n, alpha, x, test.incX, y, test.incY, aFlat, test.n) + ans := unflatten(aFlat, test.m, test.n) + dgercomp(t, x, test.x, y, test.y, ans, test.trueAns, test.name+" row maj") + + // Test with different alpha + alpha = 4.0 + aFlat = flatten(a) + blasser.Dger(test.m, test.n, alpha, x, test.incX, y, test.incY, aFlat, test.n) + ans = unflatten(aFlat, test.m, test.n) + trueCopy := sliceOfSliceCopy(test.trueAns) + for i := range trueCopy { + for j := range trueCopy[i] { + trueCopy[i][j] = alpha*(trueCopy[i][j]-a[i][j]) + a[i][j] + } + } + dgercomp(t, x, test.x, y, test.y, ans, trueCopy, test.name+" row maj alpha") + } +} + +func dgercomp(t *testing.T, x, xCopy, y, yCopy []float64, ans [][]float64, trueAns [][]float64, name string) { + if !dSliceEqual(x, xCopy) { + t.Errorf("case %v: x modified during call to dger", name) + } + if !dSliceEqual(y, yCopy) { + t.Errorf("case %v: x modified during call to dger", name) + } + + for i := range ans { + if !dSliceTolEqual(ans[i], trueAns[i]) { + t.Errorf("case %v: answer mismatch. Expected %v, Found %v", name, trueAns, ans) + break + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsbmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsbmv.go new file mode 100644 index 0000000..f4579bf --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsbmv.go @@ -0,0 +1,83 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dsbmver interface { + Dsbmv(ul blas.Uplo, n, k int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) +} + +func DsbmvTest(t *testing.T, blasser Dsbmver) { + for i, test := range []struct { + ul blas.Uplo + n int + k int + alpha float64 + beta float64 + a [][]float64 + x []float64 + y []float64 + + ans []float64 + }{ + { + ul: blas.Upper, + n: 4, + k: 2, + alpha: 2, + beta: 3, + a: [][]float64{ + {7, 8, 2, 0}, + {0, 8, 2, -3}, + {0, 0, 3, 6}, + {0, 0, 0, 9}, + }, + x: []float64{1, 2, 3, 4}, + y: []float64{-1, -2, -3, -4}, + ans: []float64{55, 30, 69, 84}, + }, + { + ul: blas.Lower, + n: 4, + k: 2, + alpha: 2, + beta: 3, + a: [][]float64{ + {7, 0, 0, 0}, + {8, 8, 0, 0}, + {2, 2, 3, 0}, + {0, -3, 6, 9}, + }, + x: []float64{1, 2, 3, 4}, + y: []float64{-1, -2, -3, -4}, + ans: []float64{55, 30, 69, 84}, + }, + } { + extra := 0 + var aFlat []float64 + if test.ul == blas.Upper { + aFlat = flattenBanded(test.a, test.k, 0) + } else { + aFlat = flattenBanded(test.a, 0, test.k) + } + incTest := func(incX, incY, extra int) { + xnew := makeIncremented(test.x, incX, extra) + ynew := makeIncremented(test.y, incY, extra) + ans := makeIncremented(test.ans, incY, extra) + blasser.Dsbmv(test.ul, test.n, test.k, test.alpha, aFlat, test.k+1, xnew, incX, test.beta, ynew, incY) + if !dSliceTolEqual(ans, ynew) { + t.Errorf("Case %v: Want %v, got %v", i, ans, ynew) + } + } + incTest(1, 1, extra) + incTest(1, 3, extra) + incTest(1, -3, extra) + incTest(2, 3, extra) + incTest(2, -3, extra) + incTest(3, 2, extra) + incTest(-3, 2, extra) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspmv.go new file mode 100644 index 0000000..7100bbb --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspmv.go @@ -0,0 +1,73 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dspmver interface { + Dspmv(ul blas.Uplo, n int, alpha float64, ap []float64, x []float64, incX int, beta float64, y []float64, incY int) +} + +func DspmvTest(t *testing.T, blasser Dspmver) { + for i, test := range []struct { + ul blas.Uplo + n int + a [][]float64 + x []float64 + y []float64 + alpha float64 + beta float64 + ans []float64 + }{ + { + ul: blas.Upper, + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 8, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + y: []float64{6, 7, 8}, + alpha: 2.1, + beta: -3, + ans: []float64{137.4, 189, 240.6}, + }, + { + ul: blas.Lower, + n: 3, + a: [][]float64{ + {5, 0, 0}, + {6, 8, 0}, + {7, 10, 13}, + }, + x: []float64{3, 4, 5}, + y: []float64{6, 7, 8}, + alpha: 2.1, + beta: -3, + ans: []float64{137.4, 189, 240.6}, + }, + } { + incTest := func(incX, incY, extra int) { + x := makeIncremented(test.x, incX, extra) + y := makeIncremented(test.y, incY, extra) + aFlat := flattenTriangular(test.a, test.ul) + ans := makeIncremented(test.ans, incY, extra) + + blasser.Dspmv(test.ul, test.n, test.alpha, aFlat, x, incX, test.beta, y, incY) + if !floats.EqualApprox(ans, y, 1e-14) { + t.Errorf("Case %v, incX=%v, incY=%v: Want %v, got %v.", i, incX, incY, ans, y) + } + } + incTest(1, 1, 0) + incTest(2, 3, 0) + incTest(3, 2, 0) + incTest(-3, 2, 0) + incTest(-2, 4, 0) + incTest(2, -1, 0) + incTest(-3, -4, 3) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspr.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspr.go new file mode 100644 index 0000000..aa31731 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspr.go @@ -0,0 +1,71 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dsprer interface { + Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64) +} + +func DsprTest(t *testing.T, blasser Dsprer) { + for i, test := range []struct { + ul blas.Uplo + n int + a [][]float64 + x []float64 + alpha float64 + ans [][]float64 + }{ + { + ul: blas.Upper, + n: 4, + a: [][]float64{ + {10, 2, 0, 1}, + {0, 1, 2, 3}, + {0, 0, 9, 15}, + {0, 0, 0, -6}, + }, + x: []float64{1, 2, 0, 5}, + alpha: 8, + ans: [][]float64{ + {18, 18, 0, 41}, + {0, 33, 2, 83}, + {0, 0, 9, 15}, + {0, 0, 0, 194}, + }, + }, + { + ul: blas.Lower, + n: 3, + a: [][]float64{ + {10, 2, 0}, + {4, 1, 2}, + {2, 7, 9}, + }, + x: []float64{3, 0, 5}, + alpha: 8, + ans: [][]float64{ + {82, 2, 0}, + {4, 1, 2}, + {122, 7, 209}, + }, + }, + } { + incTest := func(incX, extra int) { + xnew := makeIncremented(test.x, incX, extra) + aFlat := flattenTriangular(test.a, test.ul) + ans := flattenTriangular(test.ans, test.ul) + blasser.Dspr(test.ul, test.n, test.alpha, xnew, incX, aFlat) + if !dSliceTolEqual(aFlat, ans) { + t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, aFlat) + } + } + incTest(1, 3) + incTest(1, 0) + incTest(3, 2) + incTest(-2, 2) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspr2.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspr2.go new file mode 100644 index 0000000..fb657d6 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dspr2.go @@ -0,0 +1,76 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dspr2er interface { + Dspr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64) +} + +func Dspr2Test(t *testing.T, blasser Dspr2er) { + for i, test := range []struct { + n int + a [][]float64 + ul blas.Uplo + x []float64 + y []float64 + alpha float64 + ans [][]float64 + }{ + { + n: 3, + a: [][]float64{ + {7, 2, 4}, + {0, 3, 5}, + {0, 0, 6}, + }, + x: []float64{2, 3, 4}, + y: []float64{5, 6, 7}, + alpha: 2, + ul: blas.Upper, + ans: [][]float64{ + {47, 56, 72}, + {0, 75, 95}, + {0, 0, 118}, + }, + }, + { + n: 3, + a: [][]float64{ + {7, 0, 0}, + {2, 3, 0}, + {4, 5, 6}, + }, + x: []float64{2, 3, 4}, + y: []float64{5, 6, 7}, + alpha: 2, + ul: blas.Lower, + ans: [][]float64{ + {47, 0, 0}, + {56, 75, 0}, + {72, 95, 118}, + }, + }, + } { + incTest := func(incX, incY, extra int) { + aFlat := flattenTriangular(test.a, test.ul) + x := makeIncremented(test.x, incX, extra) + y := makeIncremented(test.y, incY, extra) + blasser.Dspr2(test.ul, test.n, test.alpha, x, incX, y, incY, aFlat) + ansFlat := flattenTriangular(test.ans, test.ul) + if !floats.EqualApprox(aFlat, ansFlat, 1e-14) { + t.Errorf("Case %v, incX = %v, incY = %v. Want %v, got %v.", i, incX, incY, ansFlat, aFlat) + } + } + incTest(1, 1, 0) + incTest(-2, 1, 0) + incTest(-2, 3, 0) + incTest(2, -3, 0) + incTest(3, -2, 0) + incTest(-3, -4, 0) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsymm.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsymm.go new file mode 100644 index 0000000..728d052 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsymm.go @@ -0,0 +1,277 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dsymmer interface { + Dsymm(s blas.Side, ul blas.Uplo, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) +} + +func DsymmTest(t *testing.T, blasser Dsymmer) { + for i, test := range []struct { + m int + n int + side blas.Side + ul blas.Uplo + a [][]float64 + b [][]float64 + c [][]float64 + alpha float64 + beta float64 + ans [][]float64 + }{ + { + side: blas.Left, + ul: blas.Upper, + m: 3, + n: 4, + a: [][]float64{ + {2, 3, 4}, + {0, 6, 7}, + {0, 0, 10}, + }, + b: [][]float64{ + {2, 3, 4, 8}, + {5, 6, 7, 15}, + {8, 9, 10, 20}, + }, + c: [][]float64{ + {8, 12, 2, 1}, + {9, 12, 9, 9}, + {12, 1, -1, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {126, 156, 144, 285}, + {211, 252, 275, 535}, + {282, 291, 327, 689}, + }, + }, + { + side: blas.Left, + ul: blas.Upper, + m: 4, + n: 3, + a: [][]float64{ + {2, 3, 4, 8}, + {0, 6, 7, 9}, + {0, 0, 10, 10}, + {0, 0, 0, 11}, + }, + b: [][]float64{ + {2, 3, 4}, + {5, 6, 7}, + {8, 9, 10}, + {2, 1, 1}, + }, + c: [][]float64{ + {8, 12, 2}, + {9, 12, 9}, + {12, 1, -1}, + {1, 9, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {158, 172, 160}, + {247, 270, 293}, + {322, 311, 347}, + {329, 385, 427}, + }, + }, + { + side: blas.Left, + ul: blas.Lower, + m: 3, + n: 4, + a: [][]float64{ + {2, 0, 0}, + {3, 6, 0}, + {4, 7, 10}, + }, + b: [][]float64{ + {2, 3, 4, 8}, + {5, 6, 7, 15}, + {8, 9, 10, 20}, + }, + c: [][]float64{ + {8, 12, 2, 1}, + {9, 12, 9, 9}, + {12, 1, -1, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {126, 156, 144, 285}, + {211, 252, 275, 535}, + {282, 291, 327, 689}, + }, + }, + { + side: blas.Left, + ul: blas.Lower, + m: 4, + n: 3, + a: [][]float64{ + {2, 0, 0, 0}, + {3, 6, 0, 0}, + {4, 7, 10, 0}, + {8, 9, 10, 11}, + }, + b: [][]float64{ + {2, 3, 4}, + {5, 6, 7}, + {8, 9, 10}, + {2, 1, 1}, + }, + c: [][]float64{ + {8, 12, 2}, + {9, 12, 9}, + {12, 1, -1}, + {1, 9, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {158, 172, 160}, + {247, 270, 293}, + {322, 311, 347}, + {329, 385, 427}, + }, + }, + { + side: blas.Right, + ul: blas.Upper, + m: 3, + n: 4, + a: [][]float64{ + {2, 0, 0, 0}, + {3, 6, 0, 0}, + {4, 7, 10, 0}, + {3, 4, 5, 6}, + }, + b: [][]float64{ + {2, 3, 4, 9}, + {5, 6, 7, -3}, + {8, 9, 10, -2}, + }, + c: [][]float64{ + {8, 12, 2, 10}, + {9, 12, 9, 10}, + {12, 1, -1, 10}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {32, 72, 86, 138}, + {47, 108, 167, -6}, + {68, 111, 197, 6}, + }, + }, + { + side: blas.Right, + ul: blas.Upper, + m: 4, + n: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 6, 0}, + {4, 7, 10}, + }, + b: [][]float64{ + {2, 3, 4}, + {5, 6, 7}, + {8, 9, 10}, + {2, 1, 1}, + }, + c: [][]float64{ + {8, 12, 2}, + {9, 12, 9}, + {12, 1, -1}, + {1, 9, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {32, 72, 86}, + {47, 108, 167}, + {68, 111, 197}, + {11, 39, 35}, + }, + }, + { + side: blas.Right, + ul: blas.Lower, + m: 3, + n: 4, + a: [][]float64{ + {2, 0, 0, 0}, + {3, 6, 0, 0}, + {4, 7, 10, 0}, + {3, 4, 5, 6}, + }, + b: [][]float64{ + {2, 3, 4, 2}, + {5, 6, 7, 1}, + {8, 9, 10, 1}, + }, + c: [][]float64{ + {8, 12, 2, 1}, + {9, 12, 9, 9}, + {12, 1, -1, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {94, 156, 164, 103}, + {145, 244, 301, 187}, + {208, 307, 397, 247}, + }, + }, + { + side: blas.Right, + ul: blas.Lower, + m: 4, + n: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 6, 0}, + {4, 7, 10}, + }, + b: [][]float64{ + {2, 3, 4}, + {5, 6, 7}, + {8, 9, 10}, + {2, 1, 1}, + }, + c: [][]float64{ + {8, 12, 2}, + {9, 12, 9}, + {12, 1, -1}, + {1, 9, 5}, + }, + alpha: 2, + beta: 3, + ans: [][]float64{ + {82, 140, 144}, + {139, 236, 291}, + {202, 299, 387}, + {25, 65, 65}, + }, + }, + } { + aFlat := flatten(test.a) + bFlat := flatten(test.b) + cFlat := flatten(test.c) + ansFlat := flatten(test.ans) + blasser.Dsymm(test.side, test.ul, test.m, test.n, test.alpha, aFlat, len(test.a[0]), bFlat, test.n, test.beta, cFlat, test.n) + if !floats.EqualApprox(cFlat, ansFlat, 1e-14) { + t.Errorf("Case %v: Want %v, got %v.", i, ansFlat, cFlat) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsymv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsymv.go new file mode 100644 index 0000000..f3b9e5d --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsymv.go @@ -0,0 +1,73 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dsymver interface { + Dsymv(ul blas.Uplo, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) +} + +func DsymvTest(t *testing.T, blasser Dsymver) { + for i, test := range []struct { + ul blas.Uplo + n int + a [][]float64 + x []float64 + y []float64 + alpha float64 + beta float64 + ans []float64 + }{ + { + ul: blas.Upper, + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 8, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + y: []float64{6, 7, 8}, + alpha: 2.1, + beta: -3, + ans: []float64{137.4, 189, 240.6}, + }, + { + ul: blas.Lower, + n: 3, + a: [][]float64{ + {5, 0, 0}, + {6, 8, 0}, + {7, 10, 13}, + }, + x: []float64{3, 4, 5}, + y: []float64{6, 7, 8}, + alpha: 2.1, + beta: -3, + ans: []float64{137.4, 189, 240.6}, + }, + } { + incTest := func(incX, incY, extra int) { + x := makeIncremented(test.x, incX, extra) + y := makeIncremented(test.y, incY, extra) + aFlat := flatten(test.a) + ans := makeIncremented(test.ans, incY, extra) + + blasser.Dsymv(test.ul, test.n, test.alpha, aFlat, test.n, x, incX, test.beta, y, incY) + if !floats.EqualApprox(ans, y, 1e-14) { + t.Errorf("Case %v, incX=%v, incY=%v: Want %v, got %v.", i, incX, incY, ans, y) + } + } + incTest(1, 1, 0) + incTest(2, 3, 0) + incTest(3, 2, 0) + incTest(-3, 2, 0) + incTest(-2, 4, 0) + incTest(2, -1, 0) + incTest(-3, -4, 3) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr.go new file mode 100644 index 0000000..4b4959f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr.go @@ -0,0 +1,72 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dsyrer interface { + Dsyr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int) +} + +func DsyrTest(t *testing.T, blasser Dsyrer) { + for i, test := range []struct { + ul blas.Uplo + n int + a [][]float64 + x []float64 + alpha float64 + ans [][]float64 + }{ + { + ul: blas.Upper, + n: 4, + a: [][]float64{ + {10, 2, 0, 1}, + {0, 1, 2, 3}, + {0, 0, 9, 15}, + {0, 0, 0, -6}, + }, + x: []float64{1, 2, 0, 5}, + alpha: 8, + ans: [][]float64{ + {18, 18, 0, 41}, + {0, 33, 2, 83}, + {0, 0, 9, 15}, + {0, 0, 0, 194}, + }, + }, + { + ul: blas.Lower, + n: 3, + a: [][]float64{ + {10, 2, 0}, + {4, 1, 2}, + {2, 7, 9}, + }, + x: []float64{3, 0, 5}, + alpha: 8, + ans: [][]float64{ + {82, 2, 0}, + {4, 1, 2}, + {122, 7, 209}, + }, + }, + } { + incTest := func(incX, extra int) { + xnew := makeIncremented(test.x, incX, extra) + aFlat := flatten(test.a) + ans := flatten(test.ans) + lda := test.n + blasser.Dsyr(test.ul, test.n, test.alpha, xnew, incX, aFlat, lda) + if !dSliceTolEqual(aFlat, ans) { + t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, aFlat) + } + } + incTest(1, 3) + incTest(1, 0) + incTest(3, 2) + incTest(-2, 2) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr2.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr2.go new file mode 100644 index 0000000..864e854 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr2.go @@ -0,0 +1,76 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dsyr2er interface { + Dsyr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) +} + +func Dsyr2Test(t *testing.T, blasser Dsyr2er) { + for i, test := range []struct { + n int + a [][]float64 + ul blas.Uplo + x []float64 + y []float64 + alpha float64 + ans [][]float64 + }{ + { + n: 3, + a: [][]float64{ + {7, 2, 4}, + {0, 3, 5}, + {0, 0, 6}, + }, + x: []float64{2, 3, 4}, + y: []float64{5, 6, 7}, + alpha: 2, + ul: blas.Upper, + ans: [][]float64{ + {47, 56, 72}, + {0, 75, 95}, + {0, 0, 118}, + }, + }, + { + n: 3, + a: [][]float64{ + {7, 0, 0}, + {2, 3, 0}, + {4, 5, 6}, + }, + x: []float64{2, 3, 4}, + y: []float64{5, 6, 7}, + alpha: 2, + ul: blas.Lower, + ans: [][]float64{ + {47, 0, 0}, + {56, 75, 0}, + {72, 95, 118}, + }, + }, + } { + incTest := func(incX, incY, extra int) { + aFlat := flatten(test.a) + x := makeIncremented(test.x, incX, extra) + y := makeIncremented(test.y, incY, extra) + blasser.Dsyr2(test.ul, test.n, test.alpha, x, incX, y, incY, aFlat, test.n) + ansFlat := flatten(test.ans) + if !floats.EqualApprox(aFlat, ansFlat, 1e-14) { + t.Errorf("Case %v, incX = %v, incY = %v. Want %v, got %v.", i, incX, incY, ansFlat, aFlat) + } + } + incTest(1, 1, 0) + incTest(-2, 1, 0) + incTest(-2, 3, 0) + incTest(2, -3, 0) + incTest(3, -2, 0) + incTest(-3, -4, 0) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr2k.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr2k.go new file mode 100644 index 0000000..f1e7de6 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyr2k.go @@ -0,0 +1,201 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dsyr2ker interface { + Dsyr2k(ul blas.Uplo, tA blas.Transpose, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) +} + +func Dsyr2kTest(t *testing.T, blasser Dsyr2ker) { + for i, test := range []struct { + ul blas.Uplo + tA blas.Transpose + n int + k int + alpha float64 + a [][]float64 + b [][]float64 + c [][]float64 + beta float64 + ans [][]float64 + }{ + { + ul: blas.Upper, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 0, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + b: [][]float64{ + {7, 8}, + {9, 10}, + {11, 12}, + }, + c: [][]float64{ + {1, 2, 3}, + {0, 5, 6}, + {0, 0, 9}, + }, + beta: 2, + ans: [][]float64{ + {2, 4, 6}, + {0, 10, 12}, + {0, 0, 18}, + }, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 0, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + b: [][]float64{ + {7, 8}, + {9, 10}, + {11, 12}, + }, + c: [][]float64{ + {1, 0, 0}, + {2, 3, 0}, + {4, 5, 6}, + }, + beta: 2, + ans: [][]float64{ + {2, 0, 0}, + {4, 6, 0}, + {8, 10, 12}, + }, + }, + { + ul: blas.Upper, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + b: [][]float64{ + {7, 8}, + {9, 10}, + {11, 12}, + }, + c: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + beta: 2, + ans: [][]float64{ + {140, 250, 360}, + {0, 410, 568}, + {0, 0, 774}, + }, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + b: [][]float64{ + {7, 8}, + {9, 10}, + {11, 12}, + }, + c: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + beta: 2, + ans: [][]float64{ + {140, 0, 0}, + {250, 410, 0}, + {360, 568, 774}, + }, + }, + { + ul: blas.Upper, + tA: blas.Trans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 3, 5}, + {2, 4, 6}, + }, + b: [][]float64{ + {7, 9, 11}, + {8, 10, 12}, + }, + c: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + beta: 2, + ans: [][]float64{ + {140, 250, 360}, + {0, 410, 568}, + {0, 0, 774}, + }, + }, + { + ul: blas.Lower, + tA: blas.Trans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 3, 5}, + {2, 4, 6}, + }, + b: [][]float64{ + {7, 9, 11}, + {8, 10, 12}, + }, + c: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + beta: 2, + ans: [][]float64{ + {140, 0, 0}, + {250, 410, 0}, + {360, 568, 774}, + }, + }, + } { + aFlat := flatten(test.a) + bFlat := flatten(test.b) + cFlat := flatten(test.c) + ansFlat := flatten(test.ans) + blasser.Dsyr2k(test.ul, test.tA, test.n, test.k, test.alpha, aFlat, len(test.a[0]), bFlat, len(test.b[0]), test.beta, cFlat, len(test.c[0])) + if !floats.EqualApprox(ansFlat, cFlat, 1e-14) { + t.Errorf("Case %v. Want %v, got %v.", i, ansFlat, cFlat) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyrk.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyrk.go new file mode 100644 index 0000000..23e4969 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dsyrk.go @@ -0,0 +1,171 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dsyker interface { + Dsyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int) +} + +func DsyrkTest(t *testing.T, blasser Dsyker) { + for i, test := range []struct { + ul blas.Uplo + tA blas.Transpose + n int + k int + alpha float64 + a [][]float64 + c [][]float64 + beta float64 + ans [][]float64 + }{ + { + ul: blas.Upper, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 0, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + c: [][]float64{ + {1, 2, 3}, + {0, 5, 6}, + {0, 0, 9}, + }, + beta: 2, + ans: [][]float64{ + {2, 4, 6}, + {0, 10, 12}, + {0, 0, 18}, + }, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 0, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + c: [][]float64{ + {1, 0, 0}, + {2, 3, 0}, + {4, 5, 6}, + }, + beta: 2, + ans: [][]float64{ + {2, 0, 0}, + {4, 6, 0}, + {8, 10, 12}, + }, + }, + { + ul: blas.Upper, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + c: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + beta: 2, + ans: [][]float64{ + {17, 37, 57}, + {0, 83, 127}, + {0, 0, 195}, + }, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 2}, + {3, 4}, + {5, 6}, + }, + c: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + beta: 2, + ans: [][]float64{ + {17, 0, 0}, + {37, 83, 0}, + {57, 127, 195}, + }, + }, + { + ul: blas.Upper, + tA: blas.Trans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 3, 5}, + {2, 4, 6}, + }, + c: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + beta: 2, + ans: [][]float64{ + {17, 37, 57}, + {0, 83, 127}, + {0, 0, 195}, + }, + }, + { + ul: blas.Lower, + tA: blas.Trans, + n: 3, + k: 2, + alpha: 3, + a: [][]float64{ + {1, 3, 5}, + {2, 4, 6}, + }, + c: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + beta: 2, + ans: [][]float64{ + {17, 0, 0}, + {37, 83, 0}, + {57, 127, 195}, + }, + }, + } { + aFlat := flatten(test.a) + cFlat := flatten(test.c) + ansFlat := flatten(test.ans) + blasser.Dsyrk(test.ul, test.tA, test.n, test.k, test.alpha, aFlat, len(test.a[0]), test.beta, cFlat, len(test.c[0])) + if !floats.EqualApprox(ansFlat, cFlat, 1e-14) { + t.Errorf("Case %v. Want %v, got %v.", i, ansFlat, cFlat) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtbmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtbmv.go new file mode 100644 index 0000000..497aaa0 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtbmv.go @@ -0,0 +1,123 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dtbmver interface { + Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) +} + +func DtbmvTest(t *testing.T, blasser Dtbmver) { + for i, test := range []struct { + ul blas.Uplo + tA blas.Transpose + d blas.Diag + n int + k int + a [][]float64 + x []float64 + ans []float64 + }{ + { + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + n: 3, + k: 1, + a: [][]float64{ + {1, 2, 0}, + {0, 1, 4}, + {0, 0, 1}, + }, + x: []float64{2, 3, 4}, + ans: []float64{8, 19, 4}, + }, + { + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 1, + a: [][]float64{ + {1, 3, 0, 0, 0}, + {0, 6, 7, 0, 0}, + {0, 0, 2, 1, 0}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + ans: []float64{7, 33, 10, 63, -5}, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 1, + a: [][]float64{ + {7, 0, 0, 0, 0}, + {3, 6, 0, 0, 0}, + {0, 7, 2, 0, 0}, + {0, 0, 1, 12, 0}, + {0, 0, 0, 3, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + ans: []float64{7, 15, 20, 51, 7}, + }, + { + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {7, 3, 9, 0, 0}, + {0, 6, 7, 10, 0}, + {0, 0, 2, 1, 11}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + ans: []float64{7, 15, 29, 71, 40}, + }, + { + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {7, 0, 0, 0, 0}, + {3, 6, 0, 0, 0}, + {9, 7, 2, 0, 0}, + {0, 10, 1, 12, 0}, + {0, 0, 11, 3, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + ans: []float64{40, 73, 65, 63, -5}, + }, + } { + extra := 0 + var aFlat []float64 + if test.ul == blas.Upper { + aFlat = flattenBanded(test.a, test.k, 0) + } else { + aFlat = flattenBanded(test.a, 0, test.k) + } + incTest := func(incX, extra int) { + xnew := makeIncremented(test.x, incX, extra) + ans := makeIncremented(test.ans, incX, extra) + lda := test.k + 1 + blasser.Dtbmv(test.ul, test.tA, test.d, test.n, test.k, aFlat, lda, xnew, incX) + if !dSliceTolEqual(ans, xnew) { + t.Errorf("Case %v, Inc %v: Want %v, got %v", i, incX, ans, xnew) + } + } + incTest(1, extra) + incTest(3, extra) + incTest(-2, extra) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtbsv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtbsv.go new file mode 100644 index 0000000..1e08a8d --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtbsv.go @@ -0,0 +1,256 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dtbsver interface { + Dtbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) + Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) +} + +func DtbsvTest(t *testing.T, blasser Dtbsver) { + for i, test := range []struct { + ul blas.Uplo + tA blas.Transpose + d blas.Diag + n, k int + a [][]float64 + lda int + x []float64 + incX int + ans []float64 + }{ + { + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 1, + a: [][]float64{ + {1, 3, 0, 0, 0}, + {0, 6, 7, 0, 0}, + {0, 0, 2, 1, 0}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + incX: 1, + ans: []float64{2.479166666666667, -0.493055555555556, 0.708333333333333, 1.583333333333333, -5.000000000000000}, + }, + { + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 3, 5, 0, 0}, + {0, 6, 7, 5, 0}, + {0, 0, 2, 1, 5}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + incX: 1, + ans: []float64{-15.854166666666664, -16.395833333333336, 13.208333333333334, 1.583333333333333, -5.000000000000000}, + }, + { + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 1, + a: [][]float64{ + {1, 3, 0, 0, 0}, + {0, 6, 7, 0, 0}, + {0, 0, 2, 1, 0}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701}, + incX: 2, + ans: []float64{2.479166666666667, -101, -0.493055555555556, -201, 0.708333333333333, -301, 1.583333333333333, -401, -5.000000000000000, -501, -601, -701}, + }, + { + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 3, 5, 0, 0}, + {0, 6, 7, 5, 0}, + {0, 0, 2, 1, 5}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701}, + incX: 2, + ans: []float64{-15.854166666666664, -101, -16.395833333333336, -201, 13.208333333333334, -301, 1.583333333333333, -401, -5.000000000000000, -501, -601, -701}, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 0, 0, 0, 0}, + {3, 6, 0, 0, 0}, + {5, 7, 2, 0, 0}, + {0, 5, 1, 12, 0}, + {0, 0, 5, 3, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + incX: 1, + ans: []float64{1, -0.166666666666667, -0.416666666666667, 0.437500000000000, -5.770833333333334}, + }, + { + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 0, 0, 0, 0}, + {3, 6, 0, 0, 0}, + {5, 7, 2, 0, 0}, + {0, 5, 1, 12, 0}, + {0, 0, 5, 3, -1}, + }, + x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701}, + incX: 2, + ans: []float64{1, -101, -0.166666666666667, -201, -0.416666666666667, -301, 0.437500000000000, -401, -5.770833333333334, -501, -601, -701}, + }, + { + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 3, 5, 0, 0}, + {0, 6, 7, 5, 0}, + {0, 0, 2, 1, 5}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + incX: 1, + ans: []float64{1, -0.166666666666667, -0.416666666666667, 0.437500000000000, -5.770833333333334}, + }, + { + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 3, 5, 0, 0}, + {0, 6, 7, 5, 0}, + {0, 0, 2, 1, 5}, + {0, 0, 0, 12, 3}, + {0, 0, 0, 0, -1}, + }, + x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701}, + incX: 2, + ans: []float64{1, -101, -0.166666666666667, -201, -0.416666666666667, -301, 0.437500000000000, -401, -5.770833333333334, -501, -601, -701}, + }, + { + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 0, 0, 0, 0}, + {3, 6, 0, 0, 0}, + {5, 7, 2, 0, 0}, + {0, 5, 1, 12, 0}, + {0, 0, 5, 3, -1}, + }, + x: []float64{1, 2, 3, 4, 5}, + incX: 1, + ans: []float64{-15.854166666666664, -16.395833333333336, 13.208333333333334, 1.583333333333333, -5.000000000000000}, + }, + { + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + n: 5, + k: 2, + a: [][]float64{ + {1, 0, 0, 0, 0}, + {3, 6, 0, 0, 0}, + {5, 7, 2, 0, 0}, + {0, 5, 1, 12, 0}, + {0, 0, 5, 3, -1}, + }, + x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701}, + incX: 2, + ans: []float64{-15.854166666666664, -101, -16.395833333333336, -201, 13.208333333333334, -301, 1.583333333333333, -401, -5.000000000000000, -501, -601, -701}, + }, + } { + var aFlat []float64 + if test.ul == blas.Upper { + aFlat = flattenBanded(test.a, test.k, 0) + } else { + aFlat = flattenBanded(test.a, 0, test.k) + } + xCopy := sliceCopy(test.x) + // TODO: Have tests where the banded matrix is constructed explicitly + // to allow testing for lda =! k+1 + blasser.Dtbsv(test.ul, test.tA, test.d, test.n, test.k, aFlat, test.k+1, xCopy, test.incX) + if !dSliceTolEqual(test.ans, xCopy) { + t.Errorf("Case %v: Want %v, got %v", i, test.ans, xCopy) + } + } + + /* + // TODO: Uncomment when Dtrsv is fixed + // Compare with dense for larger matrices + for _, ul := range [...]blas.Uplo{blas.Upper, blas.Lower} { + for _, tA := range [...]blas.Transpose{blas.NoTrans, blas.Trans} { + for _, n := range [...]int{7, 8, 11} { + for _, d := range [...]blas.Diag{blas.NonUnit, blas.Unit} { + for _, k := range [...]int{0, 1, 3} { + for _, incX := range [...]int{1, 3} { + a := make([][]float64, n) + for i := range a { + a[i] = make([]float64, n) + for j := range a[i] { + a[i][j] = rand.Float64() + } + } + x := make([]float64, n) + for i := range x { + x[i] = rand.Float64() + } + extra := 3 + xinc := makeIncremented(x, incX, extra) + bandX := sliceCopy(xinc) + var aFlatBand []float64 + if ul == blas.Upper { + aFlatBand = flattenBanded(a, k, 0) + } else { + aFlatBand = flattenBanded(a, 0, k) + } + blasser.Dtbsv(ul, tA, d, n, k, aFlatBand, k+1, bandX, incX) + + aFlatDense := flatten(a) + denseX := sliceCopy(xinc) + blasser.Dtrsv(ul, tA, d, n, aFlatDense, n, denseX, incX) + if !dSliceTolEqual(denseX, bandX) { + t.Errorf("Case %v: dense banded mismatch") + } + } + } + } + } + } + } + */ +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtpmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtpmv.go new file mode 100644 index 0000000..a031f31 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtpmv.go @@ -0,0 +1,129 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dtpmver interface { + Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) +} + +func DtpmvTest(t *testing.T, blasser Dtpmver) { + for i, test := range []struct { + n int + a [][]float64 + x []float64 + d blas.Diag + ul blas.Uplo + tA blas.Transpose + ans []float64 + }{ + { + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 9, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Upper, + tA: blas.NoTrans, + ans: []float64{74, 86, 65}, + }, + { + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 9, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.Unit, + ul: blas.Upper, + tA: blas.NoTrans, + ans: []float64{62, 54, 5}, + }, + { + n: 3, + a: [][]float64{ + {5, 0, 0}, + {6, 9, 0}, + {7, 10, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Lower, + tA: blas.NoTrans, + ans: []float64{15, 54, 126}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {6, 1, 0}, + {7, 10, 1}, + }, + x: []float64{3, 4, 5}, + d: blas.Unit, + ul: blas.Lower, + tA: blas.NoTrans, + ans: []float64{3, 22, 66}, + }, + { + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 9, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Upper, + tA: blas.Trans, + ans: []float64{15, 54, 126}, + }, + { + n: 3, + a: [][]float64{ + {1, 6, 7}, + {0, 1, 10}, + {0, 0, 1}, + }, + x: []float64{3, 4, 5}, + d: blas.Unit, + ul: blas.Upper, + tA: blas.Trans, + ans: []float64{3, 22, 66}, + }, + { + n: 3, + a: [][]float64{ + {5, 0, 0}, + {6, 9, 0}, + {7, 10, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Lower, + tA: blas.Trans, + ans: []float64{74, 86, 65}, + }, + } { + incTest := func(incX, extra int) { + aFlat := flattenTriangular(test.a, test.ul) + x := makeIncremented(test.x, incX, extra) + blasser.Dtpmv(test.ul, test.tA, test.d, test.n, aFlat, x, incX) + ans := makeIncremented(test.ans, incX, extra) + if !floats.EqualApprox(x, ans, 1e-14) { + t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, x) + } + } + incTest(1, 0) + incTest(-3, 3) + incTest(4, 3) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtpsv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtpsv.go new file mode 100644 index 0000000..d29ff96 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtpsv.go @@ -0,0 +1,144 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dtpsver interface { + Dtpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) +} + +func DtpsvTest(t *testing.T, blasser Dtpsver) { + for i, test := range []struct { + n int + a [][]float64 + ul blas.Uplo + tA blas.Transpose + d blas.Diag + x []float64 + ans []float64 + }{ + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 8, 15}, + {0, 0, 8}, + }, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{4.15625, -0.890625, 0.875}, + }, + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 1, 15}, + {0, 0, 1}, + }, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{182, -99, 7}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 8, 0}, + {3, 15, 8}, + }, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{5, -0.5, -0.0625}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 8, 0}, + {3, 15, 8}, + }, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{5, -4, 52}, + }, + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 8, 15}, + {0, 0, 8}, + }, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{5, -0.5, -0.0625}, + }, + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 8, 15}, + {0, 0, 8}, + }, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{5, -4, 52}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 8, 0}, + {3, 15, 8}, + }, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{4.15625, -0.890625, 0.875}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 1, 0}, + {3, 15, 1}, + }, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{182, -99, 7}, + }, + } { + incTest := func(incX, extra int) { + aFlat := flattenTriangular(test.a, test.ul) + x := makeIncremented(test.x, incX, extra) + blasser.Dtpsv(test.ul, test.tA, test.d, test.n, aFlat, x, incX) + ans := makeIncremented(test.ans, incX, extra) + if !floats.EqualApprox(x, ans, 1e-14) { + t.Errorf("Case %v, incX = %v: Want %v, got %v.", i, incX, ans, x) + } + } + incTest(1, 0) + incTest(-2, 0) + incTest(3, 0) + incTest(-3, 8) + incTest(4, 2) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrmm.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrmm.go new file mode 100644 index 0000000..070eca5 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrmm.go @@ -0,0 +1,806 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dtrmmer interface { + Dtrmm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) +} + +func DtrmmTest(t *testing.T, blasser Dtrmmer) { + for i, test := range []struct { + s blas.Side + ul blas.Uplo + tA blas.Transpose + d blas.Diag + m int + n int + alpha float64 + a [][]float64 + b [][]float64 + ans [][]float64 + }{ + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3, 4}, + {0, 5, 6, 7}, + {0, 0, 8, 9}, + {0, 0, 0, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {320, 340, 360}, + {588, 624, 660}, + {598, 632, 666}, + {380, 400, 420}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2}, + {0, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {72, 78, 84}, + {130, 140, 150}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3, 4}, + {0, 5, 6, 7}, + {0, 0, 8, 9}, + {0, 0, 0, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {320, 340, 360}, + {484, 512, 540}, + {374, 394, 414}, + {38, 40, 42}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2}, + {0, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {72, 78, 84}, + {26, 28, 30}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0, 0}, + {2, 5, 0, 0}, + {3, 6, 8, 0}, + {4, 7, 9, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 22, 24}, + {170, 184, 198}, + {472, 506, 540}, + {930, 990, 1050}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0}, + {2, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 22, 24}, + {170, 184, 198}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0, 0}, + {2, 5, 0, 0}, + {3, 6, 8, 0}, + {4, 7, 9, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 22, 24}, + {66, 72, 78}, + {248, 268, 288}, + {588, 630, 672}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0}, + {2, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 22, 24}, + {66, 72, 78}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3, 4}, + {0, 5, 6, 7}, + {0, 0, 8, 9}, + {0, 0, 0, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 22, 24}, + {170, 184, 198}, + {472, 506, 540}, + {930, 990, 1050}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2}, + {0, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 22, 24}, + {170, 184, 198}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3, 4}, + {0, 5, 6, 7}, + {0, 0, 8, 9}, + {0, 0, 0, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 22, 24}, + {66, 72, 78}, + {248, 268, 288}, + {588, 630, 672}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2}, + {0, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 22, 24}, + {66, 72, 78}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0, 0}, + {2, 5, 0, 0}, + {3, 6, 8, 0}, + {4, 7, 9, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {320, 340, 360}, + {588, 624, 660}, + {598, 632, 666}, + {380, 400, 420}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0}, + {2, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {72, 78, 84}, + {130, 140, 150}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0, 0}, + {2, 5, 0, 0}, + {3, 6, 8, 0}, + {4, 7, 9, 10}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {320, 340, 360}, + {484, 512, 540}, + {374, 394, 414}, + {38, 40, 42}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0}, + {2, 5}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {72, 78, 84}, + {26, 28, 30}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 128, 314}, + {26, 164, 398}, + {32, 200, 482}, + {38, 236, 566}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 128, 314}, + {26, 164, 398}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 62, 194}, + {26, 80, 248}, + {32, 98, 302}, + {38, 116, 356}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 62, 194}, + {26, 80, 248}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {136, 208, 144}, + {172, 262, 180}, + {208, 316, 216}, + {244, 370, 252}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {136, 208, 144}, + {172, 262, 180}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {136, 142, 24}, + {172, 178, 30}, + {208, 214, 36}, + {244, 250, 42}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {136, 142, 24}, + {172, 178, 30}, + }, + }, + + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {136, 208, 144}, + {172, 262, 180}, + {208, 316, 216}, + {244, 370, 252}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {136, 208, 144}, + {172, 262, 180}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {136, 142, 24}, + {172, 178, 30}, + {208, 214, 36}, + {244, 250, 42}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {136, 142, 24}, + {172, 178, 30}, + }, + }, + + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 128, 314}, + {26, 164, 398}, + {32, 200, 482}, + {38, 236, 566}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 128, 314}, + {26, 164, 398}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {20, 62, 194}, + {26, 80, 248}, + {32, 98, 302}, + {38, 116, 356}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 2, + a: [][]float64{ + {1, 0, 0}, + {2, 4, 0}, + {3, 5, 6}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {20, 62, 194}, + {26, 80, 248}, + }, + }, + } { + aFlat := flatten(test.a) + bFlat := flatten(test.b) + ansFlat := flatten(test.ans) + blasser.Dtrmm(test.s, test.ul, test.tA, test.d, test.m, test.n, test.alpha, aFlat, len(test.a[0]), bFlat, len(test.b[0])) + if !floats.EqualApprox(ansFlat, bFlat, 1e-14) { + t.Errorf("Case %v. Want %v, got %v.", i, ansFlat, bFlat) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrmv.go new file mode 100644 index 0000000..11c8faf --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrmv.go @@ -0,0 +1,129 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dtrmver interface { + Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) +} + +func DtrmvTest(t *testing.T, blasser Dtrmver) { + for i, test := range []struct { + n int + a [][]float64 + x []float64 + d blas.Diag + ul blas.Uplo + tA blas.Transpose + ans []float64 + }{ + { + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 9, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Upper, + tA: blas.NoTrans, + ans: []float64{74, 86, 65}, + }, + { + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 9, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.Unit, + ul: blas.Upper, + tA: blas.NoTrans, + ans: []float64{62, 54, 5}, + }, + { + n: 3, + a: [][]float64{ + {5, 0, 0}, + {6, 9, 0}, + {7, 10, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Lower, + tA: blas.NoTrans, + ans: []float64{15, 54, 126}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {6, 1, 0}, + {7, 10, 1}, + }, + x: []float64{3, 4, 5}, + d: blas.Unit, + ul: blas.Lower, + tA: blas.NoTrans, + ans: []float64{3, 22, 66}, + }, + { + n: 3, + a: [][]float64{ + {5, 6, 7}, + {0, 9, 10}, + {0, 0, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Upper, + tA: blas.Trans, + ans: []float64{15, 54, 126}, + }, + { + n: 3, + a: [][]float64{ + {1, 6, 7}, + {0, 1, 10}, + {0, 0, 1}, + }, + x: []float64{3, 4, 5}, + d: blas.Unit, + ul: blas.Upper, + tA: blas.Trans, + ans: []float64{3, 22, 66}, + }, + { + n: 3, + a: [][]float64{ + {5, 0, 0}, + {6, 9, 0}, + {7, 10, 13}, + }, + x: []float64{3, 4, 5}, + d: blas.NonUnit, + ul: blas.Lower, + tA: blas.Trans, + ans: []float64{74, 86, 65}, + }, + } { + incTest := func(incX, extra int) { + aFlat := flatten(test.a) + x := makeIncremented(test.x, incX, extra) + blasser.Dtrmv(test.ul, test.tA, test.d, test.n, aFlat, test.n, x, incX) + ans := makeIncremented(test.ans, incX, extra) + if !floats.EqualApprox(x, ans, 1e-14) { + t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, x) + } + } + incTest(1, 3) + incTest(-3, 3) + incTest(4, 3) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrsm.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrsm.go new file mode 100644 index 0000000..f00b488 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrsm.go @@ -0,0 +1,811 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dtrsmer interface { + Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas.Diag, m, n int, + alpha float64, a []float64, lda int, b []float64, ldb int) +} + +func DtrsmTest(t *testing.T, blasser Dtrsmer) { + for i, test := range []struct { + s blas.Side + ul blas.Uplo + tA blas.Transpose + d blas.Diag + m int + n int + alpha float64 + a [][]float64 + b [][]float64 + ans [][]float64 + }{ + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 3, + n: 2, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 5}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {1, 3.4}, + {-0.5, -0.5}, + {2, 3.2}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 3, + n: 2, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 5}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {60, 96}, + {-42, -66}, + {10, 16}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 3, + n: 4, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 5}, + }, + b: [][]float64{ + {3, 6, 2, 9}, + {4, 7, 1, 3}, + {5, 8, 9, 10}, + }, + ans: [][]float64{ + {1, 3.4, 1.2, 13}, + {-0.5, -0.5, -4, -3.5}, + {2, 3.2, 3.6, 4}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 3, + n: 4, + alpha: 2, + a: [][]float64{ + {1, 2, 3}, + {0, 4, 5}, + {0, 0, 5}, + }, + b: [][]float64{ + {3, 6, 2, 9}, + {4, 7, 1, 3}, + {5, 8, 9, 10}, + }, + ans: [][]float64{ + {60, 96, 126, 146}, + {-42, -66, -88, -94}, + {10, 16, 18, 20}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 3, + n: 2, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 7}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {4.5, 9}, + {-0.375, -1.5}, + {-0.75, -12.0 / 7}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 3, + n: 2, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 7}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {9, 18}, + {-15, -33}, + {60, 132}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 3, + n: 4, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 7}, + }, + b: [][]float64{ + {3, 6, 2, 9}, + {4, 7, 1, 3}, + {5, 8, 9, 10}, + }, + ans: [][]float64{ + {4.5, 9, 3, 13.5}, + {-0.375, -1.5, -1.5, -63.0 / 8}, + {-0.75, -12.0 / 7, 3, 39.0 / 28}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 3, + n: 4, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 7}, + }, + b: [][]float64{ + {3, 6, 2, 9}, + {4, 7, 1, 3}, + {5, 8, 9, 10}, + }, + ans: [][]float64{ + {9, 18, 6, 27}, + {-15, -33, -15, -72}, + {60, 132, 87, 327}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 3, + n: 2, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 7}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {4.5, 9}, + {-0.30, -1.2}, + {-6.0 / 35, -24.0 / 35}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 3, + n: 2, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 7}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {9, 18}, + {-15, -33}, + {69, 150}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 3, + n: 4, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 7}, + }, + b: [][]float64{ + {3, 6, 6, 7}, + {4, 7, 8, 9}, + {5, 8, 10, 11}, + }, + ans: [][]float64{ + {4.5, 9, 9, 10.5}, + {-0.3, -1.2, -0.6, -0.9}, + {-6.0 / 35, -24.0 / 35, -12.0 / 35, -18.0 / 35}, + }, + }, + { + s: blas.Left, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 3, + n: 4, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 7}, + }, + b: [][]float64{ + {3, 6, 6, 7}, + {4, 7, 8, 9}, + {5, 8, 10, 11}, + }, + ans: [][]float64{ + {9, 18, 18, 21}, + {-15, -33, -30, -36}, + {69, 150, 138, 165}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 3, + n: 2, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 8}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {-0.46875, 0.375}, + {0.1875, 0.75}, + {1.875, 3}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 3, + n: 2, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 8}, + }, + b: [][]float64{ + {3, 6}, + {4, 7}, + {5, 8}, + }, + ans: [][]float64{ + {168, 267}, + {-78, -123}, + {15, 24}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 3, + n: 4, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 8}, + }, + b: [][]float64{ + {3, 6, 2, 3}, + {4, 7, 4, 5}, + {5, 8, 6, 7}, + }, + ans: [][]float64{ + {-0.46875, 0.375, -2.0625, -1.78125}, + {0.1875, 0.75, -0.375, -0.1875}, + {1.875, 3, 2.25, 2.625}, + }, + }, + { + s: blas.Left, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 3, + n: 4, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 4, 0}, + {5, 6, 8}, + }, + b: [][]float64{ + {3, 6, 2, 3}, + {4, 7, 4, 5}, + {5, 8, 6, 7}, + }, + ans: [][]float64{ + {168, 267, 204, 237}, + {-78, -123, -96, -111}, + {15, 24, 18, 21}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 7}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {15, -2.4, -48.0 / 35}, + {19.5, -3.3, -66.0 / 35}, + {24, -4.2, -2.4}, + {28.5, -5.1, -102.0 / 35}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {30, -57, 258}, + {39, -75, 339}, + {48, -93, 420}, + {57, -111, 501}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 7}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {15, -2.4, -48.0 / 35}, + {19.5, -3.3, -66.0 / 35}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {30, -57, 258}, + {39, -75, 339}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {4.2, 1.2, 4.5}, + {5.775, 1.65, 5.625}, + {7.35, 2.1, 6.75}, + {8.925, 2.55, 7.875}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {435, -183, 36}, + {543, -228, 45}, + {651, -273, 54}, + {759, -318, 63}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {4.2, 1.2, 4.5}, + {5.775, 1.65, 5.625}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {435, -183, 36}, + {543, -228, 45}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {4.2, 1.2, 4.5}, + {5.775, 1.65, 5.625}, + {7.35, 2.1, 6.75}, + {8.925, 2.55, 7.875}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {435, -183, 36}, + {543, -228, 45}, + {651, -273, 54}, + {759, -318, 63}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {4.2, 1.2, 4.5}, + {5.775, 1.65, 5.625}, + }, + }, + { + s: blas.Right, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 3, 4}, + {0, 5, 6}, + {0, 0, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {435, -183, 36}, + {543, -228, 45}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {15, -2.4, -1.2}, + {19.5, -3.3, -1.65}, + {24, -4.2, -2.1}, + {28.5, -5.1, -2.55}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 4, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + {16, 17, 18}, + {19, 20, 21}, + }, + ans: [][]float64{ + {30, -57, 258}, + {39, -75, 339}, + {48, -93, 420}, + {57, -111, 501}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {15, -2.4, -1.2}, + {19.5, -3.3, -1.65}, + }, + }, + { + s: blas.Right, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + m: 2, + n: 3, + alpha: 3, + a: [][]float64{ + {2, 0, 0}, + {3, 5, 0}, + {4, 6, 8}, + }, + b: [][]float64{ + {10, 11, 12}, + {13, 14, 15}, + }, + ans: [][]float64{ + {30, -57, 258}, + {39, -75, 339}, + }, + }, + } { + aFlat := flatten(test.a) + bFlat := flatten(test.b) + ansFlat := flatten(test.ans) + var lda int + if test.s == blas.Left { + lda = test.m + } else { + lda = test.n + } + blasser.Dtrsm(test.s, test.ul, test.tA, test.d, test.m, test.n, test.alpha, aFlat, lda, bFlat, test.n) + if !floats.EqualApprox(ansFlat, bFlat, 1e-13) { + t.Errorf("Case %v: Want %v, got %v.", i, ansFlat, bFlat) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrsv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrsv.go new file mode 100644 index 0000000..003b5b7 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtrsv.go @@ -0,0 +1,144 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" + "github.com/gonum/floats" +) + +type Dtrsver interface { + Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) +} + +func DtrsvTest(t *testing.T, blasser Dtrsver) { + for i, test := range []struct { + n int + a [][]float64 + ul blas.Uplo + tA blas.Transpose + d blas.Diag + x []float64 + ans []float64 + }{ + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 8, 15}, + {0, 0, 8}, + }, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{4.15625, -0.890625, 0.875}, + }, + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 1, 15}, + {0, 0, 1}, + }, + ul: blas.Upper, + tA: blas.NoTrans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{182, -99, 7}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 8, 0}, + {3, 15, 8}, + }, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{5, -0.5, -0.0625}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 8, 0}, + {3, 15, 8}, + }, + ul: blas.Lower, + tA: blas.NoTrans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{5, -4, 52}, + }, + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 8, 15}, + {0, 0, 8}, + }, + ul: blas.Upper, + tA: blas.Trans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{5, -0.5, -0.0625}, + }, + { + n: 3, + a: [][]float64{ + {1, 2, 3}, + {0, 8, 15}, + {0, 0, 8}, + }, + ul: blas.Upper, + tA: blas.Trans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{5, -4, 52}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 8, 0}, + {3, 15, 8}, + }, + ul: blas.Lower, + tA: blas.Trans, + d: blas.NonUnit, + x: []float64{5, 6, 7}, + ans: []float64{4.15625, -0.890625, 0.875}, + }, + { + n: 3, + a: [][]float64{ + {1, 0, 0}, + {2, 1, 0}, + {3, 15, 1}, + }, + ul: blas.Lower, + tA: blas.Trans, + d: blas.Unit, + x: []float64{5, 6, 7}, + ans: []float64{182, -99, 7}, + }, + } { + incTest := func(incX, extra int) { + aFlat := flatten(test.a) + x := makeIncremented(test.x, incX, extra) + blasser.Dtrsv(test.ul, test.tA, test.d, test.n, aFlat, test.n, x, incX) + ans := makeIncremented(test.ans, incX, extra) + if !floats.EqualApprox(x, ans, 1e-14) { + t.Errorf("Case %v, incX = %v: Want %v, got %v.", i, incX, ans, x) + } + } + incTest(1, 0) + incTest(-2, 0) + incTest(3, 0) + incTest(-3, 8) + incTest(4, 2) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtxmv.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtxmv.go new file mode 100644 index 0000000..eecc10e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/dtxmv.go @@ -0,0 +1,145 @@ +package testblas + +import ( + "testing" + + "github.com/gonum/blas" +) + +type Dtxmver interface { + Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) + Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) + Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, x []float64, incX int) +} + +type vec struct { + data []float64 + inc int +} + +var cases = []struct { + n, k int + ul blas.Uplo + d blas.Diag + ldab int + tr, tb, tp []float64 + ins []vec + solNoTrans []float64 + solTrans []float64 +}{ + { + n: 3, + k: 1, + ul: blas.Upper, + d: blas.NonUnit, + tr: []float64{1, 2, 0, 0, 3, 4, 0, 0, 5}, + tb: []float64{1, 2, 3, 4, 5, 0}, + ldab: 2, + tp: []float64{1, 2, 0, 3, 4, 5}, + ins: []vec{ + {[]float64{2, 3, 4}, 1}, + {[]float64{2, 1, 3, 1, 4}, 2}, + {[]float64{4, 1, 3, 1, 2}, -2}, + }, + solNoTrans: []float64{8, 25, 20}, + solTrans: []float64{2, 13, 32}, + }, + { + n: 3, + k: 1, + ul: blas.Upper, + d: blas.Unit, + tr: []float64{1, 2, 0, 0, 3, 4, 0, 0, 5}, + tb: []float64{1, 2, 3, 4, 5, 0}, + ldab: 2, + tp: []float64{1, 2, 0, 3, 4, 5}, + ins: []vec{ + {[]float64{2, 3, 4}, 1}, + {[]float64{2, 1, 3, 1, 4}, 2}, + {[]float64{4, 1, 3, 1, 2}, -2}, + }, + solNoTrans: []float64{8, 19, 4}, + solTrans: []float64{2, 7, 16}, + }, + { + n: 3, + k: 1, + ul: blas.Lower, + d: blas.NonUnit, + tr: []float64{1, 0, 0, 2, 3, 0, 0, 4, 5}, + tb: []float64{0, 1, 2, 3, 4, 5}, + ldab: 2, + tp: []float64{1, 2, 3, 0, 4, 5}, + ins: []vec{ + {[]float64{2, 3, 4}, 1}, + {[]float64{2, 1, 3, 1, 4}, 2}, + {[]float64{4, 1, 3, 1, 2}, -2}, + }, + solNoTrans: []float64{2, 13, 32}, + solTrans: []float64{8, 25, 20}, + }, + { + n: 3, + k: 1, + ul: blas.Lower, + d: blas.Unit, + tr: []float64{1, 0, 0, 2, 3, 0, 0, 4, 5}, + tb: []float64{0, 1, 2, 3, 4, 5}, + ldab: 2, + tp: []float64{1, 2, 3, 0, 4, 5}, + ins: []vec{ + {[]float64{2, 3, 4}, 1}, + {[]float64{2, 1, 3, 1, 4}, 2}, + {[]float64{4, 1, 3, 1, 2}, -2}, + }, + solNoTrans: []float64{2, 7, 16}, + solTrans: []float64{8, 19, 4}, + }, +} + +func DtxmvTest(t *testing.T, blasser Dtxmver) { + + for nc, c := range cases { + for nx, x := range c.ins { + in := make([]float64, len(x.data)) + copy(in, x.data) + blasser.Dtrmv(c.ul, blas.NoTrans, c.d, c.n, c.tr, c.n, in, x.inc) + if !dStridedSliceTolEqual(c.n, in, x.inc, c.solNoTrans, 1) { + t.Error("Wrong Dtrmv result for: NoTrans in Case:", nc, "input:", nx) + } + + in = make([]float64, len(x.data)) + copy(in, x.data) + blasser.Dtrmv(c.ul, blas.Trans, c.d, c.n, c.tr, c.n, in, x.inc) + if !dStridedSliceTolEqual(c.n, in, x.inc, c.solTrans, 1) { + t.Error("Wrong Dtrmv result for: Trans in Case:", nc, "input:", nx) + } + in = make([]float64, len(x.data)) + copy(in, x.data) + blasser.Dtbmv(c.ul, blas.NoTrans, c.d, c.n, c.k, c.tb, c.ldab, in, x.inc) + if !dStridedSliceTolEqual(c.n, in, x.inc, c.solNoTrans, 1) { + t.Error("Wrong Dtbmv result for: NoTrans in Case:", nc, "input:", nx) + } + + in = make([]float64, len(x.data)) + copy(in, x.data) + blasser.Dtbmv(c.ul, blas.Trans, c.d, c.n, c.k, c.tb, c.ldab, in, x.inc) + if !dStridedSliceTolEqual(c.n, in, x.inc, c.solTrans, 1) { + t.Error("Wrong Dtbmv result for: Trans in Case:", nc, "input:", nx) + } + in = make([]float64, len(x.data)) + copy(in, x.data) + blasser.Dtpmv(c.ul, blas.NoTrans, c.d, c.n, c.tp, in, x.inc) + if !dStridedSliceTolEqual(c.n, in, x.inc, c.solNoTrans, 1) { + t.Error("Wrong Dtpmv result for: NoTrans in Case:", nc, "input:", nx) + } + + in = make([]float64, len(x.data)) + copy(in, x.data) + blasser.Dtpmv(c.ul, blas.Trans, c.d, c.n, c.tp, in, x.inc) + if !dStridedSliceTolEqual(c.n, in, x.inc, c.solTrans, 1) { + t.Error("Wrong Dtpmv result for: Trans in Case:", nc, "input:", nx) + } + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/level1double.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/level1double.go new file mode 100644 index 0000000..356082f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/level1double.go @@ -0,0 +1,1764 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package testblas provides tests for blas implementions. +package testblas + +import ( + "github.com/gonum/blas" + + "math" + "testing" +) + +type DoubleOneVectorCase struct { + Name string + X []float64 + Incx int + N int + Panic bool + Dasum float64 + Dnrm2 float64 + Idamax int + DscalCases []DScalCase +} + +type DScalCase struct { + Alpha float64 + Ans []float64 + Name string +} + +var DoubleOneVectorCases = []DoubleOneVectorCase{ + { + Name: "AllPositive", + X: []float64{6, 5, 4, 2, 6}, + Incx: 1, + N: 5, + Panic: false, + Dasum: 23, + Dnrm2: 10.81665382639196787935766380241148783875388972153573863813135, + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: 0, + Ans: []float64{0, 0, 0, 0, 0}, + }, + { + Alpha: 1, + Ans: []float64{6, 5, 4, 2, 6}, + }, + { + Alpha: -2, + Ans: []float64{-12, -10, -8, -4, -12}, + }, + }, + }, + { + Name: "MaxInMiddle", + X: []float64{6, 5, 9, 0, 6}, + Incx: 1, + N: 5, + Panic: false, + Dasum: 26, + Dnrm2: 13.34166406412633371248943627250846646911846482744007727141318, + Idamax: 2, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-12, -10, -18, 0, -12}, + }, + }, + }, + { + Name: "MaxAtEnd", + X: []float64{6, 5, -9, 0, 10}, + Incx: 1, + N: 5, + Panic: false, + Dasum: 30, + Dnrm2: 15.55634918610404553681857596630667886426639062914642880494347, + Idamax: 4, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-12, -10, 18, 0, -20}, + }, + }, + }, + { + Name: "AllNegative", + X: []float64{-6, -5, -4, -2, -6}, + Incx: 1, + N: 5, + Panic: false, + Dasum: 23, + Dnrm2: 10.81665382639196787935766380241148783875388972153573863813135, + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{12, 10, 8, 4, 12}, + }, + }, + }, + { + Name: "AllMixed", + X: []float64{-6, 5, 4, -2, -6}, + Incx: 1, + N: 5, + Panic: false, + Dasum: 23, + Dnrm2: 10.81665382639196787935766380241148783875388972153573863813135, + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{12, -10, -8, 4, 12}, + }, + }, + }, + { + Name: "ZeroN", + X: []float64{-6, 5, 4, -2, -6}, + Incx: 1, + N: 0, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "OneN", + X: []float64{-6, 5, 4, -2, -6}, + Incx: 1, + N: 1, + Panic: false, + Dasum: 6, + Dnrm2: 6, + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{12, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "PositiveExactInc", + X: []float64{-6, 5, 10, -2, -5}, + Incx: 2, + N: 3, + Panic: false, + Dasum: 21, + Dnrm2: 12.68857754044952038019377274608948979173952662752515253090272, + Idamax: 1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{12, 5, -20, -2, 10}, + }, + }, + }, + { + Name: "PositiveOffInc", + X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, + Incx: 3, + N: 3, + Panic: false, + Dasum: 18, + Dnrm2: 11.83215956619923208513465658312323409683100246158868064575943, + Idamax: 2, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{12, 5, 4, 4, -6, 8, -20, 11}, + }, + }, + }, + { + Name: "PositiveShortInc", + X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, + Incx: 3, + N: 2, + Panic: false, + Dasum: 8, + Dnrm2: 6.324555320336758663997787088865437067439110278650433653715009, + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{12, 5, 4, 4, -6, 8, 10, 11}, + }, + }, + }, + { + Name: "NegativeInc", + X: []float64{-6, 5, 4, -2, -6}, + Incx: -1, + N: 5, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "NegativeExactInc", + X: []float64{-6, 5, 4, -2, -6}, + Incx: -2, + N: 3, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "NegativeOffInc", + X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, + Incx: -3, + N: 2, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, + }, + }, + }, + { + Name: "NegativeShortInc", + X: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, + Incx: -3, + N: 2, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6, 8, 10, 11}, + }, + }, + }, + { + Name: "NegativeN", + X: []float64{-6, 5, 4, -2, -6}, + Incx: 2, + N: -5, + Panic: true, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "ZeroInc", + X: []float64{-6, 5, 4, -2, -6}, + Incx: 0, + N: 5, + Panic: true, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "OutOfBounds", + X: []float64{-6, 5, 4, -2, -6}, + Incx: 2, + N: 6, + Panic: true, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "NegativeOutOfBounds", + X: []float64{-6, 5, 4, -2, -6}, + Incx: -2, + N: 6, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{-6, 5, 4, -2, -6}, + }, + }, + }, + { + Name: "NaN", + X: []float64{math.NaN(), 2.0}, + Incx: 1, + N: 2, + Panic: false, + Dasum: math.NaN(), + Dnrm2: math.NaN(), + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{math.NaN(), -4.0}, + }, + { + Alpha: 0, + Ans: []float64{0, 0}, + }, + }, + }, + { + Name: "NaNInc", + X: []float64{math.NaN(), math.NaN(), 2.0}, + Incx: 2, + N: 2, + Panic: false, + Dasum: math.NaN(), + Dnrm2: math.NaN(), + Idamax: 0, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{math.NaN(), math.NaN(), -4.0}, + }, + { + Alpha: 0, + Ans: []float64{0, math.NaN(), 0}, + }, + }, + }, +} + +type DoubleTwoVectorCase struct { + Name string + X []float64 + Y []float64 + XTmp []float64 + YTmp []float64 + Incx int + Incy int + N int + Panic bool + // For Daxpy + DaxpyCases []DaxpyCase + DdotAns float64 + DswapAns DTwoVecAnswer + DcopyAns DTwoVecAnswer + DrotCases []DrotCase + DrotmCases []DrotmCase +} + +type DaxpyCase struct { + Alpha float64 + Ans []float64 +} + +type DrotCase struct { + C float64 + S float64 + XAns []float64 + YAns []float64 +} + +type DrotmCase struct { + P blas.DrotmParams + XAns []float64 + YAns []float64 + Name string +} + +type DTwoVecAnswer struct { + X []float64 + Y []float64 +} + +var DoubleTwoVectorCases = []DoubleTwoVectorCase{ + { + Name: "UnitaryInc", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0}, + Incx: 1, + Incy: 1, + N: 6, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 1, + Ans: []float64{18, 13, -2, 10, 20, 4}, + }, + { + Alpha: 2, + Ans: []float64{28, 28, -8, 13, 34, 11}, + }, + { + Alpha: -3, + Ans: []float64{-22, -47, 22, -2, -36, -24}, + }, + { + Alpha: 0, + Ans: []float64{8, -2, 4, 7, 6, -3}, + }, + }, + DdotAns: 110, + DswapAns: DTwoVecAnswer{ + X: []float64{8, -2, 4, 7, 6, -3}, + Y: []float64{10, 15, -6, 3, 14, 7}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{10, 15, -6, 3, 14, 7}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(0), + S: math.Sin(0), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3}, + }, + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{12.444023964292095, 12.749380282068351, -3.7473736752571014, 5.677251193294846, 15.224018588957296, 5.076299724034451}, + YAns: []float64{3.024279678886205, -8.151889500183792, 6.160940718590796, 5.076299724034451, -0.4788089421498931, -5.677251193294846}, + }, + { + C: math.Cos(0.5 * math.Pi), + S: math.Sin(0.5 * math.Pi), + XAns: []float64{8, -2, 4, 7, 6, -3}, + YAns: []float64{-10, -15, 6, -3, -14, -7}, + }, + { + C: math.Cos(math.Pi), + S: math.Sin(math.Pi), + XAns: []float64{-10, -15, 6, -3, -14, -7}, + YAns: []float64{-8, 2, -4, -7, -6, 3}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Identity, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3}, + Name: "Neg2Flag", + }, + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, + YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, + Name: "Neg1Flag", + }, + { + P: blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{1, 0.1, -0.1, 1}, + }, + XAns: []float64{9.2, 15.2, -6.4, 2.3, 13.4, 7.3}, + YAns: []float64{9, -0.5, 3.4, 7.3, 7.4, -2.3}, + Name: "ZeroFlag", + }, + { + P: blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0.5, -1, 1, 0.7}, + }, + XAns: []float64{13, 5.5, 1, 8.5, 13, 0.5}, + YAns: []float64{-4.4, -16.4, 8.8, 1.9, -9.8, -9.1}, + Name: "OneFlag", + }, + }, + }, + { + Name: "UnitaryIncLong", + X: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, + Y: []float64{8, -2, 4, 7, 6, -3, 7, -6}, + XTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 1, + Incy: 1, + N: 6, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 1, + Ans: []float64{18, 13, -2, 10, 20, 4, 7, -6}, + }, + { + Alpha: 2, + Ans: []float64{28, 28, -8, 13, 34, 11, 7, -6}, + }, + { + Alpha: -3, + Ans: []float64{-22, -47, 22, -2, -36, -24, 7, -6}, + }, + { + Alpha: 0, + Ans: []float64{8, -2, 4, 7, 6, -3, 7, -6}, + }, + }, + DdotAns: 110, + DswapAns: DTwoVecAnswer{ + X: []float64{8, -2, 4, 7, 6, -3, 8, -9, 10}, + Y: []float64{10, 15, -6, 3, 14, 7, 7, -6}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, + Y: []float64{10, 15, -6, 3, 14, 7, 7, -6}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(0), + S: math.Sin(0), + XAns: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, + YAns: []float64{8, -2, 4, 7, 6, -3, 7, -6}, + }, + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{12.444023964292095, 12.749380282068351, -3.7473736752571014, 5.677251193294846, 15.224018588957296, 5.076299724034451, 8, -9, 10}, + YAns: []float64{3.024279678886205, -8.151889500183792, 6.160940718590796, 5.076299724034451, -0.4788089421498931, -5.677251193294846, 7, -6}, + }, + { + C: math.Cos(0.5 * math.Pi), + S: math.Sin(0.5 * math.Pi), + XAns: []float64{8, -2, 4, 7, 6, -3, 8, -9, 10}, + YAns: []float64{-10, -15, 6, -3, -14, -7, 7, -6}, + }, + { + C: math.Cos(math.Pi), + S: math.Sin(math.Pi), + XAns: []float64{-10, -15, 6, -3, -14, -7, 8, -9, 10}, + YAns: []float64{-8, 2, -4, -7, -6, 3, 7, -6}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Identity, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{10, 15, -6, 3, 14, 7, 8, -9, 10}, + YAns: []float64{8, -2, 4, 7, 6, -3, 7, -6}, + Name: "Neg2Flag", + }, + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6, 8, -9, 10}, + YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8, 7, -6}, + Name: "Neg1Flag", + }, + { + P: blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{1, 0.1, -0.1, 1}, + }, + XAns: []float64{9.2, 15.2, -6.4, 2.3, 13.4, 7.3, 8, -9, 10}, + YAns: []float64{9, -0.5, 3.4, 7.3, 7.4, -2.3, 7, -6}, + Name: "ZeroFlag", + }, + { + P: blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0.5, -1, 1, 0.7}, + }, + XAns: []float64{13, 5.5, 1, 8.5, 13, 0.5, 8, -9, 10}, + YAns: []float64{-4.4, -16.4, 8.8, 1.9, -9.8, -9.1, 7, -6}, + Name: "OneFlag", + }, + }, + }, + { + Name: "PositiveInc", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 2, + Incy: 3, + N: 3, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{28, -2, 4, -5, 6, -3, 24, 10}, + }, + }, + DdotAns: -18, + DswapAns: DTwoVecAnswer{ + X: []float64{8, 15, 7, 3, -4, 7}, + Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{12.444023964292095, 15, -2.479518890035003, 3, 10.997835971550302, 7}, + YAns: []float64{3.024279678886205, -2, 4, 8.879864079700745, 6, -3, -9.541886812516392, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 15, -6.1, 3, 13, 7}, + YAns: []float64{5, -2, 4, 2.9, 6, -3, -0.6, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{1, 0.1, -0.1, 1}, + }, + XAns: []float64{9.2, 15, -6.7, 3, 14.4, 7}, + YAns: []float64{9, -2, 4, 6.4, 6, -3, -2.6, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0.5, -1, 1, 0.7}, + }, + XAns: []float64{13, 15, 4, 3, 3, 7}, + YAns: []float64{-4.4, -2, 4, 10.9, 6, -3, -16.8, 10}, + }, + }, + }, + { + Name: "NegativeInc", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: -2, + Incy: -3, + N: 3, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{28, -2, 4, -5, 6, -3, 24, 10}, + }, + }, + DdotAns: -18, + DswapAns: DTwoVecAnswer{ + X: []float64{8, 15, 7, 3, -4, 7}, + Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{10, -2, 4, -6, 6, -3, 14, 10}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{12.444023964292095, 15, -2.479518890035003, 3, 10.997835971550302, 7}, + YAns: []float64{3.024279678886205, -2, 4, 8.879864079700745, 6, -3, -9.541886812516392, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 15, -6.1, 3, 13, 7}, + YAns: []float64{5, -2, 4, 2.9, 6, -3, -0.6, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{1, 0.1, -0.1, 1}, + }, + XAns: []float64{9.2, 15, -6.7, 3, 14.4, 7}, + YAns: []float64{9, -2, 4, 6.4, 6, -3, -2.6, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0.5, -1, 1, 0.7}, + }, + XAns: []float64{13, 15, 4, 3, 3, 7}, + YAns: []float64{-4.4, -2, 4, 10.9, 6, -3, -16.8, 10}, + }, + }, + }, + { + Name: "MixedInc1", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 2, + Incy: -3, + N: 3, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DdotAns: 30, + DswapAns: DTwoVecAnswer{ + X: []float64{-4, 15, 7, 3, 8, 7}, + Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{7.372604823403701, 15, -2.479518890035003, 3, 16.069255112438693, 7}, + YAns: []float64{1.333806631923407, -2, 4, 8.879864079700745, 6, -3, -7.851413765553595, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{9.4, 15, -6.1, 3, 11.8, 7}, + YAns: []float64{5.4, -2, 4, 2.9, 6, -3, -1, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{1, 0.1, -0.1, 1}, + }, + XAns: []float64{10.4, 15, -6.7, 3, 13.2, 7}, + YAns: []float64{9.4, -2, 4, 6.4, 6, -3, -3, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0.5, -1, 1, 0.7}, + }, + XAns: []float64{1, 15, 4, 3, 15, 7}, + YAns: []float64{-8.4, -2, 4, 10.9, 6, -3, -12.8, 10}, + }, + }, + }, + { + Name: "MixedInc2", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: -2, + Incy: 3, + N: 3, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DdotAns: 30, + DswapAns: DTwoVecAnswer{ + X: []float64{-4, 15, 7, 3, 8, 7}, + Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{14, -2, 4, -6, 6, -3, 10, 10}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{7.372604823403701, 15, -2.479518890035003, 3, 16.069255112438693, 7}, + YAns: []float64{1.333806631923407, -2, 4, 8.879864079700745, 6, -3, -7.851413765553595, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{9.4, 15, -6.1, 3, 11.8, 7}, + YAns: []float64{5.4, -2, 4, 2.9, 6, -3, -1, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{1, 0.1, -0.1, 1}, + }, + XAns: []float64{10.4, 15, -6.7, 3, 13.2, 7}, + YAns: []float64{9.4, -2, 4, 6.4, 6, -3, -3, 10}, + }, + { + P: blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0.5, -1, 1, 0.7}, + }, + XAns: []float64{1, 15, 4, 3, 15, 7}, + YAns: []float64{-8.4, -2, 4, 10.9, 6, -3, -12.8, 10}, + }, + }, + }, + { + Name: "ZeroN", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: -2, + Incy: 3, + N: 0, + Panic: false, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DswapAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + DcopyAns: DTwoVecAnswer{ + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + }, + { + Name: "NegativeN", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: -2, + Incy: 3, + N: -3, + Panic: true, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, + YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, + }, + }, + }, + { + Name: "ZeroIncX", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 0, + Incy: 3, + N: 2, + Panic: true, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, + YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, + }, + }, + }, + { + Name: "ZeroIncY", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 1, + Incy: 0, + N: 2, + Panic: true, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, + YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, + }, + }, + }, + { + Name: "OutOfBoundsX", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 8, + Incy: 2, + N: 2, + Panic: true, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{8.2, 13.7, -5.8, 2, 12, 6.6}, + YAns: []float64{5, 0.5, 1.4, 3.8, 4.4, -0.8}, + }, + }, + }, + { + Name: "OutOfBoundsY", + X: []float64{10, 15, -6, 3, 14, 7}, + Y: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + XTmp: []float64{0, 0, 0, 0, 0, 0}, + YTmp: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + Incx: 2, + Incy: 8, + N: 2, + Panic: true, + DaxpyCases: []DaxpyCase{ + { + Alpha: 2, + Ans: []float64{36, -2, 4, -5, 6, -3, 16, 10}, + }, + }, + DrotCases: []DrotCase{ + { + C: math.Cos(25 * math.Pi / 180), + S: math.Sin(25 * math.Pi / 180), + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + DrotmCases: []DrotmCase{ + { + P: blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.9, 0.1, -0.1, 0.5}, + }, + XAns: []float64{10, 15, -6, 3, 14, 7}, + YAns: []float64{8, -2, 4, 7, 6, -3, -4, 10}, + }, + }, + }, +} + +type Ddotter interface { + Ddot(n int, x []float64, incX int, y []float64, incY int) float64 +} + +func DdotTest(t *testing.T, d Ddotter) { + ddot := d.Ddot + for _, c := range DoubleTwoVectorCases { + dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) + if c.Panic { + f := func() { ddot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) } + testpanics(f, c.Name, t) + continue + } + dot := ddot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) + if !dTolEqual(dot, c.DdotAns) { + t.Errorf("ddot: mismatch %v: expected %v, found %v", c.Name, c.DdotAns, dot) + } + } + + // check it works for 16-byte unaligned slices + x := []float64{1, 1, 1, 1, 1} + if n := ddot(4, x[:4], 1, x[1:], 1); n != 4 { + t.Errorf("ddot: mismatch Unaligned: expected %v, found %v", 4, n) + } + if n := ddot(2, x[:4], 2, x[1:], 2); n != 2 { + t.Errorf("ddot: mismatch Unaligned: expected %v, found %v", 2, n) + } + if n := ddot(2, x[:4], 3, x[1:], 3); n != 2 { + t.Errorf("ddot: mismatch Unaligned: expected %v, found %v", 2, n) + } +} + +type Dnrm2er interface { + Dnrm2(n int, x []float64, incX int) float64 +} + +func Dnrm2Test(t *testing.T, blasser Dnrm2er) { + dnrm2 := blasser.Dnrm2 + for _, c := range DoubleOneVectorCases { + if c.Panic { + f := func() { dnrm2(c.N, c.X, c.Incx) } + testpanics(f, c.Name, t) + continue + } + v := dnrm2(c.N, c.X, c.Incx) + if !dTolEqual(v, c.Dnrm2) { + t.Errorf("dnrm2: mismatch %v: expected %v, found %v", c.Name, c.Dnrm2, v) + } + } +} + +type Dasumer interface { + Dasum(n int, x []float64, incX int) float64 +} + +func DasumTest(t *testing.T, blasser Dasumer) { + dasum := blasser.Dasum + for _, c := range DoubleOneVectorCases { + if c.Panic { + f := func() { dasum(c.N, c.X, c.Incx) } + testpanics(f, c.Name, t) + continue + } + v := dasum(c.N, c.X, c.Incx) + if !dTolEqual(v, c.Dasum) { + t.Errorf("dasum: mismatch %v: expected %v, found %v", c.Name, c.Dasum, v) + } + } +} + +type Idamaxer interface { + Idamax(n int, x []float64, incX int) int +} + +func IdamaxTest(t *testing.T, blasser Idamaxer) { + idamax := blasser.Idamax + for _, c := range DoubleOneVectorCases { + if c.Panic { + f := func() { idamax(c.N, c.X, c.Incx) } + testpanics(f, c.Name, t) + continue + } + v := idamax(c.N, c.X, c.Incx) + if v != c.Idamax { + t.Errorf("idamax: mismatch %v: expected %v, found %v", c.Name, c.Idamax, v) + } + } +} + +type Dswapper interface { + Dswap(n int, x []float64, incX int, y []float64, incY int) +} + +func DswapTest(t *testing.T, d Dswapper) { + dswap := d.Dswap + for _, c := range DoubleTwoVectorCases { + dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) + if c.Panic { + f := func() { dswap(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) } + testpanics(f, c.Name, t) + continue + } + dswap(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) + if !dSliceTolEqual(c.XTmp, c.DswapAns.X) { + t.Errorf("dswap: x mismatch %v: expected %v, found %v", c.Name, c.DswapAns.X, c.XTmp) + } + if !dSliceTolEqual(c.YTmp, c.DswapAns.Y) { + t.Errorf("dswap: y mismatch %v: expected %v, found %v", c.Name, c.DswapAns.Y, c.YTmp) + } + } +} + +type Dcopier interface { + Dcopy(n int, x []float64, incX int, y []float64, incY int) +} + +func DcopyTest(t *testing.T, d Dcopier) { + dcopy := d.Dcopy + for _, c := range DoubleTwoVectorCases { + dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) + if c.Panic { + f := func() { dcopy(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) } + testpanics(f, c.Name, t) + continue + } + dcopy(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy) + if !dSliceTolEqual(c.XTmp, c.DcopyAns.X) { + t.Errorf("dswap: x mismatch %v: expected %v, found %v", c.Name, c.DcopyAns.X, c.XTmp) + } + if !dSliceTolEqual(c.YTmp, c.DcopyAns.Y) { + t.Errorf("dswap: y mismatch %v: expected %v, found %v", c.Name, c.DcopyAns.Y, c.YTmp) + } + } +} + +type Daxpyer interface { + Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) +} + +func DaxpyTest(t *testing.T, d Daxpyer) { + daxpy := d.Daxpy + for _, c := range DoubleTwoVectorCases { + for _, kind := range c.DaxpyCases { + dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) + if c.Panic { + f := func() { daxpy(c.N, kind.Alpha, c.XTmp, c.Incx, c.YTmp, c.Incy) } + testpanics(f, c.Name, t) + continue + } + daxpy(c.N, kind.Alpha, c.XTmp, c.Incx, c.YTmp, c.Incy) + if !dSliceTolEqual(c.YTmp, kind.Ans) { + t.Errorf("daxpy: mismatch %v: expected %v, found %v", c.Name, kind.Ans, c.YTmp) + } + } + } +} + +type DrotgTestStruct struct { + Name string + A, B float64 + C, S, R, Z float64 +} + +var DrotgTests = []DrotgTestStruct{ + { + Name: "ZeroAB", + C: 1, + }, + { + Name: "PosA_ZeroB", + A: 0.5, + C: 1, + R: 0.5, + }, + { + Name: "NegA_ZeroB", + A: -4.6, + C: 1, + R: -4.6, + }, + { + Name: "ZeroA_PosB", + B: 3, + S: 1, + R: 3, + Z: 1, + }, + { + Name: "ZeroA_NegB", + B: -0.3, + S: 1, + R: -0.3, + Z: 1, + }, + { + Name: "PosA_PosB_AGTB", + A: 5, + B: 0.3, + C: 0.99820484546577868593549038000, + S: 0.05989229072794672115612942280, + R: 5.00899191454727744602429072688, + Z: 0.05989229072794672115612942280, + }, + { + Name: "PosA_PosB_ALTB", + A: 3, + B: 4, + C: 3.0 / 5, + S: 4.0 / 5, + R: 5, + Z: 5.0 / 3.0, + }, + + { + Name: "PosA_NegB_AGTB", + A: 2.6, + B: -0.9, + C: 0.94498607344025815971847507095, + S: -0.32711056388316628605639521686, + R: 2.751363298439520872718790879655, + Z: -0.3271105638831662860563952168, + }, + { + Name: "PosA_NegB_ALTB", + A: 2.6, + B: -2.9, + C: -0.6675450157520258540548049558, + S: 0.7445694406464903756765132200, + R: -3.8948684188300893100043812234, + Z: 1 / -0.6675450157520258540548049558, + }, + { + Name: "NegA_PosB_AGTB", + A: -11.4, + B: 10.3, + C: 0.7419981952497362418487847947, + S: -0.6704018781642353764072353847, + R: -15.363918770938617534070671122, + Z: -0.6704018781642353764072353847, + }, + { + Name: "NegA_PosB_ALTB", + A: -1.4, + B: 10.3, + C: -0.1346838895922121112404717523, + S: 0.9908886162855605326977564640, + R: 10.394710193170370442523552032, + Z: 1 / -0.1346838895922121112404717523, + }, + { + Name: "NegA_NegB_AGTB", + A: -11.4, + B: 10.3, + C: 0.7419981952497362418487847947, + S: -0.6704018781642353764072353847, + R: -15.363918770938617534070671122, + Z: -0.6704018781642353764072353847, + }, + { + Name: "NegA_NegB_ALTB", + A: -1.4, + B: -10.3, + C: 0.1346838895922121112404717523, + S: 0.9908886162855605326977564640, + R: -10.394710193170370442523552032, + Z: 1 / 0.1346838895922121112404717523, + }, +} + +type Drotger interface { + Drotg(a, b float64) (c, s, r, z float64) +} + +func DrotgTest(t *testing.T, d Drotger) { + drotg := d.Drotg + for _, test := range DrotgTests { + c, s, r, z := drotg(test.A, test.B) + if !dTolEqual(c, test.C) { + t.Errorf("drotg: c mismatch %v: expected %v, found %v", test.Name, test.C, c) + } + if !dTolEqual(s, test.S) { + t.Errorf("drotg: s mismatch %v: expected %v, found %v", test.Name, test.S, s) + } + if !dTolEqual(r, test.R) { + t.Errorf("drotg: r mismatch %v: expected %v, found %v", test.Name, test.R, r) + } + if !dTolEqual(z, test.Z) { + t.Errorf("drotg: z mismatch %v: expected %v, found %v", test.Name, test.Z, z) + } + } +} + +type DrotmgTestStruct struct { + Name string + D1, D2, X1, Y1 float64 + P *blas.DrotmParams + Rd1, Rd2, Rx1 float64 +} + +var DrotmgTests = []DrotmgTestStruct{ + { + Name: "NegD1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + }, + D1: -4, + D2: 6, + X1: 8, + Y1: -4, + }, + { + Name: "ZeroD2", + P: &blas.DrotmParams{ + Flag: blas.Identity, + }, + D1: 4, + X1: 8, + Y1: -5, + Rd1: 4, + Rx1: 8, + }, + { + Name: "ZeroY1", + P: &blas.DrotmParams{ + Flag: blas.Identity, + }, + D1: 4, + D2: -6, + X1: 8, + Rd1: 4, + Rd2: -6, + Rx1: 8, + }, + { + Name: "NegQ2_and_AQ1_LT_AQ2", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + }, + D1: 8, + D2: -6, + X1: 4, + Y1: 8, + Rd1: 0, + Rd2: 0, + Rx1: 0, + }, + { + Name: "ZeroD1", + P: &blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{0, 0, 0, 2}, + }, + D1: 0, + D2: 2, + X1: 8, + Y1: 4, + Rd1: 2, + Rd2: 0, + Rx1: 4, + }, + { + Name: "AbsQ1_GT_AbsQU__D2_Pos", + P: &blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{0, -0.625, 0.9375, 0}, + }, + D1: 2, + D2: 3, + X1: 8, + Y1: 5, + Rd1: 1.2610837438423645, + Rd2: 1.8916256157635467, + Rx1: 12.6875, + }, + { + Name: "AbsQ1_GT_AbsQU__D2_Neg", + P: &blas.DrotmParams{ + Flag: blas.OffDiagonal, + H: [4]float64{0, -0.625, -0.9375, 0}, + }, + D1: 2, + D2: -3, + X1: 8, + Y1: 5, + Rd1: 4.830188679245283, + Rd2: -7.245283018867925, + Rx1: 3.3125, + }, + { + Name: "AbsQ1_LT_AbsQU__D2_Pos", + P: &blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{5.0 / 12, 0, 0, 0.625}, + }, + D1: 2, + D2: 3, + X1: 5, + Y1: 8, + Rd1: 2.3801652892561984, + Rd2: 1.586776859504132, + Rx1: 121.0 / 12, + }, + { + Name: "D1=D2_X1=X2", + P: &blas.DrotmParams{ + Flag: blas.Diagonal, + H: [4]float64{1, 0, 0, 1}, + }, + D1: 2, + D2: 2, + X1: 8, + Y1: 8, + Rd1: 1, + Rd2: 1, + Rx1: 16, + }, + { + Name: "RD1_Big_RD2_Big_Flag_0", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{4096, -3584, 1792, 4096}, + }, + D1: 1600000000, + D2: 800000000, + X1: 8, + Y1: 7, + Rd1: 68.96627824858757, + Rd2: 34.483139124293785, + Rx1: 45312, + }, + { + Name: "RD1_Big_RD2_Big_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{2340.5714285714284, -4096, 4096, 4681.142857142857}, + }, + D1: 800000000, + D2: 1600000000, + X1: 8, + Y1: 7, + Rd1: 57.6914092640818, + Rd2: 28.8457046320409, + Rx1: 47396.57142857142, + }, + { + Name: "RD1_Big_RD2_Med_Flag_0", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{4096, -1, 0.0004096, 1}, + }, + D1: 20000000, + D2: 2, + X1: 8, + Y1: 8, + Rd1: 1.1920927762985347, + Rd2: 1.9999998000000199, + Rx1: 32768.0032768, + }, + { + Name: "RD1_Big_RD2_Med_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{4.096e-17, -1, 4096, 1e-10}, + }, + D1: 2, + D2: 20000000000, + X1: 8, + Y1: 80000000000, + Rd1: 1192.0928955078125, + Rd2: 2, + Rx1: 3.2768e+14, + }, + + // TODO: Add D1 big, D2 small, Flag = 0 + { + Name: "D1_Big_D2_Small_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{2.8671999999999997e-26, -0.000244140625, 4096, 2.44140625e-16}, + }, + D1: 0.000000014, + D2: 2000000000, + X1: 0.000008, + Y1: 8000000, + Rd1: 119.20928955078125, + Rd2: 0.234881024, + Rx1: 3.2768e+10, + }, + + { + Name: "RD1_Med_RD2_Big_Flag_0", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{1, -0.0004096, 1000, 4096}, + }, + D1: 2, + D2: 20000000000, + X1: 80000000, + Y1: 8, + Rd1: 1.9998000199980002, + Rd2: 1191.9736981379988, + Rx1: 8.0008e+07, + }, + { + Name: "D1_Med_D2_Big_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{50, -4096, 1, 4.096e-06}, + }, + D1: 20000000000, + D2: 0.4, + X1: 80000000, + Y1: 80000000000000000, + Rd1: 0.39999998000000103, + Rd2: 1192.092835903171, + Rx1: 8.0000004e+16, + }, + { + Name: "RD1_Med_RD2_Small_Flag_0", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{1, -0.0007233796296296296, 1.1111111111111111e-10, 0.000244140625}, + }, + D1: 1.2, + D2: 0.000000000045, + X1: 2.7, + Y1: 8, + Rd1: 1.1999999996049382, + Rd2: 0.0007549747197514486, + Rx1: 2.700000000888889, + }, + { + Name: "RD1_Med_RD2_Small_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.0002197265625, -1, 0.000244140625, 3.375e-11}, + }, + D1: 1.2, + D2: 0.000000000045, + X1: 2.7, + Y1: 80000000000, + Rd1: 0.0007549747199770676, + Rd2: 1.19999999996355, + Rx1: 1.9531250000593264e+07, + }, + // TODO: Add Small, Big, 0 case + { + Name: "D1_Small_D2_Big_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{2.3731773997569866e+10, -1.6777216e+07, 0.000244140625, 1.6777216e-07}, + }, + D1: 120000000000000000, + D2: 0.000000000012345, + X1: 0.08, + Y1: 8000000000000, + Rd1: 0.00010502490698765249, + Rd2: 216.1836123957717, + Rx1: 3.8516669198055897e+09, + }, + { + Name: "RD1_Small_RD2_Med_Flag_0", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.000244140625, -1e-08, 0.24414062499999997, 1}, + }, + D1: 0.0000000002, + D2: 20, + X1: 0.8, + Y1: 0.000000008, + Rd1: 0.003355409645903541, + Rd2: 19.99980000199998, + Rx1: 0.000195314453125, + }, + { + Name: "RD1_Small_RD2_Med_Flag_1", + P: &blas.DrotmParams{ + Flag: blas.Rescaling, + H: [4]float64{0.0012207031250000002, -1, 0.000244140625, 1e-09}, + }, + D1: 0.02, + D2: 0.000000000004, + X1: 0.008, + Y1: 8000000, + Rd1: 6.710886366445568e-05, + Rd2: 0.019999999900000003, + Rx1: 1953.125009765625, + }, + // TODO: Add Small, Small, 0 case + // TODO: Add Small, Small, 1 case +} + +type Drotmger interface { + Drotmg(d1, d2, x1, y1 float64) (p blas.DrotmParams, rd1, rd2, rx1 float64) +} + +func DrotmgTest(t *testing.T, d Drotmger) { + for _, test := range DrotmgTests { + + p, rd1, rd2, rx1 := d.Drotmg(test.D1, test.D2, test.X1, test.Y1) + + if p.Flag != test.P.Flag { + t.Errorf("drotmg flag mismatch %v: expected %v, found %v", test.Name, test.P.Flag, p.Flag) + } + for i, val := range p.H { + if !dTolEqual(test.P.H[i], val) { + t.Errorf("drotmg H mismatch %v: expected %v, found %v", test.Name, test.P.H, p.H) + break + } + } + if !dTolEqual(rd1, test.Rd1) { + t.Errorf("drotmg rd1 mismatch %v: expected %v, found %v", test.Name, test.Rd1, rd1) + } + if !dTolEqual(rd2, test.Rd2) { + t.Errorf("drotmg rd2 mismatch %v: expected %v, found %v", test.Name, test.Rd2, rd2) + } + if !dTolEqual(rx1, test.Rx1) { + t.Errorf("drotmg rx1 mismatch %v: expected %v, found %v", test.Name, test.Rx1, rx1) + } + } +} + +type Droter interface { + Drot(n int, x []float64, incX int, y []float64, incY int, c, s float64) +} + +func DrotTest(t *testing.T, d Droter) { + drot := d.Drot + for _, c := range DoubleTwoVectorCases { + for _, kind := range c.DrotCases { + dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) + if c.Panic { + f := func() { drot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.C, kind.S) } + testpanics(f, c.Name, t) + continue + } + drot(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.C, kind.S) + if !dSliceTolEqual(c.XTmp, kind.XAns) { + t.Errorf("drot: x mismatch %v: expected %v, found %v", c.Name, kind.XAns, c.XTmp) + } + if !dSliceTolEqual(c.YTmp, kind.YAns) { + t.Errorf("drot: y mismatch %v: expected %v, found %v", c.Name, kind.YAns, c.YTmp) + } + } + } +} + +type Drotmer interface { + Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) +} + +func DrotmTest(t *testing.T, d Drotmer) { + drotm := d.Drotm + for _, c := range DoubleTwoVectorCases { + for _, kind := range c.DrotmCases { + dCopyTwoTmp(c.X, c.XTmp, c.Y, c.YTmp) + if c.Panic { + f := func() { drotm(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.P) } + testpanics(f, c.Name+", "+kind.Name, t) + continue + } + drotm(c.N, c.XTmp, c.Incx, c.YTmp, c.Incy, kind.P) + if !dSliceTolEqual(c.XTmp, kind.XAns) { + t.Errorf("drotm: mismatch %v: expected %v, found %v", c.Name, kind.XAns, c.XTmp) + } + if !dSliceTolEqual(c.YTmp, kind.YAns) { + t.Errorf("drotm: mismatch %v: expected %v, found %v", c.Name, kind.YAns, c.YTmp) + } + } + } +} + +type Dscaler interface { + Dscal(n int, alpha float64, x []float64, incX int) +} + +func DscalTest(t *testing.T, blasser Dscaler) { + dscal := blasser.Dscal + for _, c := range DoubleOneVectorCases { + for _, kind := range c.DscalCases { + xTmp := make([]float64, len(c.X)) + copy(xTmp, c.X) + if c.Panic { + f := func() { dscal(c.N, kind.Alpha, xTmp, c.Incx) } + testpanics(f, c.Name, t) + continue + } + dscal(c.N, kind.Alpha, xTmp, c.Incx) + if !dSliceTolEqual(xTmp, kind.Ans) { + t.Errorf("dscal: mismatch %v, %v: expected %v, found %v", c.Name, kind.Name, kind.Ans, xTmp) + } + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/level2bench.go b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/level2bench.go new file mode 100644 index 0000000..b1d29cc --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/blas/testblas/level2bench.go @@ -0,0 +1,60 @@ +package testblas + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas" +) + +func DgemvBenchmark(b *testing.B, blasser Dgemver, tA blas.Transpose, m, n, incX, incY int) { + var lenX, lenY int + if tA == blas.NoTrans { + lenX = n + lenY = m + } else { + lenX = m + lenY = n + } + xr := make([]float64, lenX) + for i := range xr { + xr[i] = rand.Float64() + } + x := makeIncremented(xr, incX, 0) + yr := make([]float64, lenY) + for i := range yr { + yr[i] = rand.Float64() + } + y := makeIncremented(yr, incY, 0) + a := make([]float64, m*n) + for i := range a { + a[i] = rand.Float64() + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + blasser.Dgemv(tA, m, n, 2, a, n, x, incX, 3, y, incY) + } +} + +func DgerBenchmark(b *testing.B, blasser Dgerer, m, n, incX, incY int) { + xr := make([]float64, m) + for i := range xr { + xr[i] = rand.Float64() + } + x := makeIncremented(xr, incX, 0) + yr := make([]float64, n) + for i := range yr { + yr[i] = rand.Float64() + } + y := makeIncremented(yr, incY, 0) + a := make([]float64, m*n) + for i := range a { + a[i] = rand.Float64() + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + blasser.Dger(m, n, 2, x, incX, y, incY, a, n) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy.go b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy.go new file mode 100644 index 0000000..79fe9a7 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy.go @@ -0,0 +1,22 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//+build !amd64 noasm + +package asm + +// The extra z parameter is needed because of floats.AddScaledTo +func DaxpyUnitary(alpha float64, x, y, z []float64) { + for i, v := range x { + z[i] = alpha * v + y[i] + } +} + +func DaxpyInc(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) { + for i := 0; i < int(n); i++ { + y[iy] += alpha * x[ix] + ix += incX + iy += incY + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy_amd64.go b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy_amd64.go new file mode 100644 index 0000000..d1aeacf --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy_amd64.go @@ -0,0 +1,12 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//+build !noasm + +package asm + +// The extra z parameter is needed because of floats.AddScaledTo +func DaxpyUnitary(alpha float64, x, y, z []float64) + +func DaxpyInc(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy_amd64.s b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy_amd64.s new file mode 100644 index 0000000..18f2d3c --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/daxpy_amd64.s @@ -0,0 +1,140 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// +// Some of the loop unrolling code is copied from: +// http://golang.org/src/math/big/arith_amd64.s +// which is distributed under these terms: +// +// Copyright (c) 2012 The Go Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +//+build !noasm + +// TODO(fhs): use textflag.h after we drop Go 1.3 support +//#include "textflag.h" +// Don't insert stack check preamble. +#define NOSPLIT 4 + + +// func DaxpyUnitary(alpha float64, x, y, z []float64) +// This function assumes len(y) >= len(x). +TEXT ·DaxpyUnitary(SB),NOSPLIT,$0 + MOVHPD alpha+0(FP), X7 + MOVLPD alpha+0(FP), X7 + MOVQ x_len+16(FP), DI // n = len(x) + MOVQ x+8(FP), R8 + MOVQ y+32(FP), R9 + MOVQ z+56(FP), R10 + + MOVQ $0, SI // i = 0 + SUBQ $2, DI // n -= 2 + JL V1 // if n < 0 goto V1 + +U1: // n >= 0 + // y[i] += alpha * x[i] unrolled 2x. + MOVUPD 0(R8)(SI*8), X0 + MOVUPD 0(R9)(SI*8), X1 + MULPD X7, X0 + ADDPD X0, X1 + MOVUPD X1, 0(R10)(SI*8) + + ADDQ $2, SI // i += 2 + SUBQ $2, DI // n -= 2 + JGE U1 // if n >= 0 goto U1 + +V1: + ADDQ $2, DI // n += 2 + JLE E1 // if n <= 0 goto E1 + + // y[i] += alpha * x[i] for last iteration if n is odd. + MOVSD 0(R8)(SI*8), X0 + MOVSD 0(R9)(SI*8), X1 + MULSD X7, X0 + ADDSD X0, X1 + MOVSD X1, 0(R10)(SI*8) + +E1: + RET + + +// func DaxpyInc(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) +TEXT ·DaxpyInc(SB),NOSPLIT,$0 + MOVHPD alpha+0(FP), X7 + MOVLPD alpha+0(FP), X7 + MOVQ x+8(FP), R8 + MOVQ y+32(FP), R9 + MOVQ n+56(FP), CX + MOVQ incX+64(FP), R11 + MOVQ incY+72(FP), R12 + MOVQ ix+80(FP), SI + MOVQ iy+88(FP), DI + + MOVQ SI, AX // nextX = ix + MOVQ DI, BX // nextY = iy + ADDQ R11, AX // nextX += incX + ADDQ R12, BX // nextY += incX + SHLQ $1, R11 // indX *= 2 + SHLQ $1, R12 // indY *= 2 + + SUBQ $2, CX // n -= 2 + JL V2 // if n < 0 goto V2 + +U2: // n >= 0 + // y[i] += alpha * x[i] unrolled 2x. + MOVHPD 0(R8)(SI*8), X0 + MOVHPD 0(R9)(DI*8), X1 + MOVLPD 0(R8)(AX*8), X0 + MOVLPD 0(R9)(BX*8), X1 + + MULPD X7, X0 + ADDPD X0, X1 + MOVHPD X1, 0(R9)(DI*8) + MOVLPD X1, 0(R9)(BX*8) + + ADDQ R11, SI // ix += incX + ADDQ R12, DI // iy += incY + ADDQ R11, AX // nextX += incX + ADDQ R12, BX // nextY += incY + + SUBQ $2, CX // n -= 2 + JGE U2 // if n >= 0 goto U2 + +V2: + ADDQ $2, CX // n += 2 + JLE E2 // if n <= 0 goto E2 + + // y[i] += alpha * x[i] for the last iteration if n is odd. + MOVSD 0(R8)(SI*8), X0 + MOVSD 0(R9)(DI*8), X1 + MULSD X7, X0 + ADDSD X0, X1 + MOVSD X1, 0(R9)(DI*8) + +E2: + RET diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot.go b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot.go new file mode 100644 index 0000000..3929a7e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot.go @@ -0,0 +1,23 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//+build !amd64 noasm + +package asm + +func DdotUnitary(x []float64, y []float64) (sum float64) { + for i, v := range x { + sum += y[i] * v + } + return +} + +func DdotInc(x, y []float64, n, incX, incY, ix, iy uintptr) (sum float64) { + for i := 0; i < int(n); i++ { + sum += y[iy] * x[ix] + ix += incX + iy += incY + } + return +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot_amd64.go b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot_amd64.go new file mode 100644 index 0000000..7fa634a --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot_amd64.go @@ -0,0 +1,10 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//+build !noasm + +package asm + +func DdotUnitary(x, y []float64) (sum float64) +func DdotInc(x, y []float64, n, incX, incY, ix, iy uintptr) (sum float64) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot_amd64.s b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot_amd64.s new file mode 100644 index 0000000..a898bbb --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/internal/asm/ddot_amd64.s @@ -0,0 +1,140 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// +// Some of the loop unrolling code is copied from: +// http://golang.org/src/math/big/arith_amd64.s +// which is distributed under these terms: +// +// Copyright (c) 2012 The Go Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +//+build !noasm + +// TODO(fhs): use textflag.h after we drop Go 1.3 support +//#include "textflag.h" +// Don't insert stack check preamble. +#define NOSPLIT 4 + + +// func DdotUnitary(x, y []float64) (sum float64) +// This function assumes len(y) >= len(x). +TEXT ·DdotUnitary(SB),NOSPLIT,$0 + MOVQ x_len+8(FP), DI // n = len(x) + MOVQ x+0(FP), R8 + MOVQ y+24(FP), R9 + + MOVQ $0, SI // i = 0 + MOVSD $(0.0), X7 // sum = 0 + + SUBQ $2, DI // n -= 2 + JL V1 // if n < 0 goto V1 + +U1: // n >= 0 + // sum += x[i] * y[i] unrolled 2x. + MOVUPD 0(R8)(SI*8), X0 + MOVUPD 0(R9)(SI*8), X1 + MULPD X1, X0 + ADDPD X0, X7 + + ADDQ $2, SI // i += 2 + SUBQ $2, DI // n -= 2 + JGE U1 // if n >= 0 goto U1 + +V1: // n > 0 + ADDQ $2, DI // n += 2 + JLE E1 // if n <= 0 goto E1 + + // sum += x[i] * y[i] for last iteration if n is odd. + MOVSD 0(R8)(SI*8), X0 + MOVSD 0(R9)(SI*8), X1 + MULSD X1, X0 + ADDSD X0, X7 + +E1: + // Add the two sums together. + MOVSD X7, X0 + UNPCKHPD X7, X7 + ADDSD X0, X7 + MOVSD X7, sum+48(FP) // return final sum + RET + + +// func DdotInc(x, y []float64, n, incX, incY, ix, iy uintptr) (sum float64) +TEXT ·DdotInc(SB),NOSPLIT,$0 + MOVQ x+0(FP), R8 + MOVQ y+24(FP), R9 + MOVQ n+48(FP), CX + MOVQ incX+56(FP), R11 + MOVQ incY+64(FP), R12 + MOVQ ix+72(FP), R13 + MOVQ iy+80(FP), R14 + + MOVSD $(0.0), X7 // sum = 0 + LEAQ (R8)(R13*8), SI // p = &x[ix] + LEAQ (R9)(R14*8), DI // q = &y[ix] + SHLQ $3, R11 // incX *= sizeof(float64) + SHLQ $3, R12 // indY *= sizeof(float64) + + SUBQ $2, CX // n -= 2 + JL V2 // if n < 0 goto V2 + +U2: // n >= 0 + // sum += *p * *q unrolled 2x. + MOVHPD (SI), X0 + MOVHPD (DI), X1 + ADDQ R11, SI // p += incX + ADDQ R12, DI // q += incY + MOVLPD (SI), X0 + MOVLPD (DI), X1 + ADDQ R11, SI // p += incX + ADDQ R12, DI // q += incY + + MULPD X1, X0 + ADDPD X0, X7 + + SUBQ $2, CX // n -= 2 + JGE U2 // if n >= 0 goto U2 + +V2: + ADDQ $2, CX // n += 2 + JLE E2 // if n <= 0 goto E2 + + // sum += *p * *q for the last iteration if n is odd. + MOVSD (SI), X0 + MULSD (DI), X0 + ADDSD X0, X7 + +E2: + // Add the two sums together. + MOVSD X7, X0 + UNPCKHPD X7, X7 + ADDSD X0, X7 + MOVSD X7, sum+88(FP) // return final sum + RET + \ No newline at end of file diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/bench_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/bench_test.go new file mode 100644 index 0000000..4a91a0e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/bench_test.go @@ -0,0 +1,10 @@ +package mat64 + +import "github.com/gonum/blas/testblas" + +const ( + Sm = testblas.SmallMat + Med = testblas.MediumMat + Lg = testblas.LargeMat + Huge = testblas.HugeMat +) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cblas_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cblas_test.go new file mode 100644 index 0000000..fd4ad03 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cblas_test.go @@ -0,0 +1,16 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//+build cblas + +package mat64 + +import ( + "github.com/gonum/blas/blas64" + "github.com/gonum/blas/cgo" +) + +func init() { + blas64.Use(cgo.Implementation{}) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cholesky.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cholesky.go new file mode 100644 index 0000000..3715ea8 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cholesky.go @@ -0,0 +1,90 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// Based on the CholeskyDecomposition class from Jama 1.0.3. + +package mat64 + +import ( + "math" +) + +type CholeskyFactor struct { + L *Dense + SPD bool +} + +// CholeskyL returns the left Cholesky decomposition of the matrix a and whether +// the matrix is symmetric and positive definite. The returned matrix l is a lower +// triangular matrix such that a = l.l'. +func Cholesky(a *Dense) CholeskyFactor { + // Initialize. + m, n := a.Dims() + spd := m == n + l := NewDense(n, n, nil) + + // Main loop. + for j := 0; j < n; j++ { + lRowj := l.RawRowView(j) + var d float64 + for k := 0; k < j; k++ { + var s float64 + for i, v := range l.RawRowView(k)[:k] { + s += v * lRowj[i] + } + s = (a.at(j, k) - s) / l.at(k, k) + lRowj[k] = s + d += s * s + spd = spd && a.at(k, j) == a.at(j, k) + } + d = a.at(j, j) - d + spd = spd && d > 0 + l.set(j, j, math.Sqrt(math.Max(d, 0))) + for k := j + 1; k < n; k++ { + l.set(j, k, 0) + } + } + + return CholeskyFactor{L: l, SPD: spd} +} + +// CholeskySolve returns a matrix x that solves a.x = b where a = l.l'. The matrix b must +// have the same number of rows as a, and a must be symmetric and positive definite. The +// matrix b is overwritten by the operation. +func (f CholeskyFactor) Solve(b *Dense) (x *Dense) { + if !f.SPD { + panic("mat64: matrix not symmetric positive definite") + } + l := f.L + + m, n := l.Dims() + bm, bn := b.Dims() + if m != bm { + panic(ErrShape) + } + + nx := bn + x = b + + // Solve L*Y = B; + for k := 0; k < n; k++ { + for j := 0; j < nx; j++ { + for i := 0; i < k; i++ { + x.set(k, j, x.at(k, j)-x.at(i, j)*l.at(k, i)) + } + x.set(k, j, x.at(k, j)/l.at(k, k)) + } + } + + // Solve L'*X = Y; + for k := n - 1; k >= 0; k-- { + for j := 0; j < nx; j++ { + for i := k + 1; i < n; i++ { + x.set(k, j, x.at(k, j)-x.at(i, j)*l.at(i, k)) + } + x.set(k, j, x.at(k, j)/l.at(k, k)) + } + } + + return x +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cholesky_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cholesky_test.go new file mode 100644 index 0000000..5096f6d --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/cholesky_test.go @@ -0,0 +1,61 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "gopkg.in/check.v1" +) + +func (s *S) TestCholesky(c *check.C) { + for _, t := range []struct { + a *Dense + spd bool + }{ + { + a: NewDense(3, 3, []float64{ + 4, 1, 1, + 1, 2, 3, + 1, 3, 6, + }), + + spd: true, + }, + } { + cf := Cholesky(t.a) + c.Check(cf.SPD, check.Equals, t.spd) + + lt := &Dense{} + lt.TCopy(cf.L) + lc := DenseCopyOf(cf.L) + + lc.Mul(lc, lt) + c.Check(lc.EqualsApprox(t.a, 1e-12), check.Equals, true) + + x := cf.Solve(eye()) + + t.a.Mul(t.a, x) + c.Check(t.a.EqualsApprox(eye(), 1e-12), check.Equals, true) + } +} + +func (s *S) TestCholeskySolve(c *check.C) { + for _, t := range []struct { + a *Dense + b *Dense + ans *Dense + }{ + { + a: NewDense(2, 2, []float64{ + 1, 0, + 0, 1, + }), + b: NewDense(2, 1, []float64{5, 6}), + ans: NewDense(2, 1, []float64{5, 6}), + }, + } { + ans := Cholesky(t.a).Solve(t.b) + c.Check(ans.EqualsApprox(t.ans, 1e-12), check.Equals, true) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense.go new file mode 100644 index 0000000..c5f32f9 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense.go @@ -0,0 +1,601 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "bytes" + "encoding/binary" + + "github.com/gonum/blas/blas64" +) + +var ( + matrix *Dense + + _ Matrix = matrix + _ Mutable = matrix + _ Vectorer = matrix + _ VectorSetter = matrix + + _ Cloner = matrix + _ Viewer = matrix + _ RowViewer = matrix + _ ColViewer = matrix + _ RawRowViewer = matrix + _ Grower = matrix + + _ Adder = matrix + _ Suber = matrix + _ Muler = matrix + _ Dotter = matrix + _ ElemMuler = matrix + _ ElemDiver = matrix + _ Exper = matrix + + _ Scaler = matrix + _ Applyer = matrix + + _ TransposeCopier = matrix + // _ TransposeViewer = matrix + + _ Tracer = matrix + _ Normer = matrix + _ Sumer = matrix + + _ Uer = matrix + _ Ler = matrix + + _ Stacker = matrix + _ Augmenter = matrix + + _ Equaler = matrix + _ ApproxEqualer = matrix + + _ RawMatrixSetter = matrix + _ RawMatrixer = matrix + + _ Reseter = matrix +) + +type Dense struct { + mat blas64.General + + capRows, capCols int +} + +// NewDense initializes and returns a *Dense of size r-by-c. +// Data stores in mat should be row-major, i.e., the (i, j) element +// in matrix should be at (i*c + j)-th position in mat. +// Note that NewDense(0, 0, nil) can be used for undetermined size +// matrix initialization. +func NewDense(r, c int, mat []float64) *Dense { + if mat != nil && r*c != len(mat) { + panic(ErrShape) + } + if mat == nil { + mat = make([]float64, r*c) + } + return &Dense{ + mat: blas64.General{ + Rows: r, + Cols: c, + Stride: c, + Data: mat, + }, + capRows: r, + capCols: c, + } +} + +// DenseCopyOf returns a newly allocated copy of the elements of a. +func DenseCopyOf(a Matrix) *Dense { + d := &Dense{} + d.Clone(a) + return d +} + +func (m *Dense) SetRawMatrix(b blas64.General) { + m.capRows, m.capCols = b.Rows, b.Cols + m.mat = b +} + +func (m *Dense) RawMatrix() blas64.General { return m.mat } + +func (m *Dense) isZero() bool { + // It must be the case that m.Dims() returns + // zeros in this case. See comment in Reset(). + return m.mat.Stride == 0 +} + +// Dims returns number of rows and number of columns. +func (m *Dense) Dims() (r, c int) { return m.mat.Rows, m.mat.Cols } + +func (m *Dense) Caps() (r, c int) { return m.capRows, m.capCols } + +func (m *Dense) Col(dst []float64, j int) []float64 { + if j >= m.mat.Cols || j < 0 { + panic(ErrColAccess) + } + + if dst == nil { + dst = make([]float64, m.mat.Rows) + } + dst = dst[:min(len(dst), m.mat.Rows)] + blas64.Copy(len(dst), + blas64.Vector{Inc: m.mat.Stride, Data: m.mat.Data[j:]}, + blas64.Vector{Inc: 1, Data: dst}, + ) + + return dst +} + +func (m *Dense) ColView(j int) *Vector { + if j >= m.mat.Cols || j < 0 { + panic(ErrColAccess) + } + return &Vector{ + mat: blas64.Vector{ + Inc: m.mat.Stride, + Data: m.mat.Data[j : m.mat.Rows*m.mat.Stride+j], + }, + n: m.mat.Rows, + } +} + +func (m *Dense) SetCol(j int, src []float64) int { + if j >= m.mat.Cols || j < 0 { + panic(ErrColAccess) + } + + blas64.Copy(min(len(src), m.mat.Rows), + blas64.Vector{Inc: 1, Data: src}, + blas64.Vector{Inc: m.mat.Stride, Data: m.mat.Data[j:]}, + ) + + return min(len(src), m.mat.Rows) +} + +// Row will copy the i-th row into dst and return it. If +// dst is nil, it will make a new slice for copying/returning. +func (m *Dense) Row(dst []float64, i int) []float64 { + if i >= m.mat.Rows || i < 0 { + panic(ErrRowAccess) + } + + if dst == nil { + dst = make([]float64, m.mat.Cols) + } + copy(dst, m.rowView(i)) + + return dst +} + +func (m *Dense) SetRow(i int, src []float64) int { + if i >= m.mat.Rows || i < 0 { + panic(ErrRowAccess) + } + + copy(m.rowView(i), src) + + return min(len(src), m.mat.Cols) +} + +func (m *Dense) RowView(i int) *Vector { + if i >= m.mat.Rows || i < 0 { + panic(ErrRowAccess) + } + return &Vector{ + mat: blas64.Vector{ + Inc: 1, + Data: m.mat.Data[i*m.mat.Stride : i*m.mat.Stride+m.mat.Cols], + }, + n: m.mat.Cols, + } +} + +func (m *Dense) RawRowView(i int) []float64 { + if i >= m.mat.Rows || i < 0 { + panic(ErrRowAccess) + } + return m.rowView(i) +} + +func (m *Dense) rowView(r int) []float64 { + return m.mat.Data[r*m.mat.Stride : r*m.mat.Stride+m.mat.Cols] +} + +func (m *Dense) View(i, j, r, c int) Matrix { + mr, mc := m.Dims() + if i < 0 || i >= mr || j < 0 || j >= mc || r <= 0 || i+r > mr || c <= 0 || j+c > mc { + panic(ErrIndexOutOfRange) + } + t := *m + t.mat.Data = t.mat.Data[i*t.mat.Stride+j : (i+r-1)*t.mat.Stride+(j+c)] + t.mat.Rows = r + t.mat.Cols = c + t.capRows -= i + t.capCols -= j + return &t +} + +func (m *Dense) Grow(r, c int) Matrix { + if r < 0 || c < 0 { + panic(ErrIndexOutOfRange) + } + if r == 0 && c == 0 { + return m + } + + r += m.mat.Rows + c += m.mat.Cols + + var t Dense + switch { + case m.mat.Rows == 0 || m.mat.Cols == 0: + t.mat = blas64.General{ + Rows: r, + Cols: c, + Stride: c, + // We zero because we don't know how the matrix will be used. + // In other places, the mat is immediately filled with a result; + // this is not the case here. + Data: useZeroed(m.mat.Data, r*c), + } + case r > m.capRows || c > m.capCols: + cr := max(r, m.capRows) + cc := max(c, m.capCols) + t.mat = blas64.General{ + Rows: r, + Cols: c, + Stride: cc, + Data: make([]float64, cr*cc), + } + t.capRows = cr + t.capCols = cc + // Copy the complete matrix over to the new matrix. + // Including elements not currently visible. + r, c, m.mat.Rows, m.mat.Cols = m.mat.Rows, m.mat.Cols, m.capRows, m.capCols + t.Copy(m) + m.mat.Rows, m.mat.Cols = r, c + return &t + default: + t.mat = blas64.General{ + Data: m.mat.Data[:(r-1)*m.mat.Stride+c], + Rows: r, + Cols: c, + Stride: m.mat.Stride, + } + } + t.capRows = r + t.capCols = c + return &t +} + +func (m *Dense) Reset() { + // No change of Stride, Rows and Cols to 0 + // may be made unless all are set to 0. + m.mat.Rows, m.mat.Cols, m.mat.Stride = 0, 0, 0 + m.capRows, m.capCols = 0, 0 + m.mat.Data = m.mat.Data[:0] +} + +func (m *Dense) Clone(a Matrix) { + r, c := a.Dims() + mat := blas64.General{ + Rows: r, + Cols: c, + Stride: c, + } + m.capRows, m.capCols = r, c + switch a := a.(type) { + case RawMatrixer: + amat := a.RawMatrix() + mat.Data = make([]float64, r*c) + for i := 0; i < r; i++ { + copy(mat.Data[i*c:(i+1)*c], amat.Data[i*amat.Stride:i*amat.Stride+c]) + } + case Vectorer: + mat.Data = use(m.mat.Data, r*c) + for i := 0; i < r; i++ { + a.Row(mat.Data[i*c:(i+1)*c], i) + } + default: + mat.Data = use(m.mat.Data, r*c) + m.mat = mat + for i := 0; i < r; i++ { + for j := 0; j < c; j++ { + m.set(i, j, a.At(i, j)) + } + } + return + } + m.mat = mat +} + +func (m *Dense) Copy(a Matrix) (r, c int) { + r, c = a.Dims() + r = min(r, m.mat.Rows) + c = min(c, m.mat.Cols) + + switch a := a.(type) { + case RawMatrixer: + amat := a.RawMatrix() + for i := 0; i < r; i++ { + copy(m.mat.Data[i*m.mat.Stride:i*m.mat.Stride+c], amat.Data[i*amat.Stride:i*amat.Stride+c]) + } + case Vectorer: + for i := 0; i < r; i++ { + a.Row(m.mat.Data[i*m.mat.Stride:i*m.mat.Stride+c], i) + } + default: + for i := 0; i < r; i++ { + for j := 0; j < c; j++ { + m.set(r, c, a.At(r, c)) + } + } + } + + return r, c +} + +func (m *Dense) U(a Matrix) { + ar, ac := a.Dims() + if ar != ac { + panic(ErrSquare) + } + + switch { + case m == a: + m.zeroLower() + return + case m.isZero(): + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + case ar != m.mat.Rows || ac != m.mat.Cols: + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + amat := a.RawMatrix() + copy(m.mat.Data[:ac], amat.Data[:ac]) + for j, ja, jm := 1, amat.Stride, m.mat.Stride; ja < ar*amat.Stride; j, ja, jm = j+1, ja+amat.Stride, jm+m.mat.Stride { + zero(m.mat.Data[jm : jm+j]) + copy(m.mat.Data[jm+j:jm+ac], amat.Data[ja+j:ja+ac]) + } + return + } + + if a, ok := a.(Vectorer); ok { + row := make([]float64, ac) + copy(m.mat.Data[:m.mat.Cols], a.Row(row, 0)) + for r := 1; r < ar; r++ { + zero(m.mat.Data[r*m.mat.Stride : r*(m.mat.Stride+1)]) + copy(m.mat.Data[r*(m.mat.Stride+1):r*m.mat.Stride+m.mat.Cols], a.Row(row, r)) + } + return + } + + m.zeroLower() + for r := 0; r < ar; r++ { + for c := r; c < ac; c++ { + m.set(r, c, a.At(r, c)) + } + } +} + +func (m *Dense) zeroLower() { + for i := 1; i < m.mat.Rows; i++ { + zero(m.mat.Data[i*m.mat.Stride : i*m.mat.Stride+i]) + } +} + +func (m *Dense) L(a Matrix) { + ar, ac := a.Dims() + if ar != ac { + panic(ErrSquare) + } + + switch { + case m == a: + m.zeroUpper() + return + case m.isZero(): + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + case ar != m.mat.Rows || ac != m.mat.Cols: + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + amat := a.RawMatrix() + copy(m.mat.Data[:ar], amat.Data[:ar]) + for j, ja, jm := 1, amat.Stride, m.mat.Stride; ja < ac*amat.Stride; j, ja, jm = j+1, ja+amat.Stride, jm+m.mat.Stride { + zero(m.mat.Data[jm : jm+j]) + copy(m.mat.Data[jm+j:jm+ar], amat.Data[ja+j:ja+ar]) + } + return + } + + if a, ok := a.(Vectorer); ok { + row := make([]float64, ac) + for r := 0; r < ar; r++ { + a.Row(row[:r+1], r) + m.SetRow(r, row) + } + return + } + + m.zeroUpper() + for c := 0; c < ac; c++ { + for r := c; r < ar; r++ { + m.set(r, c, a.At(r, c)) + } + } +} + +func (m *Dense) zeroUpper() { + for i := 0; i < m.mat.Rows-1; i++ { + zero(m.mat.Data[i*m.mat.Stride+i+1 : (i+1)*m.mat.Stride]) + } +} + +// TCopy will copy the transpose of a and save it into m. +func (m *Dense) TCopy(a Matrix) { + ar, ac := a.Dims() + + var w Dense + if m != a { + w = *m + } + if w.isZero() { + w.mat = blas64.General{ + Rows: ac, + Cols: ar, + Data: use(w.mat.Data, ar*ac), + } + w.mat.Stride = ar + } else if ar != m.mat.Cols || ac != m.mat.Rows { + panic(ErrShape) + } + switch a := a.(type) { + case *Dense: + for i := 0; i < ac; i++ { + for j := 0; j < ar; j++ { + w.set(i, j, a.at(j, i)) + } + } + default: + for i := 0; i < ac; i++ { + for j := 0; j < ar; j++ { + w.set(i, j, a.At(j, i)) + } + } + } + *m = w +} + +func (m *Dense) Stack(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + if ac != bc || m == a || m == b { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar + br, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, (ar+br)*ac), + } + } else if ar+br != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + m.Copy(a) + w := m.View(ar, 0, br, bc).(*Dense) + w.Copy(b) +} + +func (m *Dense) Augment(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + if ar != br || m == a || m == b { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac + bc, + Stride: ac + bc, + Data: use(m.mat.Data, ar*(ac+bc)), + } + } else if ar != m.mat.Rows || ac+bc != m.mat.Cols { + panic(ErrShape) + } + + m.Copy(a) + w := m.View(0, ac, br, bc).(*Dense) + w.Copy(b) +} + +// MarshalBinary encodes the receiver into a binary form and returns the result. +// +// Dense is little-endian encoded as follows: +// 0 - 8 number of rows (int64) +// 8 - 16 number of columns (int64) +// 16 - .. matrix data elements (float64) +// [0,0] [0,1] ... [0,ncols-1] +// [1,0] [1,1] ... [1,ncols-1] +// ... +// [nrows-1,0] ... [nrows-1,ncols-1] +func (m Dense) MarshalBinary() ([]byte, error) { + buf := bytes.NewBuffer(make([]byte, 0, m.mat.Rows*m.mat.Cols*sizeFloat64+2*sizeInt64)) + err := binary.Write(buf, defaultEndian, int64(m.mat.Rows)) + if err != nil { + return nil, err + } + err = binary.Write(buf, defaultEndian, int64(m.mat.Cols)) + if err != nil { + return nil, err + } + + for i := 0; i < m.mat.Rows; i++ { + for _, v := range m.rowView(i) { + err = binary.Write(buf, defaultEndian, v) + if err != nil { + return nil, err + } + } + } + return buf.Bytes(), err +} + +// UnmarshalBinary decodes the binary form into the receiver. +// It panics if the receiver is a non-zero Dense matrix. +// +// See MarshalBinary for the on-disk layout. +func (m *Dense) UnmarshalBinary(data []byte) error { + if !m.isZero() { + panic("mat64: unmarshal into non-zero matrix") + } + + buf := bytes.NewReader(data) + var rows int64 + err := binary.Read(buf, defaultEndian, &rows) + if err != nil { + return err + } + var cols int64 + err = binary.Read(buf, defaultEndian, &cols) + if err != nil { + return err + } + + m.mat.Rows = int(rows) + m.mat.Cols = int(cols) + m.mat.Stride = int(cols) + m.capRows = int(rows) + m.capCols = int(cols) + m.mat.Data = use(m.mat.Data, m.mat.Rows*m.mat.Cols) + + for i := range m.mat.Data { + err = binary.Read(buf, defaultEndian, &m.mat.Data[i]) + if err != nil { + return err + } + } + + return err +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense_arithmetic.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense_arithmetic.go new file mode 100644 index 0000000..fb00741 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense_arithmetic.go @@ -0,0 +1,954 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" +) + +func (m *Dense) Min() float64 { + min := m.mat.Data[0] + for k := 0; k < m.mat.Rows; k++ { + for _, v := range m.rowView(k) { + min = math.Min(min, v) + } + } + return min +} + +func (m *Dense) Max() float64 { + max := m.mat.Data[0] + for k := 0; k < m.mat.Rows; k++ { + for _, v := range m.rowView(k) { + max = math.Max(max, v) + } + } + return max +} + +func (m *Dense) Trace() float64 { + if m.mat.Rows != m.mat.Cols { + panic(ErrSquare) + } + var t float64 + for i := 0; i < len(m.mat.Data); i += m.mat.Stride + 1 { + t += m.mat.Data[i] + } + return t +} + +var inf = math.Inf(1) + +const ( + epsilon = 2.2204e-16 + small = math.SmallestNonzeroFloat64 +) + +// Norm calculates general matrix p-norm of m. It currently supports +// p = 1, -1, +Inf, -Inf, 2, -2. +func (m *Dense) Norm(ord float64) float64 { + var n float64 + switch { + case ord == 1: + col := make([]float64, m.mat.Rows) + for i := 0; i < m.mat.Cols; i++ { + var s float64 + for _, e := range m.Col(col, i) { + s += math.Abs(e) + } + n = math.Max(s, n) + } + case math.IsInf(ord, +1): + row := make([]float64, m.mat.Cols) + for i := 0; i < m.mat.Rows; i++ { + var s float64 + for _, e := range m.Row(row, i) { + s += math.Abs(e) + } + n = math.Max(s, n) + } + case ord == -1: + n = math.MaxFloat64 + col := make([]float64, m.mat.Rows) + for i := 0; i < m.mat.Cols; i++ { + var s float64 + for _, e := range m.Col(col, i) { + s += math.Abs(e) + } + n = math.Min(s, n) + } + case math.IsInf(ord, -1): + n = math.MaxFloat64 + row := make([]float64, m.mat.Cols) + for i := 0; i < m.mat.Rows; i++ { + var s float64 + for _, e := range m.Row(row, i) { + s += math.Abs(e) + } + n = math.Min(s, n) + } + case ord == 0: + for i := 0; i < len(m.mat.Data); i += m.mat.Stride { + for _, v := range m.mat.Data[i : i+m.mat.Cols] { + n = math.Hypot(n, v) + } + } + return n + case ord == 2, ord == -2: + s := SVD(m, epsilon, small, false, false).Sigma + if ord == 2 { + return s[0] + } + return s[len(s)-1] + default: + panic(ErrNormOrder) + } + + return n +} + +// Add adds a and b element-wise and saves the result into m. +func (m *Dense) Add(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + + if ar != br || ac != bc { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + } else if ar != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + if b, ok := b.(RawMatrixer); ok { + amat, bmat := a.RawMatrix(), b.RawMatrix() + for ja, jb, jm := 0, 0, 0; ja < ar*amat.Stride; ja, jb, jm = ja+amat.Stride, jb+bmat.Stride, jm+m.mat.Stride { + for i, v := range amat.Data[ja : ja+ac] { + m.mat.Data[i+jm] = v + bmat.Data[i+jb] + } + } + return + } + } + + if a, ok := a.(Vectorer); ok { + if b, ok := b.(Vectorer); ok { + rowa := make([]float64, ac) + rowb := make([]float64, bc) + for r := 0; r < ar; r++ { + a.Row(rowa, r) + for i, v := range b.Row(rowb, r) { + rowa[i] += v + } + copy(m.rowView(r), rowa) + } + return + } + } + + for r := 0; r < ar; r++ { + for c := 0; c < ac; c++ { + m.set(r, c, a.At(r, c)+b.At(r, c)) + } + } +} + +func (m *Dense) Sub(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + + if ar != br || ac != bc { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + } else if ar != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + if b, ok := b.(RawMatrixer); ok { + amat, bmat := a.RawMatrix(), b.RawMatrix() + for ja, jb, jm := 0, 0, 0; ja < ar*amat.Stride; ja, jb, jm = ja+amat.Stride, jb+bmat.Stride, jm+m.mat.Stride { + for i, v := range amat.Data[ja : ja+ac] { + m.mat.Data[i+jm] = v - bmat.Data[i+jb] + } + } + return + } + } + + if a, ok := a.(Vectorer); ok { + if b, ok := b.(Vectorer); ok { + rowa := make([]float64, ac) + rowb := make([]float64, bc) + for r := 0; r < ar; r++ { + a.Row(rowa, r) + for i, v := range b.Row(rowb, r) { + rowa[i] -= v + } + copy(m.rowView(r), rowa) + } + return + } + } + + for r := 0; r < ar; r++ { + for c := 0; c < ac; c++ { + m.set(r, c, a.At(r, c)-b.At(r, c)) + } + } +} + +func (m *Dense) MulElem(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + + if ar != br || ac != bc { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + } else if ar != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + if b, ok := b.(RawMatrixer); ok { + amat, bmat := a.RawMatrix(), b.RawMatrix() + for ja, jb, jm := 0, 0, 0; ja < ar*amat.Stride; ja, jb, jm = ja+amat.Stride, jb+bmat.Stride, jm+m.mat.Stride { + for i, v := range amat.Data[ja : ja+ac] { + m.mat.Data[i+jm] = v * bmat.Data[i+jb] + } + } + return + } + } + + if a, ok := a.(Vectorer); ok { + if b, ok := b.(Vectorer); ok { + rowa := make([]float64, ac) + rowb := make([]float64, bc) + for r := 0; r < ar; r++ { + a.Row(rowa, r) + for i, v := range b.Row(rowb, r) { + rowa[i] *= v + } + copy(m.rowView(r), rowa) + } + return + } + } + + for r := 0; r < ar; r++ { + for c := 0; c < ac; c++ { + m.set(r, c, a.At(r, c)*b.At(r, c)) + } + } +} + +func (m *Dense) DivElem(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + + if ar != br || ac != bc { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + } else if ar != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + if b, ok := b.(RawMatrixer); ok { + amat, bmat := a.RawMatrix(), b.RawMatrix() + for ja, jb, jm := 0, 0, 0; ja < ar*amat.Stride; ja, jb, jm = ja+amat.Stride, jb+bmat.Stride, jm+m.mat.Stride { + for i, v := range amat.Data[ja : ja+ac] { + m.mat.Data[i+jm] = v / bmat.Data[i+jb] + } + } + return + } + } + + if a, ok := a.(Vectorer); ok { + if b, ok := b.(Vectorer); ok { + rowa := make([]float64, ac) + rowb := make([]float64, bc) + for r := 0; r < ar; r++ { + a.Row(rowa, r) + for i, v := range b.Row(rowb, r) { + rowa[i] /= v + } + copy(m.rowView(r), rowa) + } + return + } + } + + for r := 0; r < ar; r++ { + for c := 0; c < ac; c++ { + m.set(r, c, a.At(r, c)/b.At(r, c)) + } + } +} + +func (m *Dense) Dot(b Matrix) float64 { + mr, mc := m.Dims() + br, bc := b.Dims() + + if mr != br || mc != bc { + panic(ErrShape) + } + + var d float64 + + if b, ok := b.(RawMatrixer); ok { + bmat := b.RawMatrix() + for jm, jb := 0, 0; jm < mr*m.mat.Stride; jm, jb = jm+m.mat.Stride, jb+bmat.Stride { + for i, v := range m.mat.Data[jm : jm+mc] { + d += v * bmat.Data[i+jb] + } + } + return d + } + + if b, ok := b.(Vectorer); ok { + row := make([]float64, bc) + for r := 0; r < br; r++ { + for i, v := range b.Row(row, r) { + d += m.mat.Data[r*m.mat.Stride+i] * v + } + } + return d + } + + for r := 0; r < mr; r++ { + for c := 0; c < mc; c++ { + d += m.At(r, c) * b.At(r, c) + } + } + return d +} + +// Mul multiplies two matrix and saves the result in m. Note that the +// arguments a or b should be either Matrix or *Dense. +// Therfore, if a or b is of type Dense, you'll need to pass them by address. +// For example: m.Mul(a, &b) when a is *Dense and b is Dense. +func (m *Dense) Mul(a, b Matrix) { + ar, ac := a.Dims() + br, bc := b.Dims() + + if ac != br { + panic(ErrShape) + } + + var w Dense + if m != a && m != b { + w = *m + } + if w.isZero() { + w.mat = blas64.General{ + Rows: ar, + Cols: bc, + Stride: bc, + Data: use(w.mat.Data, ar*bc), + } + } else if ar != w.mat.Rows || bc != w.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + if b, ok := b.(RawMatrixer); ok { + amat, bmat := a.RawMatrix(), b.RawMatrix() + blas64.Gemm(blas.NoTrans, blas.NoTrans, 1, amat, bmat, 0, w.mat) + *m = w + return + } + } + + if a, ok := a.(Vectorer); ok { + if b, ok := b.(Vectorer); ok { + row := make([]float64, ac) + col := make([]float64, br) + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for c := 0; c < bc; c++ { + dataTmp[c] = blas64.Dot(ac, + blas64.Vector{Inc: 1, Data: a.Row(row, r)}, + blas64.Vector{Inc: 1, Data: b.Col(col, c)}, + ) + } + } + *m = w + return + } + } + + row := make([]float64, ac) + for r := 0; r < ar; r++ { + for i := range row { + row[i] = a.At(r, i) + } + for c := 0; c < bc; c++ { + var v float64 + for i, e := range row { + v += e * b.At(i, c) + } + w.mat.Data[r*w.mat.Stride+c] = v + } + } + *m = w +} + +func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) { + ar, ac := a.Dims() + if aTrans { + ar, ac = ac, ar + } + + br, bc := b.Dims() + if bTrans { + br, bc = bc, br + } + + if ac != br { + panic(ErrShape) + } + + var w Dense + if m != a && m != b { + w = *m + } + if w.isZero() { + w.mat = blas64.General{ + Rows: ar, + Cols: bc, + Stride: bc, + Data: use(w.mat.Data, ar*bc), + } + } else if ar != w.mat.Rows || bc != w.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + if b, ok := b.(RawMatrixer); ok { + amat := a.RawMatrix() + if a == b && aTrans != bTrans { + var op blas.Transpose + if aTrans { + op = blas.Trans + } else { + op = blas.NoTrans + } + blas64.Syrk(op, 1, amat, 0, blas64.Symmetric{N: w.mat.Rows, Stride: w.mat.Stride, Data: w.mat.Data, Uplo: blas.Upper}) + + // Fill lower matrix with result. + // TODO(kortschak): Investigate whether using blas64.Copy improves the performance of this significantly. + for i := 0; i < w.mat.Rows; i++ { + for j := i + 1; j < w.mat.Cols; j++ { + w.set(j, i, w.at(i, j)) + } + } + } else { + var aOp, bOp blas.Transpose + if aTrans { + aOp = blas.Trans + } else { + aOp = blas.NoTrans + } + if bTrans { + bOp = blas.Trans + } else { + bOp = blas.NoTrans + } + bmat := b.RawMatrix() + blas64.Gemm(aOp, bOp, 1, amat, bmat, 0, w.mat) + } + + *m = w + return + } + } + + if a, ok := a.(Vectorer); ok { + if b, ok := b.(Vectorer); ok { + row := make([]float64, ac) + col := make([]float64, br) + if aTrans { + if bTrans { + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for c := 0; c < bc; c++ { + dataTmp[c] = blas64.Dot(ac, + blas64.Vector{Inc: 1, Data: a.Col(row, r)}, + blas64.Vector{Inc: 1, Data: b.Row(col, c)}, + ) + } + } + *m = w + return + } + // TODO(jonlawlor): determine if (b*a)' is more efficient + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for c := 0; c < bc; c++ { + dataTmp[c] = blas64.Dot(ac, + blas64.Vector{Inc: 1, Data: a.Col(row, r)}, + blas64.Vector{Inc: 1, Data: b.Col(col, c)}, + ) + } + } + *m = w + return + } + if bTrans { + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for c := 0; c < bc; c++ { + dataTmp[c] = blas64.Dot(ac, + blas64.Vector{Inc: 1, Data: a.Row(row, r)}, + blas64.Vector{Inc: 1, Data: b.Row(col, c)}, + ) + } + } + *m = w + return + } + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for c := 0; c < bc; c++ { + dataTmp[c] = blas64.Dot(ac, + blas64.Vector{Inc: 1, Data: a.Row(row, r)}, + blas64.Vector{Inc: 1, Data: b.Col(col, c)}, + ) + } + } + *m = w + return + } + } + + row := make([]float64, ac) + if aTrans { + if bTrans { + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for i := range row { + row[i] = a.At(i, r) + } + for c := 0; c < bc; c++ { + var v float64 + for i, e := range row { + v += e * b.At(c, i) + } + dataTmp[c] = v + } + } + *m = w + return + } + + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for i := range row { + row[i] = a.At(i, r) + } + for c := 0; c < bc; c++ { + var v float64 + for i, e := range row { + v += e * b.At(i, c) + } + dataTmp[c] = v + } + } + *m = w + return + } + if bTrans { + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for i := range row { + row[i] = a.At(r, i) + } + for c := 0; c < bc; c++ { + var v float64 + for i, e := range row { + v += e * b.At(c, i) + } + dataTmp[c] = v + } + } + *m = w + return + } + for r := 0; r < ar; r++ { + dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc] + for i := range row { + row[i] = a.At(r, i) + } + for c := 0; c < bc; c++ { + var v float64 + for i, e := range row { + v += e * b.At(i, c) + } + dataTmp[c] = v + } + } + *m = w +} + +// Exp uses the scaling and squaring method described in section 3 of +// http://www.cs.cornell.edu/cv/researchpdf/19ways+.pdf. +func (m *Dense) Exp(a Matrix) { + r, c := a.Dims() + if r != c { + panic(ErrShape) + } + switch { + case m.isZero(): + m.mat = blas64.General{ + Rows: r, + Cols: c, + Stride: c, + Data: use(m.mat.Data, r*r), + } + zero(m.mat.Data) + for i := 0; i < r*r; i += r + 1 { + m.mat.Data[i] = 1 + } + case r == m.mat.Rows && c == m.mat.Cols: + for i := 0; i < r; i++ { + zero(m.mat.Data[i*m.mat.Stride : i*m.mat.Stride+c]) + m.mat.Data[i*m.mat.Stride+i] = 1 + } + default: + panic(ErrShape) + } + + const ( + terms = 10 + scaling = 4 + ) + + var small, power Dense + small.Scale(math.Pow(2, -scaling), a) + power.Clone(&small) + + var ( + tmp = NewDense(r, r, nil) + factI = 1. + ) + for i := 1.; i < terms; i++ { + factI *= i + + // This is OK to do because power and tmp are + // new Dense values so all rows are contiguous. + // TODO(kortschak) Make this explicit in the NewDense doc comment. + for j, v := range power.mat.Data { + tmp.mat.Data[j] = v / factI + } + + m.Add(m, tmp) + if i < terms-1 { + power.Mul(&power, &small) + } + } + + for i := 0; i < scaling; i++ { + m.Mul(m, m) + } +} + +func (m *Dense) Pow(a Matrix, n int) { + if n < 0 { + panic("matrix: illegal power") + } + r, c := a.Dims() + if r != c { + panic(ErrShape) + } + + if m.isZero() { + m.mat = blas64.General{ + Rows: r, + Cols: c, + Stride: c, + Data: use(m.mat.Data, r*r), + } + } else if r != m.mat.Rows || c != m.mat.Cols { + panic(ErrShape) + } + + // Take possible fast paths. + switch n { + case 0: + for i := 0; i < r; i++ { + zero(m.mat.Data[i*m.mat.Stride : i*m.mat.Stride+c]) + m.mat.Data[i*m.mat.Stride+i] = 1 + } + return + case 1: + m.Copy(a) + return + case 2: + m.Mul(a, a) + return + } + + // Perform iterative exponentiation by squaring in work space. + var w, tmp Dense + w.Clone(a) + tmp.Clone(a) + for n--; n > 0; n >>= 1 { + if n&1 != 0 { + w.Mul(&w, &tmp) + } + tmp.Mul(&tmp, &tmp) + } + m.Copy(&w) +} + +func (m *Dense) Scale(f float64, a Matrix) { + ar, ac := a.Dims() + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + } else if ar != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + amat := a.RawMatrix() + for ja, jm := 0, 0; ja < ar*amat.Stride; ja, jm = ja+amat.Stride, jm+m.mat.Stride { + for i, v := range amat.Data[ja : ja+ac] { + m.mat.Data[i+jm] = v * f + } + } + return + } + + if a, ok := a.(Vectorer); ok { + row := make([]float64, ac) + for r := 0; r < ar; r++ { + for i, v := range a.Row(row, r) { + row[i] = f * v + } + copy(m.rowView(r), row) + } + return + } + + for r := 0; r < ar; r++ { + for c := 0; c < ac; c++ { + m.set(r, c, f*a.At(r, c)) + } + } +} + +func (m *Dense) Apply(f ApplyFunc, a Matrix) { + ar, ac := a.Dims() + + if m.isZero() { + m.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(m.mat.Data, ar*ac), + } + } else if ar != m.mat.Rows || ac != m.mat.Cols { + panic(ErrShape) + } + + if a, ok := a.(RawMatrixer); ok { + amat := a.RawMatrix() + for j, ja, jm := 0, 0, 0; ja < ar*amat.Stride; j, ja, jm = j+1, ja+amat.Stride, jm+m.mat.Stride { + for i, v := range amat.Data[ja : ja+ac] { + m.mat.Data[i+jm] = f(j, i, v) + } + } + return + } + + if a, ok := a.(Vectorer); ok { + row := make([]float64, ac) + for r := 0; r < ar; r++ { + for i, v := range a.Row(row, r) { + row[i] = f(r, i, v) + } + copy(m.rowView(r), row) + } + return + } + + for r := 0; r < ar; r++ { + for c := 0; c < ac; c++ { + m.set(r, c, f(r, c, a.At(r, c))) + } + } +} + +func (m *Dense) Sum() float64 { + l := m.mat.Cols + var s float64 + for i := 0; i < len(m.mat.Data); i += m.mat.Stride { + for _, v := range m.mat.Data[i : i+l] { + s += v + } + } + return s +} + +func (m *Dense) Equals(b Matrix) bool { + br, bc := b.Dims() + if br != m.mat.Rows || bc != m.mat.Cols { + return false + } + + if b, ok := b.(RawMatrixer); ok { + bmat := b.RawMatrix() + for jb, jm := 0, 0; jm < br*m.mat.Stride; jb, jm = jb+bmat.Stride, jm+m.mat.Stride { + for i, v := range m.mat.Data[jm : jm+bc] { + if v != bmat.Data[i+jb] { + return false + } + } + } + return true + } + + if b, ok := b.(Vectorer); ok { + rowb := make([]float64, bc) + for r := 0; r < br; r++ { + rowm := m.mat.Data[r*m.mat.Stride : r*m.mat.Stride+m.mat.Cols] + for i, v := range b.Row(rowb, r) { + if rowm[i] != v { + return false + } + } + } + return true + } + + for r := 0; r < br; r++ { + for c := 0; c < bc; c++ { + if m.At(r, c) != b.At(r, c) { + return false + } + } + } + return true +} + +func (m *Dense) EqualsApprox(b Matrix, epsilon float64) bool { + br, bc := b.Dims() + if br != m.mat.Rows || bc != m.mat.Cols { + return false + } + + if b, ok := b.(RawMatrixer); ok { + bmat := b.RawMatrix() + for jb, jm := 0, 0; jm < br*m.mat.Stride; jb, jm = jb+bmat.Stride, jm+m.mat.Stride { + for i, v := range m.mat.Data[jm : jm+bc] { + if math.Abs(v-bmat.Data[i+jb]) > epsilon { + return false + } + } + } + return true + } + + if b, ok := b.(Vectorer); ok { + rowb := make([]float64, bc) + for r := 0; r < br; r++ { + rowm := m.mat.Data[r*m.mat.Stride : r*m.mat.Stride+m.mat.Cols] + for i, v := range b.Row(rowb, r) { + if math.Abs(rowm[i]-v) > epsilon { + return false + } + } + } + return true + } + + for r := 0; r < br; r++ { + for c := 0; c < bc; c++ { + if math.Abs(m.At(r, c)-b.At(r, c)) > epsilon { + return false + } + } + } + return true +} + +// RankOne performs a rank-one update to the matrix b and stores the result +// in the receiver +// m = a + alpha * x * y' +func (m *Dense) RankOne(a Matrix, alpha float64, x, y []float64) { + ar, ac := a.Dims() + + var w Dense + if m == a { + w = *m + } + if w.isZero() { + w.mat = blas64.General{ + Rows: ar, + Cols: ac, + Stride: ac, + Data: use(w.mat.Data, ar*ac), + } + } else if ar != w.mat.Rows || ac != w.mat.Cols { + panic(ErrShape) + } + // Copy over to the new memory if necessary + if m != a { + w.Copy(a) + } + if len(x) != ar { + panic(ErrShape) + } + if len(y) != ac { + panic(ErrShape) + } + blas64.Ger(alpha, blas64.Vector{Inc: 1, Data: x}, blas64.Vector{Inc: 1, Data: y}, w.mat) + *m = w + return +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense_test.go new file mode 100644 index 0000000..eed0e84 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/dense_test.go @@ -0,0 +1,1387 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + "math/rand" + "testing" + + "github.com/gonum/blas/blas64" + "github.com/gonum/floats" + "gopkg.in/check.v1" +) + +func asDense(d *Dense) Matrix { + return d +} +func asBasicMatrix(d *Dense) Matrix { + return (*basicMatrix)(d) +} +func asBasicVectorer(d *Dense) Matrix { + return (*basicVectorer)(d) +} + +func (s *S) TestNewDense(c *check.C) { + for i, test := range []struct { + a []float64 + rows, cols int + min, max float64 + fro float64 + mat *Dense + }{ + { + []float64{ + 0, 0, 0, + 0, 0, 0, + 0, 0, 0, + }, + 3, 3, + 0, 0, + 0, + &Dense{ + mat: blas64.General{ + Rows: 3, Cols: 3, + Stride: 3, + Data: []float64{0, 0, 0, 0, 0, 0, 0, 0, 0}, + }, + capRows: 3, capCols: 3, + }, + }, + { + []float64{ + 1, 1, 1, + 1, 1, 1, + 1, 1, 1, + }, + 3, 3, + 1, 1, + 3, + &Dense{ + mat: blas64.General{ + Rows: 3, Cols: 3, + Stride: 3, + Data: []float64{1, 1, 1, 1, 1, 1, 1, 1, 1}, + }, + capRows: 3, capCols: 3, + }, + }, + { + []float64{ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + }, + 3, 3, + 0, 1, + 1.7320508075688772, + &Dense{ + mat: blas64.General{ + Rows: 3, Cols: 3, + Stride: 3, + Data: []float64{1, 0, 0, 0, 1, 0, 0, 0, 1}, + }, + capRows: 3, capCols: 3, + }, + }, + { + []float64{ + -1, 0, 0, + 0, -1, 0, + 0, 0, -1, + }, + 3, 3, + -1, 0, + 1.7320508075688772, + &Dense{ + mat: blas64.General{ + Rows: 3, Cols: 3, + Stride: 3, + Data: []float64{-1, 0, 0, 0, -1, 0, 0, 0, -1}, + }, + capRows: 3, capCols: 3, + }, + }, + { + []float64{ + 1, 2, 3, + 4, 5, 6, + }, + 2, 3, + 1, 6, + 9.539392014169458, + &Dense{ + mat: blas64.General{ + Rows: 2, Cols: 3, + Stride: 3, + Data: []float64{1, 2, 3, 4, 5, 6}, + }, + capRows: 2, capCols: 3, + }, + }, + { + []float64{ + 1, 2, + 3, 4, + 5, 6, + }, + 3, 2, + 1, 6, + 9.539392014169458, + &Dense{ + mat: blas64.General{ + Rows: 3, Cols: 2, + Stride: 2, + Data: []float64{1, 2, 3, 4, 5, 6}, + }, + capRows: 3, capCols: 2, + }, + }, + } { + m := NewDense(test.rows, test.cols, test.a) + rows, cols := m.Dims() + c.Check(rows, check.Equals, test.rows, check.Commentf("Test %d", i)) + c.Check(cols, check.Equals, test.cols, check.Commentf("Test %d", i)) + c.Check(m.Min(), check.Equals, test.min, check.Commentf("Test %d", i)) + c.Check(m.Max(), check.Equals, test.max, check.Commentf("Test %d", i)) + c.Check(m.Norm(0), check.Equals, test.fro, check.Commentf("Test %d", i)) + c.Check(m, check.DeepEquals, test.mat, check.Commentf("Test %d", i)) + c.Check(m.Equals(test.mat), check.Equals, true, check.Commentf("Test %d", i)) + } +} + +func (s *S) TestAtSet(c *check.C) { + for test, af := range [][][]float64{ + {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, // even + {{1, 2}, {4, 5}, {7, 8}}, // wide + {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, //skinny + } { + m := NewDense(flatten(af)) + rows, cols := m.Dims() + for i := 0; i < rows; i++ { + for j := 0; j < cols; j++ { + c.Check(m.At(i, j), check.Equals, af[i][j], check.Commentf("At test %d", test)) + + v := float64(i * j) + m.Set(i, j, v) + c.Check(m.At(i, j), check.Equals, v, check.Commentf("Set test %d", test)) + } + } + // Check access out of bounds fails + c.Check(func() { m.At(rows, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.At(rows+1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.At(0, cols) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.At(0, cols+1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.At(-1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.At(0, -1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", test)) + + // Check access out of bounds fails + c.Check(func() { m.Set(rows, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.Set(rows+1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.Set(0, cols, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.Set(0, cols+1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.Set(-1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", test)) + c.Check(func() { m.Set(0, -1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", test)) + } +} + +func (s *S) TestRowCol(c *check.C) { + for i, af := range [][][]float64{ + {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}, + } { + a := NewDense(flatten(af)) + for ri, row := range af { + c.Check(a.Row(nil, ri), check.DeepEquals, row, check.Commentf("Test %d", i)) + } + for ci := range af[0] { + col := make([]float64, a.mat.Rows) + for j := range col { + col[j] = float64(ci + 1 + j*a.mat.Cols) + } + c.Check(a.Col(nil, ci), check.DeepEquals, col, check.Commentf("Test %d", i)) + } + } +} + +func (s *S) TestSetRowColumn(c *check.C) { + for _, as := range [][][]float64{ + {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}, + } { + for ri, row := range as { + a := NewDense(flatten(as)) + t := &Dense{} + t.Clone(a) + a.SetRow(ri, make([]float64, a.mat.Cols)) + t.Sub(t, a) + c.Check(t.Norm(0), check.Equals, floats.Norm(row, 2)) + } + + for ci := range as[0] { + a := NewDense(flatten(as)) + t := &Dense{} + t.Clone(a) + a.SetCol(ci, make([]float64, a.mat.Rows)) + col := make([]float64, a.mat.Rows) + for j := range col { + col[j] = float64(ci + 1 + j*a.mat.Cols) + } + t.Sub(t, a) + c.Check(t.Norm(0), check.Equals, floats.Norm(col, 2)) + } + } +} + +func (s *S) TestRowColView(c *check.C) { + for _, test := range []struct { + mat [][]float64 + }{ + { + mat: [][]float64{ + {1, 2, 3, 4, 5}, + {6, 7, 8, 9, 10}, + {11, 12, 13, 14, 15}, + {16, 17, 18, 19, 20}, + {21, 22, 23, 24, 25}, + }, + }, + { + mat: [][]float64{ + {1, 2, 3, 4}, + {6, 7, 8, 9}, + {11, 12, 13, 14}, + {16, 17, 18, 19}, + {21, 22, 23, 24}, + }, + }, + { + mat: [][]float64{ + {1, 2, 3, 4, 5}, + {6, 7, 8, 9, 10}, + {11, 12, 13, 14, 15}, + {16, 17, 18, 19, 20}, + }, + }, + } { + m := NewDense(flatten(test.mat)) + rows, cols := m.Dims() + c.Check(func() { m.RowView(-1) }, check.PanicMatches, ErrRowAccess.Error()) + c.Check(func() { m.RowView(rows) }, check.PanicMatches, ErrRowAccess.Error()) + c.Check(func() { m.ColView(-1) }, check.PanicMatches, ErrColAccess.Error()) + c.Check(func() { m.ColView(cols) }, check.PanicMatches, ErrColAccess.Error()) + + for i := 0; i < rows; i++ { + vr := m.RowView(i) + c.Check(vr.Len(), check.Equals, cols) + for j := 0; j < cols; j++ { + c.Check(vr.At(j, 0), check.Equals, test.mat[i][j]) + } + } + for j := 0; j < cols; j++ { + vr := m.ColView(j) + c.Check(vr.Len(), check.Equals, rows) + for i := 0; i < rows; i++ { + c.Check(vr.At(i, 0), check.Equals, test.mat[i][j]) + } + } + m = m.View(1, 1, rows-2, cols-2).(*Dense) + for i := 1; i < rows-1; i++ { + vr := m.RowView(i - 1) + c.Check(vr.Len(), check.Equals, cols-2) + for j := 1; j < cols-1; j++ { + c.Check(vr.At(j-1, 0), check.Equals, test.mat[i][j]) + } + } + for j := 1; j < cols-1; j++ { + vr := m.ColView(j - 1) + c.Check(vr.Len(), check.Equals, rows-2) + for i := 1; i < rows-1; i++ { + c.Check(vr.At(i-1, 0), check.Equals, test.mat[i][j]) + } + } + } +} + +func (s *S) TestGrow(c *check.C) { + m := &Dense{} + m = m.Grow(10, 10).(*Dense) + rows, cols := m.Dims() + capRows, capCols := m.Caps() + c.Check(rows, check.Equals, 10) + c.Check(cols, check.Equals, 10) + c.Check(capRows, check.Equals, 10) + c.Check(capCols, check.Equals, 10) + + // Test grow within caps is in-place. + m.Set(1, 1, 1) + v := m.View(1, 1, 4, 4).(*Dense) + c.Check(v.At(0, 0), check.Equals, m.At(1, 1)) + v = v.Grow(5, 5).(*Dense) + c.Check(v.Equals(m.View(1, 1, 9, 9)), check.Equals, true) + + // Test grow bigger than caps copies. + v = v.Grow(5, 5).(*Dense) + c.Check(v.View(0, 0, 9, 9).(*Dense).Equals(m.View(1, 1, 9, 9)), check.Equals, true) + v.Set(0, 0, 0) + c.Check(v.View(0, 0, 9, 9).(*Dense).Equals(m.View(1, 1, 9, 9)), check.Equals, false) + + // Test grow uses existing data slice when matrix is zero size. + v.Reset() + p, l := &v.mat.Data[:1][0], cap(v.mat.Data) + *p = 1 + v = v.Grow(5, 5).(*Dense) + c.Check(&v.mat.Data[:1][0], check.Equals, p) + c.Check(cap(v.mat.Data), check.Equals, l) + c.Check(v.At(0, 0), check.Equals, 0.) +} + +func (s *S) TestAdd(c *check.C) { + for i, test := range []struct { + a, b, r [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{2, 2, 2}, {2, 2, 2}, {2, 2, 2}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-2, 0, 0}, {0, -2, 0}, {0, 0, -2}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{2, 4, 6}, {8, 10, 12}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + r := NewDense(flatten(test.r)) + + var temp Dense + temp.Add(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Add %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + zero(temp.mat.Data) + temp.Add(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Add %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + // These probably warrant a better check and failure. They should never happen in the wild though. + temp.mat.Data = nil + c.Check(func() { temp.Add(a, b) }, check.PanicMatches, "runtime error: index out of range", check.Commentf("Test %d", i)) + + a.Add(a, b) + c.Check(a.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Add %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(a.mat.Rows, a.mat.Cols, a.mat.Data))) + } +} + +func (s *S) TestSub(c *check.C) { + for i, test := range []struct { + a, b, r [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{0, 0, 0}, {0, 0, 0}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + r := NewDense(flatten(test.r)) + + var temp Dense + temp.Sub(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Sub %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + zero(temp.mat.Data) + temp.Sub(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Sub %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + // These probably warrant a better check and failure. They should never happen in the wild though. + temp.mat.Data = nil + c.Check(func() { temp.Sub(a, b) }, check.PanicMatches, "runtime error: index out of range", check.Commentf("Test %d", i)) + + a.Sub(a, b) + c.Check(a.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Sub %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(a.mat.Rows, a.mat.Cols, a.mat.Data))) + } +} + +func (s *S) TestMulElem(c *check.C) { + for i, test := range []struct { + a, b, r [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 4, 9}, {16, 25, 36}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + r := NewDense(flatten(test.r)) + + var temp Dense + temp.MulElem(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v MulElem %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + zero(temp.mat.Data) + temp.MulElem(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v MulElem %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + // These probably warrant a better check and failure. They should never happen in the wild though. + temp.mat.Data = nil + c.Check(func() { temp.MulElem(a, b) }, check.PanicMatches, "runtime error: index out of range", check.Commentf("Test %d", i)) + + a.MulElem(a, b) + c.Check(a.Equals(r), check.Equals, true, check.Commentf("Test %d: %v MulElem %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(a.mat.Rows, a.mat.Cols, a.mat.Data))) + } +} + +// A comparison that treats NaNs as equal, for testing. +func (m *Dense) same(b Matrix) bool { + br, bc := b.Dims() + if br != m.mat.Rows || bc != m.mat.Cols { + return false + } + for r := 0; r < br; r++ { + for c := 0; c < bc; c++ { + if av, bv := m.At(r, c), b.At(r, c); av != bv && !(math.IsNaN(av) && math.IsNaN(bv)) { + return false + } + } + } + return true +} + +func (s *S) TestDivElem(c *check.C) { + for i, test := range []struct { + a, b, r [][]float64 + }{ + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{math.Inf(1), math.NaN(), math.NaN()}, {math.NaN(), math.Inf(1), math.NaN()}, {math.NaN(), math.NaN(), math.Inf(1)}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, math.NaN(), math.NaN()}, {math.NaN(), 1, math.NaN()}, {math.NaN(), math.NaN(), 1}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{1, math.NaN(), math.NaN()}, {math.NaN(), 1, math.NaN()}, {math.NaN(), math.NaN(), 1}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 1, 1}, {1, 1, 1}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + r := NewDense(flatten(test.r)) + + var temp Dense + temp.DivElem(a, b) + c.Check(temp.same(r), check.Equals, true, check.Commentf("Test %d: %v DivElem %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + zero(temp.mat.Data) + temp.DivElem(a, b) + c.Check(temp.same(r), check.Equals, true, check.Commentf("Test %d: %v DivElem %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + // These probably warrant a better check and failure. They should never happen in the wild though. + temp.mat.Data = nil + c.Check(func() { temp.DivElem(a, b) }, check.PanicMatches, "runtime error: index out of range", check.Commentf("Test %d", i)) + + a.DivElem(a, b) + c.Check(a.same(r), check.Equals, true, check.Commentf("Test %d: %v DivElem %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(a.mat.Rows, a.mat.Cols, a.mat.Data))) + } +} + +func (s *S) TestMul(c *check.C) { + for i, test := range []struct { + a, b, r [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{3, 3, 3}, {3, 3, 3}, {3, 3, 3}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2}, {3, 4}, {5, 6}}, + [][]float64{{22, 28}, {49, 64}}, + }, + { + [][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}}, + [][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}}, + [][]float64{{0, 2, 2}, {0, 2, 2}, {0, 2, 2}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + r := NewDense(flatten(test.r)) + + var temp Dense + temp.Mul(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Mul %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(temp.mat.Rows, temp.mat.Cols, temp.mat.Data))) + + zero(temp.mat.Data) + temp.Mul(a, b) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v Mul %v expect %v got %v", + i, test.a, test.b, test.r, unflatten(a.mat.Rows, a.mat.Cols, a.mat.Data))) + + // These probably warrant a better check and failure. They should never happen in the wild though. + temp.mat.Data = nil + c.Check(func() { temp.Mul(a, b) }, check.PanicMatches, "blas: index of c out of range", check.Commentf("Test %d", i)) + } +} + +func (s *S) TestMulTrans(c *check.C) { + for i, test := range []struct { + a, b [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2}, {3, 4}, {5, 6}}, + }, + { + [][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}}, + [][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}}, + }, + } { + for _, matInterface := range []func(d *Dense) Matrix{asDense, asBasicMatrix, asBasicVectorer} { + a := matInterface(NewDense(flatten(test.a))) + b := matInterface(NewDense(flatten(test.b))) + for _, aTrans := range []bool{false, true} { + for _, bTrans := range []bool{false, true} { + r := NewDense(0, 0, nil) + var aCopy, bCopy Dense + if aTrans { + aCopy.TCopy(NewDense(flatten(test.a))) + } else { + aCopy = *NewDense(flatten(test.a)) + } + if bTrans { + bCopy.TCopy(NewDense(flatten(test.b))) + } else { + bCopy = *NewDense(flatten(test.b)) + } + var temp Dense + + _, ac := aCopy.Dims() + br, _ := bCopy.Dims() + if ac != br { + // check that both calls error and that the same error returns + c.Check(func() { temp.Mul(matInterface(&aCopy), matInterface(&bCopy)) }, check.PanicMatches, string(ErrShape), check.Commentf("Test Mul %d", i)) + c.Check(func() { temp.MulTrans(a, aTrans, b, bTrans) }, check.PanicMatches, string(ErrShape), check.Commentf("Test MulTrans %d", i)) + continue + } + + r.Mul(matInterface(&aCopy), matInterface(&bCopy)) + + temp.MulTrans(a, aTrans, b, bTrans) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v trans=%b MulTrans %v trans=%b expect %v got %v", + i, test.a, aTrans, test.b, bTrans, r, temp)) + + zero(temp.mat.Data) + temp.MulTrans(a, aTrans, b, bTrans) + c.Check(temp.Equals(r), check.Equals, true, check.Commentf("Test %d: %v trans=%b MulTrans %v trans=%b expect %v got %v", + i, test.a, aTrans, test.b, bTrans, r, temp)) + } + } + } + } +} + +func (s *S) TestMulTransSelf(c *check.C) { + for i, test := range []struct { + a [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + }, + { + [][]float64{{0, 1, 1}, {0, 1, 1}, {0, 1, 1}}, + }, + } { + var aT Dense + a := NewDense(flatten(test.a)) + aT.TCopy(a) + for _, trans := range []bool{false, true} { + var aCopy, bCopy Dense + if trans { + aCopy.TCopy(NewDense(flatten(test.a))) + bCopy = *NewDense(flatten(test.a)) + } else { + aCopy = *NewDense(flatten(test.a)) + bCopy.TCopy(NewDense(flatten(test.a))) + } + + var r Dense + r.Mul(&aCopy, &bCopy) + + var temp Dense + temp.MulTrans(a, trans, a, !trans) + c.Check(temp.Equals(&r), check.Equals, true, check.Commentf("Test %d: %v MulTrans self trans=%b expect %v got %v", i, test.a, trans, r, temp)) + + zero(temp.mat.Data) + temp.MulTrans(a, trans, a, !trans) + c.Check(temp.Equals(&r), check.Equals, true, check.Commentf("Test %d: %v MulTrans self trans=%b expect %v got %v", i, test.a, trans, r, temp)) + } + } +} + +func randDense(size int, rho float64, rnd func() float64) (*Dense, error) { + if size == 0 { + return nil, ErrZeroLength + } + d := &Dense{ + mat: blas64.General{ + Rows: size, Cols: size, Stride: size, + Data: make([]float64, size*size), + }, + capRows: size, capCols: size, + } + for i := 0; i < size; i++ { + for j := 0; j < size; j++ { + if rand.Float64() < rho { + d.Set(i, j, rnd()) + } + } + } + return d, nil +} + +func (s *S) TestExp(c *check.C) { + for i, t := range []struct { + a [][]float64 + want [][]float64 + mod func(*Dense) + }{ + { + a: [][]float64{{-49, 24}, {-64, 31}}, + want: [][]float64{{-0.7357587581474017, 0.5518190996594223}, {-1.4715175990917921, 1.103638240717339}}, + }, + { + a: [][]float64{{-49, 24}, {-64, 31}}, + want: [][]float64{{-0.7357587581474017, 0.5518190996594223}, {-1.4715175990917921, 1.103638240717339}}, + mod: func(a *Dense) { + d := make([]float64, 100) + for i := range d { + d[i] = math.NaN() + } + *a = *NewDense(10, 10, d).View(1, 1, 2, 2).(*Dense) + }, + }, + { + a: [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + want: [][]float64{{2.71828182845905, 0, 0}, {0, 2.71828182845905, 0}, {0, 0, 2.71828182845905}}, + }, + } { + var got Dense + if t.mod != nil { + t.mod(&got) + } + got.Exp(NewDense(flatten(t.a))) + c.Check(got.EqualsApprox(NewDense(flatten(t.want)), 1e-12), check.Equals, true, check.Commentf("Test %d", i)) + } +} + +func (s *S) TestPow(c *check.C) { + for i, t := range []struct { + a [][]float64 + n int + mod func(*Dense) + want [][]float64 + }{ + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 0, + want: [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 0, + want: [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + mod: func(a *Dense) { + d := make([]float64, 100) + for i := range d { + d[i] = math.NaN() + } + *a = *NewDense(10, 10, d).View(1, 1, 3, 3).(*Dense) + }, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 1, + want: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 1, + want: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + mod: func(a *Dense) { + d := make([]float64, 100) + for i := range d { + d[i] = math.NaN() + } + *a = *NewDense(10, 10, d).View(1, 1, 3, 3).(*Dense) + }, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 2, + want: [][]float64{{30, 36, 42}, {66, 81, 96}, {102, 126, 150}}, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 2, + want: [][]float64{{30, 36, 42}, {66, 81, 96}, {102, 126, 150}}, + mod: func(a *Dense) { + d := make([]float64, 100) + for i := range d { + d[i] = math.NaN() + } + *a = *NewDense(10, 10, d).View(1, 1, 3, 3).(*Dense) + }, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 3, + want: [][]float64{{468, 576, 684}, {1062, 1305, 1548}, {1656, 2034, 2412}}, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, + n: 3, + want: [][]float64{{468, 576, 684}, {1062, 1305, 1548}, {1656, 2034, 2412}}, + mod: func(a *Dense) { + d := make([]float64, 100) + for i := range d { + d[i] = math.NaN() + } + *a = *NewDense(10, 10, d).View(1, 1, 3, 3).(*Dense) + }, + }, + } { + var got Dense + if t.mod != nil { + t.mod(&got) + } + got.Pow(NewDense(flatten(t.a)), t.n) + c.Check(got.Equals(NewDense(flatten(t.want))), check.Equals, true, check.Commentf("Test %d", i)) + } +} + +func (s *S) TestLU(c *check.C) { + for i := 0; i < 100; i++ { + size := rand.Intn(100) + r, err := randDense(size, rand.Float64(), rand.NormFloat64) + if size == 0 { + c.Check(err, check.Equals, ErrZeroLength) + continue + } + c.Assert(err, check.Equals, nil) + + var ( + u, l Dense + rc *Dense + ) + + u.U(r) + l.L(r) + for m := 0; m < size; m++ { + for n := 0; n < size; n++ { + switch { + case m < n: // Upper triangular matrix. + c.Check(u.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + case m == n: // Diagonal matrix. + c.Check(u.At(m, n), check.Equals, l.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + c.Check(u.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + case m < n: // Lower triangular matrix. + c.Check(l.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + } + } + } + + rc = DenseCopyOf(r) + rc.U(rc) + for m := 0; m < size; m++ { + for n := 0; n < size; n++ { + switch { + case m < n: // Upper triangular matrix. + c.Check(rc.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + case m == n: // Diagonal matrix. + c.Check(rc.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + case m > n: // Lower triangular matrix. + c.Check(rc.At(m, n), check.Equals, 0., check.Commentf("Test #%d At(%d, %d)", i, m, n)) + } + } + } + + rc = DenseCopyOf(r) + rc.L(rc) + for m := 0; m < size; m++ { + for n := 0; n < size; n++ { + switch { + case m < n: // Upper triangular matrix. + c.Check(rc.At(m, n), check.Equals, 0., check.Commentf("Test #%d At(%d, %d)", i, m, n)) + case m == n: // Diagonal matrix. + c.Check(rc.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + case m > n: // Lower triangular matrix. + c.Check(rc.At(m, n), check.Equals, r.At(m, n), check.Commentf("Test #%d At(%d, %d)", i, m, n)) + } + } + } + } +} + +func (s *S) TestTranspose(c *check.C) { + for i, test := range []struct { + a, t [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 4}, {2, 5}, {3, 6}}, + }, + } { + a := NewDense(flatten(test.a)) + t := NewDense(flatten(test.t)) + + var r, rr Dense + + r.TCopy(a) + c.Check(r.Equals(t), check.Equals, true, check.Commentf("Test %d: %v transpose = %v", i, test.a, test.t)) + + rr.TCopy(&r) + c.Check(rr.Equals(a), check.Equals, true, check.Commentf("Test %d: %v transpose = I", i, test.a, test.t)) + + zero(r.mat.Data) + r.TCopy(a) + c.Check(r.Equals(t), check.Equals, true, check.Commentf("Test %d: %v transpose = %v", i, test.a, test.t)) + + zero(rr.mat.Data) + rr.TCopy(&r) + c.Check(rr.Equals(a), check.Equals, true, check.Commentf("Test %d: %v transpose = I", i, test.a, test.t)) + } +} + +func (s *S) TestNorm(c *check.C) { + for i, test := range []struct { + a [][]float64 + ord float64 + norm float64 + }{ + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: 0, + norm: 25.49509756796392, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: 1, + norm: 30, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: -1, + norm: 22, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: 2, + norm: 25.46240743603639, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: -2, + norm: 9.013990486603544e-16, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: inf, + norm: 33, + }, + { + a: [][]float64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, + ord: -inf, + norm: 6, + }, + { + a: [][]float64{{1, -2, -2}, {-4, 5, 6}}, + ord: 1, + norm: 8, + }, + { + a: [][]float64{{1, -2, -2}, {-4, 5, 6}}, + ord: -1, + norm: 5, + }, + { + a: [][]float64{{1, -2, -2}, {-4, 5, 6}}, + ord: inf, + norm: 15, + }, + { + a: [][]float64{{1, -2, -2}, {-4, 5, 6}}, + ord: -inf, + norm: 5, + }, + } { + a := NewDense(flatten(test.a)) + c.Check(a.Norm(test.ord), check.Equals, test.norm, check.Commentf("Test %d: %v norm = %f", i, test.a, test.norm)) + } +} + +func identity(r, c int, v float64) float64 { return v } + +func (s *S) TestApply(c *check.C) { + for i, test := range []struct { + a, t [][]float64 + fn ApplyFunc + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + identity, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + identity, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + identity, + }, + { + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + [][]float64{{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, + identity, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{1, 2, 3}, {4, 5, 6}}, + identity, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{2, 4, 6}, {8, 10, 12}}, + func(r, c int, v float64) float64 { return v * 2 }, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{0, 2, 0}, {0, 5, 0}}, + func(r, c int, v float64) float64 { + if c == 1 { + return v + } + return 0 + }, + }, + { + [][]float64{{1, 2, 3}, {4, 5, 6}}, + [][]float64{{0, 0, 0}, {4, 5, 6}}, + func(r, c int, v float64) float64 { + if r == 1 { + return v + } + return 0 + }, + }, + } { + a := NewDense(flatten(test.a)) + t := NewDense(flatten(test.t)) + + var r Dense + + r.Apply(test.fn, a) + c.Check(r.Equals(t), check.Equals, true, check.Commentf("Test %d: obtained %v expect: %v", i, r.mat.Data, t.mat.Data)) + + a.Apply(test.fn, a) + c.Check(a.Equals(t), check.Equals, true, check.Commentf("Test %d: obtained %v expect: %v", i, a.mat.Data, t.mat.Data)) + } +} + +func (s *S) TestClone(c *check.C) { + for i, test := range []struct { + a [][]float64 + i, j int + v float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + 1, 1, + 1, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + 0, 0, + 0, + }, + } { + a := NewDense(flatten(test.a)) + b := *a + a.Clone(a) + a.Set(test.i, test.j, test.v) + + c.Check(b.Equals(a), check.Equals, false, check.Commentf("Test %d: %v cloned and altered = %v", i, a, &b)) + } +} + +func (s *S) TestStack(c *check.C) { + for i, test := range []struct { + a, b, e [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}, + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 1, 0}, {0, 0, 1}, {1, 0, 0}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + + var s Dense + s.Stack(a, b) + + c.Check(s.Equals(NewDense(flatten(test.e))), check.Equals, true, check.Commentf("Test %d: %v stack %v = %v", i, a, b, s)) + } +} + +func (s *S) TestAugment(c *check.C) { + for i, test := range []struct { + a, b, e [][]float64 + }{ + { + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, + [][]float64{{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}, + }, + { + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, + [][]float64{{1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1}}, + }, + { + [][]float64{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, + [][]float64{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}, + [][]float64{{1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1}, {0, 0, 1, 1, 0, 0}}, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + + var s Dense + s.Augment(a, b) + + c.Check(s.Equals(NewDense(flatten(test.e))), check.Equals, true, check.Commentf("Test %d: %v stack %v = %v", i, a, b, s)) + } +} + +func (s *S) TestRankOne(c *check.C) { + for i, test := range []struct { + x []float64 + y []float64 + m [][]float64 + alpha float64 + }{ + { + x: []float64{5}, + y: []float64{10}, + m: [][]float64{{2}}, + alpha: -3, + }, + { + x: []float64{5, 6, 1}, + y: []float64{10}, + m: [][]float64{{2}, {-3}, {5}}, + alpha: -3, + }, + + { + x: []float64{5}, + y: []float64{10, 15, 8}, + m: [][]float64{{2, -3, 5}}, + alpha: -3, + }, + { + x: []float64{1, 5}, + y: []float64{10, 15}, + m: [][]float64{ + {2, -3}, + {4, -1}, + }, + alpha: -3, + }, + { + x: []float64{2, 3, 9}, + y: []float64{8, 9}, + m: [][]float64{ + {2, 3}, + {4, 5}, + {6, 7}, + }, + alpha: -3, + }, + { + x: []float64{2, 3}, + y: []float64{8, 9, 9}, + m: [][]float64{ + {2, 3, 6}, + {4, 5, 7}, + }, + alpha: -3, + }, + } { + want := &Dense{} + xm := NewDense(len(test.x), 1, test.x) + ym := NewDense(1, len(test.y), test.y) + + want.Mul(xm, ym) + want.Scale(test.alpha, want) + want.Add(want, NewDense(flatten(test.m))) + + a := NewDense(flatten(test.m)) + m := &Dense{} + // Check with a new matrix + m.RankOne(a, test.alpha, test.x, test.y) + c.Check(m.Equals(want), check.Equals, true, check.Commentf("Test %v. Want %v, Got %v", i, want, m)) + // Check with the same matrix + a.RankOne(a, test.alpha, test.x, test.y) + c.Check(a.Equals(want), check.Equals, true, check.Commentf("Test %v. Want %v, Got %v", i, want, m)) + } +} + +var ( + wd *Dense +) + +func BenchmarkMulDense100Half(b *testing.B) { denseMulBench(b, 100, 0.5) } +func BenchmarkMulDense100Tenth(b *testing.B) { denseMulBench(b, 100, 0.1) } +func BenchmarkMulDense1000Half(b *testing.B) { denseMulBench(b, 1000, 0.5) } +func BenchmarkMulDense1000Tenth(b *testing.B) { denseMulBench(b, 1000, 0.1) } +func BenchmarkMulDense1000Hundredth(b *testing.B) { denseMulBench(b, 1000, 0.01) } +func BenchmarkMulDense1000Thousandth(b *testing.B) { denseMulBench(b, 1000, 0.001) } +func denseMulBench(b *testing.B, size int, rho float64) { + b.StopTimer() + a, _ := randDense(size, rho, rand.NormFloat64) + d, _ := randDense(size, rho, rand.NormFloat64) + b.StartTimer() + for i := 0; i < b.N; i++ { + var n Dense + n.Mul(a, d) + wd = &n + } +} + +func BenchmarkPreMulDense100Half(b *testing.B) { densePreMulBench(b, 100, 0.5) } +func BenchmarkPreMulDense100Tenth(b *testing.B) { densePreMulBench(b, 100, 0.1) } +func BenchmarkPreMulDense1000Half(b *testing.B) { densePreMulBench(b, 1000, 0.5) } +func BenchmarkPreMulDense1000Tenth(b *testing.B) { densePreMulBench(b, 1000, 0.1) } +func BenchmarkPreMulDense1000Hundredth(b *testing.B) { densePreMulBench(b, 1000, 0.01) } +func BenchmarkPreMulDense1000Thousandth(b *testing.B) { densePreMulBench(b, 1000, 0.001) } +func densePreMulBench(b *testing.B, size int, rho float64) { + b.StopTimer() + a, _ := randDense(size, rho, rand.NormFloat64) + d, _ := randDense(size, rho, rand.NormFloat64) + wd = NewDense(size, size, nil) + b.StartTimer() + for i := 0; i < b.N; i++ { + wd.Mul(a, d) + } +} + +func BenchmarkExp10(b *testing.B) { expBench(b, 10) } +func BenchmarkExp100(b *testing.B) { expBench(b, 100) } +func BenchmarkExp1000(b *testing.B) { expBench(b, 1000) } + +func expBench(b *testing.B, size int) { + a, _ := randDense(size, 1, rand.NormFloat64) + + b.ResetTimer() + var m Dense + for i := 0; i < b.N; i++ { + m.Exp(a) + } +} + +func BenchmarkMulTransDense100Half(b *testing.B) { denseMulTransBench(b, 100, 0.5) } +func BenchmarkMulTransDense100Tenth(b *testing.B) { denseMulTransBench(b, 100, 0.1) } +func BenchmarkMulTransDense1000Half(b *testing.B) { denseMulTransBench(b, 1000, 0.5) } +func BenchmarkMulTransDense1000Tenth(b *testing.B) { denseMulTransBench(b, 1000, 0.1) } +func BenchmarkMulTransDense1000Hundredth(b *testing.B) { denseMulTransBench(b, 1000, 0.01) } +func BenchmarkMulTransDense1000Thousandth(b *testing.B) { denseMulTransBench(b, 1000, 0.001) } +func denseMulTransBench(b *testing.B, size int, rho float64) { + b.StopTimer() + a, _ := randDense(size, rho, rand.NormFloat64) + d, _ := randDense(size, rho, rand.NormFloat64) + b.StartTimer() + for i := 0; i < b.N; i++ { + var n Dense + n.MulTrans(a, false, d, true) + wd = &n + } +} + +func BenchmarkMulTransDenseSym100Half(b *testing.B) { denseMulTransSymBench(b, 100, 0.5) } +func BenchmarkMulTransDenseSym100Tenth(b *testing.B) { denseMulTransSymBench(b, 100, 0.1) } +func BenchmarkMulTransDenseSym1000Half(b *testing.B) { denseMulTransSymBench(b, 1000, 0.5) } +func BenchmarkMulTransDenseSym1000Tenth(b *testing.B) { denseMulTransSymBench(b, 1000, 0.1) } +func BenchmarkMulTransDenseSym1000Hundredth(b *testing.B) { denseMulTransSymBench(b, 1000, 0.01) } +func BenchmarkMulTransDenseSym1000Thousandth(b *testing.B) { denseMulTransSymBench(b, 1000, 0.001) } +func denseMulTransSymBench(b *testing.B, size int, rho float64) { + b.StopTimer() + a, _ := randDense(size, rho, rand.NormFloat64) + b.StartTimer() + for i := 0; i < b.N; i++ { + var n Dense + n.MulTrans(a, false, a, true) + wd = &n + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/eigen.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/eigen.go new file mode 100644 index 0000000..676642f --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/eigen.go @@ -0,0 +1,819 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// Based on the EigenvalueDecomposition class from Jama 1.0.3. + +package mat64 + +import ( + "math" +) + +func symmetric(m *Dense) bool { + n, _ := m.Dims() + for i := 0; i < n; i++ { + for j := 0; j < i; j++ { + if m.at(i, j) != m.at(j, i) { + return false + } + } + } + return true +} + +type EigenFactors struct { + V *Dense + d, e []float64 +} + +// Eigen returns the Eigenvalues and eigenvectors of a square real matrix. +// The matrix a is overwritten during the decomposition. If a is symmetric, +// then a = v*D*v' where the eigenvalue matrix D is diagonal and the +// eigenvector matrix v is orthogonal. +// +// If a is not symmetric, then the eigenvalue matrix D is block diagonal +// with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, +// lambda + i*mu, in 2-by-2 blocks, [lambda, mu; -mu, lambda]. The +// columns of v represent the eigenvectors in the sense that a*v = v*D, +// i.e. a.v equals v.D. The matrix v may be badly conditioned, or even +// singular, so the validity of the equation a = v*D*inverse(v) depends +// upon the 2-norm condition number of v. +func Eigen(a *Dense, epsilon float64) EigenFactors { + m, n := a.Dims() + if m != n { + panic(ErrSquare) + } + + var v *Dense + d := make([]float64, n) + e := make([]float64, n) + + if symmetric(a) { + // Tridiagonalize. + v = tred2(a, d, e) + + // Diagonalize. + tql2(d, e, v, epsilon) + } else { + // Reduce to Hessenberg form. + var hess *Dense + hess, v = orthes(a) + + // Reduce Hessenberg to real Schur form. + hqr2(d, e, hess, v, epsilon) + } + + return EigenFactors{v, d, e} +} + +// Symmetric Householder reduction to tridiagonal form. +// +// This is derived from the Algol procedures tred2 by +// Bowdler, Martin, Reinsch, and Wilkinson, Handbook for +// Auto. Comp., Vol.ii-Linear Algebra, and the corresponding +// Fortran subroutine in EISPACK. +func tred2(a *Dense, d, e []float64) (v *Dense) { + n := len(d) + v = a + + for j := 0; j < n; j++ { + d[j] = v.at(n-1, j) + } + + // Householder reduction to tridiagonal form. + for i := n - 1; i > 0; i-- { + // Scale to avoid under/overflow. + var ( + scale float64 + h float64 + ) + for k := 0; k < i; k++ { + scale += math.Abs(d[k]) + } + if scale == 0 { + e[i] = d[i-1] + for j := 0; j < i; j++ { + d[j] = v.at(i-1, j) + v.set(i, j, 0) + v.set(j, i, 0) + } + } else { + // Generate Householder vector. + for k := 0; k < i; k++ { + d[k] /= scale + h += d[k] * d[k] + } + f := d[i-1] + g := math.Sqrt(h) + if f > 0 { + g = -g + } + e[i] = scale * g + h -= f * g + d[i-1] = f - g + for j := 0; j < i; j++ { + e[j] = 0 + } + + // Apply similarity transformation to remaining columns. + for j := 0; j < i; j++ { + f = d[j] + v.set(j, i, f) + g = e[j] + v.at(j, j)*f + for k := j + 1; k <= i-1; k++ { + g += v.at(k, j) * d[k] + e[k] += v.at(k, j) * f + } + e[j] = g + } + f = 0 + for j := 0; j < i; j++ { + e[j] /= h + f += e[j] * d[j] + } + hh := f / (h + h) + for j := 0; j < i; j++ { + e[j] -= hh * d[j] + } + for j := 0; j < i; j++ { + f = d[j] + g = e[j] + for k := j; k <= i-1; k++ { + v.set(k, j, v.at(k, j)-(f*e[k]+g*d[k])) + } + d[j] = v.at(i-1, j) + v.set(i, j, 0) + } + } + d[i] = h + } + + // Accumulate transformations. + for i := 0; i < n-1; i++ { + v.set(n-1, i, v.at(i, i)) + v.set(i, i, 1) + h := d[i+1] + if h != 0 { + for k := 0; k <= i; k++ { + d[k] = v.at(k, i+1) / h + } + for j := 0; j <= i; j++ { + var g float64 + for k := 0; k <= i; k++ { + g += v.at(k, i+1) * v.at(k, j) + } + for k := 0; k <= i; k++ { + v.set(k, j, v.at(k, j)-g*d[k]) + } + } + } + for k := 0; k <= i; k++ { + v.set(k, i+1, 0) + } + } + for j := 0; j < n; j++ { + d[j] = v.at(n-1, j) + v.set(n-1, j, 0) + } + v.set(n-1, n-1, 1) + e[0] = 0 + + return v +} + +// Symmetric tridiagonal QL algorithm. +// +// This is derived from the Algol procedures tql2, by +// Bowdler, Martin, Reinsch, and Wilkinson, Handbook for +// Auto. Comp., Vol.ii-Linear Algebra, and the corresponding +// Fortran subroutine in EISPACK. +func tql2(d, e []float64, v *Dense, epsilon float64) { + n := len(d) + for i := 1; i < n; i++ { + e[i-1] = e[i] + } + e[n-1] = 0 + + var ( + f float64 + tst1 float64 + ) + for l := 0; l < n; l++ { + // Find small subdiagonal element + tst1 = math.Max(tst1, math.Abs(d[l])+math.Abs(e[l])) + m := l + for m < n { + if math.Abs(e[m]) <= epsilon*tst1 { + break + } + m++ + } + + // If m == l, d[l] is an eigenvalue, otherwise, iterate. + if m > l { + for iter := 0; ; iter++ { // Could check iteration count here. + + // Compute implicit shift + g := d[l] + p := (d[l+1] - g) / (2 * e[l]) + r := math.Hypot(p, 1) + if p < 0 { + r = -r + } + d[l] = e[l] / (p + r) + d[l+1] = e[l] * (p + r) + dl1 := d[l+1] + h := g - d[l] + for i := l + 2; i < n; i++ { + d[i] -= h + } + f += h + + // Implicit QL transformation. + p = d[m] + c := 1. + c2 := c + c3 := c + el1 := e[l+1] + var ( + s float64 + s2 float64 + ) + for i := m - 1; i >= l; i-- { + c3 = c2 + c2 = c + s2 = s + g = c * e[i] + h = c * p + r = math.Hypot(p, e[i]) + e[i+1] = s * r + s = e[i] / r + c = p / r + p = c*d[i] - s*g + d[i+1] = h + s*(c*g+s*d[i]) + + // Accumulate transformation. + for k := 0; k < n; k++ { + h = v.at(k, i+1) + v.set(k, i+1, s*v.at(k, i)+c*h) + v.set(k, i, c*v.at(k, i)-s*h) + } + } + p = -s * s2 * c3 * el1 * e[l] / dl1 + e[l] = s * p + d[l] = c * p + + // Check for convergence. + if math.Abs(e[l]) <= epsilon*tst1 { + break + } + } + } + d[l] += f + e[l] = 0 + } + + // Sort eigenvalues and corresponding vectors. + for i := 0; i < n-1; i++ { + k := i + p := d[i] + for j := i + 1; j < n; j++ { + if d[j] < p { + k = j + p = d[j] + } + } + if k != i { + d[k] = d[i] + d[i] = p + for j := 0; j < n; j++ { + p = v.at(j, i) + v.set(j, i, v.at(j, k)) + v.set(j, k, p) + } + } + } +} + +// Nonsymmetric reduction to Hessenberg form. +// +// This is derived from the Algol procedures orthes and ortran, +// by Martin and Wilkinson, Handbook for Auto. Comp., +// Vol.ii-Linear Algebra, and the corresponding +// Fortran subroutines in EISPACK. +func orthes(a *Dense) (hess, v *Dense) { + n, _ := a.Dims() + hess = a + + ort := make([]float64, n) + + low := 0 + high := n - 1 + + for m := low + 1; m <= high-1; m++ { + // Scale column. + var scale float64 + for i := m; i <= high; i++ { + scale += math.Abs(hess.at(i, m-1)) + } + if scale != 0 { + // Compute Householder transformation. + var h float64 + for i := high; i >= m; i-- { + ort[i] = hess.at(i, m-1) / scale + h += ort[i] * ort[i] + } + g := math.Sqrt(h) + if ort[m] > 0 { + g = -g + } + h -= ort[m] * g + ort[m] -= g + + // Apply Householder similarity transformation + // hess = (I-u*u'/h)*hess*(I-u*u')/h) + for j := m; j < n; j++ { + var f float64 + for i := high; i >= m; i-- { + f += ort[i] * hess.at(i, j) + } + f /= h + for i := m; i <= high; i++ { + hess.set(i, j, hess.at(i, j)-f*ort[i]) + } + } + + for i := 0; i <= high; i++ { + var f float64 + for j := high; j >= m; j-- { + f += ort[j] * hess.at(i, j) + } + f /= h + for j := m; j <= high; j++ { + hess.set(i, j, hess.at(i, j)-f*ort[j]) + } + } + ort[m] *= scale + hess.set(m, m-1, scale*g) + } + } + + // Accumulate transformations (Algol's ortran). + v = NewDense(n, n, nil) + for i := 0; i < n; i++ { + for j := 0; j < n; j++ { + if i == j { + v.set(i, j, 1) + } else { + v.set(i, j, 0) + } + } + } + for m := high - 1; m >= low+1; m-- { + if hess.at(m, m-1) != 0 { + for i := m + 1; i <= high; i++ { + ort[i] = hess.at(i, m-1) + } + for j := m; j <= high; j++ { + var g float64 + for i := m; i <= high; i++ { + g += ort[i] * v.at(i, j) + } + + // Double division avoids possible underflow + g = (g / ort[m]) / hess.at(m, m-1) + for i := m; i <= high; i++ { + v.set(i, j, v.at(i, j)+g*ort[i]) + } + } + } + } + + return hess, v +} + +// Nonsymmetric reduction from Hessenberg to real Schur form. +// +// This is derived from the Algol procedure hqr2, +// by Martin and Wilkinson, Handbook for Auto. Comp., +// Vol.ii-Linear Algebra, and the corresponding +// Fortran subroutine in EISPACK. +func hqr2(d, e []float64, hess, v *Dense, epsilon float64) { + // Initialize + nn := len(d) + n := nn - 1 + + low := 0 + high := n + + var exshift, p, q, r, s, z, t, w, x, y float64 + + // Store roots isolated by balanc and compute matrix norm + var norm float64 + for i := 0; i < nn; i++ { + if i < low || i > high { + d[i] = hess.at(i, i) + e[i] = 0 + } + for j := max(i-1, 0); j < nn; j++ { + norm += math.Abs(hess.at(i, j)) + } + } + + // Outer loop over eigenvalue index + for iter := 0; n >= low; { + // Look for single small sub-diagonal element + l := n + for l > low { + s = math.Abs(hess.at(l-1, l-1)) + math.Abs(hess.at(l, l)) + if s == 0 { + s = norm + } + if math.Abs(hess.at(l, l-1)) < epsilon*s { + break + } + l-- + } + + // Check for convergence + if l == n { + // One root found + hess.set(n, n, hess.at(n, n)+exshift) + d[n] = hess.at(n, n) + e[n] = 0 + n-- + iter = 0 + } else if l == n-1 { + // Two roots found + w = hess.at(n, n-1) * hess.at(n-1, n) + p = (hess.at(n-1, n-1) - hess.at(n, n)) / 2.0 + q = p*p + w + z = math.Sqrt(math.Abs(q)) + hess.set(n, n, hess.at(n, n)+exshift) + hess.set(n-1, n-1, hess.at(n-1, n-1)+exshift) + x = hess.at(n, n) + + // Real pair + if q >= 0 { + if p >= 0 { + z = p + z + } else { + z = p - z + } + d[n-1] = x + z + d[n] = d[n-1] + if z != 0 { + d[n] = x - w/z + } + e[n-1] = 0 + e[n] = 0 + x = hess.at(n, n-1) + s = math.Abs(x) + math.Abs(z) + p = x / s + q = z / s + r = math.Hypot(p, q) + p /= r + q /= r + + // Row modification + for j := n - 1; j < nn; j++ { + z = hess.at(n-1, j) + hess.set(n-1, j, q*z+p*hess.at(n, j)) + hess.set(n, j, q*hess.at(n, j)-p*z) + } + + // Column modification + for i := 0; i <= n; i++ { + z = hess.at(i, n-1) + hess.set(i, n-1, q*z+p*hess.at(i, n)) + hess.set(i, n, q*hess.at(i, n)-p*z) + } + + // Accumulate transformations + for i := low; i <= high; i++ { + z = v.at(i, n-1) + v.set(i, n-1, q*z+p*v.at(i, n)) + v.set(i, n, q*v.at(i, n)-p*z) + } + } else { + // Complex pair + d[n-1] = x + p + d[n] = x + p + e[n-1] = z + e[n] = -z + } + n -= 2 + iter = 0 + } else { + // No convergence yet + + // Form shift + x = hess.at(n, n) + y = 0 + w = 0 + if l < n { + y = hess.at(n-1, n-1) + w = hess.at(n, n-1) * hess.at(n-1, n) + } + + // Wilkinson's original ad hoc shift + if iter == 10 { + exshift += x + for i := low; i <= n; i++ { + hess.set(i, i, hess.at(i, i)-x) + } + s = math.Abs(hess.at(n, n-1)) + math.Abs(hess.at(n-1, n-2)) + x = 0.75 * s + y = x + w = -0.4375 * s * s + } + + // MATLAB's new ad hoc shift + if iter == 30 { + s = (y - x) / 2 + s = s*s + w + if s > 0 { + s = math.Sqrt(s) + if y < x { + s = -s + } + s = x - w/((y-x)/2+s) + for i := low; i <= n; i++ { + hess.set(i, i, hess.at(i, i)-s) + } + exshift += s + x = 0.964 + y = x + w = x + } + } + + iter++ // Could check iteration count here. + + // Look for two consecutive small sub-diagonal elements + m := n - 2 + for m >= l { + z = hess.at(m, m) + r = x - z + s = y - z + p = (r*s-w)/hess.at(m+1, m) + hess.at(m, m+1) + q = hess.at(m+1, m+1) - z - r - s + r = hess.at(m+2, m+1) + s = math.Abs(p) + math.Abs(q) + math.Abs(r) + p /= s + q /= s + r /= s + if m == l { + break + } + if math.Abs(hess.at(m, m-1))*(math.Abs(q)+math.Abs(r)) < + epsilon*(math.Abs(p)*(math.Abs(hess.at(m-1, m-1))+math.Abs(z)+math.Abs(hess.at(m+1, m+1)))) { + break + } + m-- + } + + for i := m + 2; i <= n; i++ { + hess.set(i, i-2, 0) + if i > m+2 { + hess.set(i, i-3, 0) + } + } + + // Double QR step involving rows l:n and columns m:n + for k := m; k <= n-1; k++ { + last := k == n-1 + if k != m { + p = hess.at(k, k-1) + q = hess.at(k+1, k-1) + if !last { + r = hess.at(k+2, k-1) + } else { + r = 0 + } + x = math.Abs(p) + math.Abs(q) + math.Abs(r) + if x == 0 { + continue + } + p /= x + q /= x + r /= x + } + + s = math.Sqrt(p*p + q*q + r*r) + if p < 0 { + s = -s + } + if s != 0 { + if k != m { + hess.set(k, k-1, -s*x) + } else if l != m { + hess.set(k, k-1, -hess.at(k, k-1)) + } + p += s + x = p / s + y = q / s + z = r / s + q /= p + r /= p + + // Row modification + for j := k; j < nn; j++ { + p = hess.at(k, j) + q*hess.at(k+1, j) + if !last { + p += r * hess.at(k+2, j) + hess.set(k+2, j, hess.at(k+2, j)-p*z) + } + hess.set(k, j, hess.at(k, j)-p*x) + hess.set(k+1, j, hess.at(k+1, j)-p*y) + } + + // Column modification + for i := 0; i <= min(n, k+3); i++ { + p = x*hess.at(i, k) + y*hess.at(i, k+1) + if !last { + p += z * hess.at(i, k+2) + hess.set(i, k+2, hess.at(i, k+2)-p*r) + } + hess.set(i, k, hess.at(i, k)-p) + hess.set(i, k+1, hess.at(i, k+1)-p*q) + } + + // Accumulate transformations + for i := low; i <= high; i++ { + p = x*v.at(i, k) + y*v.at(i, k+1) + if !last { + p += z * v.at(i, k+2) + v.set(i, k+2, v.at(i, k+2)-p*r) + } + v.set(i, k, v.at(i, k)-p) + v.set(i, k+1, v.at(i, k+1)-p*q) + } + } + } + } + } + + // Backsubstitute to find vectors of upper triangular form + if norm == 0 { + return + } + + for n = nn - 1; n >= 0; n-- { + p = d[n] + q = e[n] + + if q == 0 { + // Real vector + l := n + hess.set(n, n, 1) + for i := n - 1; i >= 0; i-- { + w = hess.at(i, i) - p + r = 0 + for j := l; j <= n; j++ { + r += hess.at(i, j) * hess.at(j, n) + } + if e[i] < 0 { + z = w + s = r + } else { + l = i + if e[i] == 0 { + if w != 0 { + hess.set(i, n, -r/w) + } else { + hess.set(i, n, -r/(epsilon*norm)) + } + } else { + // Solve real equations + x = hess.at(i, i+1) + y = hess.at(i+1, i) + q = (d[i]-p)*(d[i]-p) + e[i]*e[i] + t = (x*s - z*r) / q + hess.set(i, n, t) + if math.Abs(x) > math.Abs(z) { + hess.set(i+1, n, (-r-w*t)/x) + } else { + hess.set(i+1, n, (-s-y*t)/z) + } + } + + // Overflow control + t = math.Abs(hess.at(i, n)) + if epsilon*t*t > 1 { + for j := i; j <= n; j++ { + hess.set(j, n, hess.at(j, n)/t) + } + } + } + } + } else if q < 0 { + // Complex vector + + l := n - 1 + + // Last vector component imaginary so matrix is triangular + if math.Abs(hess.at(n, n-1)) > math.Abs(hess.at(n-1, n)) { + hess.set(n-1, n-1, q/hess.at(n, n-1)) + hess.set(n-1, n, -(hess.at(n, n)-p)/hess.at(n, n-1)) + } else { + c := complex(0, -hess.at(n-1, n)) / complex(hess.at(n-1, n-1)-p, q) + hess.set(n-1, n-1, real(c)) + hess.set(n-1, n, imag(c)) + } + hess.set(n, n-1, 0) + hess.set(n, n, 1) + + for i := n - 2; i >= 0; i-- { + var ra, sa, vr, vi float64 + for j := l; j <= n; j++ { + ra += hess.at(i, j) * hess.at(j, n-1) + sa += hess.at(i, j) * hess.at(j, n) + } + w = hess.at(i, i) - p + + if e[i] < 0 { + z = w + r = ra + s = sa + } else { + l = i + if e[i] == 0 { + c := complex(-ra, -sa) / complex(w, q) + hess.set(i, n-1, real(c)) + hess.set(i, n, imag(c)) + } else { + // Solve complex equations + x = hess.at(i, i+1) + y = hess.at(i+1, i) + vr = (d[i]-p)*(d[i]-p) + e[i]*e[i] - q*q + vi = (d[i] - p) * 2 * q + if vr == 0 && vi == 0 { + vr = epsilon * norm * (math.Abs(w) + math.Abs(q) + math.Abs(x) + math.Abs(y) + math.Abs(z)) + } + c := complex(x*r-z*ra+q*sa, x*s-z*sa-q*ra) / complex(vr, vi) + hess.set(i, n-1, real(c)) + hess.set(i, n, imag(c)) + if math.Abs(x) > (math.Abs(z) + math.Abs(q)) { + hess.set(i+1, n-1, (-ra-w*hess.at(i, n-1)+q*hess.at(i, n))/x) + hess.set(i+1, n, (-sa-w*hess.at(i, n)-q*hess.at(i, n-1))/x) + } else { + c := complex(-r-y*hess.at(i, n-1), -s-y*hess.at(i, n)) / complex(z, q) + hess.set(i+1, n-1, real(c)) + hess.set(i+1, n, imag(c)) + } + } + + // Overflow control + t = math.Max(math.Abs(hess.at(i, n-1)), math.Abs(hess.at(i, n))) + if (epsilon*t)*t > 1 { + for j := i; j <= n; j++ { + hess.set(j, n-1, hess.at(j, n-1)/t) + hess.set(j, n, hess.at(j, n)/t) + } + } + } + } + } + } + + // Vectors of isolated roots + for i := 0; i < nn; i++ { + if i < low || i > high { + for j := i; j < nn; j++ { + v.set(i, j, hess.at(i, j)) + } + } + } + + // Back transformation to get eigenvectors of original matrix + for j := nn - 1; j >= low; j-- { + for i := low; i <= high; i++ { + z = 0 + for k := low; k <= min(j, high); k++ { + z += v.at(i, k) * hess.at(k, j) + } + v.set(i, j, z) + } + } +} + +// D returns the block diagonal eigenvalue matrix from the real and imaginary +// components d and e. +func (f EigenFactors) D() *Dense { + d, e := f.d, f.e + var n int + if n = len(d); n != len(e) { + panic(ErrSquare) + } + dm := NewDense(n, n, nil) + for i := 0; i < n; i++ { + dm.set(i, i, d[i]) + if e[i] > 0 { + dm.set(i, i+1, e[i]) + } else if e[i] < 0 { + dm.set(i, i-1, e[i]) + } + } + return dm +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/eigen_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/eigen_test.go new file mode 100644 index 0000000..ab9f981 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/eigen_test.go @@ -0,0 +1,103 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + + "gopkg.in/check.v1" +) + +func (s *S) TestEigen(c *check.C) { + for _, t := range []struct { + a *Dense + + epsilon float64 + + e, d []float64 + v *Dense + }{ + { + a: NewDense(3, 3, []float64{ + 1, 2, 1, + 6, -1, 0, + -1, -2, -1, + }), + + epsilon: math.Pow(2, -52.0), + + d: []float64{3.0000000000000044, -4.000000000000003, -1.0980273383714707e-16}, + e: []float64{0, 0, 0}, + v: NewDense(3, 3, []float64{ + -0.48507125007266627, 0.41649656391752204, 0.11785113019775795, + -0.7276068751089995, -0.8329931278350428, 0.7071067811865481, + 0.48507125007266627, -0.4164965639175216, -1.5320646925708532, + }), + }, + { + a: NewDense(3, 3, []float64{ + 1, 6, -1, + 6, -1, -2, + -1, -2, -1, + }), + + epsilon: math.Pow(2, -52.0), + + d: []float64{-6.240753470718579, -1.3995889142010132, 6.640342384919599}, + e: []float64{0, 0, 0}, + v: NewDense(3, 3, []float64{ + -0.6134279348516111, -0.31411097261113, -0.7245967607083111, + 0.7697297716508223, -0.03251534945303795, -0.6375412384185983, + 0.17669818159240022, -0.9488293044247931, 0.2617263908869383, + }), + }, + { // Jama pvals + a: NewDense(3, 3, []float64{ + 4, 1, 1, + 1, 2, 3, + 1, 3, 6, + }), + + epsilon: math.Pow(2, -52.0), + }, + { // Jama evals + a: NewDense(4, 4, []float64{ + 0, 1, 0, 0, + 1, 0, 2e-7, 0, + 0, -2e-7, 0, 1, + 0, 0, 1, 0, + }), + + epsilon: math.Pow(2, -52.0), + }, + { // Jama badeigs + a: NewDense(5, 5, []float64{ + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, + 0, 0, 0, 1, 0, + 1, 1, 0, 0, 1, + 1, 0, 1, 0, 1, + }), + + epsilon: math.Pow(2, -52.0), + }, + } { + ef := Eigen(DenseCopyOf(t.a), t.epsilon) + if t.d != nil { + c.Check(ef.d, check.DeepEquals, t.d) + } + if t.e != nil { + c.Check(ef.e, check.DeepEquals, t.e) + } + + if t.v != nil { + c.Check(ef.V.Equals(t.v), check.Equals, true) + } + + t.a.Mul(t.a, ef.V) + ef.V.Mul(ef.V, ef.D()) + c.Check(t.a.EqualsApprox(ef.V, 1e-12), check.Equals, true) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/format.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/format.go new file mode 100644 index 0000000..a4cc6ff --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/format.go @@ -0,0 +1,153 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "fmt" + "strconv" +) + +// Format prints a pretty representation of m to the fs io.Writer. The format character c +// specifies the numerical representation of of elements; valid values are those for float64 +// specified in the fmt package, with their associated flags. In addition to this, a '#' for +// all valid verbs except 'v' indicates that zero values be represented by the dot character. +// The '#' associated with the 'v' verb formats the matrix with Go syntax representation. +// The printed range of the matrix can be limited by specifying a positive value for margin; +// If margin is greater than zero, only the first and last margin rows/columns of the matrix +// are output. +func Format(m Matrix, margin int, dot byte, fs fmt.State, c rune) { + rows, cols := m.Dims() + + var printed int + if margin <= 0 { + printed = rows + if cols > printed { + printed = cols + } + } else { + printed = margin + } + + prec, pOk := fs.Precision() + if !pOk { + prec = -1 + } + + var ( + maxWidth int + buf, pad []byte + ) + switch c { + case 'v', 'e', 'E', 'f', 'F', 'g', 'G': + // Note that the '#' flag should have been dealt with by the type. + // So %v is treated exactly as %g here. + if c == 'v' { + buf, maxWidth = maxCellWidth(m, 'g', printed, prec) + } else { + buf, maxWidth = maxCellWidth(m, c, printed, prec) + } + default: + fmt.Fprintf(fs, "%%!%c(%T=Dims(%d, %d))", c, m, rows, cols) + return + } + width, _ := fs.Width() + width = max(width, maxWidth) + pad = make([]byte, max(width, 2)) + for i := range pad { + pad[i] = ' ' + } + + if rows > 2*printed || cols > 2*printed { + fmt.Fprintf(fs, "Dims(%d, %d)\n", rows, cols) + } + + skipZero := fs.Flag('#') + for i := 0; i < rows; i++ { + var el string + switch { + case rows == 1: + fmt.Fprint(fs, "[") + el = "]" + case i == 0: + fmt.Fprint(fs, "⎡") + el = "⎤\n" + case i < rows-1: + fmt.Fprint(fs, "⎢") + el = "⎥\n" + default: + fmt.Fprint(fs, "⎣") + el = "⎦" + } + + for j := 0; j < cols; j++ { + if j >= printed && j < cols-printed { + j = cols - printed - 1 + if i == 0 || i == rows-1 { + fmt.Fprint(fs, "... ... ") + } else { + fmt.Fprint(fs, " ") + } + continue + } + + v := m.At(i, j) + if v == 0 && skipZero { + buf = buf[:1] + buf[0] = dot + } else { + if c == 'v' { + buf = strconv.AppendFloat(buf[:0], v, 'g', prec, 64) + } else { + buf = strconv.AppendFloat(buf[:0], v, byte(c), prec, 64) + } + } + if fs.Flag('-') { + fs.Write(buf) + fs.Write(pad[:width-len(buf)]) + } else { + fs.Write(pad[:width-len(buf)]) + fs.Write(buf) + } + + if j < cols-1 { + fs.Write(pad[:2]) + } + } + + fmt.Fprint(fs, el) + + if i >= printed-1 && i < rows-printed && 2*printed < rows { + i = rows - printed - 1 + fmt.Fprint(fs, " .\n .\n .\n") + continue + } + } +} + +func maxCellWidth(m Matrix, c rune, printed, prec int) ([]byte, int) { + var ( + buf = make([]byte, 0, 64) + rows, cols = m.Dims() + max int + ) + for i := 0; i < rows; i++ { + if i >= printed-1 && i < rows-printed && 2*printed < rows { + i = rows - printed - 1 + continue + } + for j := 0; j < cols; j++ { + if j >= printed && j < cols-printed { + continue + } + + buf = strconv.AppendFloat(buf, m.At(i, j), byte(c), prec, 64) + if len(buf) > max { + max = len(buf) + } + buf = buf[:0] + } + } + return buf, max +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/format_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/format_test.go new file mode 100644 index 0000000..462866e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/format_test.go @@ -0,0 +1,140 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "fmt" + "math" + + "gopkg.in/check.v1" +) + +type fm struct { + Matrix + margin int +} + +func (m fm) Format(fs fmt.State, c rune) { + if c == 'v' && fs.Flag('#') { + fmt.Fprintf(fs, "%#v", m.Matrix) + return + } + Format(m.Matrix, m.margin, '.', fs, c) +} + +func (s *S) TestFormat(c *check.C) { + type rp struct { + format string + output string + } + sqrt := func(_, _ int, v float64) float64 { return math.Sqrt(v) } + for i, test := range []struct { + m fm + rep []rp + }{ + // Dense matrix representation + { + fm{Matrix: NewDense(3, 3, []float64{0, 0, 0, 0, 0, 0, 0, 0, 0})}, + []rp{ + {"%v", "⎡0 0 0⎤\n⎢0 0 0⎥\n⎣0 0 0⎦"}, + {"%#f", "⎡. . .⎤\n⎢. . .⎥\n⎣. . .⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:3, Cols:3, Stride:3, Data:[]float64{0, 0, 0, 0, 0, 0, 0, 0, 0}}, capRows:3, capCols:3}"}, + {"%s", "%!s(*mat64.Dense=Dims(3, 3))"}, + }, + }, + { + fm{Matrix: NewDense(3, 3, []float64{1, 1, 1, 1, 1, 1, 1, 1, 1})}, + []rp{ + {"%v", "⎡1 1 1⎤\n⎢1 1 1⎥\n⎣1 1 1⎦"}, + {"%#f", "⎡1 1 1⎤\n⎢1 1 1⎥\n⎣1 1 1⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:3, Cols:3, Stride:3, Data:[]float64{1, 1, 1, 1, 1, 1, 1, 1, 1}}, capRows:3, capCols:3}"}, + }, + }, + { + fm{Matrix: NewDense(3, 3, []float64{1, 0, 0, 0, 1, 0, 0, 0, 1})}, + []rp{ + {"%v", "⎡1 0 0⎤\n⎢0 1 0⎥\n⎣0 0 1⎦"}, + {"%#f", "⎡1 . .⎤\n⎢. 1 .⎥\n⎣. . 1⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:3, Cols:3, Stride:3, Data:[]float64{1, 0, 0, 0, 1, 0, 0, 0, 1}}, capRows:3, capCols:3}"}, + }, + }, + { + fm{Matrix: NewDense(2, 3, []float64{1, 2, 3, 4, 5, 6})}, + []rp{ + {"%v", "⎡1 2 3⎤\n⎣4 5 6⎦"}, + {"%#f", "⎡1 2 3⎤\n⎣4 5 6⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:2, Cols:3, Stride:3, Data:[]float64{1, 2, 3, 4, 5, 6}}, capRows:2, capCols:3}"}, + }, + }, + { + fm{Matrix: NewDense(3, 2, []float64{1, 2, 3, 4, 5, 6})}, + []rp{ + {"%v", "⎡1 2⎤\n⎢3 4⎥\n⎣5 6⎦"}, + {"%#f", "⎡1 2⎤\n⎢3 4⎥\n⎣5 6⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:3, Cols:2, Stride:2, Data:[]float64{1, 2, 3, 4, 5, 6}}, capRows:3, capCols:2}"}, + }, + }, + { + func() fm { + m := NewDense(2, 3, []float64{0, 1, 2, 3, 4, 5}) + m.Apply(sqrt, m) + return fm{Matrix: m} + }(), + []rp{ + {"%v", "⎡ 0 1 1.4142135623730951⎤\n⎣1.7320508075688772 2 2.23606797749979⎦"}, + {"%.2f", "⎡0.00 1.00 1.41⎤\n⎣1.73 2.00 2.24⎦"}, + {"%#f", "⎡ . 1 1.4142135623730951⎤\n⎣1.7320508075688772 2 2.23606797749979⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:2, Cols:3, Stride:3, Data:[]float64{0, 1, 1.4142135623730951, 1.7320508075688772, 2, 2.23606797749979}}, capRows:2, capCols:3}"}, + }, + }, + { + func() fm { + m := NewDense(3, 2, []float64{0, 1, 2, 3, 4, 5}) + m.Apply(sqrt, m) + return fm{Matrix: m} + }(), + []rp{ + {"%v", "⎡ 0 1⎤\n⎢1.4142135623730951 1.7320508075688772⎥\n⎣ 2 2.23606797749979⎦"}, + {"%.2f", "⎡0.00 1.00⎤\n⎢1.41 1.73⎥\n⎣2.00 2.24⎦"}, + {"%#f", "⎡ . 1⎤\n⎢1.4142135623730951 1.7320508075688772⎥\n⎣ 2 2.23606797749979⎦"}, + {"%#v", "&mat64.Dense{mat:blas64.General{Rows:3, Cols:2, Stride:2, Data:[]float64{0, 1, 1.4142135623730951, 1.7320508075688772, 2, 2.23606797749979}}, capRows:3, capCols:2}"}, + }, + }, + { + func() fm { + m := NewDense(1, 10, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) + return fm{Matrix: m, margin: 3} + }(), + []rp{ + {"%v", "Dims(1, 10)\n[ 1 2 3 ... ... 8 9 10]"}, + }, + }, + { + func() fm { + m := NewDense(10, 1, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) + return fm{Matrix: m, margin: 3} + }(), + []rp{ + {"%v", "Dims(10, 1)\n⎡ 1⎤\n⎢ 2⎥\n⎢ 3⎥\n .\n .\n .\n⎢ 8⎥\n⎢ 9⎥\n⎣10⎦"}, + }, + }, + { + func() fm { + m := NewDense(10, 10, nil) + for i := 0; i < 10; i++ { + m.Set(i, i, 1) + } + return fm{Matrix: m, margin: 3} + }(), + []rp{ + {"%v", "Dims(10, 10)\n⎡1 0 0 ... ... 0 0 0⎤\n⎢0 1 0 0 0 0⎥\n⎢0 0 1 0 0 0⎥\n .\n .\n .\n⎢0 0 0 1 0 0⎥\n⎢0 0 0 0 1 0⎥\n⎣0 0 0 ... ... 0 0 1⎦"}, + }, + }, + } { + for _, rp := range test.rep { + c.Check(fmt.Sprintf(rp.format, test.m), check.Equals, rp.output, check.Commentf("Test %d", i)) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/index_bound_checks.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/index_bound_checks.go new file mode 100644 index 0000000..e4a5e18 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/index_bound_checks.go @@ -0,0 +1,149 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file must be kept in sync with index_no_bound_checks.go. + +//+build bounds + +package mat64 + +import "github.com/gonum/blas" + +func (m *Dense) At(r, c int) float64 { + return m.at(r, c) +} + +func (m *Dense) at(r, c int) float64 { + if r >= m.mat.Rows || r < 0 { + panic(ErrRowAccess) + } + if c >= m.mat.Cols || c < 0 { + panic(ErrColAccess) + } + return m.mat.Data[r*m.mat.Stride+c] +} + +func (m *Dense) Set(r, c int, v float64) { + m.set(r, c, v) +} + +func (m *Dense) set(r, c int, v float64) { + if r >= m.mat.Rows || r < 0 { + panic(ErrRowAccess) + } + if c >= m.mat.Cols || c < 0 { + panic(ErrColAccess) + } + m.mat.Data[r*m.mat.Stride+c] = v +} + +func (m *Vector) At(r, c int) float64 { + if c != 0 { + panic(ErrColAccess) + } + return m.at(r) +} + +func (m *Vector) at(r int) float64 { + if r < 0 || r >= m.n { + panic(ErrRowAccess) + } + return m.mat.Data[r*m.mat.Inc] +} + +func (m *Vector) Set(r, c int, v float64) { + if c != 0 { + panic(ErrColAccess) + } + m.set(r, v) +} + +func (m *Vector) set(r int, v float64) { + if r < 0 || r >= m.n { + panic(ErrRowAccess) + } + m.mat.Data[r*m.mat.Inc] = v +} + +// At returns the element at row r and column c. +func (t *SymDense) At(r, c int) float64 { + return t.at(r, c) +} + +func (t *SymDense) at(r, c int) float64 { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + if r > c { + r, c = c, r + } + return t.mat.Data[r*t.mat.Stride+c] +} + +// SetSym sets the elements at (r,c) and (c,r) to the value v. +func (t *SymDense) SetSym(r, c int, v float64) { + t.set(r, c, v) +} + +func (t *SymDense) set(r, c int, v float64) { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + if r > c { + r, c = c, r + } + t.mat.Data[r*t.mat.Stride+c] = v +} + +// At returns the element at row r and column c. +func (t *Triangular) At(r, c int) float64 { + return t.at(r, c) +} + +func (t *Triangular) at(r, c int) float64 { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + if t.mat.Uplo == blas.Upper { + if r > c { + return 0 + } + return t.mat.Data[r*t.mat.Stride+c] + } + if r < c { + return 0 + } + return t.mat.Data[r*t.mat.Stride+c] +} + +// SetTri sets the element of the triangular matrix at row r and column c. +// Set panics if the location is outside the appropriate half of the matrix. +func (t *Triangular) SetTri(r, c int, v float64) { + t.set(r, c, v) +} + +func (t *Triangular) set(r, c int, v float64) { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + if t.mat.Uplo == blas.Upper && r > c { + panic("mat64: triangular set out of bounds") + } + if t.mat.Uplo == blas.Lower && r < c { + panic("mat64: triangular set out of bounds") + } + t.mat.Data[r*t.mat.Stride+c] = v +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/index_no_bound_checks.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/index_no_bound_checks.go new file mode 100644 index 0000000..cab0025 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/index_no_bound_checks.go @@ -0,0 +1,149 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file must be kept in sync with index_bound_checks.go. + +//+build !bounds + +package mat64 + +import "github.com/gonum/blas" + +func (m *Dense) At(r, c int) float64 { + if r >= m.mat.Rows || r < 0 { + panic(ErrRowAccess) + } + if c >= m.mat.Cols || c < 0 { + panic(ErrColAccess) + } + return m.at(r, c) +} + +func (m *Dense) at(r, c int) float64 { + return m.mat.Data[r*m.mat.Stride+c] +} + +func (m *Dense) Set(r, c int, v float64) { + if r >= m.mat.Rows || r < 0 { + panic(ErrRowAccess) + } + if c >= m.mat.Cols || c < 0 { + panic(ErrColAccess) + } + m.set(r, c, v) +} + +func (m *Dense) set(r, c int, v float64) { + m.mat.Data[r*m.mat.Stride+c] = v +} + +func (m *Vector) At(r, c int) float64 { + if r < 0 || r >= m.n { + panic(ErrRowAccess) + } + if c != 0 { + panic(ErrColAccess) + } + return m.at(r) +} + +func (m *Vector) at(r int) float64 { + return m.mat.Data[r*m.mat.Inc] +} + +func (m *Vector) Set(r, c int, v float64) { + if r < 0 || r >= m.n { + panic(ErrRowAccess) + } + if c != 0 { + panic(ErrColAccess) + } + m.set(r, v) +} + +func (m *Vector) set(r int, v float64) { + m.mat.Data[r*m.mat.Inc] = v +} + +// At returns the element at row r and column c. +func (t *SymDense) At(r, c int) float64 { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + return t.at(r, c) +} + +func (t *SymDense) at(r, c int) float64 { + if r > c { + r, c = c, r + } + return t.mat.Data[r*t.mat.Stride+c] +} + +// SetSym sets the elements at (r,c) and (c,r) to the value v. +func (t *SymDense) SetSym(r, c int, v float64) { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + t.set(r, c, v) +} + +func (t *SymDense) set(r, c int, v float64) { + if r > c { + r, c = c, r + } + t.mat.Data[r*t.mat.Stride+c] = v +} + +// At returns the element at row r and column c. +func (t *Triangular) At(r, c int) float64 { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + return t.at(r, c) +} + +func (t *Triangular) at(r, c int) float64 { + if t.mat.Uplo == blas.Upper { + if r > c { + return 0 + } + return t.mat.Data[r*t.mat.Stride+c] + } + if r < c { + return 0 + } + return t.mat.Data[r*t.mat.Stride+c] +} + +// Set sets the element at row r and column c. Set panics if the location is outside +// the appropriate half of the matrix. +func (t *Triangular) SetTri(r, c int, v float64) { + if r >= t.mat.N || r < 0 { + panic(ErrRowAccess) + } + if c >= t.mat.N || c < 0 { + panic(ErrColAccess) + } + if t.mat.Uplo == blas.Upper && r > c { + panic("mat64: triangular set out of bounds") + } + if t.mat.Uplo == blas.Lower && r < c { + panic("mat64: triangular set out of bounds") + } + t.set(r, c, v) +} + +func (t *Triangular) set(r, c int, v float64) { + t.mat.Data[r*t.mat.Stride+c] = v +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/inner.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/inner.go new file mode 100644 index 0000000..3b4e780 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/inner.go @@ -0,0 +1,56 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import "github.com/gonum/internal/asm" + +// Inner computes the generalized inner product +// x^T A y +// between vectors x and y with matrix A. This is only a true inner product if +// A is symmetric positive definite, though the operation works for any matrix A. +// +// Inner panics if len(x) != m or len(y) != n when A is an m x n matrix. +func Inner(x []float64, A Matrix, y []float64) float64 { + m, n := A.Dims() + if len(x) != m { + panic(ErrShape) + } + if len(y) != n { + panic(ErrShape) + } + if m == 0 || n == 0 { + return 0 + } + + var sum float64 + + switch b := A.(type) { + case RawSymmetricer: + bmat := b.RawSymmetric() + for i, xi := range x { + if xi != 0 { + sum += xi * asm.DdotUnitary(bmat.Data[i*bmat.Stride+i:i*bmat.Stride+n], y[i:]) + } + yi := y[i] + if i != n-1 && yi != 0 { + sum += yi * asm.DdotUnitary(bmat.Data[i*bmat.Stride+i+1:i*bmat.Stride+n], x[i+1:]) + } + } + case RawMatrixer: + bmat := b.RawMatrix() + for i, xi := range x { + if xi != 0 { + sum += xi * asm.DdotUnitary(bmat.Data[i*bmat.Stride:i*bmat.Stride+n], y) + } + } + default: + for i, xi := range x { + for j, yj := range y { + sum += xi * A.At(i, j) * yj + } + } + } + return sum +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/inner_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/inner_test.go new file mode 100644 index 0000000..f0a155d --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/inner_test.go @@ -0,0 +1,138 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + "math/rand" + "testing" + + "github.com/gonum/blas/blas64" + "gopkg.in/check.v1" +) + +func (s *S) TestInner(c *check.C) { + for i, test := range []struct { + x []float64 + y []float64 + m [][]float64 + }{ + { + x: []float64{5}, + y: []float64{10}, + m: [][]float64{{2}}, + }, + { + x: []float64{5, 6, 1}, + y: []float64{10}, + m: [][]float64{{2}, {-3}, {5}}, + }, + { + x: []float64{5}, + y: []float64{10, 15}, + m: [][]float64{{2, -3}}, + }, + { + x: []float64{1, 5}, + y: []float64{10, 15}, + m: [][]float64{ + {2, -3}, + {4, -1}, + }, + }, + { + x: []float64{2, 3, 9}, + y: []float64{8, 9}, + m: [][]float64{ + {2, 3}, + {4, 5}, + {6, 7}, + }, + }, + { + x: []float64{2, 3}, + y: []float64{8, 9, 9}, + m: [][]float64{ + {2, 3, 6}, + {4, 5, 7}, + }, + }, + } { + x := NewDense(1, len(test.x), test.x) + m := NewDense(flatten(test.m)) + mWant := NewDense(flatten(test.m)) + y := NewDense(len(test.y), 1, test.y) + + mWant.Mul(mWant, y) + mWant.Mul(x, mWant) + + rm, cm := mWant.Dims() + c.Check(rm, check.Equals, 1, check.Commentf("Test %v result doesn't have 1 row", i)) + c.Check(cm, check.Equals, 1, check.Commentf("Test %v result doesn't have 1 column", i)) + + want := mWant.At(0, 0) + + got := Inner(test.x, m, test.y) + c.Check(want, check.Equals, got, check.Commentf("Test %v: want %v, got %v", i, want, got)) + } +} + +func (s *S) TestInnerSym(c *check.C) { + n := 10 + x := make([]float64, n) + y := make([]float64, n) + data := make([]float64, n*n) + for i := 0; i < n; i++ { + x[i] = float64(i) + y[i] = float64(i) + for j := i; j < n; j++ { + data[i*n+j] = float64(i*n + j) + data[j*n+i] = data[i*n+j] + } + } + m := NewDense(n, n, data) + ans := Inner(x, m, y) + sym := NewSymDense(n, data) + // scramble the lower half of data to ensure it is not used + for i := 1; i < n; i++ { + for j := 0; j < i; j++ { + data[i*n+j] = rand.Float64() + } + } + + if math.Abs(Inner(x, sym, y)-ans) > 1e-14 { + c.Error("inner different symmetric and dense") + } +} + +func benchmarkInner(b *testing.B, m, n int) { + x := make([]float64, m) + randomSlice(x) + y := make([]float64, n) + randomSlice(y) + data := make([]float64, m*n) + randomSlice(data) + mat := &Dense{mat: blas64.General{Rows: m, Cols: n, Stride: n, Data: data}, capRows: m, capCols: n} + b.ResetTimer() + for i := 0; i < b.N; i++ { + Inner(x, mat, y) + } +} + +func BenchmarkInnerSmSm(b *testing.B) { + benchmarkInner(b, Sm, Sm) +} + +func BenchmarkInnerMedMed(b *testing.B) { + benchmarkInner(b, Med, Med) +} + +func BenchmarkInnerLgLg(b *testing.B) { + benchmarkInner(b, Lg, Lg) +} + +func BenchmarkInnerLgSm(b *testing.B) { + benchmarkInner(b, Lg, Sm) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/io.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/io.go new file mode 100644 index 0000000..043d4cf --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/io.go @@ -0,0 +1,18 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "encoding/binary" +) + +var ( + littleEndian = binary.LittleEndian + bigEndian = binary.BigEndian + defaultEndian = littleEndian + + sizeInt64 = binary.Size(int64(0)) + sizeFloat64 = binary.Size(float64(0)) +) diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/io_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/io_test.go new file mode 100644 index 0000000..a83335e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/io_test.go @@ -0,0 +1,35 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "gopkg.in/check.v1" +) + +func (s *S) TestDenseRW(c *check.C) { + for i, test := range []*Dense{ + NewDense(0, 0, []float64{}), + NewDense(2, 2, []float64{1, 2, 3, 4}), + NewDense(2, 3, []float64{1, 2, 3, 4, 5, 6}), + NewDense(3, 2, []float64{1, 2, 3, 4, 5, 6}), + NewDense(3, 3, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}), + NewDense(3, 3, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}).View(0, 0, 2, 2).(*Dense), + NewDense(3, 3, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}).View(1, 1, 2, 2).(*Dense), + NewDense(3, 3, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}).View(0, 1, 3, 2).(*Dense), + } { + buf, err := test.MarshalBinary() + c.Check(err, check.Equals, nil, check.Commentf("error encoding test #%d: %v\n", i, err)) + + nrows, ncols := test.Dims() + sz := nrows*ncols*sizeFloat64 + 2*sizeInt64 + c.Check(len(buf), check.Equals, sz, check.Commentf("encoded size test #%d: want=%d got=%d\n", i, sz, len(buf))) + + var got Dense + err = got.UnmarshalBinary(buf) + c.Check(err, check.Equals, nil, check.Commentf("error decoding test #%d: %v\n", i, err)) + + c.Check(got.Equals(test), check.Equals, true, check.Commentf("r/w test #%d failed\nwant=%#v\n got=%#v\n", i, test, &got)) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lq.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lq.go new file mode 100644 index 0000000..6d1c616 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lq.go @@ -0,0 +1,193 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" +) + +type LQFactor struct { + LQ *Dense + lDiag []float64 +} + +// LQ computes an LQ Decomposition for an m-by-n matrix a with m <= n by Householder +// reflections. The LQ decomposition is an m-by-n orthogonal matrix q and an m-by-m +// lower triangular matrix l so that a = l.q. LQ will panic with ErrShape if m > n. +// +// The LQ decomposition always exists, even if the matrix does not have full rank, +// so LQ will never fail unless m > n. The primary use of the LQ decomposition is +// in the least squares solution of non-square systems of simultaneous linear equations. +// This will fail if LQIsFullRank() returns false. The matrix a is overwritten by the +// decomposition. +func LQ(a *Dense) LQFactor { + // Initialize. + m, n := a.Dims() + if m > n { + panic(ErrShape) + } + + lq := *a + + lDiag := make([]float64, m) + projs := NewVector(m, nil) + + // Main loop. + for k := 0; k < m; k++ { + hh := lq.RawRowView(k)[k:] + norm := blas64.Nrm2(len(hh), blas64.Vector{Inc: 1, Data: hh}) + lDiag[k] = norm + + if norm != 0 { + hhNorm := (norm * math.Sqrt(1-hh[0]/norm)) + if hhNorm == 0 { + hh[0] = 0 + } else { + // Form k-th Householder vector. + s := 1 / hhNorm + hh[0] -= norm + blas64.Scal(len(hh), s, blas64.Vector{Inc: 1, Data: hh}) + + // Apply transformation to remaining columns. + if k < m-1 { + a = lq.View(k+1, k, m-k-1, n-k).(*Dense) + projs = projs.ViewVec(0, m-k-1) + projs.MulVec(a, false, NewVector(len(hh), hh)) + + for j := 0; j < m-k-1; j++ { + dst := a.RawRowView(j) + blas64.Axpy(len(dst), -projs.at(j), + blas64.Vector{Inc: 1, Data: hh}, + blas64.Vector{Inc: 1, Data: dst}, + ) + } + } + } + } + } + *a = lq + + return LQFactor{a, lDiag} +} + +// IsFullRank returns whether the L matrix and hence a has full rank. +func (f LQFactor) IsFullRank() bool { + for _, v := range f.lDiag { + if v == 0 { + return false + } + } + return true +} + +// L returns the lower triangular factor for the LQ decomposition. +func (f LQFactor) L() *Dense { + lq, lDiag := f.LQ, f.lDiag + m, _ := lq.Dims() + l := NewDense(m, m, nil) + for i, v := range lDiag { + for j := 0; j < m; j++ { + if i < j { + l.set(j, i, lq.at(j, i)) + } else if i == j { + l.set(j, i, v) + } + } + } + return l +} + +// replaces x with Q.x +func (f LQFactor) applyQTo(x *Dense, trans bool) { + nh, nc := f.LQ.Dims() + m, n := x.Dims() + if m != nc { + panic(ErrShape) + } + proj := make([]float64, n) + + if trans { + for k := nh - 1; k >= 0; k-- { + hh := f.LQ.RawRowView(k)[k:] + + sub := x.View(k, 0, m-k, n).(*Dense) + + blas64.Gemv(blas.Trans, + 1, sub.mat, blas64.Vector{Inc: 1, Data: hh}, + 0, blas64.Vector{Inc: 1, Data: proj}, + ) + for i := k; i < m; i++ { + row := x.RawRowView(i) + blas64.Axpy(n, -hh[i-k], + blas64.Vector{Inc: 1, Data: proj}, + blas64.Vector{Inc: 1, Data: row}, + ) + } + } + } else { + for k := 0; k < nh; k++ { + hh := f.LQ.RawRowView(k)[k:] + + sub := x.View(k, 0, m-k, n).(*Dense) + + blas64.Gemv(blas.Trans, + 1, sub.mat, blas64.Vector{Inc: 1, Data: hh}, + 0, blas64.Vector{Inc: 1, Data: proj}, + ) + for i := k; i < m; i++ { + row := x.RawRowView(i) + blas64.Axpy(n, -hh[i-k], + blas64.Vector{Inc: 1, Data: proj}, + blas64.Vector{Inc: 1, Data: row}, + ) + } + } + } +} + +// Solve computes minimum norm least squares solution of a.x = b where b has as many rows as a. +// A matrix x is returned that minimizes the two norm of Q*R*X-B. Solve will panic +// if a is not full rank. +func (f LQFactor) Solve(b *Dense) (x *Dense) { + lq := f.LQ + lDiag := f.lDiag + m, n := lq.Dims() + bm, bn := b.Dims() + if bm != m { + panic(ErrShape) + } + if !f.IsFullRank() { + panic(ErrSingular) + } + + x = NewDense(n, bn, nil) + x.Copy(b) + + tau := make([]float64, m) + for i := range tau { + tau[i] = lq.at(i, i) + lq.set(i, i, lDiag[i]) + } + lqT := blas64.Triangular{ + // N omitted since it is not used by Trsm. + Stride: lq.mat.Stride, + Data: lq.mat.Data, + Uplo: blas.Lower, + Diag: blas.NonUnit, + } + x.mat.Rows = bm + blas64.Trsm(blas.Left, blas.NoTrans, 1, lqT, x.mat) + x.mat.Rows = n + for i := range tau { + lq.set(i, i, tau[i]) + } + + f.applyQTo(x, true) + + return x +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lq_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lq_test.go new file mode 100644 index 0000000..c9ee75b --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lq_test.go @@ -0,0 +1,120 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + + "gopkg.in/check.v1" +) + +func isLowerTriangular(a *Dense) bool { + rows, cols := a.Dims() + for r := 0; r < rows; r++ { + for c := r + 1; c < cols; c++ { + if math.Abs(a.At(r, c)) > 1e-14 { + return false + } + } + } + return true +} + +func (s *S) TestLQD(c *check.C) { + for _, test := range []struct { + a [][]float64 + name string + }{ + { + name: "Square", + a: [][]float64{ + {1.3, 2.4, 8.9}, + {-2.6, 8.7, 9.1}, + {5.6, 5.8, 2.1}, + }, + }, + { + name: "Skinny", + a: [][]float64{ + {1.3, 2.4, 8.9}, + {-2.6, 8.7, 9.1}, + {5.6, 5.8, 2.1}, + {19.4, 5.2, -26.1}, + }, + }, + { + name: "Id", + a: [][]float64{ + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1}, + }, + }, + { + name: "Id", + a: [][]float64{ + {0, 0, 2}, + {0, 1, 0}, + {3, 0, 0}, + }, + }, + { + name: "small", + a: [][]float64{ + {1, 1}, + {1, 2}, + }, + }, + } { + a := NewDense(flatten(test.a)) + + at := new(Dense) + at.TCopy(a) + + lq := LQ(DenseCopyOf(at)) + + rows, cols := a.Dims() + + Q := NewDense(rows, cols, nil) + for i := 0; i < cols; i++ { + Q.Set(i, i, 1) + } + lq.applyQTo(Q, true) + l := lq.L() + + lt := NewDense(rows, cols, nil) + ltview := lt.View(0, 0, cols, cols).(*Dense) + ltview.TCopy(l) + lq.applyQTo(lt, true) + + c.Check(isOrthogonal(Q), check.Equals, true, check.Commentf("Test %v: Q not orthogonal", test.name)) + c.Check(a.EqualsApprox(lt, 1e-13), check.Equals, true, check.Commentf("Test %v: Q*R != A", test.name)) + c.Check(isLowerTriangular(l), check.Equals, true, + check.Commentf("Test %v: L not lower triangular", test.name)) + + nrhs := 2 + barr := make([]float64, nrhs*cols) + for i := range barr { + barr[i] = float64(i) + } + b := NewDense(cols, nrhs, barr) + + x := lq.Solve(b) + + var bProj Dense + bProj.Mul(at, x) + + c.Check(bProj.EqualsApprox(b, 1e-13), check.Equals, true, check.Commentf("Test %v: A*X != B", test.name)) + + qr := QR(DenseCopyOf(a)) + lambda := qr.Solve(DenseCopyOf(x)) + + var xCheck Dense + xCheck.Mul(a, lambda) + + c.Check(xCheck.EqualsApprox(x, 1e-13), check.Equals, true, + check.Commentf("Test %v: A*lambda != X", test.name)) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lu.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lu.go new file mode 100644 index 0000000..13af609 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lu.go @@ -0,0 +1,269 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// Based on the LUDecomposition class from Jama 1.0.3. + +package mat64 + +import ( + "math" +) + +type LUFactors struct { + LU *Dense + Pivot []int + Sign int +} + +// LU performs an LU Decomposition for an m-by-n matrix a. +// +// If m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, +// an n-by-n upper triangular matrix U, and a permutation vector piv of length m +// so that A(piv,:) = L*U. +// +// If m < n, then L is m-by-m and U is m-by-n. +// +// The LU decompostion with pivoting always exists, even if the matrix is +// singular, so LU will never fail. The primary use of the LU decomposition +// is in the solution of square systems of simultaneous linear equations. This +// will fail if IsSingular() returns true. +func LU(a *Dense) LUFactors { + // Use a "left-looking", dot-product, Crout/Doolittle algorithm. + m, n := a.Dims() + lu := a + + piv := make([]int, m) + for i := range piv { + piv[i] = i + } + sign := 1 + + // Outer loop. + luColj := make([]float64, m) + for j := 0; j < n; j++ { + + // Make a copy of the j-th column to localize references. + for i := 0; i < m; i++ { + luColj[i] = lu.at(i, j) + } + + // Apply previous transformations. + for i := 0; i < m; i++ { + luRowi := lu.RawRowView(i) + + // Most of the time is spent in the following dot product. + kmax := min(i, j) + var s float64 + for k, v := range luRowi[:kmax] { + s += v * luColj[k] + } + + luColj[i] -= s + luRowi[j] = luColj[i] + } + + // Find pivot and exchange if necessary. + p := j + for i := j + 1; i < m; i++ { + if math.Abs(luColj[i]) > math.Abs(luColj[p]) { + p = i + } + } + if p != j { + for k := 0; k < n; k++ { + t := lu.at(p, k) + lu.set(p, k, lu.at(j, k)) + lu.set(j, k, t) + } + piv[p], piv[j] = piv[j], piv[p] + sign = -sign + } + + // Compute multipliers. + if j < m && lu.at(j, j) != 0 { + for i := j + 1; i < m; i++ { + lu.set(i, j, lu.at(i, j)/lu.at(j, j)) + } + } + } + + return LUFactors{lu, piv, sign} +} + +// LUGaussian performs an LU Decomposition for an m-by-n matrix a using Gaussian elimination. +// L and U are found using the "daxpy"-based elimination algorithm used in LINPACK and +// MATLAB. +// +// If m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, +// an n-by-n upper triangular matrix U, and a permutation vector piv of length m +// so that A(piv,:) = L*U. +// +// If m < n, then L is m-by-m and U is m-by-n. +// +// The LU decompostion with pivoting always exists, even if the matrix is +// singular, so LUGaussian will never fail. The primary use of the LU decomposition +// is in the solution of square systems of simultaneous linear equations. This +// will fail if IsSingular() returns true. +func LUGaussian(a *Dense) LUFactors { + // Initialize. + m, n := a.Dims() + lu := a + + piv := make([]int, m) + for i := range piv { + piv[i] = i + } + sign := 1 + + // Main loop. + for k := 0; k < n; k++ { + // Find pivot. + p := k + for i := k + 1; i < m; i++ { + if math.Abs(lu.at(i, k)) > math.Abs(lu.at(p, k)) { + p = i + } + } + + // Exchange if necessary. + if p != k { + for j := 0; j < n; j++ { + t := lu.at(p, j) + lu.set(p, j, lu.at(k, j)) + lu.set(k, j, t) + } + piv[p], piv[k] = piv[k], piv[p] + sign = -sign + } + + // Compute multipliers and eliminate k-th column. + if lu.at(k, k) != 0 { + for i := k + 1; i < m; i++ { + lu.set(i, k, lu.at(i, k)/lu.at(k, k)) + for j := k + 1; j < n; j++ { + lu.set(i, j, lu.at(i, j)-lu.at(i, k)*lu.at(k, j)) + } + } + } + } + + return LUFactors{lu, piv, sign} +} + +// IsSingular returns whether the the upper triangular factor and hence a is +// singular. +func (f LUFactors) IsSingular() bool { + lu := f.LU + _, n := lu.Dims() + for j := 0; j < n; j++ { + if lu.at(j, j) == 0 { + return true + } + } + return false +} + +// L returns the lower triangular factor of the LU decomposition. +func (f LUFactors) L() *Dense { + lu := f.LU + m, n := lu.Dims() + l := NewDense(m, n, nil) + for i := 0; i < m; i++ { + for j := 0; j < n; j++ { + if i > j { + l.set(i, j, lu.at(i, j)) + } else if i == j { + l.set(i, j, 1) + } + } + } + return l +} + +// U returns the upper triangular factor of the LU decomposition. +func (f LUFactors) U() *Dense { + lu := f.LU + m, n := lu.Dims() + u := NewDense(m, n, nil) + for i := 0; i < n; i++ { + for j := 0; j < n; j++ { + if i <= j { + u.set(i, j, lu.at(i, j)) + } + } + } + return u +} + +// Det returns the determinant of matrix a decomposed into lu. The matrix +// a must have been square. +func (f LUFactors) Det() float64 { + lu, sign := f.LU, f.Sign + m, n := lu.Dims() + if m != n { + panic(ErrSquare) + } + d := float64(sign) + for j := 0; j < n; j++ { + d *= lu.at(j, j) + } + return d +} + +// Solve computes a solution of a.x = b where b has as many rows as a. A matrix x +// is returned that minimizes the two norm of L*U*X - B(piv,:). Solve will panic +// if a is singular. The matrix b is overwritten during the call. +func (f LUFactors) Solve(b *Dense) (x *Dense) { + lu, piv := f.LU, f.Pivot + m, n := lu.Dims() + bm, bn := b.Dims() + if bm != m { + panic(ErrShape) + } + if f.IsSingular() { + panic(ErrSingular) + } + + // Copy right hand side with pivoting + nx := bn + x = pivotRows(b, piv) + + // Solve L*Y = B(piv,:) + for k := 0; k < n; k++ { + for i := k + 1; i < n; i++ { + for j := 0; j < nx; j++ { + x.set(i, j, x.at(i, j)-x.at(k, j)*lu.at(i, k)) + } + } + } + + // Solve U*X = Y; + for k := n - 1; k >= 0; k-- { + for j := 0; j < nx; j++ { + x.set(k, j, x.at(k, j)/lu.at(k, k)) + } + for i := 0; i < k; i++ { + for j := 0; j < nx; j++ { + x.set(i, j, x.at(i, j)-x.at(k, j)*lu.at(i, k)) + } + } + } + + return x +} + +func pivotRows(a *Dense, piv []int) *Dense { + visit := make([]bool, len(piv)) + _, n := a.Dims() + tmpRow := make([]float64, n) + for to, from := range piv { + for to != from && !visit[from] { + visit[from], visit[to] = true, true + a.Row(tmpRow, from) + a.SetRow(from, a.rowView(to)) + a.SetRow(to, tmpRow) + to, from = from, piv[from] + } + } + return a +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lu_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lu_test.go new file mode 100644 index 0000000..163d7f2 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/lu_test.go @@ -0,0 +1,132 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "gopkg.in/check.v1" +) + +func (s *S) TestLUD(c *check.C) { + for _, t := range []struct { + a *Dense + + l *Dense + u *Dense + + pivot []int + sign int + }{ + { // This is a hard coded equivalent of the approach used in the Jama LU test. + a: NewDense(3, 3, []float64{ + 0, 2, 3, + 4, 5, 6, + 7, 8, 9, + }), + + l: NewDense(3, 3, []float64{ + 1, 0, 0, + 0, 1, 0, + 0.5714285714285714, 0.2142857142857144, 1, + }), + u: NewDense(3, 3, []float64{ + 7, 8, 9, + 0, 2, 3, + 0, 0, 0.2142857142857144, + }), + pivot: []int{ + 2, // 0 0 1 + 0, // 1 0 0 + 1, // 0 1 0 + }, + sign: 1, + }, + } { + lf := LU(DenseCopyOf(t.a)) + if t.pivot != nil { + c.Check(lf.Pivot, check.DeepEquals, t.pivot) + c.Check(lf.Sign, check.Equals, t.sign) + } + + l := lf.L() + if t.l != nil { + c.Check(l.Equals(t.l), check.Equals, true) + } + u := lf.U() + if t.u != nil { + c.Check(u.Equals(t.u), check.Equals, true) + } + + l.Mul(l, u) + c.Check(l.EqualsApprox(pivotRows(DenseCopyOf(t.a), lf.Pivot), 1e-12), check.Equals, true) + + x := lf.Solve(eye()) + t.a.Mul(t.a, x) + c.Check(t.a.EqualsApprox(eye(), 1e-12), check.Equals, true) + } +} + +func (s *S) TestLUDGaussian(c *check.C) { + for _, t := range []struct { + a *Dense + + l *Dense + u *Dense + + pivot []int + sign int + }{ + { // This is a hard coded equivalent of the approach used in the Jama LU test. + a: NewDense(3, 3, []float64{ + 0, 2, 3, + 4, 5, 6, + 7, 8, 9, + }), + + l: NewDense(3, 3, []float64{ + 1, 0, 0, + 0, 1, 0, + 0.5714285714285714, 0.2142857142857144, 1, + }), + u: NewDense(3, 3, []float64{ + 7, 8, 9, + 0, 2, 3, + 0, 0, 0.2142857142857144, + }), + pivot: []int{ + 2, // 0 0 1 + 0, // 1 0 0 + 1, // 0 1 0 + }, + sign: 1, + }, + } { + lf := LUGaussian(DenseCopyOf(t.a)) + if t.pivot != nil { + c.Check(lf.Pivot, check.DeepEquals, t.pivot) + c.Check(lf.Sign, check.Equals, t.sign) + } + + l := lf.L() + if t.l != nil { + c.Check(l.Equals(t.l), check.Equals, true) + } + u := lf.U() + if t.u != nil { + c.Check(u.Equals(t.u), check.Equals, true) + } + + l.Mul(l, u) + c.Check(l.EqualsApprox(pivotRows(DenseCopyOf(t.a), lf.Pivot), 1e-12), check.Equals, true) + + aInv, err := Inverse(t.a) + c.Check(err, check.Equals, nil) + aInv.Mul(aInv, t.a) + c.Check(aInv.EqualsApprox(eye(), 1e-12), check.Equals, true) + + x := lf.Solve(eye()) + t.a.Mul(t.a, x) + c.Check(t.a.EqualsApprox(eye(), 1e-12), check.Equals, true) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/matrix.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/matrix.go new file mode 100644 index 0000000..e9f213c --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/matrix.go @@ -0,0 +1,458 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package mat64 provides basic linear algebra operations for float64 matrices. +// +// Note that in all interfaces that assign the result to the receiver, the receiver must +// be either the correct dimensions for the result or a zero-sized matrix. In the latter +// case, matrix data is allocated and stored in the receiver. If the matrix dimensions +// do not match the result, the method must panic. +package mat64 + +import ( + "github.com/gonum/blas/blas64" +) + +// Matrix is the basic matrix interface type. +type Matrix interface { + // Dims returns the dimensions of a Matrix. + Dims() (r, c int) + + // At returns the value of a matrix element at (r, c). It will panic if r or c are + // out of bounds for the matrix. + At(r, c int) float64 +} + +// Mutable is a matrix interface type that allows elements to be altered. +type Mutable interface { + // Set alters the matrix element at (r, c) to v. It will panic if r or c are out of + // bounds for the matrix. + Set(r, c int, v float64) + + Matrix +} + +// A Vectorer can return rows and columns of the represented matrix. +type Vectorer interface { + // Row returns a slice of float64 for the row specified. It will panic if the index + // is out of bounds. If the call requires a copy and dst is not nil it will be used and + // returned, if it is not nil the number of elements copied will be the minimum of the + // length of the slice and the number of columns in the matrix. + Row(dst []float64, i int) []float64 + + // Col returns a slice of float64 for the column specified. It will panic if the index + // is out of bounds. If the call requires a copy and dst is not nil it will be used and + // returned, if it is not nil the number of elements copied will be the minimum of the + // length of the slice and the number of rows in the matrix. + Col(dst []float64, j int) []float64 +} + +// A VectorSetter can set rows and columns in the represented matrix. +type VectorSetter interface { + // SetRow sets the values of the specified row to the values held in a slice of float64. + // It will panic if the index is out of bounds. The number of elements copied is + // returned and will be the minimum of the length of the slice and the number of columns + // in the matrix. + SetRow(i int, src []float64) int + + // SetCol sets the values of the specified column to the values held in a slice of float64. + // It will panic if the index is out of bounds. The number of elements copied is + // returned and will be the minimum of the length of the slice and the number of rows + // in the matrix. + SetCol(i int, src []float64) int +} + +// A RowViewer can return a Vector reflecting a row that is backed by the matrix +// data. The Vector returned will have Len() == nCols. +type RowViewer interface { + RowView(r int) *Vector +} + +// A RawRowViewer can return a slice of float64 reflecting a row that is backed by the matrix +// data. +type RawRowViewer interface { + RawRowView(r int) []float64 +} + +// A ColViewer can return a Vector reflecting a row that is backed by the matrix +// data. The Vector returned will have Len() == nRows. +type ColViewer interface { + ColView(c int) *Vector +} + +// A RawColViewer can return a slice of float64 reflecting a column that is backed by the matrix +// data. +type RawColViewer interface { + RawColView(c int) *Vector +} + +// A Cloner can make a copy of a into the receiver, overwriting the previous value of the +// receiver. The clone operation does not make any restriction on shape. +type Cloner interface { + Clone(a Matrix) +} + +// A Reseter can reset the matrix so that it can be reused as the receiver of a dimensionally +// restricted operation. This is commonly used when the matrix is being used a a workspace +// or temporary matrix. +// +// If the matrix is a view, using the reset matrix may result in data corruption in elements +// outside the view. +type Reseter interface { + Reset() +} + +// A Copier can make a copy of elements of a into the receiver. The submatrix copied +// starts at row and column 0 and has dimensions equal to the minimum dimensions of +// the two matrices. The number of row and columns copied is returned. +type Copier interface { + Copy(a Matrix) (r, c int) +} + +// A Viewer returns a submatrix view of the Matrix parameter, starting at row i, column j +// and extending r rows and c columns. If i or j are out of range, or r or c are zero or +// extend beyond the bounds of the matrix View will panic with ErrIndexOutOfRange. The +// returned matrix must retain the receiver's reference to the original matrix such that +// changes in the elements of the submatrix are reflected in the original and vice versa. +type Viewer interface { + View(i, j, r, c int) Matrix +} + +// A Grower can grow the size of the represented matrix by the given number of rows and columns. +// Growing beyond the size given by the Caps method will result in the allocation of a new +// matrix and copying of the elements. If Grow is called with negative increments it will +// panic with ErrIndexOutOfRange. +type Grower interface { + Caps() (r, c int) + Grow(r, c int) Matrix +} + +// A Normer can return the specified matrix norm, o of the matrix represented by the receiver. +// +// Valid order values are: +// +// 1 - max of the sum of the absolute values of columns +// -1 - min of the sum of the absolute values of columns +// Inf - max of the sum of the absolute values of rows +// -Inf - min of the sum of the absolute values of rows +// 0 - Frobenius norm +// +// Norm will panic with ErrNormOrder if an illegal norm order is specified. +type Normer interface { + Norm(o float64) float64 +} + +// A TransposeCopier can make a copy of the transpose the matrix represented by a, placing the elements +// into the receiver. +type TransposeCopier interface { + TCopy(a Matrix) +} + +// A Transposer can create a transposed view matrix from the matrix represented by the receiver. +// Changes made to the returned Matrix may be reflected in the original. +type Transposer interface { + T() Matrix +} + +// A Deter can return the determinant of the represented matrix. +type Deter interface { + Det() float64 +} + +// An Inver can calculate the inverse of the matrix represented by a and stored in the receiver. +// ErrSingular is returned if there is no inverse of the matrix. +type Inver interface { + Inv(a Matrix) error +} + +// An Adder can add the matrices represented by a and b, placing the result in the receiver. Add +// will panic if the two matrices do not have the same shape. +type Adder interface { + Add(a, b Matrix) +} + +// A Suber can subtract the matrix b from a, placing the result in the receiver. Sub will panic if +// the two matrices do not have the same shape. +type Suber interface { + Sub(a, b Matrix) +} + +// An ElemMuler can perform element-wise multiplication of the matrices represented by a and b, +// placing the result in the receiver. MulEmen will panic if the two matrices do not have the same +// shape. +type ElemMuler interface { + MulElem(a, b Matrix) +} + +// An ElemDiver can perform element-wise division a / b of the matrices represented by a and b, +// placing the result in the receiver. DivElem will panic if the two matrices do not have the same +// shape. +type ElemDiver interface { + DivElem(a, b Matrix) +} + +// An Equaler can compare the matrices represented by b and the receiver. Matrices with non-equal shapes +// are not equal. +type Equaler interface { + Equals(b Matrix) bool +} + +// An ApproxEqualer can compare the matrices represented by b and the receiver, with tolerance for +// element-wise equailty specified by epsilon. Matrices with non-equal shapes are not equal. +type ApproxEqualer interface { + EqualsApprox(b Matrix, epsilon float64) bool +} + +// A Scaler can perform scalar multiplication of the matrix represented by a with c, placing +// the result in the receiver. +type Scaler interface { + Scale(c float64, a Matrix) +} + +// A Sumer can return the sum of elements of the matrix represented by the receiver. +type Sumer interface { + Sum() float64 +} + +// A Muler can determine the matrix product of a and b, placing the result in the receiver. +// If the number of columns in a does not equal the number of rows in b, Mul will panic. +type Muler interface { + Mul(a, b Matrix) +} + +// A MulTranser can determine the matrix product of a and b, optionally taking the transpose +// of either a, b, or both, placing the result in the receiver. It performs OpA(a) * OpB(b), +// where OpA is transpose(a) when aTrans is true, and does nothing when aTrans == blas.NoTrans. +// The same logic applies to OpB. If the number of columns in OpA(a) does not equal the +// number of rows in OpB(b), MulTrans will panic. +type MulTranser interface { + MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) +} + +// An Exper can perform a matrix exponentiation of the square matrix a. Exp will panic with ErrShape +// if a is not square. +type Exper interface { + Exp(a Matrix) +} + +// A Power can raise a square matrix, a to a positive integral power, n. Pow will panic if n is negative +// or if a is not square. +type Power interface { + Pow(a Matrix, n int) +} + +// A Dotter can determine the sum of the element-wise products of the elements of the receiver and b. +// If the shapes of the two matrices differ, Dot will panic. +type Dotter interface { + Dot(b Matrix) float64 +} + +// A Stacker can create the stacked matrix of a with b, where b is placed in the greater indexed rows. +// The result of stacking is placed in the receiver, overwriting the previous value of the receiver. +// Stack will panic if the two input matrices do not have the same number of columns. +type Stacker interface { + Stack(a, b Matrix) +} + +// An Augmenter can create the augmented matrix of a with b, where b is placed in the greater indexed +// columns. The result of augmentation is placed in the receiver, overwriting the previous value of the +// receiver. Augment will panic if the two input matrices do not have the same number of rows. +type Augmenter interface { + Augment(a, b Matrix) +} + +// An ApplyFunc takes a row/column index and element value and returns some function of that tuple. +type ApplyFunc func(r, c int, v float64) float64 + +// An Applyer can apply an Applyfunc f to each of the elements of the matrix represented by a, +// placing the resulting matrix in the receiver. +type Applyer interface { + Apply(f ApplyFunc, a Matrix) +} + +// A Tracer can return the trace of the matrix represented by the receiver. Trace will panic if the +// matrix is not square. +type Tracer interface { + Trace() float64 +} + +// A Uer can return the upper triangular matrix of the matrix represented by a, placing the result +// in the receiver. If the concrete value of a is the receiver, the lower residue is zeroed in place. +type Uer interface { + U(a Matrix) +} + +// An Ler can return the lower triangular matrix of the matrix represented by a, placing the result +// in the receiver. If the concrete value of a is the receiver, the upper residue is zeroed in place. +type Ler interface { + L(a Matrix) +} + +// A BandWidther represents a banded matrix and can return the left and right half-bandwidths, k1 and +// k2. +type BandWidther interface { + BandWidth() (k1, k2 int) +} + +// A RawMatrixSetter can set the underlying blas64.General used by the receiver. There is no restriction +// on the shape of the receiver. Changes to the receiver's elements will be reflected in the blas64.General.Data. +type RawMatrixSetter interface { + SetRawMatrix(a blas64.General) +} + +// A RawMatrixer can return a blas64.General representation of the receiver. Changes to the blas64.General.Data +// slice will be reflected in the original matrix, changes to the Rows, Cols and Stride fields will not. +type RawMatrixer interface { + RawMatrix() blas64.General +} + +// Det returns the determinant of the matrix a. +func Det(a Matrix) float64 { + if a, ok := a.(Deter); ok { + return a.Det() + } + return LU(DenseCopyOf(a)).Det() +} + +// Inverse returns the inverse or pseudoinverse of the matrix a. +// It returns a nil matrix and ErrSingular if a is singular. +func Inverse(a Matrix) (*Dense, error) { + m, _ := a.Dims() + d := make([]float64, m*m) + for i := 0; i < m*m; i += m + 1 { + d[i] = 1 + } + eye := NewDense(m, m, d) + return Solve(a, eye) +} + +// Solve returns a matrix x that satisfies ax = b. +// It returns a nil matrix and ErrSingular if a is singular. +func Solve(a, b Matrix) (x *Dense, err error) { + switch m, n := a.Dims(); { + case m == n: + lu := LU(DenseCopyOf(a)) + if lu.IsSingular() { + return nil, ErrSingular + } + return lu.Solve(DenseCopyOf(b)), nil + case m > n: + qr := QR(DenseCopyOf(a)) + if !qr.IsFullRank() { + return nil, ErrSingular + } + return qr.Solve(DenseCopyOf(b)), nil + default: + lq := LQ(DenseCopyOf(a)) + if !lq.IsFullRank() { + return nil, ErrSingular + } + switch b := b.(type) { + case *Dense: + return lq.Solve(b), nil + default: + return lq.Solve(DenseCopyOf(b)), nil + } + } +} + +// A Panicker is a function that may panic. +type Panicker func() + +// Maybe will recover a panic with a type mat64.Error from fn, and return this error. +// Any other error is re-panicked. +func Maybe(fn Panicker) (err error) { + defer func() { + if r := recover(); r != nil { + var ok bool + if err, ok = r.(Error); ok { + return + } + panic(r) + } + }() + fn() + return +} + +// A FloatPanicker is a function that returns a float64 and may panic. +type FloatPanicker func() float64 + +// MaybeFloat will recover a panic with a type mat64.Error from fn, and return this error. +// Any other error is re-panicked. +func MaybeFloat(fn FloatPanicker) (f float64, err error) { + defer func() { + if r := recover(); r != nil { + if e, ok := r.(Error); ok { + err = e + return + } + panic(r) + } + }() + return fn(), nil +} + +// Type Error represents matrix handling errors. These errors can be recovered by Maybe wrappers. +type Error string + +func (err Error) Error() string { return string(err) } + +const ( + ErrIndexOutOfRange = Error("mat64: index out of range") + ErrRowAccess = Error("mat64: row index out of range") + ErrColAccess = Error("mat64: column index out of range") + ErrZeroLength = Error("mat64: zero length in matrix definition") + ErrRowLength = Error("mat64: row length mismatch") + ErrColLength = Error("mat64: col length mismatch") + ErrSquare = Error("mat64: expect square matrix") + ErrNormOrder = Error("mat64: invalid norm order for matrix") + ErrSingular = Error("mat64: matrix is singular") + ErrShape = Error("mat64: dimension mismatch") + ErrIllegalStride = Error("mat64: illegal stride") + ErrPivot = Error("mat64: malformed pivot list") +) + +func min(a, b int) int { + if a < b { + return a + } + return b +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +// use returns a float64 slice with l elements, using f if it +// has the necessary capacity, otherwise creating a new slice. +func use(f []float64, l int) []float64 { + if l <= cap(f) { + return f[:l] + } + return make([]float64, l) +} + +// useZeroed returns a float64 slice with l elements, using f if it +// has the necessary capacity, otherwise creating a new slice. The +// elements of the returned slice are guaranteed to be zero. +func useZeroed(f []float64, l int) []float64 { + if l <= cap(f) { + f = f[:l] + zero(f) + return f + } + return make([]float64, l) +} + +// zero does a fast zeroing of the given slice's elements. +func zero(f []float64) { + f[0] = 0 + for i := 1; i < len(f); { + i += copy(f[i:], f[:i]) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/matrix_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/matrix_test.go new file mode 100644 index 0000000..100ebc1 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/matrix_test.go @@ -0,0 +1,289 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "fmt" + "testing" + + "gopkg.in/check.v1" +) + +// Tests +func Test(t *testing.T) { check.TestingT(t) } + +type S struct{} + +var _ = check.Suite(&S{}) + +func leaksPanic(fn Panicker) (panicked bool) { + defer func() { + r := recover() + panicked = r != nil + }() + Maybe(fn) + return +} + +func panics(fn func()) (panicked bool, message string) { + defer func() { + r := recover() + panicked = r != nil + message = fmt.Sprint(r) + }() + fn() + return +} + +func flatten(f [][]float64) (r, c int, d []float64) { + for _, r := range f { + d = append(d, r...) + } + return len(f), len(f[0]), d +} + +func unflatten(r, c int, d []float64) [][]float64 { + m := make([][]float64, r) + for i := 0; i < r; i++ { + m[i] = d[i*c : (i+1)*c] + } + return m +} + +func eye() *Dense { + return NewDense(3, 3, []float64{ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + }) +} + +func (s *S) TestMaybe(c *check.C) { + for i, test := range []struct { + fn Panicker + panics bool + }{ + { + func() {}, + false, + }, + { + func() { panic("panic") }, + true, + }, + { + func() { panic(Error("panic")) }, + false, + }, + } { + c.Check(leaksPanic(test.fn), check.Equals, test.panics, check.Commentf("Test %d", i)) + } +} + +func (s *S) TestSolve(c *check.C) { + for _, test := range []struct { + name string + panics bool + singular bool + a [][]float64 + b [][]float64 + x [][]float64 + }{ + { + name: "OneElement", + panics: false, + a: [][]float64{{6}}, + b: [][]float64{{3}}, + x: [][]float64{{0.5}}, + }, + { + name: "SquareIdentity", + panics: false, + a: [][]float64{ + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1}, + }, + b: [][]float64{ + {3}, + {2}, + {1}, + }, + x: [][]float64{ + {3}, + {2}, + {1}, + }, + }, + { + name: "Square", + panics: false, + a: [][]float64{ + {0.8147, 0.9134, 0.5528}, + {0.9058, 0.6324, 0.8723}, + {0.1270, 0.0975, 0.7612}, + }, + b: [][]float64{ + {0.278}, + {0.547}, + {0.958}, + }, + x: [][]float64{ + {-0.932687281002860}, + {0.303963920182067}, + {1.375216503507109}, + }, + }, + { + name: "ColumnMismatch", + panics: true, + a: [][]float64{ + {0.6046602879796196, 0.9405090880450124, 0.6645600532184904}, + {0.4377141871869802, 0.4246374970712657, 0.6868230728671094}, + }, + b: [][]float64{ + {0.30091186058528707}, + {0.5152126285020654}, + {0.8136399609900968}, + {0.12345}, + }, + x: [][]float64{ + {-26.618512183136257}, + {8.730387239011677}, + {12.316510032082446}, + {0.1234}, + }, + }, + { + name: "WideMatrix", + panics: false, + a: [][]float64{ + {0.8147, 0.9134, 0.5528}, + {0.9058, 0.6324, 0.8723}, + }, + b: [][]float64{ + {0.278}, + {0.547}, + }, + x: [][]float64{ + {0.25919787248965376}, + {-0.25560256266441034}, + {0.5432324059702451}, + }, + }, + + { + name: "Skinny1", + panics: false, + a: [][]float64{ + {0.8147, 0.9134, 0.9}, + {0.9058, 0.6324, 0.9}, + {0.1270, 0.0975, 0.1}, + {1.6, 2.8, -3.5}, + }, + b: [][]float64{ + {0.278}, + {0.547}, + {-0.958}, + {1.452}, + }, + x: [][]float64{ + {0.820970340787782}, + {-0.218604626527306}, + {-0.212938815234215}, + }, + }, + { + name: "Skinny2", + panics: false, + a: [][]float64{ + {0.8147, 0.9134, 0.231, -1.65}, + {0.9058, 0.6324, 0.9, 0.72}, + {0.1270, 0.0975, 0.1, 1.723}, + {1.6, 2.8, -3.5, 0.987}, + {7.231, 9.154, 1.823, 0.9}, + }, + b: [][]float64{ + {0.278, 8.635}, + {0.547, 9.125}, + {-0.958, -0.762}, + {1.452, 1.444}, + {1.999, -7.234}, + }, + x: [][]float64{ + {1.863006789511373, 44.467887791812750}, + {-1.127270935407224, -34.073794226035126}, + {-0.527926457947330, -8.032133759788573}, + {-0.248621916204897, -2.366366415805275}, + }, + }, + { + name: "Singular square", + singular: true, + a: [][]float64{ + {0, 0}, + {0, 0}, + }, + b: [][]float64{ + {3}, + {2}, + }, + x: nil, + }, + { + name: "Singular tall", + singular: true, + a: [][]float64{ + {0, 0}, + {0, 0}, + {0, 0}, + }, + b: [][]float64{ + {3}, + {2}, + }, + x: nil, + }, + { + name: "Singular wide", + singular: true, + a: [][]float64{ + {0, 0, 0}, + {0, 0, 0}, + }, + b: [][]float64{ + {3}, + {2}, + {1}, + }, + x: nil, + }, + } { + a := NewDense(flatten(test.a)) + b := NewDense(flatten(test.b)) + + var x *Dense + fn := func() { + var err error + x, err = Solve(a, b) + if (err == ErrSingular) != test.singular { + c.Errorf("Unexpected error for Solve %v: got:%v", test.name, err) + } + } + + panicked, message := panics(fn) + if test.singular { + c.Check(x, check.Equals, (*Dense)(nil)) + continue + } + if panicked { + c.Check(panicked, check.Equals, test.panics, check.Commentf("Test %v panicked: %s", test.name, message)) + continue + } + + trueX := NewDense(flatten(test.x)) + c.Check(x.EqualsApprox(trueX, 1e-13), check.Equals, true, check.Commentf("Test %v solution mismatch: Found %v, expected %v ", test.name, x, trueX)) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/mul_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/mul_test.go new file mode 100644 index 0000000..9b7e66e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/mul_test.go @@ -0,0 +1,275 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math/rand" + "testing" + + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" + "github.com/gonum/floats" +) + +// TODO: Need to add tests where one is overwritten. +func TestMul(t *testing.T) { + for _, test := range []struct { + ar int + ac int + br int + bc int + Panics bool + }{ + { + ar: 5, + ac: 5, + br: 5, + bc: 5, + Panics: false, + }, + { + ar: 10, + ac: 5, + br: 5, + bc: 3, + Panics: false, + }, + { + ar: 10, + ac: 5, + br: 5, + bc: 8, + Panics: false, + }, + { + ar: 8, + ac: 10, + br: 10, + bc: 3, + Panics: false, + }, + { + ar: 8, + ac: 3, + br: 3, + bc: 10, + Panics: false, + }, + { + ar: 5, + ac: 8, + br: 8, + bc: 10, + Panics: false, + }, + { + ar: 5, + ac: 12, + br: 12, + bc: 8, + Panics: false, + }, + { + ar: 5, + ac: 7, + br: 8, + bc: 10, + Panics: true, + }, + } { + ar := test.ar + ac := test.ac + br := test.br + bc := test.bc + + // Generate random matrices + avec := make([]float64, ar*ac) + randomSlice(avec) + a := NewDense(ar, ac, avec) + + bvec := make([]float64, br*bc) + randomSlice(bvec) + + b := NewDense(br, bc, bvec) + + // Check that it panics if it is supposed to + if test.Panics { + c := NewDense(0, 0, nil) + fn := func() { + c.Mul(a, b) + } + pan, _ := panics(fn) + if !pan { + t.Errorf("Mul did not panic with dimension mismatch") + } + continue + } + + cvec := make([]float64, ar*bc) + + // Get correct matrix multiply answer from blas64.Gemm + blas64.Gemm(blas.NoTrans, blas.NoTrans, + 1, a.mat, b.mat, + 0, blas64.General{Rows: ar, Cols: bc, Stride: bc, Data: cvec}, + ) + + avecCopy := append([]float64{}, avec...) + bvecCopy := append([]float64{}, bvec...) + cvecCopy := append([]float64{}, cvec...) + + acomp := matComp{r: ar, c: ac, data: avecCopy} + bcomp := matComp{r: br, c: bc, data: bvecCopy} + ccomp := matComp{r: ar, c: bc, data: cvecCopy} + + // Do normal multiply with empty dense + d := NewDense(0, 0, nil) + + testMul(t, a, b, d, acomp, bcomp, ccomp, false, "zero receiver") + + // Normal multiply with existing receiver + c := NewDense(ar, bc, cvec) + randomSlice(cvec) + testMul(t, a, b, c, acomp, bcomp, ccomp, false, "existing receiver") + + // Test with vectorers + avm := (*basicVectorer)(a) + bvm := (*basicVectorer)(b) + d.Reset() + testMul(t, avm, b, d, acomp, bcomp, ccomp, true, "a vectoror with zero receiver") + d.Reset() + testMul(t, a, bvm, d, acomp, bcomp, ccomp, true, "b vectoror with zero receiver") + d.Reset() + testMul(t, avm, bvm, d, acomp, bcomp, ccomp, true, "both vectoror with zero receiver") + randomSlice(cvec) + testMul(t, avm, b, c, acomp, bcomp, ccomp, true, "a vectoror with existing receiver") + randomSlice(cvec) + testMul(t, a, bvm, c, acomp, bcomp, ccomp, true, "b vectoror with existing receiver") + randomSlice(cvec) + testMul(t, avm, bvm, c, acomp, bcomp, ccomp, true, "both vectoror with existing receiver") + + // Cast a as a basic matrix + am := (*basicMatrix)(a) + bm := (*basicMatrix)(b) + d.Reset() + testMul(t, am, b, d, acomp, bcomp, ccomp, true, "a is basic, receiver is zero") + d.Reset() + testMul(t, a, bm, d, acomp, bcomp, ccomp, true, "b is basic, receiver is zero") + d.Reset() + testMul(t, am, bm, d, acomp, bcomp, ccomp, true, "both basic, receiver is zero") + randomSlice(cvec) + testMul(t, am, b, d, acomp, bcomp, ccomp, true, "a is basic, receiver is full") + randomSlice(cvec) + testMul(t, a, bm, d, acomp, bcomp, ccomp, true, "b is basic, receiver is full") + randomSlice(cvec) + testMul(t, am, bm, d, acomp, bcomp, ccomp, true, "both basic, receiver is full") + } +} +func randomSlice(s []float64) { + for i := range s { + s[i] = rand.NormFloat64() + } +} + +type matComp struct { + r, c int + data []float64 +} + +func testMul(t *testing.T, a, b Matrix, c *Dense, acomp, bcomp, ccomp matComp, cvecApprox bool, name string) { + c.Mul(a, b) + var aDense *Dense + switch t := a.(type) { + case *Dense: + aDense = t + case *basicMatrix: + aDense = (*Dense)(t) + case *basicVectorer: + aDense = (*Dense)(t) + } + + var bDense *Dense + switch t := b.(type) { + case *Dense: + bDense = t + case *basicMatrix: + bDense = (*Dense)(t) + case *basicVectorer: + bDense = (*Dense)(t) + } + + if !denseEqual(aDense, acomp) { + t.Errorf("a changed unexpectedly for %v", name) + } + if !denseEqual(bDense, bcomp) { + t.Errorf("b changed unexpectedly for %v", name) + } + if cvecApprox { + if !denseEqualApprox(c, ccomp, 1e-14) { + t.Errorf("mul answer not within tol for %v", name) + } + return + } + + if !denseEqual(c, ccomp) { + t.Errorf("mul answer not equal for %v", name) + } + return +} + +type basicMatrix Dense + +func (m *basicMatrix) At(r, c int) float64 { + return (*Dense)(m).At(r, c) +} + +func (m *basicMatrix) Dims() (r, c int) { + return (*Dense)(m).Dims() +} + +type basicVectorer Dense + +func (m *basicVectorer) At(r, c int) float64 { + return (*Dense)(m).At(r, c) +} + +func (m *basicVectorer) Dims() (r, c int) { + return (*Dense)(m).Dims() +} + +func (m *basicVectorer) Row(row []float64, r int) []float64 { + return (*Dense)(m).Row(row, r) +} + +func (m *basicVectorer) Col(row []float64, c int) []float64 { + return (*Dense)(m).Col(row, c) +} + +func denseEqual(a *Dense, acomp matComp) bool { + ar2, ac2 := a.Dims() + if ar2 != acomp.r { + return false + } + if ac2 != acomp.c { + return false + } + if !floats.Equal(a.mat.Data, acomp.data) { + return false + } + return true +} + +func denseEqualApprox(a *Dense, acomp matComp, tol float64) bool { + ar2, ac2 := a.Dims() + if ar2 != acomp.r { + return false + } + if ac2 != acomp.c { + return false + } + if !floats.EqualApprox(a.mat.Data, acomp.data, tol) { + return false + } + return true +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/qr.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/qr.go new file mode 100644 index 0000000..1b87a98 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/qr.go @@ -0,0 +1,185 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// Based on the QRDecomposition class from Jama 1.0.3. + +package mat64 + +import ( + "math" +) + +type QRFactor struct { + QR *Dense + rDiag []float64 +} + +// QR computes a QR Decomposition for an m-by-n matrix a with m >= n by Householder +// reflections, the QR decomposition is an m-by-n orthogonal matrix q and an n-by-n +// upper triangular matrix r so that a = q.r. QR will panic with ErrShape if m < n. +// +// The QR decomposition always exists, even if the matrix does not have full rank, +// so QR will never fail unless m < n. The primary use of the QR decomposition is +// in the least squares solution of non-square systems of simultaneous linear equations. +// This will fail if QRIsFullRank() returns false. The matrix a is overwritten by the +// decomposition. +func QR(a *Dense) QRFactor { + // Initialize. + m, n := a.Dims() + if m < n { + panic(ErrShape) + } + + qr := a + rDiag := make([]float64, n) + + // Main loop. + for k := 0; k < n; k++ { + // Compute 2-norm of k-th column without under/overflow. + var norm float64 + for i := k; i < m; i++ { + norm = math.Hypot(norm, qr.at(i, k)) + } + + if norm != 0 { + // Form k-th Householder vector. + if qr.at(k, k) < 0 { + norm = -norm + } + for i := k; i < m; i++ { + qr.set(i, k, qr.at(i, k)/norm) + } + qr.set(k, k, qr.at(k, k)+1) + + // Apply transformation to remaining columns. + for j := k + 1; j < n; j++ { + var s float64 + for i := k; i < m; i++ { + s += qr.at(i, k) * qr.at(i, j) + } + s /= -qr.at(k, k) + for i := k; i < m; i++ { + qr.set(i, j, qr.at(i, j)+s*qr.at(i, k)) + } + } + } + rDiag[k] = -norm + } + + return QRFactor{qr, rDiag} +} + +// IsFullRank returns whether the R matrix and hence a has full rank. +func (f QRFactor) IsFullRank() bool { + for _, v := range f.rDiag { + if v == 0 { + return false + } + } + return true +} + +// H returns the Householder vectors in a lower trapezoidal matrix +// whose columns define the reflections. +func (f QRFactor) H() *Dense { + qr := f.QR + m, n := qr.Dims() + h := NewDense(m, n, nil) + for i := 0; i < m; i++ { + for j := 0; j < n; j++ { + if i >= j { + h.set(i, j, qr.at(i, j)) + } + } + } + return h +} + +// R returns the upper triangular factor for the QR decomposition. +func (f QRFactor) R() *Dense { + qr, rDiag := f.QR, f.rDiag + _, n := qr.Dims() + r := NewDense(n, n, nil) + for i, v := range rDiag[:n] { + for j := 0; j < n; j++ { + if i < j { + r.set(i, j, qr.at(i, j)) + } else if i == j { + r.set(i, j, v) + } + } + } + return r +} + +// Q generates and returns the (economy-sized) orthogonal factor. +func (f QRFactor) Q() *Dense { + qr := f.QR + m, n := qr.Dims() + q := NewDense(m, n, nil) + + for k := n - 1; k >= 0; k-- { + q.set(k, k, 1) + for j := k; j < n; j++ { + if qr.at(k, k) != 0 { + var s float64 + for i := k; i < m; i++ { + s += qr.at(i, k) * q.at(i, j) + } + s /= -qr.at(k, k) + for i := k; i < m; i++ { + q.set(i, j, q.at(i, j)+s*qr.at(i, k)) + } + } + } + } + + return q +} + +// Solve computes a least squares solution of a.x = b where b has as many rows as a. +// A matrix x is returned that minimizes the two norm of Q*R*X-B. Solve will panic +// if a is not full rank. The matrix b is overwritten during the call. +func (f QRFactor) Solve(b *Dense) (x *Dense) { + qr := f.QR + rDiag := f.rDiag + m, n := qr.Dims() + bm, bn := b.Dims() + if bm != m { + panic(ErrShape) + } + if !f.IsFullRank() { + panic(ErrSingular) + } + + // Compute Y = transpose(Q)*B + for k := 0; k < n; k++ { + for j := 0; j < bn; j++ { + var s float64 + for i := k; i < m; i++ { + s += qr.at(i, k) * b.at(i, j) + } + s /= -qr.at(k, k) + + for i := k; i < m; i++ { + b.set(i, j, b.at(i, j)+s*qr.at(i, k)) + } + } + } + + // Solve R*X = Y; + for k := n - 1; k >= 0; k-- { + row := b.rowView(k) + for j := range row[:bn] { + row[j] /= rDiag[k] + } + for i := 0; i < k; i++ { + row := b.rowView(i) + for j := range row[:bn] { + row[j] -= b.at(k, j) * qr.at(i, k) + } + } + } + + return b.View(0, 0, n, bn).(*Dense) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/qr_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/qr_test.go new file mode 100644 index 0000000..40c8b80 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/qr_test.go @@ -0,0 +1,81 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + + "github.com/gonum/floats" + + "gopkg.in/check.v1" +) + +func isUpperTriangular(a *Dense) bool { + rows, cols := a.Dims() + for c := 0; c < cols-1; c++ { + for r := c + 1; r < rows; r++ { + if math.Abs(a.At(r, c)) > 1e-14 { + return false + } + } + } + return true +} + +func isOrthogonal(a *Dense) bool { + rows, cols := a.Dims() + col1 := make([]float64, rows) + col2 := make([]float64, rows) + for i := 0; i < cols-1; i++ { + for j := i + 1; j < cols; j++ { + a.Col(col1, i) + a.Col(col2, j) + dot := floats.Dot(col1, col2) + if math.Abs(dot) > 1e-14 { + return false + } + } + } + return true +} + +func (s *S) TestQRD(c *check.C) { + for _, test := range []struct { + a [][]float64 + name string + }{ + { + name: "Square", + a: [][]float64{ + {1.3, 2.4, 8.9}, + {-2.6, 8.7, 9.1}, + {5.6, 5.8, 2.1}, + }, + }, + { + name: "Skinny", + a: [][]float64{ + {1.3, 2.4, 8.9}, + {-2.6, 8.7, 9.1}, + {5.6, 5.8, 2.1}, + {19.4, 5.2, -26.1}, + }, + }, + } { + + a := NewDense(flatten(test.a)) + qf := QR(DenseCopyOf(a)) + r := qf.R() + q := qf.Q() + + rows, cols := a.Dims() + newA := NewDense(rows, cols, nil) + newA.Mul(q, r) + + c.Check(isOrthogonal(q), check.Equals, true, check.Commentf("Test %v: Q not orthogonal", test.name)) + c.Check(isUpperTriangular(r), check.Equals, true, check.Commentf("Test %v: R not upper triangular", test.name)) + c.Check(a.EqualsApprox(newA, 1e-13), check.Equals, true, check.Commentf("Test %v: Q*R != A", test.name)) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/svd.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/svd.go new file mode 100644 index 0000000..0b046ee --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/svd.go @@ -0,0 +1,479 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// Based on the SingularValueDecomposition class from Jama 1.0.3. + +package mat64 + +import ( + "math" +) + +type SVDFactors struct { + U *Dense + Sigma []float64 + V *Dense + m, n int +} + +// SVD performs singular value decomposition for an m-by-n matrix a. The +// singular value decomposition is an m-by-n orthogonal matrix u, an n-by-n +// diagonal matrix s, and an n-by-n orthogonal matrix v so that a = u*s*v'. If +// a is a wide matrix a copy of its transpose is allocated, otherwise a is +// overwritten during the decomposition. Matrices u and v are only created when +// wantu and wantv are true respectively. +// +// The singular values, sigma[k] = s[k][k], are ordered so that +// +// sigma[0] >= sigma[1] >= ... >= sigma[n-1]. +// +// The matrix condition number and the effective numerical rank can be computed from +// this decomposition. +func SVD(a *Dense, epsilon, small float64, wantu, wantv bool) SVDFactors { + m, n := a.Dims() + + trans := false + if m < n { + a.TCopy(a) + m, n = n, m + wantu, wantv = wantv, wantu + trans = true + } + + sigma := make([]float64, min(m+1, n)) + nu := min(m, n) + var u, v *Dense + if wantu { + u = NewDense(m, nu, nil) + } + if wantv { + v = NewDense(n, n, nil) + } + + var ( + e = make([]float64, n) + work = make([]float64, m) + ) + + // Reduce a to bidiagonal form, storing the diagonal elements + // in sigma and the super-diagonal elements in e. + nct := min(m-1, n) + nrt := max(0, min(n-2, m)) + for k := 0; k < max(nct, nrt); k++ { + if k < nct { + // Compute the transformation for the k-th column and + // place the k-th diagonal in sigma[k]. + // Compute 2-norm of k-th column without under/overflow. + sigma[k] = 0 + for i := k; i < m; i++ { + sigma[k] = math.Hypot(sigma[k], a.at(i, k)) + } + if sigma[k] != 0 { + if a.at(k, k) < 0 { + sigma[k] = -sigma[k] + } + for i := k; i < m; i++ { + a.set(i, k, a.at(i, k)/sigma[k]) + } + a.set(k, k, a.at(k, k)+1) + } + sigma[k] = -sigma[k] + } + + for j := k + 1; j < n; j++ { + if k < nct && sigma[k] != 0 { + // Apply the transformation. + var t float64 + for i := k; i < m; i++ { + t += a.at(i, k) * a.at(i, j) + } + t = -t / a.at(k, k) + for i := k; i < m; i++ { + a.set(i, j, a.at(i, j)+t*a.at(i, k)) + } + } + + // Place the k-th row of a into e for the + // subsequent calculation of the row transformation. + e[j] = a.at(k, j) + } + + if wantu && k < nct { + // Place the transformation in u for subsequent back + // multiplication. + for i := k; i < m; i++ { + u.set(i, k, a.at(i, k)) + } + } + + if k < nrt { + // Compute the k-th row transformation and place the + // k-th super-diagonal in e[k]. + // Compute 2-norm without under/overflow. + e[k] = 0 + for i := k + 1; i < n; i++ { + e[k] = math.Hypot(e[k], e[i]) + } + if e[k] != 0 { + if e[k+1] < 0 { + e[k] = -e[k] + } + for i := k + 1; i < n; i++ { + e[i] /= e[k] + } + e[k+1] += 1 + } + e[k] = -e[k] + if k+1 < m && e[k] != 0 { + // Apply the transformation. + for i := k + 1; i < m; i++ { + work[i] = 0 + } + for j := k + 1; j < n; j++ { + for i := k + 1; i < m; i++ { + work[i] += e[j] * a.at(i, j) + } + } + for j := k + 1; j < n; j++ { + t := -e[j] / e[k+1] + for i := k + 1; i < m; i++ { + a.set(i, j, a.at(i, j)+t*work[i]) + } + } + } + if wantv { + // Place the transformation in v for subsequent + // back multiplication. + for i := k + 1; i < n; i++ { + v.set(i, k, e[i]) + } + } + } + } + + // set up the final bidiagonal matrix or order p. + p := min(n, m+1) + if nct < n { + sigma[nct] = a.at(nct, nct) + } + if m < p { + sigma[p-1] = 0 + } + if nrt+1 < p { + e[nrt] = a.at(nrt, p-1) + } + e[p-1] = 0 + + // If requested, generate u. + if wantu { + for j := nct; j < nu; j++ { + for i := 0; i < m; i++ { + u.set(i, j, 0) + } + u.set(j, j, 1) + } + for k := nct - 1; k >= 0; k-- { + if sigma[k] != 0 { + for j := k + 1; j < nu; j++ { + var t float64 + for i := k; i < m; i++ { + t += u.at(i, k) * u.at(i, j) + } + t /= -u.at(k, k) + for i := k; i < m; i++ { + u.set(i, j, u.at(i, j)+t*u.at(i, k)) + } + } + for i := k; i < m; i++ { + u.set(i, k, -u.at(i, k)) + } + u.set(k, k, 1+u.at(k, k)) + for i := 0; i < k-1; i++ { + u.set(i, k, 0) + } + } else { + for i := 0; i < m; i++ { + u.set(i, k, 0) + } + u.set(k, k, 1) + } + } + } + + // If requested, generate v. + if wantv { + for k := n - 1; k >= 0; k-- { + if k < nrt && e[k] != 0 { + for j := k + 1; j < nu; j++ { + var t float64 + for i := k + 1; i < n; i++ { + t += v.at(i, k) * v.at(i, j) + } + t /= -v.at(k+1, k) + for i := k + 1; i < n; i++ { + v.set(i, j, v.at(i, j)+t*v.at(i, k)) + } + } + } + for i := 0; i < n; i++ { + v.set(i, k, 0) + } + v.set(k, k, 1) + } + } + + // Main iteration loop for the singular values. + pp := p - 1 + for iter := 0; p > 0; { + var k, kase int + + // Here is where a test for too many iterations would go. + + // This section of the program inspects for + // negligible elements in the sigma and e arrays. On + // completion the variables kase and k are set as follows. + // + // kase = 1 if sigma(p) and e[k-1] are negligible and k

= -1; k-- { + if k == -1 { + break + } + if math.Abs(e[k]) <= small+epsilon*(math.Abs(sigma[k])+math.Abs(sigma[k+1])) { + e[k] = 0 + break + } + } + + if k == p-2 { + kase = 4 + } else { + var ks int + for ks = p - 1; ks >= k; ks-- { + if ks == k { + break + } + var t float64 + if ks != p { + t = math.Abs(e[ks]) + } + if ks != k+1 { + t += math.Abs(e[ks-1]) + } + if math.Abs(sigma[ks]) <= small+epsilon*t { + sigma[ks] = 0 + break + } + } + if ks == k { + kase = 3 + } else if ks == p-1 { + kase = 1 + } else { + kase = 2 + k = ks + } + } + k++ + + switch kase { + // Deflate negligible sigma(p). + case 1: + f := e[p-2] + e[p-2] = 0 + for j := p - 2; j >= k; j-- { + t := math.Hypot(sigma[j], f) + cs := sigma[j] / t + sn := f / t + sigma[j] = t + if j != k { + f = -sn * e[j-1] + e[j-1] *= cs + } + if wantv { + for i := 0; i < n; i++ { + t = cs*v.at(i, j) + sn*v.at(i, p-1) + v.set(i, p-1, -sn*v.at(i, j)+cs*v.at(i, p-1)) + v.set(i, j, t) + } + } + } + + // Split at negligible sigma(k). + case 2: + f := e[k-1] + e[k-1] = 0 + for j := k; j < p; j++ { + t := math.Hypot(sigma[j], f) + cs := sigma[j] / t + sn := f / t + sigma[j] = t + f = -sn * e[j] + e[j] *= cs + if wantu { + for i := 0; i < m; i++ { + t = cs*u.at(i, j) + sn*u.at(i, k-1) + u.set(i, k-1, -sn*u.at(i, j)+cs*u.at(i, k-1)) + u.set(i, j, t) + } + } + } + + // Perform one qr step. + case 3: + // Calculate the shift. + scale := math.Max(math.Max(math.Max(math.Max( + math.Abs(sigma[p-1]), math.Abs(sigma[p-2])), math.Abs(e[p-2])), math.Abs(sigma[k])), math.Abs(e[k]), + ) + sp := sigma[p-1] / scale + spm1 := sigma[p-2] / scale + epm1 := e[p-2] / scale + sk := sigma[k] / scale + ek := e[k] / scale + b := ((spm1+sp)*(spm1-sp) + epm1*epm1) / 2 + c := (sp * epm1) * (sp * epm1) + + var shift float64 + if b != 0 || c != 0 { + shift = math.Sqrt(b*b + c) + if b < 0 { + shift = -shift + } + shift = c / (b + shift) + } + f := (sk+sp)*(sk-sp) + shift + g := sk * ek + + // Chase zeros. + for j := k; j < p-1; j++ { + t := math.Hypot(f, g) + cs := f / t + sn := g / t + if j != k { + e[j-1] = t + } + f = cs*sigma[j] + sn*e[j] + e[j] = cs*e[j] - sn*sigma[j] + g = sn * sigma[j+1] + sigma[j+1] *= cs + if wantv { + for i := 0; i < n; i++ { + t = cs*v.at(i, j) + sn*v.at(i, j+1) + v.set(i, j+1, -sn*v.at(i, j)+cs*v.at(i, j+1)) + v.set(i, j, t) + } + } + t = math.Hypot(f, g) + cs = f / t + sn = g / t + sigma[j] = t + f = cs*e[j] + sn*sigma[j+1] + sigma[j+1] = -sn*e[j] + cs*sigma[j+1] + g = sn * e[j+1] + e[j+1] *= cs + if wantu && j < m-1 { + for i := 0; i < m; i++ { + t = cs*u.at(i, j) + sn*u.at(i, j+1) + u.set(i, j+1, -sn*u.at(i, j)+cs*u.at(i, j+1)) + u.set(i, j, t) + } + } + } + e[p-2] = f + iter++ + + // Convergence. + case 4: + // Make the singular values positive. + if sigma[k] <= 0 { + if sigma[k] < 0 { + sigma[k] = -sigma[k] + } else { + sigma[k] = 0 + } + if wantv { + for i := 0; i <= pp; i++ { + v.set(i, k, -v.at(i, k)) + } + } + } + + // Order the singular values. + for k < pp { + if sigma[k] >= sigma[k+1] { + break + } + sigma[k], sigma[k+1] = sigma[k+1], sigma[k] + if wantv && k < n-1 { + for i := 0; i < n; i++ { + t := v.at(i, k+1) + v.set(i, k+1, v.at(i, k)) + v.set(i, k, t) + } + } + if wantu && k < m-1 { + for i := 0; i < m; i++ { + t := u.at(i, k+1) + u.set(i, k+1, u.at(i, k)) + u.set(i, k, t) + } + } + k++ + } + iter = 0 + p-- + } + } + + if trans { + return SVDFactors{ + U: v, + Sigma: sigma, + V: u, + + m: m, n: n, + } + } + return SVDFactors{ + U: u, + Sigma: sigma, + V: v, + + m: m, n: n, + } +} + +// S returns a newly allocated S matrix from the sigma values held by the +// factorisation. +func (f SVDFactors) S() *Dense { + s := NewDense(len(f.Sigma), len(f.Sigma), nil) + for i, v := range f.Sigma { + s.set(i, i, v) + } + return s +} + +// Rank returns the number of non-negligible singular values in the sigma held by +// the factorisation with the given epsilon. +func (f SVDFactors) Rank(epsilon float64) int { + if len(f.Sigma) == 0 { + return 0 + } + tol := float64(max(f.m, len(f.Sigma))) * f.Sigma[0] * epsilon + var r int + for _, v := range f.Sigma { + if v > tol { + r++ + } + } + return r +} + +// Cond returns the 2-norm condition number for the S matrix. +func (f SVDFactors) Cond() float64 { + return f.Sigma[0] / f.Sigma[min(f.m, f.n)-1] +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/svd_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/svd_test.go new file mode 100644 index 0000000..85a4817 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/svd_test.go @@ -0,0 +1,202 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "math" + + "gopkg.in/check.v1" +) + +func (s *S) TestSVD(c *check.C) { + for _, t := range []struct { + a *Dense + + epsilon float64 + small float64 + + wantu bool + u *Dense + + sigma []float64 + + wantv bool + v *Dense + }{ + { + a: NewDense(4, 2, []float64{2, 4, 1, 3, 0, 0, 0, 0}), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + wantu: true, + u: NewDense(4, 2, []float64{ + 0.8174155604703632, -0.5760484367663209, + 0.5760484367663209, 0.8174155604703633, + 0, 0, + 0, 0, + }), + + sigma: []float64{5.464985704219041, 0.365966190626258}, + + wantv: true, + v: NewDense(2, 2, []float64{ + 0.4045535848337571, -0.9145142956773044, + 0.9145142956773044, 0.4045535848337571, + }), + }, + { + a: NewDense(4, 2, []float64{2, 4, 1, 3, 0, 0, 0, 0}), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + wantu: true, + u: NewDense(4, 2, []float64{ + 0.8174155604703632, -0.5760484367663209, + 0.5760484367663209, 0.8174155604703633, + 0, 0, + 0, 0, + }), + + sigma: []float64{5.464985704219041, 0.365966190626258}, + + wantv: false, + }, + { + a: NewDense(4, 2, []float64{2, 4, 1, 3, 0, 0, 0, 0}), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + wantu: false, + + sigma: []float64{5.464985704219041, 0.365966190626258}, + + wantv: true, + v: NewDense(2, 2, []float64{ + 0.4045535848337571, -0.9145142956773044, + 0.9145142956773044, 0.4045535848337571, + }), + }, + { + a: NewDense(4, 2, []float64{2, 4, 1, 3, 0, 0, 0, 0}), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + sigma: []float64{5.464985704219041, 0.365966190626258}, + }, + { // Issue #5. + a: NewDense(3, 11, []float64{ + 1, 1, 0, 1, 0, 0, 0, 0, 0, 11, 1, + 1, 0, 0, 0, 0, 0, 1, 0, 0, 12, 2, + 1, 1, 0, 0, 0, 0, 0, 0, 1, 13, 3, + }), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + sigma: []float64{21.259500881097434, 1.5415021616856566, 1.2873979074613628}, + + wantu: true, + u: NewDense(3, 3, []float64{ + 0.5224167862273765, -0.7864430360363114, 0.3295270133658976, + 0.5739526766688285, 0.03852203026050301, -0.8179818935216693, + 0.6306021141833781, 0.6164603833618163, 0.4715056408282468, + }), + + wantv: true, + v: NewDense(11, 3, []float64{ + 0.08123293141915189, -0.08528085505260324, -0.013165501690885152, + 0.05423546426886932, -0.1102707844980355, 0.622210623111631, + 0, 0, 0, + 0.0245733326078166, -0.510179651760153, 0.25596360803140994, + 0, 0, 0, + 0, 0, 0, + 0.026997467150282436, 0.024989929445430496, -0.6353761248025164, + 0, 0, 0, + 0.029662131661052707, 0.3999088672621176, 0.3662470150802212, + 0.9798839760830571, -0.11328174160898856, -0.047702613241813366, + 0.16755466189153964, 0.7395268089170608, 0.08395240366704032, + }), + }, + { // Issue #5: test that correct matrices are constructed. + a: NewDense(3, 11, []float64{ + 1, 1, 0, 1, 0, 0, 0, 0, 0, 11, 1, + 1, 0, 0, 0, 0, 0, 1, 0, 0, 12, 2, + 1, 1, 0, 0, 0, 0, 0, 0, 1, 13, 3, + }), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + sigma: []float64{21.259500881097434, 1.5415021616856566, 1.2873979074613628}, + + wantu: true, + u: NewDense(3, 3, []float64{ + 0.5224167862273765, -0.7864430360363114, 0.3295270133658976, + 0.5739526766688285, 0.03852203026050301, -0.8179818935216693, + 0.6306021141833781, 0.6164603833618163, 0.4715056408282468, + }), + }, + { // Issue #5: test that correct matrices are constructed. + a: NewDense(3, 11, []float64{ + 1, 1, 0, 1, 0, 0, 0, 0, 0, 11, 1, + 1, 0, 0, 0, 0, 0, 1, 0, 0, 12, 2, + 1, 1, 0, 0, 0, 0, 0, 0, 1, 13, 3, + }), + + epsilon: math.Pow(2, -52.0), + small: math.Pow(2, -966.0), + + sigma: []float64{21.259500881097434, 1.5415021616856566, 1.2873979074613628}, + + wantv: true, + v: NewDense(11, 3, []float64{ + 0.08123293141915189, -0.08528085505260324, -0.013165501690885152, + 0.05423546426886932, -0.1102707844980355, 0.622210623111631, + 0, 0, 0, + 0.0245733326078166, -0.510179651760153, 0.25596360803140994, + 0, 0, 0, + 0, 0, 0, + 0.026997467150282436, 0.024989929445430496, -0.6353761248025164, + 0, 0, 0, + 0.029662131661052707, 0.3999088672621176, 0.3662470150802212, + 0.9798839760830571, -0.11328174160898856, -0.047702613241813366, + 0.16755466189153964, 0.7395268089170608, 0.08395240366704032, + }), + }, + } { + svd := SVD(DenseCopyOf(t.a), t.epsilon, t.small, t.wantu, t.wantv) + if t.sigma != nil { + c.Check(svd.Sigma, check.DeepEquals, t.sigma) + } + s := svd.S() + + if svd.U != nil { + c.Check(svd.U.Equals(t.u), check.Equals, true) + } else { + c.Check(t.wantu, check.Equals, false) + c.Check(t.u, check.IsNil) + } + if svd.V != nil { + c.Check(svd.V.Equals(t.v), check.Equals, true) + } else { + c.Check(t.wantv, check.Equals, false) + c.Check(t.v, check.IsNil) + } + + if t.wantu && t.wantv { + c.Assert(svd.U, check.NotNil) + c.Assert(svd.V, check.NotNil) + vt := &Dense{} + vt.TCopy(svd.V) + svd.U.Mul(svd.U, s) + svd.U.Mul(svd.U, vt) + c.Check(svd.U.EqualsApprox(t.a, 1e-12), check.Equals, true) + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/symmetric.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/symmetric.go new file mode 100644 index 0000000..288e4c5 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/symmetric.go @@ -0,0 +1,200 @@ +package mat64 + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" +) + +var ( + symDense *SymDense + + _ Matrix = symDense + _ Symmetric = symDense + _ RawSymmetricer = symDense +) + +const ( + ErrUplo = "mat64: blas64.Symmetric not upper" +) + +// SymDense is a symmetric matrix that uses Dense storage. +type SymDense struct { + mat blas64.Symmetric +} + +// Symmetric represents a symmetric matrix (where the element at {i, j} equals +// the element at {j, i}). Symmetric matrices are always square. +type Symmetric interface { + Matrix + // Symmetric returns the number of rows/columns in the matrix. + Symmetric() int +} + +// A RawSymmetricer can return a view of itself as a BLAS Symmetric matrix. +type RawSymmetricer interface { + RawSymmetric() blas64.Symmetric +} + +// NewSymDense constructs an n x n symmetric matrix. If len(mat) == n * n, +// mat will be used to hold the underlying data, or if mat == nil, new data will be allocated. +// The underlying data representation is the same as a Dense matrix, except +// the values of the entries in the lower triangular portion are completely ignored. +func NewSymDense(n int, mat []float64) *SymDense { + if n < 0 { + panic("mat64: negative dimension") + } + if mat != nil && n*n != len(mat) { + panic(ErrShape) + } + if mat == nil { + mat = make([]float64, n*n) + } + return &SymDense{blas64.Symmetric{ + N: n, + Stride: n, + Data: mat, + Uplo: blas.Upper, + }} +} + +func (s *SymDense) Dims() (r, c int) { + return s.mat.N, s.mat.N +} + +func (s *SymDense) Symmetric() int { + return s.mat.N +} + +// RawSymmetric returns the matrix as a blas64.Symmetric. The returned +// value must be stored in upper triangular format. +func (s *SymDense) RawSymmetric() blas64.Symmetric { + return s.mat +} + +func (s *SymDense) isZero() bool { + return s.mat.N == 0 +} + +func (s *SymDense) AddSym(a, b Symmetric) { + n := a.Symmetric() + if n != b.Symmetric() { + panic(ErrShape) + } + if s.isZero() { + s.mat = blas64.Symmetric{ + N: n, + Stride: n, + Data: use(s.mat.Data, n*n), + Uplo: blas.Upper, + } + } else if s.mat.N != n { + panic(ErrShape) + } + + if a, ok := a.(RawSymmetricer); ok { + if b, ok := b.(RawSymmetricer); ok { + amat, bmat := a.RawSymmetric(), b.RawSymmetric() + for i := 0; i < n; i++ { + btmp := bmat.Data[i*bmat.Stride+i : i*bmat.Stride+n] + stmp := s.mat.Data[i*s.mat.Stride+i : i*s.mat.Stride+n] + for j, v := range amat.Data[i*amat.Stride+i : i*amat.Stride+n] { + stmp[j] = v + btmp[j] + } + } + return + } + } + + for i := 0; i < n; i++ { + stmp := s.mat.Data[i*s.mat.Stride : i*s.mat.Stride+n] + for j := i; j < n; j++ { + stmp[j] = a.At(i, j) + b.At(i, j) + } + } +} + +func (s *SymDense) CopySym(a Symmetric) int { + n := a.Symmetric() + n = min(n, s.mat.N) + switch a := a.(type) { + case RawSymmetricer: + amat := a.RawSymmetric() + if amat.Uplo != blas.Upper { + panic(ErrUplo) + } + for i := 0; i < n; i++ { + copy(s.mat.Data[i*s.mat.Stride+i:i*s.mat.Stride+n], amat.Data[i*amat.Stride+i:i*amat.Stride+n]) + } + default: + for i := 0; i < n; i++ { + stmp := s.mat.Data[i*s.mat.Stride : i*s.mat.Stride+n] + for j := i; j < n; j++ { + stmp[j] = a.At(i, j) + } + } + } + return n +} + +// SymRankOne performs a symetric rank-one update to the matrix a and stores +// the result in the receiver +// s = a + alpha * x * x' +func (s *SymDense) SymRankOne(a Symmetric, alpha float64, x []float64) { + n := s.mat.N + var w SymDense + if s == a { + w = *s + } + if w.isZero() { + w.mat = blas64.Symmetric{ + N: n, + Stride: n, + Uplo: blas.Upper, + Data: use(w.mat.Data, n*n), + } + } else if n != w.mat.N { + panic(ErrShape) + } + if s != a { + w.CopySym(a) + } + if len(x) != n { + panic(ErrShape) + } + blas64.Syr(alpha, blas64.Vector{Inc: 1, Data: x}, w.mat) + *s = w + return +} + +// RankTwo performs a symmmetric rank-two update to the matrix a and stores +// the result in the receiver +// m = a + alpha * (x * y' + y * x') +func (s *SymDense) RankTwo(a Symmetric, alpha float64, x, y []float64) { + n := s.mat.N + var w SymDense + if s == a { + w = *s + } + if w.isZero() { + w.mat = blas64.Symmetric{ + N: n, + Stride: n, + Uplo: blas.Upper, + Data: use(w.mat.Data, n*n), + } + } else if n != w.mat.N { + panic(ErrShape) + } + if s != a { + w.CopySym(a) + } + if len(x) != n { + panic(ErrShape) + } + if len(y) != n { + panic(ErrShape) + } + blas64.Syr2(alpha, blas64.Vector{Inc: 1, Data: x}, blas64.Vector{Inc: 1, Data: y}, w.mat) + *s = w + return +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/symmetric_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/symmetric_test.go new file mode 100644 index 0000000..cdf4a20 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/symmetric_test.go @@ -0,0 +1,255 @@ +package mat64 + +import ( + "math/rand" + + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" + "gopkg.in/check.v1" +) + +func (s *S) TestNewSymmetric(c *check.C) { + for i, test := range []struct { + data []float64 + N int + mat *SymDense + }{ + { + data: []float64{ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + }, + N: 3, + mat: &SymDense{blas64.Symmetric{ + N: 3, + Stride: 3, + Uplo: blas.Upper, + Data: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, + }}, + }, + } { + t := NewSymDense(test.N, test.data) + rows, cols := t.Dims() + c.Check(rows, check.Equals, test.N, check.Commentf("Test %d", i)) + c.Check(cols, check.Equals, test.N, check.Commentf("Test %d", i)) + c.Check(t, check.DeepEquals, test.mat, check.Commentf("Test %d", i)) + + m := NewDense(test.N, test.N, test.data) + c.Check(t.mat.Data, check.DeepEquals, m.mat.Data, check.Commentf("Test %d", i)) + + c.Check(func() { NewSymDense(3, []float64{1, 2}) }, check.PanicMatches, ErrShape.Error()) + } +} + +func (s *S) TestSymAtSet(c *check.C) { + t := &SymDense{blas64.Symmetric{ + N: 3, + Stride: 3, + Uplo: blas.Upper, + Data: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, + }} + rows, cols := t.Dims() + // Check At out of bounds + c.Check(func() { t.At(rows, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.At(0, cols) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.At(rows+1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.At(0, cols+1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.At(-1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.At(0, -1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + + // Check Set out of bounds + c.Check(func() { t.SetSym(rows, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.SetSym(0, cols, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.SetSym(rows+1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.SetSym(0, cols+1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.SetSym(-1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.SetSym(0, -1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + + c.Check(t.At(2, 1), check.Equals, 6.0) + c.Check(t.At(1, 2), check.Equals, 6.0) + t.SetSym(1, 2, 15) + c.Check(t.At(2, 1), check.Equals, 15.0) + c.Check(t.At(1, 2), check.Equals, 15.0) + t.SetSym(2, 1, 12) + c.Check(t.At(2, 1), check.Equals, 12.0) + c.Check(t.At(1, 2), check.Equals, 12.0) +} + +func (s *S) TestSymAdd(c *check.C) { + for _, test := range []struct { + n int + }{ + {n: 1}, + {n: 2}, + {n: 3}, + {n: 4}, + {n: 5}, + {n: 10}, + } { + n := test.n + a := NewSymDense(n, nil) + for i := range a.mat.Data { + a.mat.Data[i] = rand.Float64() + } + b := NewSymDense(n, nil) + for i := range a.mat.Data { + b.mat.Data[i] = rand.Float64() + } + var m Dense + m.Add(a, b) + + // Check with new receiver + var s SymDense + s.AddSym(a, b) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := m.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + + // Check with equal receiver + s.CopySym(a) + s.AddSym(&s, b) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := m.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + } +} + +func (s *S) TestCopy(c *check.C) { + for _, test := range []struct { + n int + }{ + {n: 1}, + {n: 2}, + {n: 3}, + {n: 4}, + {n: 5}, + {n: 10}, + } { + n := test.n + a := NewSymDense(n, nil) + for i := range a.mat.Data { + a.mat.Data[i] = rand.Float64() + } + s := NewSymDense(n, nil) + s.CopySym(a) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := a.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + } +} + +func (s *S) TestSymRankOne(c *check.C) { + for _, test := range []struct { + n int + }{ + {n: 1}, + {n: 2}, + {n: 3}, + {n: 4}, + {n: 5}, + {n: 10}, + } { + n := test.n + alpha := 2.0 + a := NewSymDense(n, nil) + for i := range a.mat.Data { + a.mat.Data[i] = rand.Float64() + } + x := make([]float64, n) + for i := range x { + x[i] = rand.Float64() + } + + xMat := NewDense(n, 1, x) + var m Dense + m.MulTrans(xMat, false, xMat, true) + m.Scale(alpha, &m) + m.Add(&m, a) + + // Check with new receiver + s := NewSymDense(n, nil) + s.SymRankOne(a, alpha, x) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := m.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + + // Check with reused receiver + copy(s.mat.Data, a.mat.Data) + s.SymRankOne(s, alpha, x) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := m.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + } +} + +func (s *S) TestRankTwo(c *check.C) { + for _, test := range []struct { + n int + }{ + {n: 1}, + {n: 2}, + {n: 3}, + {n: 4}, + {n: 5}, + {n: 10}, + } { + n := test.n + alpha := 2.0 + a := NewSymDense(n, nil) + for i := range a.mat.Data { + a.mat.Data[i] = rand.Float64() + } + x := make([]float64, n) + y := make([]float64, n) + for i := range x { + x[i] = rand.Float64() + y[i] = rand.Float64() + } + + xMat := NewDense(n, 1, x) + yMat := NewDense(n, 1, y) + var m Dense + m.MulTrans(xMat, false, yMat, true) + var tmp Dense + tmp.MulTrans(yMat, false, xMat, true) + m.Add(&m, &tmp) + m.Scale(alpha, &m) + m.Add(&m, a) + + // Check with new receiver + s := NewSymDense(n, nil) + s.RankTwo(a, alpha, x, y) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := m.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + + // Check with reused receiver + copy(s.mat.Data, a.mat.Data) + s.RankTwo(s, alpha, x, y) + for i := 0; i < n; i++ { + for j := i; j < n; j++ { + v := m.At(i, j) + c.Check(s.At(i, j), check.Equals, v) + } + } + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/triangular.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/triangular.go new file mode 100644 index 0000000..729d756 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/triangular.go @@ -0,0 +1,54 @@ +package mat64 + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" +) + +var ( + triangular *Triangular + _ Matrix = triangular +) + +// Triangular represents an upper or lower triangular matrix. +type Triangular struct { + mat blas64.Triangular +} + +// NewTriangular constructs an n x n triangular matrix. The constructed matrix +// is upper triangular if upper == true and lower triangular otherwise. +// If len(mat) == n * n, mat will be used to hold the underlying data, if +// mat == nil, new data will be allocated, and will panic if neither of these +// cases is true. +// The underlying data representation is the same as that of a Dense matrix, +// except the values of the entries in the opposite half are completely ignored. +func NewTriangular(n int, upper bool, mat []float64) *Triangular { + if n < 0 { + panic("mat64: negative dimension") + } + if mat != nil && len(mat) != n*n { + panic(ErrShape) + } + if mat == nil { + mat = make([]float64, n*n) + } + uplo := blas.Lower + if upper { + uplo = blas.Upper + } + return &Triangular{blas64.Triangular{ + N: n, + Stride: n, + Data: mat, + Uplo: uplo, + Diag: blas.NonUnit, + }} +} + +func (t *Triangular) Dims() (r, c int) { + return t.mat.N, t.mat.N +} + +func (t *Triangular) RawTriangular() blas64.Triangular { + return t.mat +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/triangular_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/triangular_test.go new file mode 100644 index 0000000..7093012 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/triangular_test.go @@ -0,0 +1,73 @@ +package mat64 + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" + "gopkg.in/check.v1" +) + +func (s *S) TestNewTriangular(c *check.C) { + for i, test := range []struct { + data []float64 + N int + upper bool + mat *Triangular + }{ + { + data: []float64{ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, + }, + N: 3, + upper: true, + mat: &Triangular{blas64.Triangular{ + N: 3, + Stride: 3, + Uplo: blas.Upper, + Data: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, + Diag: blas.NonUnit, + }}, + }, + } { + t := NewTriangular(test.N, test.upper, test.data) + rows, cols := t.Dims() + c.Check(rows, check.Equals, test.N, check.Commentf("Test %d", i)) + c.Check(cols, check.Equals, test.N, check.Commentf("Test %d", i)) + c.Check(t, check.DeepEquals, test.mat, check.Commentf("Test %d", i)) + } +} +func (s *S) TestTriAtSet(c *check.C) { + t := &Triangular{blas64.Triangular{ + N: 3, + Stride: 3, + Uplo: blas.Upper, + Data: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, + Diag: blas.NonUnit, + }} + rows, cols := t.Dims() + // Check At out of bounds + c.Check(func() { t.At(rows, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.At(0, cols) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.At(rows+1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.At(0, cols+1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.At(-1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.At(0, -1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + // Check Set out of bounds + c.Check(func() { t.SetTri(rows, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.SetTri(0, cols, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.SetTri(rows+1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.SetTri(0, cols+1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.SetTri(-1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) + c.Check(func() { t.SetTri(0, -1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) + c.Check(func() { t.SetTri(2, 1, 1.2) }, check.PanicMatches, "mat64: triangular set out of bounds", check.Commentf("Test lower access")) + t.mat.Uplo = blas.Lower + c.Check(func() { t.SetTri(1, 2, 1.2) }, check.PanicMatches, "mat64: triangular set out of bounds", check.Commentf("Test upper access")) + c.Check(t.At(2, 1), check.Equals, 8.0) + t.SetTri(2, 1, 15) + c.Check(t.At(2, 1), check.Equals, 15.0) + t.mat.Uplo = blas.Upper + c.Check(t.At(1, 2), check.Equals, 6.0) + t.SetTri(1, 2, 15) + c.Check(t.At(1, 2), check.Equals, 15.0) +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/vector.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/vector.go new file mode 100644 index 0000000..a51aeb0 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/vector.go @@ -0,0 +1,187 @@ +// Copyright ©2013 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mat64 + +import ( + "github.com/gonum/blas" + "github.com/gonum/blas/blas64" +) + +var ( + vector *Vector + + _ Matrix = vector + _ Mutable = vector + + // _ Cloner = vector + // _ Viewer = vector + // _ Subvectorer = vector + + // _ Adder = vector + // _ Suber = vector + // _ Muler = vector + // _ Dotter = vector + // _ ElemMuler = vector + + // _ Scaler = vector + // _ Applyer = vector + + // _ Normer = vector + // _ Sumer = vector + + // _ Stacker = vector + // _ Augmenter = vector + + // _ Equaler = vector + // _ ApproxEqualer = vector + + // _ RawMatrixLoader = vector + // _ RawMatrixer = vector +) + +// Vector represents a column vector. +type Vector struct { + mat blas64.Vector + n int + // A BLAS vector can have a negative increment, but allowing this + // in the mat64 type complicates a lot of code, and doesn't gain anything. + // Vector must have positive increment in this package. +} + +// NewVector creates a new Vector of length n. If len(data) == n, data is used +// as the backing data slice. If data == nil, a new slice is allocated. If +// neither of these is true, NewVector will panic. +func NewVector(n int, data []float64) *Vector { + if len(data) != n && data != nil { + panic(ErrShape) + } + if data == nil { + data = make([]float64, n) + } + return &Vector{ + mat: blas64.Vector{ + Inc: 1, + Data: data, + }, + n: n, + } +} + +// ViewVec returns a sub-vector view of the receiver starting at element i and +// extending n columns. If i is out of range, or if n is zero or extend beyond the +// bounds of the Vector ViewVec will panic with ErrIndexOutOfRange. The returned +// Vector retains reference to the underlying vector. +func (m *Vector) ViewVec(i, n int) *Vector { + if i+n > m.n { + panic(ErrIndexOutOfRange) + } + return &Vector{ + n: n, + mat: blas64.Vector{ + Inc: m.mat.Inc, + Data: m.mat.Data[i*m.mat.Inc:], + }, + } +} + +func (m *Vector) Dims() (r, c int) { return m.n, 1 } + +// Len returns the length of the vector. +func (m *Vector) Len() int { + return m.n +} + +func (m *Vector) Reset() { + m.mat.Data = m.mat.Data[:0] + m.mat.Inc = 0 + m.n = 0 +} + +func (m *Vector) RawVector() blas64.Vector { + return m.mat +} + +// MulVec computes a * b if trans == false and a^T * b if trans == true. The +// result is stored into the reciever. MulVec panics if the number of columns in +// a does not equal the number of rows in b. +func (m *Vector) MulVec(a Matrix, trans bool, b *Vector) { + ar, ac := a.Dims() + br, _ := b.Dims() + if trans { + if ar != br { + panic(ErrShape) + } + } else { + if ac != br { + panic(ErrShape) + } + } + + var w Vector + if m != a && m != b { + w = *m + } + if w.n == 0 { + if trans { + w.mat.Data = use(w.mat.Data, ac) + } else { + w.mat.Data = use(w.mat.Data, ar) + } + + w.mat.Inc = 1 + w.n = ar + } else { + if trans { + if ac != w.n { + panic(ErrShape) + } + } else { + if ar != w.n { + panic(ErrShape) + } + } + } + + switch a := a.(type) { + case RawSymmetricer: + amat := a.RawSymmetric() + blas64.Symv(1, amat, b.mat, 0, w.mat) + *m = w + return + case RawMatrixer: + amat := a.RawMatrix() + t := blas.NoTrans + if trans { + t = blas.Trans + } + blas64.Gemv(t, 1, amat, b.mat, 0, w.mat) + *m = w + return + case Vectorer: + row := make([]float64, ac) + for r := 0; r < ar; r++ { + w.mat.Data[r*m.mat.Inc] = blas64.Dot(ac, + blas64.Vector{Inc: 1, Data: a.Row(row, r)}, + b.mat, + ) + } + *m = w + return + default: + row := make([]float64, ac) + for r := 0; r < ar; r++ { + for i := range row { + row[i] = a.At(r, i) + } + var v float64 + for i, e := range row { + v += e * b.mat.Data[i*b.mat.Inc] + } + w.mat.Data[r*m.mat.Inc] = v + } + *m = w + return + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/vector_test.go b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/vector_test.go new file mode 100644 index 0000000..2ac46e0 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/gonum/matrix/mat64/vector_test.go @@ -0,0 +1,135 @@ +package mat64 + +import ( + "math/rand" + + "github.com/gonum/blas/blas64" + "github.com/gonum/floats" + "gopkg.in/check.v1" +) + +func (s *S) TestNewVector(c *check.C) { + for i, test := range []struct { + n int + data []float64 + vector *Vector + }{ + { + n: 3, + data: []float64{4, 5, 6}, + vector: &Vector{ + mat: blas64.Vector{ + Data: []float64{4, 5, 6}, + Inc: 1, + }, + n: 3, + }, + }, + } { + v := NewVector(test.n, test.data) + rows, cols := v.Dims() + c.Check(rows, check.Equals, test.n, check.Commentf("Test %d", i)) + c.Check(cols, check.Equals, 1, check.Commentf("Test %d", i)) + c.Check(v, check.DeepEquals, test.vector, check.Commentf("Test %d", i)) + v2 := NewVector(test.n, nil) + c.Check(v2.mat.Data, check.DeepEquals, []float64{0, 0, 0}, check.Commentf("Test %d", i)) + } +} + +func (s *S) TestVectorAtSet(c *check.C) { + for i, test := range []struct { + vector *Vector + }{ + { + vector: &Vector{ + mat: blas64.Vector{ + Data: []float64{0, 1, 2}, + Inc: 1, + }, + n: 3, + }, + }, + { + vector: &Vector{ + mat: blas64.Vector{ + Data: []float64{0, 10, 10, 1, 10, 10, 2}, + Inc: 3, + }, + n: 3, + }, + }, + } { + v := test.vector + n := test.vector.n + c.Check(func() { v.At(n, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", i)) + c.Check(func() { v.At(-1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", i)) + c.Check(func() { v.At(0, 1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", i)) + c.Check(func() { v.At(0, -1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", i)) + + c.Check(v.At(0, 0), check.Equals, 0.0, check.Commentf("Test %d", i)) + c.Check(v.At(1, 0), check.Equals, 1.0, check.Commentf("Test %d", i)) + c.Check(v.At(n-1, 0), check.Equals, float64(n-1), check.Commentf("Test %d", i)) + + c.Check(func() { v.Set(n, 0, 100) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", i)) + c.Check(func() { v.Set(-1, 0, 100) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test %d", i)) + c.Check(func() { v.Set(0, 1, 100) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", i)) + c.Check(func() { v.Set(0, -1, 100) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test %d", i)) + + v.Set(0, 0, 100) + c.Check(v.At(0, 0), check.Equals, 100.0, check.Commentf("Test %d", i)) + v.Set(2, 0, 101) + c.Check(v.At(2, 0), check.Equals, 101.0, check.Commentf("Test %d", i)) + } +} + +func (s *S) TestVectorMul(c *check.C) { + + for i, test := range []struct { + m int + n int + }{ + { + m: 10, + n: 5, + }, + { + m: 5, + n: 5, + }, + { + m: 5, + n: 10, + }, + } { + vData := make([]float64, test.n) + for i := range vData { + vData[i] = rand.Float64() + } + vDataCopy := make([]float64, test.n) + copy(vDataCopy, vData) + v := NewVector(test.n, vData) + aData := make([]float64, test.n*test.m) + for i := range aData { + aData[i] = rand.Float64() + } + a := NewDense(test.m, test.n, aData) + var v2 Vector + v2.MulVec(a, false, v) + var v2M Dense + v2M.Mul(a, v) + same := floats.EqualApprox(v2.mat.Data, v2M.mat.Data, 1e-14) + c.Check(same, check.Equals, true, check.Commentf("Test %d", i)) + + var aT Dense + aT.TCopy(a) + v2.MulVec(&aT, true, v) + same = floats.EqualApprox(v2.mat.Data, v2M.mat.Data, 1e-14) + c.Check(same, check.Equals, true, check.Commentf("Test %d", i)) + + /* + v.MulVec(&aT, true, v) + same = floats.EqualApprox(v.mat.Data, v2M.mat.Data, 1e-14) + c.Check(same, check.Equals, true, check.Commentf("Test %d", i)) + */ + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go new file mode 100644 index 0000000..ced25f0 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go @@ -0,0 +1,824 @@ +package assert + +import ( + "bufio" + "bytes" + "fmt" + "reflect" + "regexp" + "runtime" + "strings" + "time" +) + +// TestingT is an interface wrapper around *testing.T +type TestingT interface { + Errorf(format string, args ...interface{}) +} + +// Comparison a custom function that returns true on success and false on failure +type Comparison func() (success bool) + +/* + Helper functions +*/ + +// ObjectsAreEqual determines if two objects are considered equal. +// +// This function does no assertion of any kind. +func ObjectsAreEqual(expected, actual interface{}) bool { + + if expected == nil || actual == nil { + return expected == actual + } + + if reflect.DeepEqual(expected, actual) { + return true + } + + // Last ditch effort + if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) { + return true + } + + return false + +} + +func ObjectsAreEqualValues(expected, actual interface{}) bool { + if ObjectsAreEqual(expected, actual) { + return true + } + + actualType := reflect.TypeOf(actual) + expectedValue := reflect.ValueOf(expected) + if expectedValue.Type().ConvertibleTo(actualType) { + // Attempt comparison after type conversion + if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) { + return true + } + } + + return false +} + +/* CallerInfo is necessary because the assert functions use the testing object +internally, causing it to print the file:line of the assert method, rather than where +the problem actually occured in calling code.*/ + +// CallerInfo returns a string containing the file and line number of the assert call +// that failed. +func CallerInfo() string { + + file := "" + line := 0 + ok := false + + for i := 0; ; i++ { + _, file, line, ok = runtime.Caller(i) + if !ok { + return "" + } + parts := strings.Split(file, "/") + dir := parts[len(parts)-2] + file = parts[len(parts)-1] + if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" { + break + } + } + + return fmt.Sprintf("%s:%d", file, line) +} + +// getWhitespaceString returns a string that is long enough to overwrite the default +// output from the go testing framework. +func getWhitespaceString() string { + + _, file, line, ok := runtime.Caller(1) + if !ok { + return "" + } + parts := strings.Split(file, "/") + file = parts[len(parts)-1] + + return strings.Repeat(" ", len(fmt.Sprintf("%s:%d: ", file, line))) + +} + +func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { + if len(msgAndArgs) == 0 || msgAndArgs == nil { + return "" + } + if len(msgAndArgs) == 1 { + return msgAndArgs[0].(string) + } + if len(msgAndArgs) > 1 { + return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...) + } + return "" +} + +// Indents all lines of the message by appending a number of tabs to each line, in an output format compatible with Go's +// test printing (see inner comment for specifics) +func indentMessageLines(message string, tabs int) string { + outBuf := new(bytes.Buffer) + + for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ { + if i != 0 { + outBuf.WriteRune('\n') + } + for ii := 0; ii < tabs; ii++ { + outBuf.WriteRune('\t') + // Bizarrely, all lines except the first need one fewer tabs prepended, so deliberately advance the counter + // by 1 prematurely. + if ii == 0 && i > 0 { + ii++ + } + } + outBuf.WriteString(scanner.Text()) + } + + return outBuf.String() +} + +// Fail reports a failure through +func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { + + message := messageFromMsgAndArgs(msgAndArgs...) + + if len(message) > 0 { + t.Errorf("\r%s\r\tLocation:\t%s\n"+ + "\r\tError:%s\n"+ + "\r\tMessages:\t%s\n\r", + getWhitespaceString(), + CallerInfo(), + indentMessageLines(failureMessage, 2), + message) + } else { + t.Errorf("\r%s\r\tLocation:\t%s\n"+ + "\r\tError:%s\n\r", + getWhitespaceString(), + CallerInfo(), + indentMessageLines(failureMessage, 2)) + } + + return false +} + +// Implements asserts that an object is implemented by the specified interface. +// +// assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject") +func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool { + + interfaceType := reflect.TypeOf(interfaceObject).Elem() + + if !reflect.TypeOf(object).Implements(interfaceType) { + return Fail(t, fmt.Sprintf("Object must implement %v", interfaceType), msgAndArgs...) + } + + return true + +} + +// IsType asserts that the specified objects are of the same type. +func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool { + + if !ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType)) { + return Fail(t, fmt.Sprintf("Object expected to be of type %v, but was %v", reflect.TypeOf(expectedType), reflect.TypeOf(object)), msgAndArgs...) + } + + return true +} + +// Equal asserts that two objects are equal. +// +// assert.Equal(t, 123, 123, "123 and 123 should be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + + if !ObjectsAreEqual(expected, actual) { + return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+ + " != %#v (actual)", expected, actual), msgAndArgs...) + } + + return true + +} + +// EqualValues asserts that two objects are equal or convertable to the same types +// and equal. +// +// assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + + if !ObjectsAreEqualValues(expected, actual) { + return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+ + " != %#v (actual)", expected, actual), msgAndArgs...) + } + + return true + +} + +// Exactly asserts that two objects are equal is value and type. +// +// assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + + aType := reflect.TypeOf(expected) + bType := reflect.TypeOf(actual) + + if aType != bType { + return Fail(t, "Types expected to match exactly", "%v != %v", aType, bType) + } + + return Equal(t, expected, actual, msgAndArgs...) + +} + +// NotNil asserts that the specified object is not nil. +// +// assert.NotNil(t, err, "err should be something") +// +// Returns whether the assertion was successful (true) or not (false). +func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + + success := true + + if object == nil { + success = false + } else { + value := reflect.ValueOf(object) + kind := value.Kind() + if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() { + success = false + } + } + + if !success { + Fail(t, "Expected not to be nil.", msgAndArgs...) + } + + return success +} + +// isNil checks if a specified object is nil or not, without Failing. +func isNil(object interface{}) bool { + if object == nil { + return true + } + + value := reflect.ValueOf(object) + kind := value.Kind() + if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() { + return true + } + + return false +} + +// Nil asserts that the specified object is nil. +// +// assert.Nil(t, err, "err should be nothing") +// +// Returns whether the assertion was successful (true) or not (false). +func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + if isNil(object) { + return true + } + return Fail(t, fmt.Sprintf("Expected nil, but got: %#v", object), msgAndArgs...) +} + +var zeros = []interface{}{ + int(0), + int8(0), + int16(0), + int32(0), + int64(0), + uint(0), + uint8(0), + uint16(0), + uint32(0), + uint64(0), + float32(0), + float64(0), +} + +// isEmpty gets whether the specified object is considered empty or not. +func isEmpty(object interface{}) bool { + + if object == nil { + return true + } else if object == "" { + return true + } else if object == false { + return true + } + + for _, v := range zeros { + if object == v { + return true + } + } + + objValue := reflect.ValueOf(object) + + switch objValue.Kind() { + case reflect.Map: + fallthrough + case reflect.Slice, reflect.Chan: + { + return (objValue.Len() == 0) + } + case reflect.Ptr: + { + switch object.(type) { + case *time.Time: + return object.(*time.Time).IsZero() + default: + return false + } + } + } + return false +} + +// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// assert.Empty(t, obj) +// +// Returns whether the assertion was successful (true) or not (false). +func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + + pass := isEmpty(object) + if !pass { + Fail(t, fmt.Sprintf("Should be empty, but was %v", object), msgAndArgs...) + } + + return pass + +} + +// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either +// a slice or a channel with len == 0. +// +// if assert.NotEmpty(t, obj) { +// assert.Equal(t, "two", obj[1]) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + + pass := !isEmpty(object) + if !pass { + Fail(t, fmt.Sprintf("Should NOT be empty, but was %v", object), msgAndArgs...) + } + + return pass + +} + +// getLen try to get length of object. +// return (false, 0) if impossible. +func getLen(x interface{}) (ok bool, length int) { + v := reflect.ValueOf(x) + defer func() { + if e := recover(); e != nil { + ok = false + } + }() + return true, v.Len() +} + +// Len asserts that the specified object has specific length. +// Len also fails if the object has a type that len() not accept. +// +// assert.Len(t, mySlice, 3, "The size of slice is not 3") +// +// Returns whether the assertion was successful (true) or not (false). +func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool { + ok, l := getLen(object) + if !ok { + return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", object), msgAndArgs...) + } + + if l != length { + return Fail(t, fmt.Sprintf("\"%s\" should have %d item(s), but has %d", object, length, l), msgAndArgs...) + } + return true +} + +// True asserts that the specified value is true. +// +// assert.True(t, myBool, "myBool should be true") +// +// Returns whether the assertion was successful (true) or not (false). +func True(t TestingT, value bool, msgAndArgs ...interface{}) bool { + + if value != true { + return Fail(t, "Should be true", msgAndArgs...) + } + + return true + +} + +// False asserts that the specified value is true. +// +// assert.False(t, myBool, "myBool should be false") +// +// Returns whether the assertion was successful (true) or not (false). +func False(t TestingT, value bool, msgAndArgs ...interface{}) bool { + + if value != false { + return Fail(t, "Should be false", msgAndArgs...) + } + + return true + +} + +// NotEqual asserts that the specified values are NOT equal. +// +// assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + + if ObjectsAreEqual(expected, actual) { + return Fail(t, "Should not be equal", msgAndArgs...) + } + + return true + +} + +// containsElement try loop over the list check if the list includes the element. +// return (false, false) if impossible. +// return (true, false) if element was not found. +// return (true, true) if element was found. +func includeElement(list interface{}, element interface{}) (ok, found bool) { + + listValue := reflect.ValueOf(list) + elementValue := reflect.ValueOf(element) + defer func() { + if e := recover(); e != nil { + ok = false + found = false + } + }() + + if reflect.TypeOf(list).Kind() == reflect.String { + return true, strings.Contains(listValue.String(), elementValue.String()) + } + + for i := 0; i < listValue.Len(); i++ { + if ObjectsAreEqual(listValue.Index(i).Interface(), element) { + return true, true + } + } + return true, false + +} + +// Contains asserts that the specified string or list(array, slice...) contains the +// specified substring or element. +// +// assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'") +// assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'") +// +// Returns whether the assertion was successful (true) or not (false). +func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool { + + ok, found := includeElement(s, contains) + if !ok { + return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", s), msgAndArgs...) + } + if !found { + return Fail(t, fmt.Sprintf("\"%s\" does not contain \"%s\"", s, contains), msgAndArgs...) + } + + return true + +} + +// NotContains asserts that the specified string or list(array, slice...) does NOT contain the +// specified substring or element. +// +// assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'") +// assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'") +// +// Returns whether the assertion was successful (true) or not (false). +func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool { + + ok, found := includeElement(s, contains) + if !ok { + return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", s), msgAndArgs...) + } + if found { + return Fail(t, fmt.Sprintf("\"%s\" should not contain \"%s\"", s, contains), msgAndArgs...) + } + + return true + +} + +// Condition uses a Comparison to assert a complex condition. +func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool { + result := comp() + if !result { + Fail(t, "Condition failed!", msgAndArgs...) + } + return result +} + +// PanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics +// methods, and represents a simple func that takes no arguments, and returns nothing. +type PanicTestFunc func() + +// didPanic returns true if the function passed to it panics. Otherwise, it returns false. +func didPanic(f PanicTestFunc) (bool, interface{}) { + + didPanic := false + var message interface{} + func() { + + defer func() { + if message = recover(); message != nil { + didPanic = true + } + }() + + // call the target function + f() + + }() + + return didPanic, message + +} + +// Panics asserts that the code inside the specified PanicTestFunc panics. +// +// assert.Panics(t, func(){ +// GoCrazy() +// }, "Calling GoCrazy() should panic") +// +// Returns whether the assertion was successful (true) or not (false). +func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool { + + if funcDidPanic, panicValue := didPanic(f); !funcDidPanic { + return Fail(t, fmt.Sprintf("func %#v should panic\n\r\tPanic value:\t%v", f, panicValue), msgAndArgs...) + } + + return true +} + +// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. +// +// assert.NotPanics(t, func(){ +// RemainCalm() +// }, "Calling RemainCalm() should NOT panic") +// +// Returns whether the assertion was successful (true) or not (false). +func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool { + + if funcDidPanic, panicValue := didPanic(f); funcDidPanic { + return Fail(t, fmt.Sprintf("func %#v should not panic\n\r\tPanic value:\t%v", f, panicValue), msgAndArgs...) + } + + return true +} + +// WithinDuration asserts that the two times are within duration delta of each other. +// +// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s") +// +// Returns whether the assertion was successful (true) or not (false). +func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool { + + dt := expected.Sub(actual) + if dt < -delta || dt > delta { + return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) + } + + return true +} + +func toFloat(x interface{}) (float64, bool) { + var xf float64 + xok := true + + switch xn := x.(type) { + case uint8: + xf = float64(xn) + case uint16: + xf = float64(xn) + case uint32: + xf = float64(xn) + case uint64: + xf = float64(xn) + case int: + xf = float64(xn) + case int8: + xf = float64(xn) + case int16: + xf = float64(xn) + case int32: + xf = float64(xn) + case int64: + xf = float64(xn) + case float32: + xf = float64(xn) + case float64: + xf = float64(xn) + default: + xok = false + } + + return xf, xok +} + +// InDelta asserts that the two numerals are within delta of each other. +// +// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01) +// +// Returns whether the assertion was successful (true) or not (false). +func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { + + af, aok := toFloat(expected) + bf, bok := toFloat(actual) + + if !aok || !bok { + return Fail(t, fmt.Sprintf("Parameters must be numerical"), msgAndArgs...) + } + + dt := af - bf + if dt < -delta || dt > delta { + return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) + } + + return true +} + +func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { + if reflect.TypeOf(actual).Kind() != reflect.Slice || + reflect.TypeOf(expected).Kind() != reflect.Slice { + return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...) + } + + actualSlice := reflect.ValueOf(actual) + expectedSlice := reflect.ValueOf(expected) + + for i := 0; i < actualSlice.Len(); i++ { + result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta) + if !result { + return result + } + } + + return true +} + +// min(|expected|, |actual|) * epsilon +func calcEpsilonDelta(expected, actual interface{}, epsilon float64) float64 { + af, aok := toFloat(expected) + bf, bok := toFloat(actual) + + if !aok || !bok { + // invalid input + return 0 + } + + if af < 0 { + af = -af + } + if bf < 0 { + bf = -bf + } + var delta float64 + if af < bf { + delta = af * epsilon + } else { + delta = bf * epsilon + } + return delta +} + +// InEpsilon asserts that expected and actual have a relative error less than epsilon +// +// Returns whether the assertion was successful (true) or not (false). +func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { + delta := calcEpsilonDelta(expected, actual, epsilon) + + return InDelta(t, expected, actual, delta, msgAndArgs...) +} + +/* + Errors +*/ + +// NoError asserts that a function returned no error (i.e. `nil`). +// +// actualObj, err := SomeFunction() +// if assert.NoError(t, err) { +// assert.Equal(t, actualObj, expectedObj) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { + if isNil(err) { + return true + } + + return Fail(t, fmt.Sprintf("No error is expected but got %v", err), msgAndArgs...) +} + +// Error asserts that a function returned an error (i.e. not `nil`). +// +// actualObj, err := SomeFunction() +// if assert.Error(t, err, "An error was expected") { +// assert.Equal(t, err, expectedError) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func Error(t TestingT, err error, msgAndArgs ...interface{}) bool { + + message := messageFromMsgAndArgs(msgAndArgs...) + return NotNil(t, err, "An error is expected but got nil. %s", message) + +} + +// EqualError asserts that a function returned an error (i.e. not `nil`) +// and that it is equal to the provided error. +// +// actualObj, err := SomeFunction() +// if assert.Error(t, err, "An error was expected") { +// assert.Equal(t, err, expectedError) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { + + message := messageFromMsgAndArgs(msgAndArgs...) + if !NotNil(t, theError, "An error is expected but got nil. %s", message) { + return false + } + s := "An error with value \"%s\" is expected but got \"%s\". %s" + return Equal(t, theError.Error(), errString, + s, errString, theError.Error(), message) +} + +// matchRegexp return true if a specified regexp matches a string. +func matchRegexp(rx interface{}, str interface{}) bool { + + var r *regexp.Regexp + if rr, ok := rx.(*regexp.Regexp); ok { + r = rr + } else { + r = regexp.MustCompile(fmt.Sprint(rx)) + } + + return (r.FindStringIndex(fmt.Sprint(str)) != nil) + +} + +// Regexp asserts that a specified regexp matches a string. +// +// assert.Regexp(t, regexp.MustCompile("start"), "it's starting") +// assert.Regexp(t, "start...$", "it's not starting") +// +// Returns whether the assertion was successful (true) or not (false). +func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + + match := matchRegexp(rx, str) + + if !match { + Fail(t, fmt.Sprintf("Expect \"%v\" to match \"%v\"", str, rx), msgAndArgs...) + } + + return match +} + +// NotRegexp asserts that a specified regexp does not match a string. +// +// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") +// assert.NotRegexp(t, "^start", "it's not starting") +// +// Returns whether the assertion was successful (true) or not (false). +func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + match := matchRegexp(rx, str) + + if match { + Fail(t, fmt.Sprintf("Expect \"%v\" to NOT match \"%v\"", str, rx), msgAndArgs...) + } + + return !match + +} diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go new file mode 100644 index 0000000..2cb58db --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go @@ -0,0 +1,768 @@ +package assert + +import ( + "errors" + "regexp" + "testing" + "time" +) + +// AssertionTesterInterface defines an interface to be used for testing assertion methods +type AssertionTesterInterface interface { + TestMethod() +} + +// AssertionTesterConformingObject is an object that conforms to the AssertionTesterInterface interface +type AssertionTesterConformingObject struct { +} + +func (a *AssertionTesterConformingObject) TestMethod() { +} + +// AssertionTesterNonConformingObject is an object that does not conform to the AssertionTesterInterface interface +type AssertionTesterNonConformingObject struct { +} + +func TestObjectsAreEqual(t *testing.T) { + + if !ObjectsAreEqual("Hello World", "Hello World") { + t.Error("objectsAreEqual should return true") + } + if !ObjectsAreEqual(123, 123) { + t.Error("objectsAreEqual should return true") + } + if !ObjectsAreEqual(123.5, 123.5) { + t.Error("objectsAreEqual should return true") + } + if !ObjectsAreEqual([]byte("Hello World"), []byte("Hello World")) { + t.Error("objectsAreEqual should return true") + } + if !ObjectsAreEqual(nil, nil) { + t.Error("objectsAreEqual should return true") + } + if ObjectsAreEqual(map[int]int{5: 10}, map[int]int{10: 20}) { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual('x', "x") { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual("x", 'x') { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual(0, 0.1) { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual(0.1, 0) { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual(uint32(10), int32(10)) { + t.Error("objectsAreEqual should return false") + } + if !ObjectsAreEqualValues(uint32(10), int32(10)) { + t.Error("ObjectsAreEqualValues should return true") + } + +} + +func TestImplements(t *testing.T) { + + mockT := new(testing.T) + + if !Implements(mockT, (*AssertionTesterInterface)(nil), new(AssertionTesterConformingObject)) { + t.Error("Implements method should return true: AssertionTesterConformingObject implements AssertionTesterInterface") + } + if Implements(mockT, (*AssertionTesterInterface)(nil), new(AssertionTesterNonConformingObject)) { + t.Error("Implements method should return false: AssertionTesterNonConformingObject does not implements AssertionTesterInterface") + } + +} + +func TestIsType(t *testing.T) { + + mockT := new(testing.T) + + if !IsType(mockT, new(AssertionTesterConformingObject), new(AssertionTesterConformingObject)) { + t.Error("IsType should return true: AssertionTesterConformingObject is the same type as AssertionTesterConformingObject") + } + if IsType(mockT, new(AssertionTesterConformingObject), new(AssertionTesterNonConformingObject)) { + t.Error("IsType should return false: AssertionTesterConformingObject is not the same type as AssertionTesterNonConformingObject") + } + +} + +func TestEqual(t *testing.T) { + + mockT := new(testing.T) + + if !Equal(mockT, "Hello World", "Hello World") { + t.Error("Equal should return true") + } + if !Equal(mockT, 123, 123) { + t.Error("Equal should return true") + } + if !Equal(mockT, 123.5, 123.5) { + t.Error("Equal should return true") + } + if !Equal(mockT, []byte("Hello World"), []byte("Hello World")) { + t.Error("Equal should return true") + } + if !Equal(mockT, nil, nil) { + t.Error("Equal should return true") + } + if !Equal(mockT, int32(123), int32(123)) { + t.Error("Equal should return true") + } + if !Equal(mockT, uint64(123), uint64(123)) { + t.Error("Equal should return true") + } + funcA := func() int { return 42 } + if !Equal(mockT, funcA, funcA) { + t.Error("Equal should return true") + } + +} + +func TestNotNil(t *testing.T) { + + mockT := new(testing.T) + + if !NotNil(mockT, new(AssertionTesterConformingObject)) { + t.Error("NotNil should return true: object is not nil") + } + if NotNil(mockT, nil) { + t.Error("NotNil should return false: object is nil") + } + +} + +func TestNil(t *testing.T) { + + mockT := new(testing.T) + + if !Nil(mockT, nil) { + t.Error("Nil should return true: object is nil") + } + if Nil(mockT, new(AssertionTesterConformingObject)) { + t.Error("Nil should return false: object is not nil") + } + +} + +func TestTrue(t *testing.T) { + + mockT := new(testing.T) + + if !True(mockT, true) { + t.Error("True should return true") + } + if True(mockT, false) { + t.Error("True should return false") + } + +} + +func TestFalse(t *testing.T) { + + mockT := new(testing.T) + + if !False(mockT, false) { + t.Error("False should return true") + } + if False(mockT, true) { + t.Error("False should return false") + } + +} + +func TestExactly(t *testing.T) { + + mockT := new(testing.T) + + a := float32(1) + b := float64(1) + c := float32(1) + d := float32(2) + + if Exactly(mockT, a, b) { + t.Error("Exactly should return false") + } + if Exactly(mockT, a, d) { + t.Error("Exactly should return false") + } + if !Exactly(mockT, a, c) { + t.Error("Exactly should return true") + } + + if Exactly(mockT, nil, a) { + t.Error("Exactly should return false") + } + if Exactly(mockT, a, nil) { + t.Error("Exactly should return false") + } + +} + +func TestNotEqual(t *testing.T) { + + mockT := new(testing.T) + + if !NotEqual(mockT, "Hello World", "Hello World!") { + t.Error("NotEqual should return true") + } + if !NotEqual(mockT, 123, 1234) { + t.Error("NotEqual should return true") + } + if !NotEqual(mockT, 123.5, 123.55) { + t.Error("NotEqual should return true") + } + if !NotEqual(mockT, []byte("Hello World"), []byte("Hello World!")) { + t.Error("NotEqual should return true") + } + if !NotEqual(mockT, nil, new(AssertionTesterConformingObject)) { + t.Error("NotEqual should return true") + } + funcA := func() int { return 23 } + funcB := func() int { return 42 } + if !NotEqual(mockT, funcA, funcB) { + t.Error("NotEqual should return true") + } + + if NotEqual(mockT, "Hello World", "Hello World") { + t.Error("NotEqual should return false") + } + if NotEqual(mockT, 123, 123) { + t.Error("NotEqual should return false") + } + if NotEqual(mockT, 123.5, 123.5) { + t.Error("NotEqual should return false") + } + if NotEqual(mockT, []byte("Hello World"), []byte("Hello World")) { + t.Error("NotEqual should return false") + } + if NotEqual(mockT, new(AssertionTesterConformingObject), new(AssertionTesterConformingObject)) { + t.Error("NotEqual should return false") + } +} + +type A struct { + Name, Value string +} + +func TestContains(t *testing.T) { + + mockT := new(testing.T) + list := []string{"Foo", "Bar"} + complexList := []*A{ + {"b", "c"}, + {"d", "e"}, + {"g", "h"}, + {"j", "k"}, + } + + if !Contains(mockT, "Hello World", "Hello") { + t.Error("Contains should return true: \"Hello World\" contains \"Hello\"") + } + if Contains(mockT, "Hello World", "Salut") { + t.Error("Contains should return false: \"Hello World\" does not contain \"Salut\"") + } + + if !Contains(mockT, list, "Bar") { + t.Error("Contains should return true: \"[\"Foo\", \"Bar\"]\" contains \"Bar\"") + } + if Contains(mockT, list, "Salut") { + t.Error("Contains should return false: \"[\"Foo\", \"Bar\"]\" does not contain \"Salut\"") + } + if !Contains(mockT, complexList, &A{"g", "h"}) { + t.Error("Contains should return true: complexList contains {\"g\", \"h\"}") + } + if Contains(mockT, complexList, &A{"g", "e"}) { + t.Error("Contains should return false: complexList contains {\"g\", \"e\"}") + } +} + +func TestNotContains(t *testing.T) { + + mockT := new(testing.T) + list := []string{"Foo", "Bar"} + + if !NotContains(mockT, "Hello World", "Hello!") { + t.Error("NotContains should return true: \"Hello World\" does not contain \"Hello!\"") + } + if NotContains(mockT, "Hello World", "Hello") { + t.Error("NotContains should return false: \"Hello World\" contains \"Hello\"") + } + + if !NotContains(mockT, list, "Foo!") { + t.Error("NotContains should return true: \"[\"Foo\", \"Bar\"]\" does not contain \"Foo!\"") + } + if NotContains(mockT, list, "Foo") { + t.Error("NotContains should return false: \"[\"Foo\", \"Bar\"]\" contains \"Foo\"") + } + +} + +func Test_includeElement(t *testing.T) { + + list1 := []string{"Foo", "Bar"} + list2 := []int{1, 2} + + ok, found := includeElement("Hello World", "World") + True(t, ok) + True(t, found) + + ok, found = includeElement(list1, "Foo") + True(t, ok) + True(t, found) + + ok, found = includeElement(list1, "Bar") + True(t, ok) + True(t, found) + + ok, found = includeElement(list2, 1) + True(t, ok) + True(t, found) + + ok, found = includeElement(list2, 2) + True(t, ok) + True(t, found) + + ok, found = includeElement(list1, "Foo!") + True(t, ok) + False(t, found) + + ok, found = includeElement(list2, 3) + True(t, ok) + False(t, found) + + ok, found = includeElement(list2, "1") + True(t, ok) + False(t, found) + + ok, found = includeElement(1433, "1") + False(t, ok) + False(t, found) + +} + +func TestCondition(t *testing.T) { + mockT := new(testing.T) + + if !Condition(mockT, func() bool { return true }, "Truth") { + t.Error("Condition should return true") + } + + if Condition(mockT, func() bool { return false }, "Lie") { + t.Error("Condition should return false") + } + +} + +func TestDidPanic(t *testing.T) { + + if funcDidPanic, _ := didPanic(func() { + panic("Panic!") + }); !funcDidPanic { + t.Error("didPanic should return true") + } + + if funcDidPanic, _ := didPanic(func() { + }); funcDidPanic { + t.Error("didPanic should return false") + } + +} + +func TestPanics(t *testing.T) { + + mockT := new(testing.T) + + if !Panics(mockT, func() { + panic("Panic!") + }) { + t.Error("Panics should return true") + } + + if Panics(mockT, func() { + }) { + t.Error("Panics should return false") + } + +} + +func TestNotPanics(t *testing.T) { + + mockT := new(testing.T) + + if !NotPanics(mockT, func() { + }) { + t.Error("NotPanics should return true") + } + + if NotPanics(mockT, func() { + panic("Panic!") + }) { + t.Error("NotPanics should return false") + } + +} + +func TestEqual_Funcs(t *testing.T) { + + type f func() int + f1 := func() int { return 1 } + f2 := func() int { return 2 } + + f1Copy := f1 + + Equal(t, f1Copy, f1, "Funcs are the same and should be considered equal") + NotEqual(t, f1, f2, "f1 and f2 are different") + +} + +func TestNoError(t *testing.T) { + + mockT := new(testing.T) + + // start with a nil error + var err error + + True(t, NoError(mockT, err), "NoError should return True for nil arg") + + // now set an error + err = errors.New("some error") + + False(t, NoError(mockT, err), "NoError with error should return False") + +} + +func TestError(t *testing.T) { + + mockT := new(testing.T) + + // start with a nil error + var err error + + False(t, Error(mockT, err), "Error should return False for nil arg") + + // now set an error + err = errors.New("some error") + + True(t, Error(mockT, err), "Error with error should return True") + +} + +func TestEqualError(t *testing.T) { + mockT := new(testing.T) + + // start with a nil error + var err error + False(t, EqualError(mockT, err, ""), + "EqualError should return false for nil arg") + + // now set an error + err = errors.New("some error") + False(t, EqualError(mockT, err, "Not some error"), + "EqualError should return false for different error string") + True(t, EqualError(mockT, err, "some error"), + "EqualError should return true") +} + +func Test_isEmpty(t *testing.T) { + + chWithValue := make(chan struct{}, 1) + chWithValue <- struct{}{} + + True(t, isEmpty("")) + True(t, isEmpty(nil)) + True(t, isEmpty([]string{})) + True(t, isEmpty(0)) + True(t, isEmpty(int32(0))) + True(t, isEmpty(int64(0))) + True(t, isEmpty(false)) + True(t, isEmpty(map[string]string{})) + True(t, isEmpty(new(time.Time))) + True(t, isEmpty(make(chan struct{}))) + False(t, isEmpty("something")) + False(t, isEmpty(errors.New("something"))) + False(t, isEmpty([]string{"something"})) + False(t, isEmpty(1)) + False(t, isEmpty(true)) + False(t, isEmpty(map[string]string{"Hello": "World"})) + False(t, isEmpty(chWithValue)) + +} + +func TestEmpty(t *testing.T) { + + mockT := new(testing.T) + chWithValue := make(chan struct{}, 1) + chWithValue <- struct{}{} + + True(t, Empty(mockT, ""), "Empty string is empty") + True(t, Empty(mockT, nil), "Nil is empty") + True(t, Empty(mockT, []string{}), "Empty string array is empty") + True(t, Empty(mockT, 0), "Zero int value is empty") + True(t, Empty(mockT, false), "False value is empty") + True(t, Empty(mockT, make(chan struct{})), "Channel without values is empty") + + False(t, Empty(mockT, "something"), "Non Empty string is not empty") + False(t, Empty(mockT, errors.New("something")), "Non nil object is not empty") + False(t, Empty(mockT, []string{"something"}), "Non empty string array is not empty") + False(t, Empty(mockT, 1), "Non-zero int value is not empty") + False(t, Empty(mockT, true), "True value is not empty") + False(t, Empty(mockT, chWithValue), "Channel with values is not empty") +} + +func TestNotEmpty(t *testing.T) { + + mockT := new(testing.T) + chWithValue := make(chan struct{}, 1) + chWithValue <- struct{}{} + + False(t, NotEmpty(mockT, ""), "Empty string is empty") + False(t, NotEmpty(mockT, nil), "Nil is empty") + False(t, NotEmpty(mockT, []string{}), "Empty string array is empty") + False(t, NotEmpty(mockT, 0), "Zero int value is empty") + False(t, NotEmpty(mockT, false), "False value is empty") + False(t, NotEmpty(mockT, make(chan struct{})), "Channel without values is empty") + + True(t, NotEmpty(mockT, "something"), "Non Empty string is not empty") + True(t, NotEmpty(mockT, errors.New("something")), "Non nil object is not empty") + True(t, NotEmpty(mockT, []string{"something"}), "Non empty string array is not empty") + True(t, NotEmpty(mockT, 1), "Non-zero int value is not empty") + True(t, NotEmpty(mockT, true), "True value is not empty") + True(t, NotEmpty(mockT, chWithValue), "Channel with values is not empty") +} + +func Test_getLen(t *testing.T) { + falseCases := []interface{}{ + nil, + 0, + true, + false, + 'A', + struct{}{}, + } + for _, v := range falseCases { + ok, l := getLen(v) + False(t, ok, "Expected getLen fail to get length of %#v", v) + Equal(t, 0, l, "getLen should return 0 for %#v", v) + } + + ch := make(chan int, 5) + ch <- 1 + ch <- 2 + ch <- 3 + trueCases := []struct { + v interface{} + l int + }{ + {[]int{1, 2, 3}, 3}, + {[...]int{1, 2, 3}, 3}, + {"ABC", 3}, + {map[int]int{1: 2, 2: 4, 3: 6}, 3}, + {ch, 3}, + + {[]int{}, 0}, + {map[int]int{}, 0}, + {make(chan int), 0}, + + {[]int(nil), 0}, + {map[int]int(nil), 0}, + {(chan int)(nil), 0}, + } + + for _, c := range trueCases { + ok, l := getLen(c.v) + True(t, ok, "Expected getLen success to get length of %#v", c.v) + Equal(t, c.l, l) + } +} + +func TestLen(t *testing.T) { + mockT := new(testing.T) + + False(t, Len(mockT, nil, 0), "nil does not have length") + False(t, Len(mockT, 0, 0), "int does not have length") + False(t, Len(mockT, true, 0), "true does not have length") + False(t, Len(mockT, false, 0), "false does not have length") + False(t, Len(mockT, 'A', 0), "Rune does not have length") + False(t, Len(mockT, struct{}{}, 0), "Struct does not have length") + + ch := make(chan int, 5) + ch <- 1 + ch <- 2 + ch <- 3 + + cases := []struct { + v interface{} + l int + }{ + {[]int{1, 2, 3}, 3}, + {[...]int{1, 2, 3}, 3}, + {"ABC", 3}, + {map[int]int{1: 2, 2: 4, 3: 6}, 3}, + {ch, 3}, + + {[]int{}, 0}, + {map[int]int{}, 0}, + {make(chan int), 0}, + + {[]int(nil), 0}, + {map[int]int(nil), 0}, + {(chan int)(nil), 0}, + } + + for _, c := range cases { + True(t, Len(mockT, c.v, c.l), "%#v have %d items", c.v, c.l) + } + + cases = []struct { + v interface{} + l int + }{ + {[]int{1, 2, 3}, 4}, + {[...]int{1, 2, 3}, 2}, + {"ABC", 2}, + {map[int]int{1: 2, 2: 4, 3: 6}, 4}, + {ch, 2}, + + {[]int{}, 1}, + {map[int]int{}, 1}, + {make(chan int), 1}, + + {[]int(nil), 1}, + {map[int]int(nil), 1}, + {(chan int)(nil), 1}, + } + + for _, c := range cases { + False(t, Len(mockT, c.v, c.l), "%#v have %d items", c.v, c.l) + } +} + +func TestWithinDuration(t *testing.T) { + + mockT := new(testing.T) + a := time.Now() + b := a.Add(10 * time.Second) + + True(t, WithinDuration(mockT, a, b, 10*time.Second), "A 10s difference is within a 10s time difference") + True(t, WithinDuration(mockT, b, a, 10*time.Second), "A 10s difference is within a 10s time difference") + + False(t, WithinDuration(mockT, a, b, 9*time.Second), "A 10s difference is not within a 9s time difference") + False(t, WithinDuration(mockT, b, a, 9*time.Second), "A 10s difference is not within a 9s time difference") + + False(t, WithinDuration(mockT, a, b, -9*time.Second), "A 10s difference is not within a 9s time difference") + False(t, WithinDuration(mockT, b, a, -9*time.Second), "A 10s difference is not within a 9s time difference") + + False(t, WithinDuration(mockT, a, b, -11*time.Second), "A 10s difference is not within a 9s time difference") + False(t, WithinDuration(mockT, b, a, -11*time.Second), "A 10s difference is not within a 9s time difference") +} + +func TestInDelta(t *testing.T) { + mockT := new(testing.T) + + True(t, InDelta(mockT, 1.001, 1, 0.01), "|1.001 - 1| <= 0.01") + True(t, InDelta(mockT, 1, 1.001, 0.01), "|1 - 1.001| <= 0.01") + True(t, InDelta(mockT, 1, 2, 1), "|1 - 2| <= 1") + False(t, InDelta(mockT, 1, 2, 0.5), "Expected |1 - 2| <= 0.5 to fail") + False(t, InDelta(mockT, 2, 1, 0.5), "Expected |2 - 1| <= 0.5 to fail") + False(t, InDelta(mockT, "", nil, 1), "Expected non numerals to fail") + + cases := []struct { + a, b interface{} + delta float64 + }{ + {uint8(2), uint8(1), 1}, + {uint16(2), uint16(1), 1}, + {uint32(2), uint32(1), 1}, + {uint64(2), uint64(1), 1}, + + {int(2), int(1), 1}, + {int8(2), int8(1), 1}, + {int16(2), int16(1), 1}, + {int32(2), int32(1), 1}, + {int64(2), int64(1), 1}, + + {float32(2), float32(1), 1}, + {float64(2), float64(1), 1}, + } + + for _, tc := range cases { + True(t, InDelta(mockT, tc.a, tc.b, tc.delta), "Expected |%V - %V| <= %v", tc.a, tc.b, tc.delta) + } +} + +func TestInEpsilon(t *testing.T) { + mockT := new(testing.T) + + cases := []struct { + a, b interface{} + epsilon float64 + }{ + {uint8(2), uint16(2), .001}, + {2.1, 2.2, 0.1}, + {2.2, 2.1, 0.1}, + {-2.1, -2.2, 0.1}, + {-2.2, -2.1, 0.1}, + {uint64(100), uint8(101), 0.01}, + {0.1, -0.1, 2}, + } + + for _, tc := range cases { + True(t, InEpsilon(mockT, tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon)) + } + + cases = []struct { + a, b interface{} + epsilon float64 + }{ + {uint8(2), int16(-2), .001}, + {uint64(100), uint8(102), 0.01}, + {2.1, 2.2, 0.001}, + {2.2, 2.1, 0.001}, + {2.1, -2.2, 1}, + {2.1, "bla-bla", 0}, + {0.1, -0.1, 1.99}, + } + + for _, tc := range cases { + False(t, InEpsilon(mockT, tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon)) + } + +} + +func TestRegexp(t *testing.T) { + mockT := new(testing.T) + + cases := []struct { + rx, str string + }{ + {"^start", "start of the line"}, + {"end$", "in the end"}, + {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12.34"}, + } + + for _, tc := range cases { + True(t, Regexp(mockT, tc.rx, tc.str)) + True(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str)) + False(t, NotRegexp(mockT, tc.rx, tc.str)) + False(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str)) + } + + cases = []struct { + rx, str string + }{ + {"^asdfastart", "Not the start of the line"}, + {"end$", "in the end."}, + {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12a.34"}, + } + + for _, tc := range cases { + False(t, Regexp(mockT, tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str) + False(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str)) + True(t, NotRegexp(mockT, tc.rx, tc.str)) + True(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str)) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go new file mode 100644 index 0000000..1c6de28 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go @@ -0,0 +1,150 @@ +// A set of comprehensive testing tools for use with the normal Go testing system. +// +// Example Usage +// +// The following is a complete example using assert in a standard test function: +// import ( +// "testing" +// "github.com/stretchr/testify/assert" +// ) +// +// func TestSomething(t *testing.T) { +// +// var a string = "Hello" +// var b string = "Hello" +// +// assert.Equal(t, a, b, "The two words should be the same.") +// +// } +// +// if you assert many times, use the below: +// +// import ( +// "testing" +// "github.com/stretchr/testify/assert" +// ) +// +// func TestSomething(t *testing.T) { +// assert := assert.New(t) +// +// var a string = "Hello" +// var b string = "Hello" +// +// assert.Equal(a, b, "The two words should be the same.") +// } +// +// Assertions +// +// Assertions allow you to easily write test code, and are global funcs in the `assert` package. +// All assertion functions take, as the first argument, the `*testing.T` object provided by the +// testing framework. This allows the assertion funcs to write the failings and other details to +// the correct place. +// +// Every assertion function also takes an optional string message as the final argument, +// allowing custom error messages to be appended to the message the assertion method outputs. +// +// Here is an overview of the assert functions: +// +// assert.Equal(t, expected, actual [, message [, format-args]) +// +// assert.NotEqual(t, notExpected, actual [, message [, format-args]]) +// +// assert.True(t, actualBool [, message [, format-args]]) +// +// assert.False(t, actualBool [, message [, format-args]]) +// +// assert.Nil(t, actualObject [, message [, format-args]]) +// +// assert.NotNil(t, actualObject [, message [, format-args]]) +// +// assert.Empty(t, actualObject [, message [, format-args]]) +// +// assert.NotEmpty(t, actualObject [, message [, format-args]]) +// +// assert.Len(t, actualObject, expectedLength, [, message [, format-args]]) +// +// assert.Error(t, errorObject [, message [, format-args]]) +// +// assert.NoError(t, errorObject [, message [, format-args]]) +// +// assert.EqualError(t, theError, errString [, message [, format-args]]) +// +// assert.Implements(t, (*MyInterface)(nil), new(MyObject) [,message [, format-args]]) +// +// assert.IsType(t, expectedObject, actualObject [, message [, format-args]]) +// +// assert.Contains(t, stringOrSlice, substringOrElement [, message [, format-args]]) +// +// assert.NotContains(t, stringOrSlice, substringOrElement [, message [, format-args]]) +// +// assert.Panics(t, func(){ +// +// // call code that should panic +// +// } [, message [, format-args]]) +// +// assert.NotPanics(t, func(){ +// +// // call code that should not panic +// +// } [, message [, format-args]]) +// +// assert.WithinDuration(t, timeA, timeB, deltaTime, [, message [, format-args]]) +// +// assert.InDelta(t, numA, numB, delta, [, message [, format-args]]) +// +// assert.InEpsilon(t, numA, numB, epsilon, [, message [, format-args]]) +// +// assert package contains Assertions object. it has assertion methods. +// +// Here is an overview of the assert functions: +// assert.Equal(expected, actual [, message [, format-args]) +// +// assert.NotEqual(notExpected, actual [, message [, format-args]]) +// +// assert.True(actualBool [, message [, format-args]]) +// +// assert.False(actualBool [, message [, format-args]]) +// +// assert.Nil(actualObject [, message [, format-args]]) +// +// assert.NotNil(actualObject [, message [, format-args]]) +// +// assert.Empty(actualObject [, message [, format-args]]) +// +// assert.NotEmpty(actualObject [, message [, format-args]]) +// +// assert.Len(actualObject, expectedLength, [, message [, format-args]]) +// +// assert.Error(errorObject [, message [, format-args]]) +// +// assert.NoError(errorObject [, message [, format-args]]) +// +// assert.EqualError(theError, errString [, message [, format-args]]) +// +// assert.Implements((*MyInterface)(nil), new(MyObject) [,message [, format-args]]) +// +// assert.IsType(expectedObject, actualObject [, message [, format-args]]) +// +// assert.Contains(stringOrSlice, substringOrElement [, message [, format-args]]) +// +// assert.NotContains(stringOrSlice, substringOrElement [, message [, format-args]]) +// +// assert.Panics(func(){ +// +// // call code that should panic +// +// } [, message [, format-args]]) +// +// assert.NotPanics(func(){ +// +// // call code that should not panic +// +// } [, message [, format-args]]) +// +// assert.WithinDuration(timeA, timeB, deltaTime, [, message [, format-args]]) +// +// assert.InDelta(numA, numB, delta, [, message [, format-args]]) +// +// assert.InEpsilon(numA, numB, epsilon, [, message [, format-args]]) +package assert diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/errors.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/errors.go new file mode 100644 index 0000000..ac9dc9d --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/errors.go @@ -0,0 +1,10 @@ +package assert + +import ( + "errors" +) + +// AnError is an error instance useful for testing. If the code does not care +// about error specifics, and only needs to return the error for example, this +// error should be used to make the test code more readable. +var AnError = errors.New("assert.AnError general error for testing") diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go new file mode 100644 index 0000000..6a98848 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go @@ -0,0 +1,252 @@ +package assert + +import "time" + +type Assertions struct { + t TestingT +} + +func New(t TestingT) *Assertions { + return &Assertions{ + t: t, + } +} + +// Fail reports a failure through +func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool { + return Fail(a.t, failureMessage, msgAndArgs...) +} + +// Implements asserts that an object is implemented by the specified interface. +// +// assert.Implements((*MyInterface)(nil), new(MyObject), "MyObject") +func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool { + return Implements(a.t, interfaceObject, object, msgAndArgs...) +} + +// IsType asserts that the specified objects are of the same type. +func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool { + return IsType(a.t, expectedType, object, msgAndArgs...) +} + +// Equal asserts that two objects are equal. +// +// assert.Equal(123, 123, "123 and 123 should be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Equal(expected, actual interface{}, msgAndArgs ...interface{}) bool { + return Equal(a.t, expected, actual, msgAndArgs...) +} + +// Exactly asserts that two objects are equal is value and type. +// +// assert.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Exactly(expected, actual interface{}, msgAndArgs ...interface{}) bool { + return Exactly(a.t, expected, actual, msgAndArgs...) +} + +// NotNil asserts that the specified object is not nil. +// +// assert.NotNil(err, "err should be something") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool { + return NotNil(a.t, object, msgAndArgs...) +} + +// Nil asserts that the specified object is nil. +// +// assert.Nil(err, "err should be nothing") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool { + return Nil(a.t, object, msgAndArgs...) +} + +// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or a +// slice with len == 0. +// +// assert.Empty(obj) +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool { + return Empty(a.t, object, msgAndArgs...) +} + +// Empty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or a +// slice with len == 0. +// +// if assert.NotEmpty(obj) { +// assert.Equal("two", obj[1]) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool { + return NotEmpty(a.t, object, msgAndArgs...) +} + +// Len asserts that the specified object has specific length. +// Len also fails if the object has a type that len() not accept. +// +// assert.Len(mySlice, 3, "The size of slice is not 3") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool { + return Len(a.t, object, length, msgAndArgs...) +} + +// True asserts that the specified value is true. +// +// assert.True(myBool, "myBool should be true") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool { + return True(a.t, value, msgAndArgs...) +} + +// False asserts that the specified value is true. +// +// assert.False(myBool, "myBool should be false") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool { + return False(a.t, value, msgAndArgs...) +} + +// NotEqual asserts that the specified values are NOT equal. +// +// assert.NotEqual(obj1, obj2, "two objects shouldn't be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NotEqual(expected, actual interface{}, msgAndArgs ...interface{}) bool { + return NotEqual(a.t, expected, actual, msgAndArgs...) +} + +// Contains asserts that the specified string contains the specified substring. +// +// assert.Contains("Hello World", "World", "But 'Hello World' does contain 'World'") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Contains(s, contains interface{}, msgAndArgs ...interface{}) bool { + return Contains(a.t, s, contains, msgAndArgs...) +} + +// NotContains asserts that the specified string does NOT contain the specified substring. +// +// assert.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NotContains(s, contains interface{}, msgAndArgs ...interface{}) bool { + return NotContains(a.t, s, contains, msgAndArgs...) +} + +// Uses a Comparison to assert a complex condition. +func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool { + return Condition(a.t, comp, msgAndArgs...) +} + +// Panics asserts that the code inside the specified PanicTestFunc panics. +// +// assert.Panics(func(){ +// GoCrazy() +// }, "Calling GoCrazy() should panic") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool { + return Panics(a.t, f, msgAndArgs...) +} + +// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. +// +// assert.NotPanics(func(){ +// RemainCalm() +// }, "Calling RemainCalm() should NOT panic") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool { + return NotPanics(a.t, f, msgAndArgs...) +} + +// WithinDuration asserts that the two times are within duration delta of each other. +// +// assert.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) WithinDuration(expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool { + return WithinDuration(a.t, expected, actual, delta, msgAndArgs...) +} + +// InDelta asserts that the two numerals are within delta of each other. +// +// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01) +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) InDelta(expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { + return InDelta(a.t, expected, actual, delta, msgAndArgs...) +} + +// InEpsilon asserts that expected and actual have a relative error less than epsilon +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) InEpsilon(expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { + return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) +} + +// NoError asserts that a function returned no error (i.e. `nil`). +// +// actualObj, err := SomeFunction() +// if assert.NoError(err) { +// assert.Equal(actualObj, expectedObj) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NoError(theError error, msgAndArgs ...interface{}) bool { + return NoError(a.t, theError, msgAndArgs...) +} + +// Error asserts that a function returned an error (i.e. not `nil`). +// +// actualObj, err := SomeFunction() +// if assert.Error(err, "An error was expected") { +// assert.Equal(err, expectedError) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Error(theError error, msgAndArgs ...interface{}) bool { + return Error(a.t, theError, msgAndArgs...) +} + +// EqualError asserts that a function returned an error (i.e. not `nil`) +// and that it is equal to the provided error. +// +// actualObj, err := SomeFunction() +// if assert.Error(err, "An error was expected") { +// assert.Equal(err, expectedError) +// } +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool { + return EqualError(a.t, theError, errString, msgAndArgs...) +} + +// Regexp asserts that a specified regexp matches a string. +// +// assert.Regexp(t, regexp.MustCompile("start"), "it's starting") +// assert.Regexp(t, "start...$", "it's not starting") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + return Regexp(a.t, rx, str, msgAndArgs...) +} + +// NotRegexp asserts that a specified regexp does not match a string. +// +// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") +// assert.NotRegexp(t, "^start", "it's not starting") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + return NotRegexp(a.t, rx, str, msgAndArgs...) +} diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go new file mode 100644 index 0000000..20cca6e --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go @@ -0,0 +1,518 @@ +package assert + +import ( + "errors" + "regexp" + "testing" + "time" +) + +func TestImplementsWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.Implements((*AssertionTesterInterface)(nil), new(AssertionTesterConformingObject)) { + t.Error("Implements method should return true: AssertionTesterConformingObject implements AssertionTesterInterface") + } + if assert.Implements((*AssertionTesterInterface)(nil), new(AssertionTesterNonConformingObject)) { + t.Error("Implements method should return false: AssertionTesterNonConformingObject does not implements AssertionTesterInterface") + } +} + +func TestIsTypeWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.IsType(new(AssertionTesterConformingObject), new(AssertionTesterConformingObject)) { + t.Error("IsType should return true: AssertionTesterConformingObject is the same type as AssertionTesterConformingObject") + } + if assert.IsType(new(AssertionTesterConformingObject), new(AssertionTesterNonConformingObject)) { + t.Error("IsType should return false: AssertionTesterConformingObject is not the same type as AssertionTesterNonConformingObject") + } + +} + +func TestEqualWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.Equal("Hello World", "Hello World") { + t.Error("Equal should return true") + } + if !assert.Equal(123, 123) { + t.Error("Equal should return true") + } + if !assert.Equal(123.5, 123.5) { + t.Error("Equal should return true") + } + if !assert.Equal([]byte("Hello World"), []byte("Hello World")) { + t.Error("Equal should return true") + } + if !assert.Equal(nil, nil) { + t.Error("Equal should return true") + } +} + +func TestNotNilWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.NotNil(new(AssertionTesterConformingObject)) { + t.Error("NotNil should return true: object is not nil") + } + if assert.NotNil(nil) { + t.Error("NotNil should return false: object is nil") + } + +} + +func TestNilWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.Nil(nil) { + t.Error("Nil should return true: object is nil") + } + if assert.Nil(new(AssertionTesterConformingObject)) { + t.Error("Nil should return false: object is not nil") + } + +} + +func TestTrueWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.True(true) { + t.Error("True should return true") + } + if assert.True(false) { + t.Error("True should return false") + } + +} + +func TestFalseWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.False(false) { + t.Error("False should return true") + } + if assert.False(true) { + t.Error("False should return false") + } + +} + +func TestExactlyWrapper(t *testing.T) { + assert := New(new(testing.T)) + + a := float32(1) + b := float64(1) + c := float32(1) + d := float32(2) + + if assert.Exactly(a, b) { + t.Error("Exactly should return false") + } + if assert.Exactly(a, d) { + t.Error("Exactly should return false") + } + if !assert.Exactly(a, c) { + t.Error("Exactly should return true") + } + + if assert.Exactly(nil, a) { + t.Error("Exactly should return false") + } + if assert.Exactly(a, nil) { + t.Error("Exactly should return false") + } + +} + +func TestNotEqualWrapper(t *testing.T) { + + assert := New(new(testing.T)) + + if !assert.NotEqual("Hello World", "Hello World!") { + t.Error("NotEqual should return true") + } + if !assert.NotEqual(123, 1234) { + t.Error("NotEqual should return true") + } + if !assert.NotEqual(123.5, 123.55) { + t.Error("NotEqual should return true") + } + if !assert.NotEqual([]byte("Hello World"), []byte("Hello World!")) { + t.Error("NotEqual should return true") + } + if !assert.NotEqual(nil, new(AssertionTesterConformingObject)) { + t.Error("NotEqual should return true") + } +} + +func TestContainsWrapper(t *testing.T) { + + assert := New(new(testing.T)) + list := []string{"Foo", "Bar"} + + if !assert.Contains("Hello World", "Hello") { + t.Error("Contains should return true: \"Hello World\" contains \"Hello\"") + } + if assert.Contains("Hello World", "Salut") { + t.Error("Contains should return false: \"Hello World\" does not contain \"Salut\"") + } + + if !assert.Contains(list, "Foo") { + t.Error("Contains should return true: \"[\"Foo\", \"Bar\"]\" contains \"Foo\"") + } + if assert.Contains(list, "Salut") { + t.Error("Contains should return false: \"[\"Foo\", \"Bar\"]\" does not contain \"Salut\"") + } + +} + +func TestNotContainsWrapper(t *testing.T) { + + assert := New(new(testing.T)) + list := []string{"Foo", "Bar"} + + if !assert.NotContains("Hello World", "Hello!") { + t.Error("NotContains should return true: \"Hello World\" does not contain \"Hello!\"") + } + if assert.NotContains("Hello World", "Hello") { + t.Error("NotContains should return false: \"Hello World\" contains \"Hello\"") + } + + if !assert.NotContains(list, "Foo!") { + t.Error("NotContains should return true: \"[\"Foo\", \"Bar\"]\" does not contain \"Foo!\"") + } + if assert.NotContains(list, "Foo") { + t.Error("NotContains should return false: \"[\"Foo\", \"Bar\"]\" contains \"Foo\"") + } + +} + +func TestConditionWrapper(t *testing.T) { + + assert := New(new(testing.T)) + + if !assert.Condition(func() bool { return true }, "Truth") { + t.Error("Condition should return true") + } + + if assert.Condition(func() bool { return false }, "Lie") { + t.Error("Condition should return false") + } + +} + +func TestDidPanicWrapper(t *testing.T) { + + if funcDidPanic, _ := didPanic(func() { + panic("Panic!") + }); !funcDidPanic { + t.Error("didPanic should return true") + } + + if funcDidPanic, _ := didPanic(func() { + }); funcDidPanic { + t.Error("didPanic should return false") + } + +} + +func TestPanicsWrapper(t *testing.T) { + + assert := New(new(testing.T)) + + if !assert.Panics(func() { + panic("Panic!") + }) { + t.Error("Panics should return true") + } + + if assert.Panics(func() { + }) { + t.Error("Panics should return false") + } + +} + +func TestNotPanicsWrapper(t *testing.T) { + + assert := New(new(testing.T)) + + if !assert.NotPanics(func() { + }) { + t.Error("NotPanics should return true") + } + + if assert.NotPanics(func() { + panic("Panic!") + }) { + t.Error("NotPanics should return false") + } + +} + +func TestEqualWrapper_Funcs(t *testing.T) { + + assert := New(t) + + type f func() int + var f1 f = func() int { return 1 } + var f2 f = func() int { return 2 } + + var f1_copy f = f1 + + assert.Equal(f1_copy, f1, "Funcs are the same and should be considered equal") + assert.NotEqual(f1, f2, "f1 and f2 are different") + +} + +func TestNoErrorWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + // start with a nil error + var err error = nil + + assert.True(mockAssert.NoError(err), "NoError should return True for nil arg") + + // now set an error + err = errors.New("Some error") + + assert.False(mockAssert.NoError(err), "NoError with error should return False") + +} + +func TestErrorWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + // start with a nil error + var err error = nil + + assert.False(mockAssert.Error(err), "Error should return False for nil arg") + + // now set an error + err = errors.New("Some error") + + assert.True(mockAssert.Error(err), "Error with error should return True") + +} + +func TestEqualErrorWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + // start with a nil error + var err error + assert.False(mockAssert.EqualError(err, ""), + "EqualError should return false for nil arg") + + // now set an error + err = errors.New("some error") + assert.False(mockAssert.EqualError(err, "Not some error"), + "EqualError should return false for different error string") + assert.True(mockAssert.EqualError(err, "some error"), + "EqualError should return true") +} + +func TestEmptyWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + assert.True(mockAssert.Empty(""), "Empty string is empty") + assert.True(mockAssert.Empty(nil), "Nil is empty") + assert.True(mockAssert.Empty([]string{}), "Empty string array is empty") + assert.True(mockAssert.Empty(0), "Zero int value is empty") + assert.True(mockAssert.Empty(false), "False value is empty") + + assert.False(mockAssert.Empty("something"), "Non Empty string is not empty") + assert.False(mockAssert.Empty(errors.New("something")), "Non nil object is not empty") + assert.False(mockAssert.Empty([]string{"something"}), "Non empty string array is not empty") + assert.False(mockAssert.Empty(1), "Non-zero int value is not empty") + assert.False(mockAssert.Empty(true), "True value is not empty") + +} + +func TestNotEmptyWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + assert.False(mockAssert.NotEmpty(""), "Empty string is empty") + assert.False(mockAssert.NotEmpty(nil), "Nil is empty") + assert.False(mockAssert.NotEmpty([]string{}), "Empty string array is empty") + assert.False(mockAssert.NotEmpty(0), "Zero int value is empty") + assert.False(mockAssert.NotEmpty(false), "False value is empty") + + assert.True(mockAssert.NotEmpty("something"), "Non Empty string is not empty") + assert.True(mockAssert.NotEmpty(errors.New("something")), "Non nil object is not empty") + assert.True(mockAssert.NotEmpty([]string{"something"}), "Non empty string array is not empty") + assert.True(mockAssert.NotEmpty(1), "Non-zero int value is not empty") + assert.True(mockAssert.NotEmpty(true), "True value is not empty") + +} + +func TestLenWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + assert.False(mockAssert.Len(nil, 0), "nil does not have length") + assert.False(mockAssert.Len(0, 0), "int does not have length") + assert.False(mockAssert.Len(true, 0), "true does not have length") + assert.False(mockAssert.Len(false, 0), "false does not have length") + assert.False(mockAssert.Len('A', 0), "Rune does not have length") + assert.False(mockAssert.Len(struct{}{}, 0), "Struct does not have length") + + ch := make(chan int, 5) + ch <- 1 + ch <- 2 + ch <- 3 + + cases := []struct { + v interface{} + l int + }{ + {[]int{1, 2, 3}, 3}, + {[...]int{1, 2, 3}, 3}, + {"ABC", 3}, + {map[int]int{1: 2, 2: 4, 3: 6}, 3}, + {ch, 3}, + + {[]int{}, 0}, + {map[int]int{}, 0}, + {make(chan int), 0}, + + {[]int(nil), 0}, + {map[int]int(nil), 0}, + {(chan int)(nil), 0}, + } + + for _, c := range cases { + assert.True(mockAssert.Len(c.v, c.l), "%#v have %d items", c.v, c.l) + } +} + +func TestWithinDurationWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + a := time.Now() + b := a.Add(10 * time.Second) + + assert.True(mockAssert.WithinDuration(a, b, 10*time.Second), "A 10s difference is within a 10s time difference") + assert.True(mockAssert.WithinDuration(b, a, 10*time.Second), "A 10s difference is within a 10s time difference") + + assert.False(mockAssert.WithinDuration(a, b, 9*time.Second), "A 10s difference is not within a 9s time difference") + assert.False(mockAssert.WithinDuration(b, a, 9*time.Second), "A 10s difference is not within a 9s time difference") + + assert.False(mockAssert.WithinDuration(a, b, -9*time.Second), "A 10s difference is not within a 9s time difference") + assert.False(mockAssert.WithinDuration(b, a, -9*time.Second), "A 10s difference is not within a 9s time difference") + + assert.False(mockAssert.WithinDuration(a, b, -11*time.Second), "A 10s difference is not within a 9s time difference") + assert.False(mockAssert.WithinDuration(b, a, -11*time.Second), "A 10s difference is not within a 9s time difference") +} + +func TestInDeltaWrapper(t *testing.T) { + assert := New(new(testing.T)) + + True(t, assert.InDelta(1.001, 1, 0.01), "|1.001 - 1| <= 0.01") + True(t, assert.InDelta(1, 1.001, 0.01), "|1 - 1.001| <= 0.01") + True(t, assert.InDelta(1, 2, 1), "|1 - 2| <= 1") + False(t, assert.InDelta(1, 2, 0.5), "Expected |1 - 2| <= 0.5 to fail") + False(t, assert.InDelta(2, 1, 0.5), "Expected |2 - 1| <= 0.5 to fail") + False(t, assert.InDelta("", nil, 1), "Expected non numerals to fail") + + cases := []struct { + a, b interface{} + delta float64 + }{ + {uint8(2), uint8(1), 1}, + {uint16(2), uint16(1), 1}, + {uint32(2), uint32(1), 1}, + {uint64(2), uint64(1), 1}, + + {int(2), int(1), 1}, + {int8(2), int8(1), 1}, + {int16(2), int16(1), 1}, + {int32(2), int32(1), 1}, + {int64(2), int64(1), 1}, + + {float32(2), float32(1), 1}, + {float64(2), float64(1), 1}, + } + + for _, tc := range cases { + True(t, assert.InDelta(tc.a, tc.b, tc.delta), "Expected |%V - %V| <= %v", tc.a, tc.b, tc.delta) + } +} + +func TestInEpsilonWrapper(t *testing.T) { + assert := New(new(testing.T)) + + cases := []struct { + a, b interface{} + epsilon float64 + }{ + {uint8(2), uint16(2), .001}, + {2.1, 2.2, 0.1}, + {2.2, 2.1, 0.1}, + {-2.1, -2.2, 0.1}, + {-2.2, -2.1, 0.1}, + {uint64(100), uint8(101), 0.01}, + {0.1, -0.1, 2}, + } + + for _, tc := range cases { + True(t, assert.InEpsilon(tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon)) + } + + cases = []struct { + a, b interface{} + epsilon float64 + }{ + {uint8(2), int16(-2), .001}, + {uint64(100), uint8(102), 0.01}, + {2.1, 2.2, 0.001}, + {2.2, 2.1, 0.001}, + {2.1, -2.2, 1}, + {2.1, "bla-bla", 0}, + {0.1, -0.1, 1.99}, + } + + for _, tc := range cases { + False(t, assert.InEpsilon(tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon)) + } +} + +func TestRegexpWrapper(t *testing.T) { + + assert := New(new(testing.T)) + + cases := []struct { + rx, str string + }{ + {"^start", "start of the line"}, + {"end$", "in the end"}, + {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12.34"}, + } + + for _, tc := range cases { + True(t, assert.Regexp(tc.rx, tc.str)) + True(t, assert.Regexp(regexp.MustCompile(tc.rx), tc.str)) + False(t, assert.NotRegexp(tc.rx, tc.str)) + False(t, assert.NotRegexp(regexp.MustCompile(tc.rx), tc.str)) + } + + cases = []struct { + rx, str string + }{ + {"^asdfastart", "Not the start of the line"}, + {"end$", "in the end."}, + {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12a.34"}, + } + + for _, tc := range cases { + False(t, assert.Regexp(tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str) + False(t, assert.Regexp(regexp.MustCompile(tc.rx), tc.str)) + True(t, assert.NotRegexp(tc.rx, tc.str)) + True(t, assert.NotRegexp(regexp.MustCompile(tc.rx), tc.str)) + } +} diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go new file mode 100644 index 0000000..0419c1b --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go @@ -0,0 +1,157 @@ +package assert + +import ( + "fmt" + "net/http" + "net/http/httptest" + "net/url" + "strings" +) + +// httpCode is a helper that returns HTTP code of the response. It returns -1 +// if building a new request fails. +func httpCode(handler http.HandlerFunc, mode, url string, values url.Values) int { + w := httptest.NewRecorder() + req, err := http.NewRequest(mode, url+"?"+values.Encode(), nil) + if err != nil { + return -1 + } + handler(w, req) + return w.Code +} + +// HTTPSuccess asserts that a specified handler returns a success status code. +// +// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPSuccess(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values) bool { + code := httpCode(handler, mode, url, values) + if code == -1 { + return false + } + return code >= http.StatusOK && code <= http.StatusPartialContent +} + +// HTTPRedirect asserts that a specified handler returns a redirect status code. +// +// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPRedirect(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values) bool { + code := httpCode(handler, mode, url, values) + if code == -1 { + return false + } + return code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect +} + +// HTTPError asserts that a specified handler returns an error status code. +// +// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPError(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values) bool { + code := httpCode(handler, mode, url, values) + if code == -1 { + return false + } + return code >= http.StatusBadRequest +} + +// HttpBody is a helper that returns HTTP body of the response. It returns +// empty string if building a new request fails. +func HttpBody(handler http.HandlerFunc, mode, url string, values url.Values) string { + w := httptest.NewRecorder() + req, err := http.NewRequest(mode, url+"?"+values.Encode(), nil) + if err != nil { + return "" + } + handler(w, req) + return w.Body.String() +} + +// HTTPBodyContains asserts that a specified handler returns a +// body that contains a string. +// +// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPBodyContains(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool { + body := HttpBody(handler, mode, url, values) + + contains := strings.Contains(body, fmt.Sprint(str)) + if !contains { + Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) + } + + return contains +} + +// HTTPBodyNotContains asserts that a specified handler returns a +// body that does not contain a string. +// +// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool { + body := HttpBody(handler, mode, url, values) + + contains := strings.Contains(body, fmt.Sprint(str)) + if contains { + Fail(t, "Expected response body for %s to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body) + } + + return !contains +} + +// +// Assertions Wrappers +// + +// HTTPSuccess asserts that a specified handler returns a success status code. +// +// assert.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil) +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, mode, url string, values url.Values) bool { + return HTTPSuccess(a.t, handler, mode, url, values) +} + +// HTTPRedirect asserts that a specified handler returns a redirect status code. +// +// assert.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, mode, url string, values url.Values) bool { + return HTTPRedirect(a.t, handler, mode, url, values) +} + +// HTTPError asserts that a specified handler returns an error status code. +// +// assert.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPError(handler http.HandlerFunc, mode, url string, values url.Values) bool { + return HTTPError(a.t, handler, mode, url, values) +} + +// HTTPBodyContains asserts that a specified handler returns a +// body that contains a string. +// +// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool { + return HTTPBodyContains(a.t, handler, mode, url, values, str) +} + +// HTTPBodyNotContains asserts that a specified handler returns a +// body that does not contain a string. +// +// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// +// Returns whether the assertion was successful (true) or not (false). +func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool { + return HTTPBodyNotContains(a.t, handler, mode, url, values, str) +} diff --git a/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions_test.go b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions_test.go new file mode 100644 index 0000000..684c2d5 --- /dev/null +++ b/gocv/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions_test.go @@ -0,0 +1,86 @@ +package assert + +import ( + "fmt" + "net/http" + "net/url" + "testing" +) + +func httpOK(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) +} + +func httpRedirect(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusTemporaryRedirect) +} + +func httpError(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusInternalServerError) +} + +func TestHTTPStatuses(t *testing.T) { + assert := New(t) + mockT := new(testing.T) + + assert.Equal(HTTPSuccess(mockT, httpOK, "GET", "/", nil), true) + assert.Equal(HTTPSuccess(mockT, httpRedirect, "GET", "/", nil), false) + assert.Equal(HTTPSuccess(mockT, httpError, "GET", "/", nil), false) + + assert.Equal(HTTPRedirect(mockT, httpOK, "GET", "/", nil), false) + assert.Equal(HTTPRedirect(mockT, httpRedirect, "GET", "/", nil), true) + assert.Equal(HTTPRedirect(mockT, httpError, "GET", "/", nil), false) + + assert.Equal(HTTPError(mockT, httpOK, "GET", "/", nil), false) + assert.Equal(HTTPError(mockT, httpRedirect, "GET", "/", nil), false) + assert.Equal(HTTPError(mockT, httpError, "GET", "/", nil), true) +} + +func TestHTTPStatusesWrapper(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + assert.Equal(mockAssert.HTTPSuccess(httpOK, "GET", "/", nil), true) + assert.Equal(mockAssert.HTTPSuccess(httpRedirect, "GET", "/", nil), false) + assert.Equal(mockAssert.HTTPSuccess(httpError, "GET", "/", nil), false) + + assert.Equal(mockAssert.HTTPRedirect(httpOK, "GET", "/", nil), false) + assert.Equal(mockAssert.HTTPRedirect(httpRedirect, "GET", "/", nil), true) + assert.Equal(mockAssert.HTTPRedirect(httpError, "GET", "/", nil), false) + + assert.Equal(mockAssert.HTTPError(httpOK, "GET", "/", nil), false) + assert.Equal(mockAssert.HTTPError(httpRedirect, "GET", "/", nil), false) + assert.Equal(mockAssert.HTTPError(httpError, "GET", "/", nil), true) +} + +func httpHelloName(w http.ResponseWriter, r *http.Request) { + name := r.FormValue("name") + w.Write([]byte(fmt.Sprintf("Hello, %s!", name))) +} + +func TestHttpBody(t *testing.T) { + assert := New(t) + mockT := new(testing.T) + + assert.True(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) + assert.True(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) + assert.False(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) + + assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) + assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) + assert.True(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) +} + +func TestHttpBodyWrappers(t *testing.T) { + assert := New(t) + mockAssert := New(new(testing.T)) + + assert.True(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) + assert.True(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) + assert.False(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) + + assert.False(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) + assert.False(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) + assert.True(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) + +} diff --git a/gocv/gocv_calib3d.cpp b/gocv/gocv_calib3d.cpp index 88ed529..b557145 100644 --- a/gocv/gocv_calib3d.cpp +++ b/gocv/gocv_calib3d.cpp @@ -30,10 +30,10 @@ double GcvCalibrateCamera_(VecPoint3f objPts, VecPoint2f imgPts, objPtsArr.push_back(objPts); imgPtsArr.push_back(imgPts); - std::cout << "objPts " << std::endl << objPtsArr[0] << std::endl; - std::cout << "imgPts " << std::endl << imgPtsArr[0] << std::endl; - std::cout << "imgSize " << std::endl << imgSize << std::endl; - std::cout << "Before CamMat " << std::endl << cameraMatrix << std::endl; + /* std::cout << "objPts " << std::endl << objPtsArr[0] << std::endl; */ + /* std::cout << "imgPts " << std::endl << imgPtsArr[0] << std::endl; */ + /* std::cout << "imgSize " << std::endl << imgSize << std::endl; */ + /* std::cout << "Before CamMat " << std::endl << cameraMatrix << std::endl; */ rtn = cv::calibrateCamera(objPtsArr, imgPtsArr, imgSize, cameraMatrix, distCoeffs, @@ -42,11 +42,11 @@ double GcvCalibrateCamera_(VecPoint3f objPts, VecPoint2f imgPts, rvec = rvecs[0]; tvec = tvecs[0]; - std::cout << "After CamMat " << std::endl << cameraMatrix << std::endl; - std::cout << "distCoeffs " << std::endl << distCoeffs << std::endl; - std::cout << "rvec " << std::endl << rvec << std::endl; - std::cout << "tvec " << std::endl << tvec << std::endl; - std::cout << "rms " << std::endl << rtn << std::endl; + /* std::cout << "After CamMat " << std::endl << cameraMatrix << std::endl; */ + /* std::cout << "distCoeffs " << std::endl << distCoeffs << std::endl; */ + /* std::cout << "rvec " << std::endl << rvec << std::endl; */ + /* std::cout << "tvec " << std::endl << tvec << std::endl; */ + /* std::cout << "rms " << std::endl << rtn << std::endl; */ return rtn; } diff --git a/gocv/gocv_calib3d_test.go b/gocv/gocv_calib3d_test.go index cc527df..3c6e7e9 100644 --- a/gocv/gocv_calib3d_test.go +++ b/gocv/gocv_calib3d_test.go @@ -7,71 +7,99 @@ import ( "github.com/stretchr/testify/assert" ) +const ( + DELTA float64 = 1e-5 +) + func TestGcvInitCameraMatrix2D(t *testing.T) { - objPts := mat64.NewDense(4, 3, []float64{ - 0, 25, 0, - 0, -25, 0, - -47, 25, 0, - -47, -25, 0, + objPts := mat64.NewDense(10, 3, []float64{ + -1.482676, -1.419348, 1.166475, + -0.043819, -0.729445, 1.212821, + 0.960825, 1.147328, 0.485541, + 1.738245, 0.597865, 1.026016, + -0.430206, -1.281281, 0.870726, + -1.627323, -2.203264, -0.381758, + 0.166347, -0.571246, 0.428893, + 0.376266, 0.213996, -0.299131, + -0.226950, 0.942377, -0.899869, + -1.148912, 0.093725, 0.634745, }) - imgPts := mat64.NewDense(4, 2, []float64{ - 1136.4140625, 1041.89208984, - 1845.33190918, 671.39581299, - 302.73373413, 634.79998779, - 1051.46154785, 352.76107788, + imgPts := mat64.NewDense(10, 2, []float64{ + -0.384281, -0.299055, + 0.361833, 0.087737, + 1.370253, 1.753933, + 1.421390, 0.853312, + 0.107177, -0.443076, + 3.773328, 5.437829, + 0.624914, -0.280949, + -0.825577, -0.245594, + 0.631444, -0.340257, + -0.647580, 0.502113, }) camMat := GcvInitCameraMatrix2D(objPts, imgPts) - assert.Equal(t, camMat.Row(nil, 0), []float64{4828.129063751587, 0, 959.5}) - assert.Equal(t, camMat.Row(nil, 1), []float64{0, 4828.129063751587, 539.5}) - assert.Equal(t, camMat.Row(nil, 2), []float64{0, 0, 1}) + assert.InDeltaSlice(t, []float64{1.47219772e+03, 0.00000000e+00, 9.59500000e+02}, + camMat.Row(nil, 0), DELTA) + assert.InDeltaSlice(t, []float64{0.00000000e+00, 1.47219772e+03, 5.39500000e+02}, + camMat.Row(nil, 1), DELTA) + assert.InDeltaSlice(t, []float64{0.00000000e+00, 0.00000000e+00, 1.00000000e+00}, + camMat.Row(nil, 2), DELTA) } func TestGcvCalibrateCamera(t *testing.T) { - objPts := mat64.NewDense(4, 3, []float64{ - 0, 25, 0, - 0, -25, 0, - -47, 25, 0, - -47, -25, 0, + objPts := mat64.NewDense(10, 3, []float64{ + -1.482676, -1.419348, 1.166475, + -0.043819, -0.729445, 1.212821, + 0.960825, 1.147328, 0.485541, + 1.738245, 0.597865, 1.026016, + -0.430206, -1.281281, 0.870726, + -1.627323, -2.203264, -0.381758, + 0.166347, -0.571246, 0.428893, + 0.376266, 0.213996, -0.299131, + -0.226950, 0.942377, -0.899869, + -1.148912, 0.093725, 0.634745, }) - imgPts := mat64.NewDense(4, 2, []float64{ - 1136.4140625, 1041.89208984, - 1845.33190918, 671.39581299, - 302.73373413, 634.79998779, - 1051.46154785, 352.76107788, + imgPts := mat64.NewDense(10, 2, []float64{ + -0.384281, -0.299055, + 0.361833, 0.087737, + 1.370253, 1.753933, + 1.421390, 0.853312, + 0.107177, -0.443076, + 3.773328, 5.437829, + 0.624914, -0.280949, + -0.825577, -0.245594, + 0.631444, -0.340257, + -0.647580, 0.502113, }) camMat := GcvInitCameraMatrix2D(objPts, imgPts) camMat, rvec, tvec := GcvCalibrateCamera(objPts, imgPts, camMat) - assert.Equal(t, camMat.Row(nil, 0), []float64{5.47022369e+03, 0.00000000e+00, 9.59500000e+02}) - assert.Equal(t, camMat.Row(nil, 1), []float64{0.00000000e+00, 5.47022369e+03, 5.39500000e+02}) - assert.Equal(t, camMat.Row(nil, 2), []float64{0.00000000e+00, 0.00000000e+00, 1.00000000e+00}) + // stackedMat := *mat64.NewDense(0, 0, nil) + // stackedMat.Augment(GcvRodrigues(rvec), tvec) - assert.Equal(t, rvec.Col(nil, 0), []float64{-0.99458984, 0.54674764, -2.69721055}) - assert.Equal(t, tvec.Col(nil, 0), []float64{-23.25417757, -12.6155423, -227.64212085}) + // camMat.Mul(camMat, &stackedMat) + + assert.InDeltaSlice(t, []float64{-46.15296606, 0., 959.5}, camMat.Row(nil, 0), DELTA) + assert.InDeltaSlice(t, []float64{0., -46.15296606, 539.5}, camMat.Row(nil, 1), DELTA) + assert.InDeltaSlice(t, []float64{0., 0., 1.}, camMat.Row(nil, 2), DELTA) + + assert.InDeltaSlice(t, []float64{-0.98405029, -0.93443411, -0.26304667}, rvec.Col(nil, 0), DELTA) + assert.InDeltaSlice(t, []float64{0.6804739, 0.47530207, -0.04833094}, tvec.Col(nil, 0), DELTA) } func TestGcvRodrigues(t *testing.T) { rvec := mat64.NewDense(3, 1, []float64{ - -0.99458984, - 0.54674764, - -2.69721055, + -0.98405029, + -0.93443411, + -0.26304667, }) rmat := GcvRodrigues(rvec) - assert.InDelta(t, rmat.At(0, 0), -0.74853587, 1e-6) - assert.InDelta(t, rmat.At(0, 1), 0.07139127, 1e-6) - assert.InDelta(t, rmat.At(0, 2), 0.65923997, 1e-6) - - assert.InDelta(t, rmat.At(1, 0), -0.32247419, 1e-6) - assert.InDelta(t, rmat.At(1, 1), -0.90789575, 1e-6) - assert.InDelta(t, rmat.At(1, 2), -0.26783521, 1e-6) - - assert.InDelta(t, rmat.At(2, 0), 0.57940008, 1e-6) - assert.InDelta(t, rmat.At(2, 1), -0.41307214, 1e-6) - assert.InDelta(t, rmat.At(2, 2), 0.70261437, 1e-6) + assert.InDeltaSlice(t, []float64{0.59922526, 0.57799222, -0.55394411}, rmat.Row(nil, 0), DELTA) + assert.InDeltaSlice(t, []float64{0.20413818, 0.558743, 0.80382452}, rmat.Row(nil, 1), DELTA) + assert.InDeltaSlice(t, []float64{0.77411672, -0.5947531, 0.21682264}, rmat.Row(nil, 2), DELTA) }