mirror of
https://github.com/gonum/gonum.git
synced 2025-10-25 00:00:24 +08:00
travis,unit: fix and check unit code generation
Also fix blas generate check for move.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
go generate gonum.org/v1/gonum/blas/native
|
go generate gonum.org/v1/gonum/blas/gonum
|
||||||
|
go generate gonum.org/v1/gonum/unit
|
||||||
if [ -n "$(git diff)" ]; then
|
if [ -n "$(git diff)" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -197,7 +203,7 @@ func init() {
|
|||||||
log.Fatal("no gopath")
|
log.Fatal("no gopath")
|
||||||
}
|
}
|
||||||
|
|
||||||
unitPkgPath = filepath.Join(gopath, "src", "github.com", "gonum", "unit")
|
unitPkgPath = filepath.Join(gopath, "src", "gonum.org", "v1", "gonum", "unit")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate generates a file for each of the units
|
// Generate generates a file for each of the units
|
||||||
@@ -207,8 +213,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const headerTemplate = `// This file is autogenerated by github.com/gonum/unit/autogen
|
const headerTemplate = `// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT.
|
||||||
// Changes should be made to the autogenerated template rather than this one
|
|
||||||
|
|
||||||
// Copyright ©2014 The gonum Authors. All rights reserved.
|
// Copyright ©2014 The gonum Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
@@ -243,7 +248,7 @@ var prefix = template.Must(template.New("prefix").Parse(constTemplate))
|
|||||||
|
|
||||||
const methodTemplate = `
|
const methodTemplate = `
|
||||||
// Unit converts the {{.Name}} to a *Unit
|
// Unit converts the {{.Name}} to a *Unit
|
||||||
func ({{.Receiver}} {{.Name}}) Unit() *Unit{
|
func ({{.Receiver}} {{.Name}}) Unit() *Unit {
|
||||||
return New(float64({{.Receiver}}), Dimensions{
|
return New(float64({{.Receiver}}), Dimensions{
|
||||||
{{range .Dimensions}} {{.Name}}: {{.Power}},
|
{{range .Dimensions}} {{.Name}}: {{.Power}},
|
||||||
{{end}}
|
{{end}}
|
||||||
@@ -257,7 +262,7 @@ func ({{.Receiver}} {{.Name}}) {{.Name}}() {{.Name}} {
|
|||||||
|
|
||||||
// From converts the unit into the receiver. From returns an
|
// From converts the unit into the receiver. From returns an
|
||||||
// error if there is a mismatch in dimension
|
// error if there is a mismatch in dimension
|
||||||
func ({{.Receiver}} *{{.Name}}) From(u Uniter) error{
|
func ({{.Receiver}} *{{.Name}}) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, {{.Singular}}){
|
if !DimensionsMatch(u, {{.Singular}}){
|
||||||
*{{.Receiver}} = {{.Name}}(math.NaN())
|
*{{.Receiver}} = {{.Name}}(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("Dimension mismatch")
|
||||||
@@ -270,7 +275,7 @@ func ({{.Receiver}} *{{.Name}}) From(u Uniter) error{
|
|||||||
var methods = template.Must(template.New("methods").Parse(methodTemplate))
|
var methods = template.Must(template.New("methods").Parse(methodTemplate))
|
||||||
|
|
||||||
const formatTemplate = `
|
const formatTemplate = `
|
||||||
func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune){
|
func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune) {
|
||||||
switch c {
|
switch c {
|
||||||
case 'v':
|
case 'v':
|
||||||
if fs.Flag('#') {
|
if fs.Flag('#') {
|
||||||
@@ -280,19 +285,21 @@ func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune){
|
|||||||
fallthrough
|
fallthrough
|
||||||
case 'e', 'E', 'f', 'F', 'g', 'G':
|
case 'e', 'E', 'f', 'F', 'g', 'G':
|
||||||
p, pOk := fs.Precision()
|
p, pOk := fs.Precision()
|
||||||
if !pOk {
|
|
||||||
p = -1
|
|
||||||
}
|
|
||||||
w, wOk := fs.Width()
|
w, wOk := fs.Width()
|
||||||
if !wOk {
|
switch {
|
||||||
w = -1
|
case pOk && wOk:
|
||||||
|
fmt.Fprintf(fs, "%*.*"+string(c), w, p, float64({{.Receiver}}))
|
||||||
|
case pOk:
|
||||||
|
fmt.Fprintf(fs, "%.*"+string(c), p, float64({{.Receiver}}))
|
||||||
|
case wOk:
|
||||||
|
fmt.Fprintf(fs, "%*"+string(c), w, float64({{.Receiver}}))
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(fs, "%"+string(c), float64({{.Receiver}}))
|
||||||
}
|
}
|
||||||
fmt.Fprintf(fs, "%*.*"+string(c), w, p, float64({{.Receiver}}))
|
|
||||||
fmt.Fprint(fs, " {{.PrintString}}")
|
fmt.Fprint(fs, " {{.PrintString}}")
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(fs, "%%!%c(%T=%g {{.PrintString}})", c, {{.Receiver}}, float64({{.Receiver}}))
|
fmt.Fprintf(fs, "%%!%c(%T=%g {{.PrintString}})", c, {{.Receiver}}, float64({{.Receiver}}))
|
||||||
return
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:generate go run autogen.go
|
||||||
|
|
||||||
// Package unit provides a set of types and constants that facilitate
|
// Package unit provides a set of types and constants that facilitate
|
||||||
// the use of the International System of Units (SI).
|
// the use of the International System of Units (SI).
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// This file is autogenerated by github.com/gonum/unit/autogen
|
// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT.
|
||||||
// Changes should be made to the autogenerated template rather than this one
|
|
||||||
|
|
||||||
// Copyright ©2014 The gonum Authors. All rights reserved.
|
// Copyright ©2014 The gonum Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
@@ -87,6 +86,5 @@ func (l Length) Format(fs fmt.State, c rune) {
|
|||||||
fmt.Fprint(fs, " m")
|
fmt.Fprint(fs, " m")
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(fs, "%%!%c(%T=%g m)", c, l, float64(l))
|
fmt.Fprintf(fs, "%%!%c(%T=%g m)", c, l, float64(l))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// This file is autogenerated by github.com/gonum/unit/autogen
|
// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT.
|
||||||
// Changes should be made to the autogenerated template rather than this one
|
|
||||||
|
|
||||||
// Copyright ©2014 The gonum Authors. All rights reserved.
|
// Copyright ©2014 The gonum Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
@@ -87,6 +86,5 @@ func (m Mass) Format(fs fmt.State, c rune) {
|
|||||||
fmt.Fprint(fs, " kg")
|
fmt.Fprint(fs, " kg")
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(fs, "%%!%c(%T=%g kg)", c, m, float64(m))
|
fmt.Fprintf(fs, "%%!%c(%T=%g kg)", c, m, float64(m))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// This file is autogenerated by github.com/gonum/unit/autogen
|
// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT.
|
||||||
// Changes should be made to the autogenerated template rather than this one
|
|
||||||
|
|
||||||
// Copyright ©2014 The gonum Authors. All rights reserved.
|
// Copyright ©2014 The gonum Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
@@ -90,6 +89,5 @@ func (t Time) Format(fs fmt.State, c rune) {
|
|||||||
fmt.Fprint(fs, " s")
|
fmt.Fprint(fs, " s")
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(fs, "%%!%c(%T=%g s)", c, t, float64(t))
|
fmt.Fprintf(fs, "%%!%c(%T=%g s)", c, t, float64(t))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user