-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e98fc1b
commit 67a7796
Showing
5 changed files
with
108 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package transpose | ||
|
||
import ( | ||
"github.com/advancedclimatesystems/gonnx/onnx" | ||
"github.com/advancedclimatesystems/gonnx/ops" | ||
"gorgonia.org/tensor" | ||
) | ||
|
||
var transposeTypeConstraint = [][]tensor.Dtype{ops.AllTypes} | ||
|
||
// Transpose represents the ONNX transpose operator. | ||
type Transpose struct { | ||
ops.BaseOperator | ||
|
||
perm []int | ||
} | ||
|
||
// newTranspose creates a new transpose operator. | ||
func newTranspose(version int, typeConstraint [][]tensor.Dtype) *Transpose { | ||
return &Transpose{ | ||
BaseOperator: ops.NewBaseOperator( | ||
version, | ||
1, | ||
1, | ||
typeConstraint, | ||
"transpose", | ||
), | ||
} | ||
} | ||
|
||
// Init initializes the transpose operator. | ||
func (t *Transpose) Init(n *onnx.NodeProto) error { | ||
attributes := n.GetAttribute() | ||
|
||
if len(attributes) == 1 { | ||
attr := attributes[0] | ||
|
||
if attr.GetName() != "perm" { | ||
return ops.ErrInvalidAttribute(attr.GetName(), t) | ||
} | ||
|
||
attrPerm := attr.GetInts() | ||
for _, val := range attrPerm { | ||
t.perm = append(t.perm, int(val)) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Apply applies the transpose operator. | ||
func (t *Transpose) Apply(inputs []tensor.Tensor) ([]tensor.Tensor, error) { | ||
out, err := tensor.Transpose(inputs[0], t.perm...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return []tensor.Tensor{out}, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters