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

Commit 60f63e1

Browse files
authored
Conform Tensor to PointwiseMultiplicative. (#297)
Friend PR: swiftlang/swift#25772
1 parent 76a69b7 commit 60f63e1

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Sources/TensorFlow/Core/Tensor.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,9 @@ extension Tensor: Codable where Scalar: Codable {
500500
//===------------------------------------------------------------------------------------------===//
501501

502502
extension Tensor: AdditiveArithmetic where Scalar: Numeric {
503-
/// A scalar zero tensor.
503+
/// The scalar zero tensor.
504504
@inlinable
505-
public static var zero: Tensor {
506-
return Tensor(0)
507-
}
505+
public static var zero: Tensor { Tensor(0) }
508506

509507
/// Adds two tensors and produces their sum.
510508
/// - Note: `+` supports broadcasting.
@@ -553,6 +551,26 @@ internal extension Tensor where Scalar: TensorFlowFloatingPoint {
553551
}
554552
}
555553

554+
//===------------------------------------------------------------------------------------------===//
555+
// Multiplicative Group
556+
//===------------------------------------------------------------------------------------------===//
557+
558+
extension Tensor: PointwiseMultiplicative where Scalar: Numeric {
559+
/// The scalar one tensor.
560+
@inlinable
561+
public static var one: Tensor { Tensor(1) }
562+
563+
/// Returns the pointwise reciprocal of `self`.
564+
@inlinable
565+
public var reciprocal: Tensor { 1 / self }
566+
567+
/// Multiplies two tensors element-wise and produces their product.
568+
/// - Note: `.*` supports broadcasting.
569+
public static func .* (lhs: Tensor, rhs: Tensor) -> Tensor {
570+
return lhs * rhs
571+
}
572+
}
573+
556574
//===------------------------------------------------------------------------------------------===//
557575
// Differentiable
558576
//===------------------------------------------------------------------------------------------===//

0 commit comments

Comments
 (0)