Skip to content

Commit

Permalink
fix integral image
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenebokhan committed Mar 24, 2024
1 parent 0847e1d commit d49d18c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void integralImage(
const auto currentValue = source.read(currentPosition);
const auto resultValue = previousValue + currentValue;
destination.write(resultValue, currentPosition);
previousValue = currentValue;
previousValue = resultValue;
}
} else {
if (!deviceSupportsNonuniformThreadgroups) {
Expand All @@ -42,7 +42,7 @@ void integralImage(
const auto currentValue = source.read(currentPosition);
const auto resultValue = previousValue + currentValue;
destination.write(resultValue, currentPosition);
previousValue = currentValue;
previousValue = resultValue;
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions Tests/MetalComputeToolsTests/IntegralImageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class IntegralImageTests: XCTestCase {
usage: [.shaderRead, .shaderRead]
)

let sourceValues = [Float32](repeating: .random(0, 0.3), count: 16)
let sourceValues = [Float32](repeating: 0.1, count: 16)
sourceValues.withUnsafeBufferPointer {
if let baseAddress = $0.baseAddress {
self.source.replace(
Expand All @@ -53,24 +53,26 @@ final class IntegralImageTests: XCTestCase {
for column in 0 ..< 4 {
let position = row * 4 + column
let currentValue = sourceValues[position]
self.expectedResult[position] = currentValue + previousValue
previousValue = currentValue
let resulValue = currentValue + previousValue
self.expectedResult[position] = resulValue
previousValue = resulValue
}
}
for column in 0 ..< 4 {
var previousValue: Float32 = 0
for row in 0 ..< 4 {
let position = row * 4 + column
let currentValue = self.expectedResult[position]
self.expectedResult[position] = currentValue + previousValue
previousValue = currentValue
let resulValue = currentValue + previousValue
self.expectedResult[position] = resulValue
previousValue = resulValue
}
}
}

// MARK: - Testing

func testEuclideanDistance() throws {
func testIntegralImage() throws {
try self.context.scheduleAndWait { commandBuffer in
self.integralImageFloat(
source: self.source,
Expand Down

0 comments on commit d49d18c

Please sign in to comment.