Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Add ConstTensor attribute to LazyTensorOperation. #265

Merged
merged 3 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Sources/TensorFlow/Core/LazyTensorOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ class LazyTensorOperation: TensorOperation {
func updateAttribute(_ name: String, _ value: [String]) {
attributes[name] = Attribute.stringArray(value)
}
func updateAttribute(_ name: String, _ value: _TensorFunctionPointer) {
attributes[name] = Attribute.tensorFunctionPointer(value)
}
}

extension LazyTensorOperation: TFTensorOperation {
Expand Down Expand Up @@ -336,6 +333,13 @@ extension LazyTensorOperation: TFTensorOperation {
func updateAttribute(_ name: String, _ value: [TensorShape?]) {
attributes[name] = Attribute.optionalTensorShapeArray(value)
}
func updateAttribute(_ name: String, _ value: _TensorFunctionPointer) {
attributes[name] = Attribute.tensorFunctionPointer(value)
}
func updateAttribute(_ name: String, _ value: TFETensorHandle) {
attributes[name] = Attribute.constTensor(value)
}

func updateAttribute<In: TensorGroup, Out: TensorGroup>(
_ name: String, _ value: (In) -> Out) {
// TODO:
Expand Down
11 changes: 11 additions & 0 deletions Tests/TensorFlowTests/LazyTensorOperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ final class LazyTensorOperationTests: XCTestCase {
XCTAssertEqual(op0.description, "%0 = Nop[shapes: [nil, Optional([4, 5])]]()")
}

func testConstTensorAttribute() {
let op0 = LazyTensorOperation(
_id: "0", name: "Nop", outputCount: 1)
let a = Tensor<Float>(5.5)
let b = Tensor<Float>([1,2])
op0.updateAttribute("a", a.handle.handle._tfeTensorHandle)
op0.updateAttribute("b", b.handle.handle._tfeTensorHandle)
XCTAssertEqual(op0.description, "%0 = Nop[a: 5.5, b: [1.0, 2.0]]()")
}

func testArrayAttributes() {
let op0 = LazyTensorOperation(
_id: "0", name: "Nop", outputCount: 1)
Expand Down Expand Up @@ -231,6 +241,7 @@ final class LazyTensorOperationTests: XCTestCase {
("testOptionalTensorShapeAttribute", testOptionalTensorShapeAttribute),
("testTensorShapeArrayAttribute",
testOptionalTensorShapeArrayAttribute),
("testConstTensorAttribute", testConstTensorAttribute),
("testArrayAttributes", testArrayAttributes),
("testMultipleAttributes", testMultipleAttributes),
("testFunctionAttribute", testFunctionAttribute),
Expand Down