mat: rename Cloner=>ClonerFrom and Clone=>CloneFrom

This commit is contained in:
Dan Kortschak
2019-06-05 07:48:01 +09:30
parent 14af50e936
commit c5f01565d8
15 changed files with 34 additions and 34 deletions

View File

@@ -15,7 +15,7 @@ var (
_ Matrix = dense _ Matrix = dense
_ Mutable = dense _ Mutable = dense
_ Cloner = dense _ ClonerFrom = dense
_ RowViewer = dense _ RowViewer = dense
_ ColViewer = dense _ ColViewer = dense
_ RawRowViewer = dense _ RawRowViewer = dense
@@ -186,7 +186,7 @@ func (m *Dense) asTriDense(n int, diag blas.Diag, uplo blas.Uplo) *TriDense {
// DenseCopyOf returns a newly allocated copy of the elements of a. // DenseCopyOf returns a newly allocated copy of the elements of a.
func DenseCopyOf(a Matrix) *Dense { func DenseCopyOf(a Matrix) *Dense {
d := &Dense{} d := &Dense{}
d.Clone(a) d.CloneFrom(a)
return d return d
} }
@@ -375,12 +375,12 @@ func (m *Dense) Grow(r, c int) Matrix {
return &t return &t
} }
// Clone makes a copy of a into the receiver, overwriting the previous value of // CloneFrom makes a copy of a into the receiver, overwriting the previous value of
// the receiver. The clone operation does not make any restriction on shape and // the receiver. The clone from operation does not make any restriction on shape and
// will not cause shadowing. // will not cause shadowing.
// //
// See the Cloner interface for more information. // See the ClonerFrom interface for more information.
func (m *Dense) Clone(a Matrix) { func (m *Dense) CloneFrom(a Matrix) {
r, c := a.Dims() r, c := a.Dims()
mat := blas64.General{ mat := blas64.General{
Rows: r, Rows: r,

View File

@@ -229,7 +229,7 @@ func TestDenseSetRowColumn(t *testing.T) {
for ri, row := range as { for ri, row := range as {
a := NewDense(flatten(as)) a := NewDense(flatten(as))
m := &Dense{} m := &Dense{}
m.Clone(a) m.CloneFrom(a)
a.SetRow(ri, make([]float64, a.mat.Cols)) a.SetRow(ri, make([]float64, a.mat.Cols))
m.Sub(m, a) m.Sub(m, a)
nt := Norm(m, 2) nt := Norm(m, 2)
@@ -242,7 +242,7 @@ func TestDenseSetRowColumn(t *testing.T) {
for ci := range as[0] { for ci := range as[0] {
a := NewDense(flatten(as)) a := NewDense(flatten(as))
m := &Dense{} m := &Dense{}
m.Clone(a) m.CloneFrom(a)
a.SetCol(ci, make([]float64, a.mat.Rows)) a.SetCol(ci, make([]float64, a.mat.Rows))
col := make([]float64, a.mat.Rows) col := make([]float64, a.mat.Rows)
for j := range col { for j := range col {
@@ -1137,7 +1137,7 @@ func TestDensePowN(t *testing.T) {
} }
func (m *Dense) iterativePow(a Matrix, n int) { func (m *Dense) iterativePow(a Matrix, n int) {
m.Clone(a) m.CloneFrom(a)
for i := 1; i < n; i++ { for i := 1; i < n; i++ {
m.Mul(m, a) m.Mul(m, a)
} }
@@ -1174,12 +1174,12 @@ func TestDenseCloneT(t *testing.T) {
var got, gotT Dense var got, gotT Dense
for j := 0; j < 2; j++ { for j := 0; j < 2; j++ {
got.Clone(a.T()) got.CloneFrom(a.T())
if !Equal(&got, want) { if !Equal(&got, want) {
t.Errorf("expected transpose for test %d iteration %d: %v transpose = %v", t.Errorf("expected transpose for test %d iteration %d: %v transpose = %v",
i, j, test.a, test.want) i, j, test.a, test.want)
} }
gotT.Clone(got.T()) gotT.CloneFrom(got.T())
if !Equal(&gotT, a) { if !Equal(&gotT, a) {
t.Errorf("expected transpose for test %d iteration %d: %v transpose = %v", t.Errorf("expected transpose for test %d iteration %d: %v transpose = %v",
i, j, test.a, test.want) i, j, test.a, test.want)
@@ -1438,7 +1438,7 @@ func TestDenseClone(t *testing.T) {
} { } {
a := NewDense(flatten(test.a)) a := NewDense(flatten(test.a))
b := *a b := *a
a.Clone(a) a.CloneFrom(a)
a.Set(test.i, test.j, test.v) a.Set(test.i, test.j, test.v)
if Equal(&b, a) { if Equal(&b, a) {
@@ -1925,7 +1925,7 @@ func TestDenseInverse(t *testing.T) {
} }
var tmp Dense var tmp Dense
tmp.Clone(test.a) tmp.CloneFrom(test.a)
aU, transposed := untranspose(test.a) aU, transposed := untranspose(test.a)
if transposed { if transposed {
switch aU := aU.(type) { switch aU := aU.(type) {

View File

@@ -176,7 +176,7 @@ func (e *Eigen) Factorize(a Matrix, kind EigenKind) (ok bool) {
panic(ErrShape) panic(ErrShape)
} }
var sd Dense var sd Dense
sd.Clone(a) sd.CloneFrom(a)
left := kind&EigenLeft != 0 left := kind&EigenLeft != 0
right := kind&EigenRight != 0 right := kind&EigenRight != 0

View File

@@ -136,7 +136,7 @@ func (gsvd *HOGSVD) Factorize(m ...Matrix) (ok bool) {
if gsvd.err != nil { if gsvd.err != nil {
return false return false
} }
b[i].Clone(biT.T()) b[i].CloneFrom(biT.T())
} }
gsvd.n = len(m) gsvd.n = len(m)

View File

@@ -547,7 +547,7 @@ func makeCopyOf(a Matrix) Matrix {
return retranspose(a, makeCopyOf(t.Untranspose())) return retranspose(a, makeCopyOf(t.Untranspose()))
case *Dense, *basicMatrix: case *Dense, *basicMatrix:
var m Dense var m Dense
m.Clone(a) m.CloneFrom(a)
return returnAs(&m, t) return returnAs(&m, t)
case *SymDense, *basicSymmetric: case *SymDense, *basicSymmetric:
n := t.(Symmetric).Symmetric() n := t.(Symmetric).Symmetric()
@@ -925,7 +925,7 @@ func testOneInputFunc(t *testing.T,
var want interface{} var want interface{}
if dimsOK { if dimsOK {
var aDense Dense var aDense Dense
aDense.Clone(a) aDense.CloneFrom(a)
want = denseComparison(&aDense) want = denseComparison(&aDense)
} }
aCopy := makeCopyOf(a) aCopy := makeCopyOf(a)
@@ -1095,8 +1095,8 @@ func testTwoInputFunc(t *testing.T,
var want interface{} var want interface{}
if dimsOK { if dimsOK {
var aDense, bDense Dense var aDense, bDense Dense
aDense.Clone(a) aDense.CloneFrom(a)
bDense.Clone(b) bDense.CloneFrom(b)
want = denseComparison(&aDense, &bDense) want = denseComparison(&aDense, &bDense)
} }
aCopy := makeCopyOf(a) aCopy := makeCopyOf(a)
@@ -1175,7 +1175,7 @@ func testOneInput(t *testing.T,
var want Dense var want Dense
if dimsOK { if dimsOK {
var aDense Dense var aDense Dense
aDense.Clone(a) aDense.CloneFrom(a)
denseComparison(&want, &aDense) denseComparison(&want, &aDense)
} }
aCopy := makeCopyOf(a) aCopy := makeCopyOf(a)
@@ -1327,8 +1327,8 @@ func testTwoInput(t *testing.T,
var want Dense var want Dense
if dimsOK { if dimsOK {
var aDense, bDense Dense var aDense, bDense Dense
aDense.Clone(a) aDense.CloneFrom(a)
bDense.Clone(b) bDense.CloneFrom(b)
denseComparison(&want, &aDense, &bDense) denseComparison(&want, &aDense, &bDense)
} }
aCopy := makeCopyOf(a) aCopy := makeCopyOf(a)

View File

@@ -59,7 +59,7 @@ func (lq *LQ) factorize(a Matrix, norm lapack.MatrixNorm) {
if lq.lq == nil { if lq.lq == nil {
lq.lq = &Dense{} lq.lq = &Dense{}
} }
lq.lq.Clone(a) lq.lq.CloneFrom(a)
work := []float64{0} work := []float64{0}
lq.tau = make([]float64, k) lq.tau = make([]float64, k)
lapack64.Gelqf(lq.lq.mat, lq.tau, work, -1) lapack64.Gelqf(lq.lq.mat, lq.tau, work, -1)

View File

@@ -26,7 +26,7 @@ func TestLQ(t *testing.T) {
} }
} }
var want Dense var want Dense
want.Clone(a) want.CloneFrom(a)
var lq LQ var lq LQ
lq.Factorize(a) lq.Factorize(a)

View File

@@ -19,7 +19,7 @@ func TestLUD(t *testing.T) {
} }
} }
var want Dense var want Dense
want.Clone(a) want.CloneFrom(a)
var lu LU var lu LU
lu.Factorize(a) lu.Factorize(a)

View File

@@ -129,11 +129,11 @@ type RawColViewer interface {
RawColView(j int) []float64 RawColView(j int) []float64
} }
// A Cloner can make a copy of a into the receiver, overwriting the previous value of the // A ClonerFrom 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 and will not cause // receiver. The clone operation does not make any restriction on shape and will not cause
// shadowing. // shadowing.
type Cloner interface { type ClonerFrom interface {
Clone(a Matrix) CloneFrom(a Matrix)
} }
// A Reseter can reset the matrix so that it can be reused as the receiver of a dimensionally // A Reseter can reset the matrix so that it can be reused as the receiver of a dimensionally

View File

@@ -118,7 +118,7 @@ func TestProduct(t *testing.T) {
var a *Dense var a *Dense
for i, b := range factors { for i, b := range factors {
if i == 0 { if i == 0 {
want.Clone(b) want.CloneFrom(b)
continue continue
} }
a, want = want, &Dense{} a, want = want, &Dense{}

View File

@@ -59,7 +59,7 @@ func (qr *QR) factorize(a Matrix, norm lapack.MatrixNorm) {
if qr.qr == nil { if qr.qr == nil {
qr.qr = &Dense{} qr.qr = &Dense{}
} }
qr.qr.Clone(a) qr.qr.CloneFrom(a)
work := []float64{0} work := []float64{0}
qr.tau = make([]float64, k) qr.tau = make([]float64, k)
lapack64.Geqrf(qr.qr.mat, qr.tau, work, -1) lapack64.Geqrf(qr.qr.mat, qr.tau, work, -1)

View File

@@ -29,7 +29,7 @@ func TestQR(t *testing.T) {
} }
} }
var want Dense var want Dense
want.Clone(a) want.CloneFrom(a)
var qr QR var qr QR
qr.Factorize(a) qr.Factorize(a)

View File

@@ -217,7 +217,7 @@ func testSimplex(t *testing.T, initialBasic []int, c []float64, a mat.Matrix, b
// subject to -A^T * nu <= c // subject to -A^T * nu <= c
negAT := &mat.Dense{} negAT := &mat.Dense{}
negAT.Clone(a.T()) negAT.CloneFrom(a.T())
negAT.Scale(-1, negAT) negAT.Scale(-1, negAT)
cNew, aNew, bNew := Convert(b, negAT, c, nil, nil) cNew, aNew, bNew := Convert(b, negAT, c, nil, nil)

View File

@@ -94,7 +94,7 @@ func ExampleCC() {
// Canonical Correlation Matrix, or the correlations between the sphered // Canonical Correlation Matrix, or the correlations between the sphered
// data. // data.
var corSph mat.Dense var corSph mat.Dense
corSph.Clone(pVecs) corSph.CloneFrom(pVecs)
col := make([]float64, xd) col := make([]float64, xd)
for j := 0; j < yd; j++ { for j := 0; j < yd; j++ {
mat.Col(col, j, &corSph) mat.Col(col, j, &corSph)

View File

@@ -34,7 +34,7 @@ func CovarianceMatrix(dst *mat.SymDense, x mat.Matrix, weights []float64) {
} }
var xt mat.Dense var xt mat.Dense
xt.Clone(x.T()) xt.CloneFrom(x.T())
// Subtract the mean of each of the columns. // Subtract the mean of each of the columns.
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
v := xt.RawRowView(i) v := xt.RawRowView(i)