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

Conform Tensor to PointwiseMultiplicative. #297

Merged
merged 1 commit into from
Jun 27, 2019
Merged
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
26 changes: 22 additions & 4 deletions Sources/TensorFlow/Core/Tensor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,9 @@ extension Tensor: Codable where Scalar: Codable {
//===------------------------------------------------------------------------------------------===//

extension Tensor: AdditiveArithmetic where Scalar: Numeric {
/// A scalar zero tensor.
/// The scalar zero tensor.
@inlinable
public static var zero: Tensor {
return Tensor(0)
}
public static var zero: Tensor { Tensor(0) }

/// Adds two tensors and produces their sum.
/// - Note: `+` supports broadcasting.
Expand Down Expand Up @@ -553,6 +551,26 @@ internal extension Tensor where Scalar: TensorFlowFloatingPoint {
}
}

//===------------------------------------------------------------------------------------------===//
// Multiplicative Group
//===------------------------------------------------------------------------------------------===//

extension Tensor: PointwiseMultiplicative where Scalar: Numeric {
/// The scalar one tensor.
@inlinable
public static var one: Tensor { Tensor(1) }

/// Returns the pointwise reciprocal of `self`.
@inlinable
public var reciprocal: Tensor { 1 / self }

/// Multiplies two tensors element-wise and produces their product.
/// - Note: `.*` supports broadcasting.
public static func .* (lhs: Tensor, rhs: Tensor) -> Tensor {
return lhs * rhs
}
}

//===------------------------------------------------------------------------------------------===//
// Differentiable
//===------------------------------------------------------------------------------------------===//
Expand Down