-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathonetoone.go
52 lines (43 loc) · 1.16 KB
/
onetoone.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2019, The Emergent 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 paths
import "cogentcore.org/lab/tensor"
// OneToOne implements point-to-point one-to-one pattern of connectivity between two layers
type OneToOne struct {
// number of recv connections to make (0 for entire size of recv layer)
NCons int
// starting unit index for sending connections
SendStart int
// starting unit index for recv connections
RecvStart int
}
func NewOneToOne() *OneToOne {
return &OneToOne{}
}
func (ot *OneToOne) Name() string {
return "OneToOne"
}
func (ot *OneToOne) Connect(send, recv *tensor.Shape, same bool) (sendn, recvn *tensor.Int32, cons *tensor.Bool) {
sendn, recvn, cons = NewTensors(send, recv)
nsend := send.Len()
nrecv := recv.Len()
rnv := recvn.Values
snv := sendn.Values
ncon := nrecv
if ot.NCons > 0 {
ncon = min(ot.NCons, nrecv)
}
for i := 0; i < ncon; i++ {
ri := ot.RecvStart + i
si := ot.SendStart + i
if ri >= nrecv || si >= nsend {
break
}
off := ri*nsend + si
cons.Values.Set(true, off)
rnv[ri] = 1
snv[si] = 1
}
return
}