Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.
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: 21 additions & 5 deletions Sources/DeepLearning/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ public extension Tensor where Scalar: BinaryFloatingPoint {
}

//===------------------------------------------------------------------------------------------===//
// Convolution and pooling
// Convolution and Pooling
//===------------------------------------------------------------------------------------------===//

/// A padding scheme. Used by padding, convolution, and pooling ops.
// @_frozen // SR-9739
public enum Padding {
/// The "explicit" padding scheme, which is defined by an array indicating the explicit padding
/// sizes at the start and end of each dimension.
case explicit([Int32])
/// The "valid" padding scheme.
case valid
/// The "same" padding scheme.
Expand All @@ -112,12 +115,22 @@ public enum Padding {

public extension Padding {
@inlinable
var raw: Raw.Padding {
var raw: Raw.Padding2 {
switch self {
case .explicit: return .explicit
case .same: return .same
case .valid: return .valid
}
}

@inlinable
internal var explicitPaddings: [Int32] {
switch self {
case .explicit(let paddings): return paddings
case .same: return []
case .valid: return []
}
}
}

public extension Tensor where Scalar: TensorFlowFloatingPoint {
Expand All @@ -135,7 +148,8 @@ public extension Tensor where Scalar: TensorFlowFloatingPoint {
filter: filter,
outBackprop: self,
strides: [strides.0, strides.1, strides.2, strides.3],
padding: padding.raw)
padding: padding.raw,
explicitPaddings: padding.explicitPaddings)
}

/// TensorFlow builtin conv2d gradient helper for the filter.
Expand All @@ -152,7 +166,8 @@ public extension Tensor where Scalar: TensorFlowFloatingPoint {
filterSizes: filterSizes,
outBackprop: self,
strides: [strides.0, strides.1, strides.2, strides.3],
padding: padding.raw)
padding: padding.raw,
explicitPaddings: padding.explicitPaddings)
}

@inlinable
Expand Down Expand Up @@ -282,7 +297,8 @@ public extension Tensor where Scalar: FloatingPoint {
self,
filter: filter,
strides: [strides.0, strides.1, strides.2, strides.3],
padding: padding.raw)
padding: padding.raw,
explicitPaddings: padding.explicitPaddings)
}

/// Computes a 2-D max pooling, with the specified kernel sizes, strides, and
Expand Down