profile
viewpoint
marcrasi Google I work on Swift for TensorFlow.

apple/swift 53917

The Swift Programming Language

google/swift 845

The Swift Programming Language

apple/swift-lldb 645

This is the version of LLDB that supports the Swift programming language & REPL.

fastai/fastai_dev 594

fast.ai early development experiments

KarthikRIyer/swiftplot 296

Swift library for Data Visualization :bar_chart:

apple/llvm-project 273

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. This fork is used to manage Apple’s stable releases of Clang as well as support the Swift project.

push eventborglab/SwiftFusion

Marc Rasi

commit sha 22071268e1b0676cbade34242294b2db854afb34

add VJP to AppearanceTrackingFactor

view details

push time in 5 hours

delete branch borglab/SwiftFusion

delete branch : fix-extensions

delete time in a day

push eventborglab/SwiftFusion

marcrasi

commit sha 4ae925cd2759e4fccc7578c076cb4f71f782b003

remove algorithms that are in penguin now (#195) saeta/penguin#120 moved these into Penguin. For some reason, defining them in both places causes a compiler crash. This PR fixes #194.

view details

push time in a day

issue closedborglab/SwiftFusion

Colab (Hosted Runtime) failed to compile SwiftFusion

However, my local runtime using latest release (RELEASE-0.11-rc2) works.

SwiftFusion tag is d9153d9ef93d25010a8089bedd70fa766424359f.

swift-frontend: /swift-base/swift/lib/Sema/CSSimplify.cpp:9630: void swift::constraints::ConstraintSystem::recordPotentialHole(swift::TypeVariableType *): Assertion `typeVar' failed.
Stack dump:
0.	Program arguments: /swift/toolchain/usr/bin/swift-frontend -frontend -c /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/DataTypes.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/Dictionary+Differentiable.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/FixedSizeMatrix.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/LieGroup.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/Manifold.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/MathUtil.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/TensorVector.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/TrappingDouble.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/Tuple+Vector.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/TypeKeyedArrayBuffers.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/Vector.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Core/VectorN.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Datasets/DatasetCache.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Datasets/G2OReader.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Geometry/Pose2.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Geometry/Pose3.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Geometry/Rot2.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Geometry/Rot3.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Image/ArrayImage.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Image/OrientedBoundingBox.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Image/Patch.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/AllVectors.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/AnyArrayBuffer+Differentiable.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/AnyArrayBuffer+Vector.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/AppearanceTrackingFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/ArrayBuffer+Differentiable.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/ArrayBuffer+Tensor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/ArrayBuffer+Vector.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/ArrayStorage+Tensor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/BearingRangeFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/BetweenFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/BetweenFactorAlternative.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/ChordalInitialization.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/DiscreteTransitionFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/Factor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/FactorBoilerplate.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/FactorGraph.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/FactorsStorage.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/FlattenedScalars.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/GaussianFactorGraph.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/IdentityLinearizationFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/JacobianFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PPCA.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PPCATrackingFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PenguinExtensions.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PriorFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/ScalarJacobianFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/SwitchingBetweenFactor.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/VariableAssignments.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/MCMC/RandomWalkMetropolis.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/MCMC/TransitionKernel.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/MCMC/sample.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Optimizers/CGLS.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Optimizers/GradientDescent.swift /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Optimizers/LM.swift -supplementary-output-file-map /tmp/supplementaryOutputs-293059 -target x86_64-unknown-linux-gnu -disable-objc-interop -I /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release -I /content/swift-install2/package/.build/checkouts/penguin/Sources/CPenguinParallel/include -g -module-cache-path /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/ModuleCache -swift-version 5 -O -D SWIFT_PACKAGE -Xcc -fmodule-map-file=/content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/CPenguinParallel.build/module.modulemap -parse-as-library -module-name SwiftFusion -num-threads 2 -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/DataTypes.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/Dictionary+Differentiable.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/FixedSizeMatrix.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/LieGroup.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/Manifold.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/MathUtil.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/TensorVector.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/TrappingDouble.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/Tuple+Vector.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/TypeKeyedArrayBuffers.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/Vector.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Core/VectorN.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Datasets/DatasetCache.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Datasets/G2OReader.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Geometry/Pose2.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Geometry/Pose3.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Geometry/Rot2.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Geometry/Rot3.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Image/ArrayImage.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Image/OrientedBoundingBox.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Image/Patch.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/AllVectors.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/AnyArrayBuffer+Differentiable.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/AnyArrayBuffer+Vector.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/AppearanceTrackingFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/ArrayBuffer+Differentiable.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/ArrayBuffer+Tensor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/ArrayBuffer+Vector.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/ArrayStorage+Tensor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/BearingRangeFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/BetweenFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/BetweenFactorAlternative.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/ChordalInitialization.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/DiscreteTransitionFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/Factor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/FactorBoilerplate.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/FactorGraph.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/FactorsStorage.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/FlattenedScalars.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/GaussianFactorGraph.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/IdentityLinearizationFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/JacobianFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/PPCA.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/PPCATrackingFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/PenguinExtensions.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/PriorFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/ScalarJacobianFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/SwitchingBetweenFactor.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Inference/VariableAssignments.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/MCMC/RandomWalkMetropolis.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/MCMC/TransitionKernel.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/MCMC/sample.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Optimizers/CGLS.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Optimizers/GradientDescent.swift.o -o /content/swift-install2/package/.build/x86_64-unknown-linux-gnu/release/SwiftFusion.build/Optimizers/LM.swift.o 
1.	Swift version 5.3-dev (LLVM db8896f3f345af2, Swift 61684f62a6132c0)
2.	While evaluating request TypeCheckSourceFileRequest(source_file "/content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PenguinExtensions.swift")
3.	While evaluating request TypeCheckFunctionBodyRequest(SwiftFusion.(file).MutableCollection extension.assign@/content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PenguinExtensions.swift:790:17)
4.	While type-checking statement at [/content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PenguinExtensions.swift:792:3 - line:798:3] RangeText="{
    var stream = sourceElements.makeIterator()
    let (count, unwritten) = writePrefix(from: &stream)
    precondition(unwritten == endIndex, "source too short")
    precondition(stream.next() == nil, "source too long")
    return count
  "
5.	While type-checking declaration 0xa2d0bc8 (at /content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PenguinExtensions.swift:794:5)
6.	While evaluating request PatternBindingEntryRequest((unknown decl), 0)
7.	While type-checking expression at [/content/swift-install2/package/.build/checkouts/SwiftFusion/Sources/SwiftFusion/Inference/PenguinExtensions.swift:794:30 - line:794:55] RangeText="writePrefix(from: &stream"
/swift/toolchain/usr/bin/swift-frontend[0x5214dc4]
/swift/toolchain/usr/bin/swift-frontend[0x52129be]
/swift/toolchain/usr/bin/swift-frontend[0x521509c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x128a0)[0x7f350ba038a0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f350a4acf47]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f350a4ae8b1]
/lib/x86_64-linux-gnu/libc.so.6(+0x3042a)[0x7f350a49e42a]
/lib/x86_64-linux-gnu/libc.so.6(+0x304a2)[0x7f350a49e4a2]
/swift/toolchain/usr/bin/swift-frontend[0x123fb4f]
/swift/toolchain/usr/bin/swift-frontend[0x1247e40]
/swift/toolchain/usr/bin/swift-frontend[0x1239656]
/swift/toolchain/usr/bin/swift-frontend[0x125c6fd]
/swift/toolchain/usr/bin/swift-frontend[0x1267de7]
/swift/toolchain/usr/bin/swift-frontend[0x1270ccf]
/swift/toolchain/usr/bin/swift-frontend[0x12835cd]
/swift/toolchain/usr/bin/swift-frontend[0x1282d4b]
/swift/toolchain/usr/bin/swift-frontend[0x1282a68]
/swift/toolchain/usr/bin/swift-frontend[0x1269ed5]
/swift/toolchain/usr/bin/swift-frontend[0x12ea379]
/swift/toolchain/usr/bin/swift-frontend[0x126b73b]
/swift/toolchain/usr/bin/swift-frontend[0x1353b9b]
/swift/toolchain/usr/bin/swift-frontend[0x1353f9e]
/swift/toolchain/usr/bin/swift-frontend[0x135428e]
/swift/toolchain/usr/bin/swift-frontend[0x1400299]
/swift/toolchain/usr/bin/swift-frontend[0x137a793]
/swift/toolchain/usr/bin/swift-frontend[0x137a4af]
/swift/toolchain/usr/bin/swift-frontend[0x136cc71]
/swift/toolchain/usr/bin/swift-frontend[0x14d180f]
/swift/toolchain/usr/bin/swift-frontend[0x14d0871]
/swift/toolchain/usr/bin/swift-frontend[0x14d07a1]
/swift/toolchain/usr/bin/swift-frontend[0x13f99de]
/swift/toolchain/usr/bin/swift-frontend[0x13f6b5f]
/swift/toolchain/usr/bin/swift-frontend[0x13f5e8d]
/swift/toolchain/usr/bin/swift-frontend[0x13fe05e]
/swift/toolchain/usr/bin/swift-frontend[0x13fdb56]
/swift/toolchain/usr/bin/swift-frontend[0x13fda21]
/swift/toolchain/usr/bin/swift-frontend[0x13f5640]
/swift/toolchain/usr/bin/swift-frontend[0x13f55b0]
/swift/toolchain/usr/bin/swift-frontend[0x142ba26]
/swift/toolchain/usr/bin/swift-frontend[0x142cc70]
/swift/toolchain/usr/bin/swift-frontend[0x142c9a7]
/swift/toolchain/usr/bin/swift-frontend[0x142c8b1]
/swift/toolchain/usr/bin/swift-frontend[0x142b6de]
/swift/toolchain/usr/bin/swift-frontend[0x142b6b4]
/swift/toolchain/usr/bin/swift-frontend[0x63d404]
/swift/toolchain/usr/bin/swift-frontend[0x63d296]
/swift/toolchain/usr/bin/swift-frontend[0x4fd485]
/swift/toolchain/usr/bin/swift-frontend[0x490dd8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f350a48fb97]
/swift/toolchain/usr/bin/swift-frontend[0x49098a]
Install Error: swift-build returned nonzero exit code 1.

closed time in a day

ProfFan

PR merged borglab/SwiftFusion

remove algorithms that are in penguin now

https://github.com/saeta/penguin/pull/120 moved these into Penguin.

For some reason, defining them in both places causes a compiler crash.

This PR fixes https://github.com/borglab/SwiftFusion/issues/194.

+4 -63

2 comments

4 changed files

marcrasi

pr closed time in a day

pull request commentborglab/SwiftFusion

remove algorithms that are in penguin now

Ok it works now.

I also needed to change Xcode_beta to Xcode_12.2. Not sure exactly why. It might be related to some of the recent announcements here.

marcrasi

comment created time in a day

push eventborglab/SwiftFusion

Marc Rasi

commit sha 3bfbc58bed92dc105fad326f486cded2b861b486

attempt to fix compile again

view details

push time in a day

push eventborglab/SwiftFusion

Marc Rasi

commit sha abb1a23f96c53a57aa27a63251229aea26a87194

fix compile errors

view details

push time in a day

pull request commentborglab/SwiftFusion

remove algorithms that are in penguin now

Oh sorry, I'm gonna need to update the tests to import penguin now. I'll do this in an hour after a meeting,

marcrasi

comment created time in a day

PR opened borglab/SwiftFusion

Reviewers
remove algorithms that are in penguin now

https://github.com/saeta/penguin/pull/120 moved these into Penguin.

For some reason, defining them in both places causes a compiler crash.

This PR fixes https://github.com/borglab/SwiftFusion/issues/194.

+0 -60

0 comment

1 changed file

pr created time in a day

create barnchborglab/SwiftFusion

branch : fix-extensions

created branch time in a day

issue commentborglab/SwiftFusion

Colab (Hosted Runtime) failed to compile SwiftFusion

Looking!

ProfFan

comment created time in a day

PullRequestReviewEvent

push eventborglab/SwiftFusion

Marc Rasi

commit sha f26cca3715bb62a9f2afe166322d34dc8b0b0b85

fix test

view details

push time in 12 days

PR opened borglab/SwiftFusion

Reviewers
add a gradient descent factor graph optimizer

I included a test on a simple factor graph, but I haven't tried to use it on anything more complicated like the PPCA tracking factor graph. I would expect it to work without any problems.

+159 -1

0 comment

5 changed files

pr created time in 12 days

create barnchborglab/SwiftFusion

branch : feature/fg_gradient

created branch time in 12 days

PullRequestReviewEvent

issue commentgoogle/swift-jupyter

Docker image fails to run Swift code

Oh I figured it out. The latest toolchains require --privileged instead of --cap-add SYS_PTRACE. I have updated the README, and I have also filed https://github.com/google/swift-jupyter/issues/116 because I would like to have it working without needing --privileged.

goccmack

comment created time in 16 days

push eventgoogle/swift-jupyter

marcrasi

commit sha 57b6963500af1ad0013c7c2250e477e938578201

Update README.md

view details

push time in 16 days

issue commentgoogle/swift-jupyter

Docker image fails to run Swift code

Hmm, it should work even without the change. I'll take a look. Thanks for reporting this!

Do you have the latest master commit of swift-jupyter? I remember recently fixing an error that looks a lot like this, so maybe you just have a slightly older version.

goccmack

comment created time in 16 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

Make AnyArrayBuffer pass vector testing.

 import SwiftFusion  class AnyArrayBufferTests: XCTestCase {   // TODO(#184): Make this test pass.

Can also remove this TODO.

dabrahams

comment created time in 21 days

PullRequestReviewEvent

Pull request review commentapple/swift

[AutoDiff] Add forward mode differentiation control flow support (conditionals)

 class JVPCloner::Implementation final         type.getCategory());   } +  void addPayloadPointerArgument(SILBasicBlock *bb, SILBasicBlock *newBb) {+    SILType builtinRawPtrTy = SILType::getRawPointerType(getASTContext());+    newBb->createPhiArgument(builtinRawPtrTy, ValueOwnershipKind::Owned);+  }++  SILBasicBlock *createTrampolineBlock(SILBasicBlock *bb) {+    auto *trampBlock = jvp->createBasicBlock();+    for (auto &arg : bb->getArguments())+      trampBlock->createPhiArgument(arg->getType(), arg->getOwnershipKind());+    addPayloadPointerArgument(bb, trampBlock);+    return trampBlock;+  }++  void addBranchInstToTrampolineBlock(SILLocation loc, TermInst *origTermInst,+                                      SILBasicBlock *origSuccBB) {+    auto *bb = origTermInst->getParent();+    auto *trampBB = jvpTrampolineBBMap.lookup({bb, origSuccBB});+    assert(trampBB && "Trampoline block should exist");++    auto *jvpTermInst = getOpBasicBlock(bb)->getTerminator();+    SILBuilderWithScope trampBuilder(trampBB, jvpTermInst);+    getBuilder().setCurrentDebugScope(trampBuilder.getCurrentDebugScope());++    // Step 1: Create enum with the undef payload for the next successor bb.+    auto *succStruct = differentialInfo.getLinearMapStruct(origSuccBB);+    auto succStructLoweredTy =+        getLoweredType(succStruct->getDeclaredInterfaceType());+    auto *undefStruct = SILUndef::get(succStructLoweredTy, getModule(),+                                      ValueOwnershipKind::Owned);+    auto *curEnum = differentialInfo.getBranchingTraceDecl(bb);+    auto enumLoweredTy = getNominalDeclLoweredType(curEnum);+    auto *enumEltDecl =+        differentialInfo.lookUpBranchingTraceEnumElement(origSuccBB, bb);+    assert(enumEltDecl && "Successor enum element declaration not found");++    auto *succEnum =+        trampBuilder.createEnum(loc, undefStruct, enumEltDecl, enumLoweredTy);

I wrote up a detailed explanation and question here: https://forums.swift.org/t/possible-to-inject-enum-case-before-initializing-payload-in-sil/40764

efremale

comment created time in 22 days

PullRequestReviewEvent

Pull request review commentapple/swift

[AutoDiff] Add forward mode differentiation control flow support (conditionals)

 class JVPCloner::Implementation final   /// blocks.   llvm::DenseMap<SILBasicBlock *, SILBasicBlock *> diffBBMap; +  /// Mapping from original basic blocks and successor basic blocks to+  /// corresponding jvp trampoline basic blocks. Trampoline basic blocks+  /// take additional arguments in addition to the successor enum argument.

Could you describe in more detail what a trampoline basic block does, or refer to something that describes in more detail?

efremale

comment created time in 22 days

PullRequestReviewEvent

Pull request review commentapple/swift

[AutoDiff] Add forward mode differentiation control flow support (conditionals)

 class JVPCloner::Implementation final   /// blocks.   llvm::DenseMap<SILBasicBlock *, SILBasicBlock *> diffBBMap; +  /// Mapping from original basic blocks and successor basic blocks to+  /// corresponding jvp trampoline basic blocks. Trampoline basic blocks+  /// take additional arguments in addition to the successor enum argument.+  llvm::DenseMap<std::pair<SILBasicBlock *, SILBasicBlock *>, SILBasicBlock *>+      jvpTrampolineBBMap;+   /// Mapping from original basic blocks and original values to corresponding   /// tangent values.   llvm::DenseMap<SILValue, AdjointValue> tangentValueMap; +  /// The main differential linear value map struct which has all the other+  /// structs nested within.+  AllocStackInst *bb0Struct = nullptr;+   /// Mapping from original basic blocks and original buffers to corresponding   /// tangent buffers.

Remove "original basic blocks" from this comment.

efremale

comment created time in 22 days

Pull request review commentapple/swift

[AutoDiff] Add forward mode differentiation control flow support (conditionals)

 class JVPCloner::Implementation final   /// blocks.   llvm::DenseMap<SILBasicBlock *, SILBasicBlock *> diffBBMap; +  /// Mapping from original basic blocks and successor basic blocks to+  /// corresponding jvp trampoline basic blocks. Trampoline basic blocks+  /// take additional arguments in addition to the successor enum argument.+  llvm::DenseMap<std::pair<SILBasicBlock *, SILBasicBlock *>, SILBasicBlock *>+      jvpTrampolineBBMap;+   /// Mapping from original basic blocks and original values to corresponding   /// tangent values.   llvm::DenseMap<SILValue, AdjointValue> tangentValueMap; +  /// The main differential linear value map struct which has all the other+  /// structs nested within.+  AllocStackInst *bb0Struct = nullptr;+   /// Mapping from original basic blocks and original buffers to corresponding   /// tangent buffers.-  llvm::DenseMap<std::pair<SILBasicBlock *, SILValue>, SILValue> bufferMap;+  llvm::DenseMap<SILValue, SILValue> bufferMap;++  llvm::DenseMap<SILBasicBlock *, SILValue> branchEnumFieldMap;

Could you add a doc comment?

efremale

comment created time in 22 days

Pull request review commentapple/swift

[AutoDiff] Add forward mode differentiation control flow support (conditionals)

 class LinearMapInfo {   /// original function linkage.   void computeAccessLevel(NominalTypeDecl *nominal, SILLinkage originalLinkage); +  void addEnumToStruct(SILBasicBlock *predBB, SILBasicBlock *originalBB,+                       EnumDecl *branchingTraceDecl);

Could you add a documentation comment?

It looks like the predBB argument is used for the successor when doing forwards mode, so predBB isn't a good name. Maybe nextTraceBB would be clearer.

efremale

comment created time in 22 days

Pull request review commentapple/swift

[AutoDiff] Add forward mode differentiation control flow support (conditionals)

 class JVPCloner::Implementation final         type.getCategory());   } +  void addPayloadPointerArgument(SILBasicBlock *bb, SILBasicBlock *newBb) {+    SILType builtinRawPtrTy = SILType::getRawPointerType(getASTContext());+    newBb->createPhiArgument(builtinRawPtrTy, ValueOwnershipKind::Owned);+  }++  SILBasicBlock *createTrampolineBlock(SILBasicBlock *bb) {+    auto *trampBlock = jvp->createBasicBlock();+    for (auto &arg : bb->getArguments())+      trampBlock->createPhiArgument(arg->getType(), arg->getOwnershipKind());+    addPayloadPointerArgument(bb, trampBlock);+    return trampBlock;+  }++  void addBranchInstToTrampolineBlock(SILLocation loc, TermInst *origTermInst,+                                      SILBasicBlock *origSuccBB) {+    auto *bb = origTermInst->getParent();+    auto *trampBB = jvpTrampolineBBMap.lookup({bb, origSuccBB});+    assert(trampBB && "Trampoline block should exist");++    auto *jvpTermInst = getOpBasicBlock(bb)->getTerminator();+    SILBuilderWithScope trampBuilder(trampBB, jvpTermInst);+    getBuilder().setCurrentDebugScope(trampBuilder.getCurrentDebugScope());++    // Step 1: Create enum with the undef payload for the next successor bb.+    auto *succStruct = differentialInfo.getLinearMapStruct(origSuccBB);+    auto succStructLoweredTy =+        getLoweredType(succStruct->getDeclaredInterfaceType());+    auto *undefStruct = SILUndef::get(succStructLoweredTy, getModule(),+                                      ValueOwnershipKind::Owned);+    auto *curEnum = differentialInfo.getBranchingTraceDecl(bb);+    auto enumLoweredTy = getNominalDeclLoweredType(curEnum);+    auto *enumEltDecl =+        differentialInfo.lookUpBranchingTraceEnumElement(origSuccBB, bb);+    assert(enumEltDecl && "Successor enum element declaration not found");++    auto *succEnum =+        trampBuilder.createEnum(loc, undefStruct, enumEltDecl, enumLoweredTy);

Based on https://github.com/apple/swift/blob/master/docs/SIL.rst#enums, and in particular the "init_enum_data_addr" and "inject_enum_addr" sections, I think that this strategy of initializing the enum with an undefined payload and then writing to the "init_enum_data_addr" address is undefined behavior.

Given what's written in that documentation, I don't see any way to avoid walking backwards through the trace to finish up the initializations.

This will be a pretty big change which you probably won't have time to do in your remaining time with us.

efremale

comment created time in 22 days

PullRequestReviewEvent

pull request commentborglab/SwiftFusion

[WIP] PPCA

@ProfFan, I pushed a commit that removes FixedSizeVector and makes it possible to use tensors of any size without needing to add any code.

ProfFan

comment created time in 23 days

push eventborglab/SwiftFusion

Marc Rasi

commit sha 971fc4d5b711289f27be0c1b0080bc83f6426e27

remove requirement that error vector is fixed size

view details

push time in 23 days

delete branch borglab/SwiftFusion

delete branch : scalars_tests

delete time in a month

push eventborglab/SwiftFusion

marcrasi

commit sha a07af749bdd416c5217c363b3f1da509c58d2d14

test vector semantics (#167) Adds a `checkVectorSemantics` method that checks the recently-added `Scalars` and `scalars` requirements. Migrates all the existing vector semantics checks to be inside of `checkVectorSemantics` too.

view details

push time in a month

PR merged borglab/SwiftFusion

test vector semantics

Adds a checkVectorSemantics method that checks the recently-added Scalars and scalars requirements.

Migrates all the existing vector semantics checks to be inside of checkVectorSemantics too.

+353 -359

3 comments

10 changed files

marcrasi

pr closed time in a month

push eventborglab/SwiftFusion

Marc Rasi

commit sha b8ead530deb3c27170b2c0f260d9560965a04836

address one more comment

view details

push time in a month

push eventborglab/SwiftFusion

Marc Rasi

commit sha a07c72a0120dcaaac1e31d5bab7e98291c332853

address comments

view details

push time in a month

Pull request review commentborglab/SwiftFusion

test vector semantics

 import Foundation+import PenguinTesting import TensorFlow import XCTest  import SwiftFusion+import PenguinStructures import PenguinTesting -/// Conform to this and call `runAllFixedSizeVectorTests()` to test all the `FixedSizeVector`-/// requirements on a concrete type.-protocol FixedSizeVectorTests {-  /// The concrete type that we are testing.-  associatedtype Testee: FixedSizeVector--  /// The dimension of the vector we are testing.-  static var dimension: Int { get }-}--extension FixedSizeVectorTests {-  /// A set of basis vectors.-  fileprivate var basisVectors: [Testee] {-    return (0..<Self.dimension).map { index in-      var v = Array(repeating: Double(0), count: Self.dimension)-      v[index] = 1-      return Testee(v)-    }-  }--  /// Make a vector whose first element is `start` and whose subsequent elements increment by-  /// `stride`.-  fileprivate func makeVector(from start: Double, stride: Double) -> Testee {-    return Testee(Array((0..<Self.dimension).map { start + Double($0) * stride }))-  }--  /// Tests all `FixedSizeVector` requirements.-  func runAllFixedSizeVectorTests() {-    testEquality()-    testMove()-    testAddMutating()-    testAddFunctional()-    testSubtractMutating()-    testSubtractFunctional()-    testScalarProductMutating()-    testScalarProductFunctional()-    testDot()-    testNegate()-    testSquaredNorm()-    testNorm()-    testDimension()-    testWithUnsafeBufferPointer()-    testWithUnsafeMutableBufferPointer()-    testInitFromFlatTensor()-    testFlatTensor()-    testStandardBasis()-  }--  /// Tests ==.-  func testEquality() {-    let v1 = makeVector(from: 0, stride: 0)-    let v2 = makeVector(from: 1, stride: 0)-    XCTAssertTrue(v1 == v1)-    XCTAssertFalse(v1 == v2)-  }--  /// Tests move (exponential map).-  func testMove() {-    var v = makeVector(from: 0, stride: 1)-    let t = makeVector(from: 1, stride: 1)-    v.move(along: t)-    XCTAssertEqual(v, makeVector(from: 1, stride: 2))-  }--  /// Tests the value and derivative of the mutating +=.-  func testAddMutating() {-    func doMutatingAdd(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result += v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(doMutatingAdd(v1, v2), makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingAdd)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the functional +.-  func testAddFunctional() {-    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(v1 + v2, makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: +)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the mutating -=.-  func testSubtractMutating() {-    func doMutatingSubtract(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result -= v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 1, stride: -1)-    XCTAssertEqual(doMutatingSubtract(v1, v2), makeVector(from: 0, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingSubtract)-    XCTAssertEqual(value, makeVector(from: 0, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, -v)+extension Vector {+  /// XCTests `self`'s semantic conformance to `Vector`, expecting its scalars to match+  /// `expectedScalars`.+  ///+  /// - Requires: `!distinctScalars.elementsEqual(self.scalars)`.+  /// - Complexity: O(N²), where N is `self.dimension`.+  func checkVectorSemantics<S1: Collection, S2: Collection>(+    expecting expectedScalars: S1,+    writing distinctScalars: S2,+    maxSupportedScalarCount: Int = Int.max+  ) where S1.Element == Double, S2.Element == Double {++    // MARK: - Check the `scalars` property semantics.++    self.scalars.checkCollectionSemantics(+      expecting: expectedScalars, maxSupportedCount: maxSupportedScalarCount)++    var mutableScalars = self.scalars+    mutableScalars.checkMutableCollectionSemantics(writing: distinctScalars)++    // Check that setting `scalars` actually changes it.+    var mutableSelf = self+    for (i, e) in zip(mutableSelf.scalars.indices, distinctScalars) { mutableSelf.scalars[i] = e }+    XCTAssertTrue(mutableSelf.scalars.elementsEqual(distinctScalars))++    // MARK: - Check the `dimension` property semantics.++    XCTAssertEqual(self.dimension, expectedScalars.count)++    // MARK: - Check the mathematical vector operation (`+`, `+=`, `-`, `-=`, `*`, `*=`, `dot`,+    // `zeroValue`) semantics.++    /// Returns a vector with the same `scalars.indices` as `self` but with the scalars replaced+    /// by the stride from `start` by `stride`.

Done

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 import Foundation+import PenguinTesting import TensorFlow import XCTest  import SwiftFusion+import PenguinStructures import PenguinTesting -/// Conform to this and call `runAllFixedSizeVectorTests()` to test all the `FixedSizeVector`-/// requirements on a concrete type.-protocol FixedSizeVectorTests {-  /// The concrete type that we are testing.-  associatedtype Testee: FixedSizeVector--  /// The dimension of the vector we are testing.-  static var dimension: Int { get }-}--extension FixedSizeVectorTests {-  /// A set of basis vectors.-  fileprivate var basisVectors: [Testee] {-    return (0..<Self.dimension).map { index in-      var v = Array(repeating: Double(0), count: Self.dimension)-      v[index] = 1-      return Testee(v)-    }-  }--  /// Make a vector whose first element is `start` and whose subsequent elements increment by-  /// `stride`.-  fileprivate func makeVector(from start: Double, stride: Double) -> Testee {-    return Testee(Array((0..<Self.dimension).map { start + Double($0) * stride }))-  }--  /// Tests all `FixedSizeVector` requirements.-  func runAllFixedSizeVectorTests() {-    testEquality()-    testMove()-    testAddMutating()-    testAddFunctional()-    testSubtractMutating()-    testSubtractFunctional()-    testScalarProductMutating()-    testScalarProductFunctional()-    testDot()-    testNegate()-    testSquaredNorm()-    testNorm()-    testDimension()-    testWithUnsafeBufferPointer()-    testWithUnsafeMutableBufferPointer()-    testInitFromFlatTensor()-    testFlatTensor()-    testStandardBasis()-  }--  /// Tests ==.-  func testEquality() {-    let v1 = makeVector(from: 0, stride: 0)-    let v2 = makeVector(from: 1, stride: 0)-    XCTAssertTrue(v1 == v1)-    XCTAssertFalse(v1 == v2)-  }--  /// Tests move (exponential map).-  func testMove() {-    var v = makeVector(from: 0, stride: 1)-    let t = makeVector(from: 1, stride: 1)-    v.move(along: t)-    XCTAssertEqual(v, makeVector(from: 1, stride: 2))-  }--  /// Tests the value and derivative of the mutating +=.-  func testAddMutating() {-    func doMutatingAdd(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result += v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(doMutatingAdd(v1, v2), makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingAdd)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the functional +.-  func testAddFunctional() {-    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(v1 + v2, makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: +)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the mutating -=.-  func testSubtractMutating() {-    func doMutatingSubtract(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result -= v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 1, stride: -1)-    XCTAssertEqual(doMutatingSubtract(v1, v2), makeVector(from: 0, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingSubtract)-    XCTAssertEqual(value, makeVector(from: 0, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, -v)+extension Vector {+  /// XCTests `self`'s semantic conformance to `Vector`, expecting its scalars to match+  /// `expectedScalars`.

Done

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 import Foundation+import PenguinTesting import TensorFlow import XCTest  import SwiftFusion+import PenguinStructures import PenguinTesting -/// Conform to this and call `runAllFixedSizeVectorTests()` to test all the `FixedSizeVector`-/// requirements on a concrete type.-protocol FixedSizeVectorTests {-  /// The concrete type that we are testing.-  associatedtype Testee: FixedSizeVector--  /// The dimension of the vector we are testing.-  static var dimension: Int { get }-}--extension FixedSizeVectorTests {-  /// A set of basis vectors.-  fileprivate var basisVectors: [Testee] {-    return (0..<Self.dimension).map { index in-      var v = Array(repeating: Double(0), count: Self.dimension)-      v[index] = 1-      return Testee(v)-    }-  }--  /// Make a vector whose first element is `start` and whose subsequent elements increment by-  /// `stride`.-  fileprivate func makeVector(from start: Double, stride: Double) -> Testee {-    return Testee(Array((0..<Self.dimension).map { start + Double($0) * stride }))-  }--  /// Tests all `FixedSizeVector` requirements.-  func runAllFixedSizeVectorTests() {-    testEquality()-    testMove()-    testAddMutating()-    testAddFunctional()-    testSubtractMutating()-    testSubtractFunctional()-    testScalarProductMutating()-    testScalarProductFunctional()-    testDot()-    testNegate()-    testSquaredNorm()-    testNorm()-    testDimension()-    testWithUnsafeBufferPointer()-    testWithUnsafeMutableBufferPointer()-    testInitFromFlatTensor()-    testFlatTensor()-    testStandardBasis()-  }--  /// Tests ==.-  func testEquality() {-    let v1 = makeVector(from: 0, stride: 0)-    let v2 = makeVector(from: 1, stride: 0)-    XCTAssertTrue(v1 == v1)-    XCTAssertFalse(v1 == v2)-  }--  /// Tests move (exponential map).-  func testMove() {-    var v = makeVector(from: 0, stride: 1)-    let t = makeVector(from: 1, stride: 1)-    v.move(along: t)-    XCTAssertEqual(v, makeVector(from: 1, stride: 2))-  }--  /// Tests the value and derivative of the mutating +=.-  func testAddMutating() {-    func doMutatingAdd(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result += v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(doMutatingAdd(v1, v2), makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingAdd)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the functional +.-  func testAddFunctional() {-    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(v1 + v2, makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: +)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the mutating -=.-  func testSubtractMutating() {-    func doMutatingSubtract(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result -= v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 1, stride: -1)-    XCTAssertEqual(doMutatingSubtract(v1, v2), makeVector(from: 0, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingSubtract)-    XCTAssertEqual(value, makeVector(from: 0, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, -v)+extension Vector {+  /// XCTests `self`'s semantic conformance to `Vector`, expecting its scalars to match+  /// `expectedScalars`.+  ///+  /// - Requires: `!distinctScalars.elementsEqual(self.scalars)`.+  /// - Complexity: O(N²), where N is `self.dimension`.+  func checkVectorSemantics<S1: Collection, S2: Collection>(+    expecting expectedScalars: S1,+    writing distinctScalars: S2,+    maxSupportedScalarCount: Int = Int.max+  ) where S1.Element == Double, S2.Element == Double {++    // MARK: - Check the `scalars` property semantics.++    self.scalars.checkCollectionSemantics(+      expecting: expectedScalars, maxSupportedCount: maxSupportedScalarCount)++    var mutableScalars = self.scalars+    mutableScalars.checkMutableCollectionSemantics(writing: distinctScalars)++    // Check that setting `scalars` actually changes it.+    var mutableSelf = self+    for (i, e) in zip(mutableSelf.scalars.indices, distinctScalars) { mutableSelf.scalars[i] = e }

Changed.

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 import Foundation+import PenguinTesting import TensorFlow import XCTest  import SwiftFusion+import PenguinStructures import PenguinTesting -/// Conform to this and call `runAllFixedSizeVectorTests()` to test all the `FixedSizeVector`-/// requirements on a concrete type.-protocol FixedSizeVectorTests {-  /// The concrete type that we are testing.-  associatedtype Testee: FixedSizeVector--  /// The dimension of the vector we are testing.-  static var dimension: Int { get }-}--extension FixedSizeVectorTests {-  /// A set of basis vectors.-  fileprivate var basisVectors: [Testee] {-    return (0..<Self.dimension).map { index in-      var v = Array(repeating: Double(0), count: Self.dimension)-      v[index] = 1-      return Testee(v)-    }-  }--  /// Make a vector whose first element is `start` and whose subsequent elements increment by-  /// `stride`.-  fileprivate func makeVector(from start: Double, stride: Double) -> Testee {-    return Testee(Array((0..<Self.dimension).map { start + Double($0) * stride }))-  }--  /// Tests all `FixedSizeVector` requirements.-  func runAllFixedSizeVectorTests() {-    testEquality()-    testMove()-    testAddMutating()-    testAddFunctional()-    testSubtractMutating()-    testSubtractFunctional()-    testScalarProductMutating()-    testScalarProductFunctional()-    testDot()-    testNegate()-    testSquaredNorm()-    testNorm()-    testDimension()-    testWithUnsafeBufferPointer()-    testWithUnsafeMutableBufferPointer()-    testInitFromFlatTensor()-    testFlatTensor()-    testStandardBasis()-  }--  /// Tests ==.-  func testEquality() {-    let v1 = makeVector(from: 0, stride: 0)-    let v2 = makeVector(from: 1, stride: 0)-    XCTAssertTrue(v1 == v1)-    XCTAssertFalse(v1 == v2)-  }--  /// Tests move (exponential map).-  func testMove() {-    var v = makeVector(from: 0, stride: 1)-    let t = makeVector(from: 1, stride: 1)-    v.move(along: t)-    XCTAssertEqual(v, makeVector(from: 1, stride: 2))-  }--  /// Tests the value and derivative of the mutating +=.-  func testAddMutating() {-    func doMutatingAdd(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result += v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(doMutatingAdd(v1, v2), makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingAdd)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the functional +.-  func testAddFunctional() {-    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 2, stride: 1)-    XCTAssertEqual(v1 + v2, makeVector(from: 3, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: +)-    XCTAssertEqual(value, makeVector(from: 3, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, v)-    }-  }--  /// Tests the value and derivative of the mutating -=.-  func testSubtractMutating() {-    func doMutatingSubtract(_ v1: Testee, _ v2: Testee) -> Testee {-      var result = v1-      result -= v2-      return result-    }--    let v1 = makeVector(from: 1, stride: 1)-    let v2 = makeVector(from: 1, stride: -1)-    XCTAssertEqual(doMutatingSubtract(v1, v2), makeVector(from: 0, stride: 2))--    let (value, pb) = valueWithPullback(at: v1, v2, in: doMutatingSubtract)-    XCTAssertEqual(value, makeVector(from: 0, stride: 2))-    for v in basisVectors {-      XCTAssertEqual(pb(v).0, v)-      XCTAssertEqual(pb(v).1, -v)+extension Vector {+  /// XCTests `self`'s semantic conformance to `Vector`, expecting its scalars to match+  /// `expectedScalars`.+  ///+  /// - Requires: `!distinctScalars.elementsEqual(self.scalars)`.+  /// - Complexity: O(N²), where N is `self.dimension`.+  func checkVectorSemantics<S1: Collection, S2: Collection>(+    expecting expectedScalars: S1,+    writing distinctScalars: S2,+    maxSupportedScalarCount: Int = Int.max+  ) where S1.Element == Double, S2.Element == Double {++    // MARK: - Check the `scalars` property semantics.++    self.scalars.checkCollectionSemantics(+      expecting: expectedScalars, maxSupportedCount: maxSupportedScalarCount)++    var mutableScalars = self.scalars+    mutableScalars.checkMutableCollectionSemantics(writing: distinctScalars)++    // Check that setting `scalars` actually changes it.+    var mutableSelf = self+    for (i, e) in zip(mutableSelf.scalars.indices, distinctScalars) { mutableSelf.scalars[i] = e }+    XCTAssertTrue(mutableSelf.scalars.elementsEqual(distinctScalars))++    // MARK: - Check the `dimension` property semantics.++    XCTAssertEqual(self.dimension, expectedScalars.count)

Yeah. I'll do this refactoring in a separate PR.

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 class MultipleVectorTests: XCTestCase {     XCTAssertEqual(pb(Vector5(0, 0, 0, 1, 0)).1, Vector3(0, 1, 0))     XCTAssertEqual(pb(Vector5(0, 0, 0, 0, 1)).1, Vector3(0, 0, 1))   }++  func testConvertToTensor() {

It is testing some methods that are implemented as extensions of Vector. Maybe changing the class name to VectorExtensionTests clarifies this?

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 fileprivate typealias Matrix3x2 = FixedSizeMatrix<Array3<Vector2>> fileprivate typealias Matrix3x2_3x3 = FixedSizeMatrix<Array3<Tuple2<Vector2, Vector3>>>  class FixedSizeMatrixTests: XCTestCase {+  func testVectorConformance() {+    let s1 = (0..<6).lazy.map { Double($0) }+    let v1 = Matrix3x2(s1)+    v1.checkVectorSemantics(expecting: s1, writing: (6..<12).lazy.map { Double($0) })

Done

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 class FixedShapeTensorTests: XCTestCase {       }     }   }-} -class FixedShapeTensorVectorTests: XCTestCase, FixedSizeVectorTests {-  typealias Testee = Tensor10x10-  static var dimension: Int { 100 }-  func testAll() {-    runAllFixedSizeVectorTests()+  func testVectorConformance() {

runAllFixedSizeVectorTests is what ran the old equivalent of the vector semantics checks. I have completely replaced it with the new vector semantics checks, which test pretty much the same thing but are written very differently.

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 extension ArrayBuffer: Vector where Element: Vector {   @differentiable   private static func minus (_ lhs: ArrayBuffer, _ rhs: ArrayBuffer) -> ArrayBuffer {     if rhs.isEmpty { return lhs }+    if lhs.isEmpty { return .init(rhs.lazy.map { $0.zeroValue - $0 }) }

Yes :)

marcrasi

comment created time in a month

PullRequestReviewEvent

Pull request review commentborglab/SwiftFusion

test vector semantics

 extension FixedShapeTensor {   }    public static var zero: Self { .init(Tensor(zeros: Self.shape)) }++  public var zeroTangentVectorInitializer: () -> Self {

hmm, this doesn't look like it's necessary and the tests still pass when I remove it. so I'll remove it.

marcrasi

comment created time in a month

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentborglab/SwiftFusion

[WIP] PPCA

Sorry, I didn't notice this email earlier. The mu shape had an extra dimension and I pushed a commit that fixes it.

ProfFan

comment created time in a month

push eventborglab/SwiftFusion

Marc Rasi

commit sha 2dc1a870fb894d888787570af2e0af39521f2d6c

fix PPCA mu shape

view details

push time in a month

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

issue commenttensorflow/swift

0.11 cannot build with package manager, 0.10 can

A workaround that works for me is to run swift build first, and then run the swift run command that I want.

rezahussain

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

+// Copyright 2020 The TensorFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+//     http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++// The following GIF writer has been ported to Swift from https://github.com/lecram/gifenc++import Foundation++class Node {

Make this fileprivate so that it doesn't show up in other parts of the module where it might be confusing.

Also I'd suggest making a lot of the internal methods on struct GIF fileprivate.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

+// Copyright 2020 The TensorFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+//     http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++import Foundation+import TensorFlow++struct AnimatedImage {+  let frames: [Tensor<Float>]++  public init(_ frames: [Tensor<Float>]) {+    guard frames.count > 0 else { fatalError("No frames were provided to animated image.") }+    guard frames[0].rank == 3 else {+      fatalError("Rank-3 tensors are needed, and rank \(frames[0].rank) frames were provided.")+    }+    self.frames = frames+  }++  func quantize(_ frames: [Tensor<Float>]) -> (quantizedFrames: [[UInt8]], palette: [UInt8]) {+    // TODO: Adapt the following to the colors in the input image.+    let palette: [UInt8] = GIF.defaultPalette++    let colorComponents = frames.first!.shape[2]+    var quantizedFrames: [[UInt8]] = []+    for frame in frames {+      let scalars = frame.scalars+      var quantizedFrame: [UInt8] = []+      for index in stride(from: 0, to: scalars.count, by: colorComponents) {+        let red: UInt8+        let green: UInt8+        let blue: UInt8+        if colorComponents == 4 {+          // I'm placing values with an alpha channel on a white background.+          let alpha = scalars[index + 3]+          red = UInt8(max(min(round(scalars[index] + (255.0 - alpha)), 255.0), 0.0))+          green = UInt8(max(min(round(scalars[index + 1] + (255.0 - alpha)), 255.0), 0.0))+          blue = UInt8(max(min(round(scalars[index + 2] + (255.0 - alpha)), 255.0), 0.0))+        } else {+          red = UInt8(max(min(scalars[index], 255.0), 0.0))+          green = UInt8(max(min(scalars[index + 1], 255.0), 0.0))+          blue = UInt8(max(min(scalars[index + 2], 255.0), 0.0))+        }+        let redQuantized = red / 51+        let greenQuantized = green / 51+        let blueQuantized = blue / 51+        let lookup = redQuantized * 6 * 6 + greenQuantized * 6 + blueQuantized + 16+        quantizedFrame.append(lookup)+      }+      quantizedFrames.append(quantizedFrame)+    }+    return (quantizedFrames: quantizedFrames, palette: palette)+  }++  public func save(to url: URL, delay: Int, loop: Bool = true) throws {+    let width = frames[0].shape[1]+    let height = frames[0].shape[0]++    let (quantizedFrames, palette) = quantize(frames)+    var gif = GIF(width: width, height: height, palette: palette, loop: loop)++    for frame in quantizedFrames {+      gif.append(frame: frame, delay: delay)+    }++    gif.close()+    try gif.bytes.write(to: url)+  }+}++public func saveAnimatedImage(

I might prefer having this as a method in AnimatedImage. Advantages are:

  • Users can refer to doc comments in the AnimatedImage initializers to answer questions about the shape/values of the tensors.
  • If there are any conversions (like resizing or resampling) that users want to do before saving, these could be implemented as as methods on AnimatedImage instead of additional arguments on this function.
  • Users can use autocomplete on AnimatedImage to discover ways of saving them.

I have a similar comment on saveImage below in Image.swift.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {+        switch self.imageData {+        case let .uint8(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(Tensor<Float>(data)))+        case let .float(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(data))         }     } }  public func saveImage(-    _ tensor: Tensor<Float>, shape: (Int, Int), size: (Int, Int)? = nil,-    format: Image.Colorspace = .rgb, directory: String, name: String,-    quality: Int64 = 95+    _ tensor: Tensor<Float>, shape: (Int, Int)? = nil, size: (Int, Int)? = nil,+    colorspace: Image.Colorspace = .rgb, directory: String, name: String,+    format: Image.Format = .jpeg(quality: 95) ) throws {     try createDirectoryIfMissing(at: directory)      let channels: Int-    switch format {+    switch colorspace {     case .rgb: channels = 3+    case .rgba: channels = 4     case .grayscale: channels = 1     }+  +    let reshapedTensor: Tensor<Float>+    if let shape = shape {+        reshapedTensor = tensor.reshaped(to: [shape.0, shape.1, channels])+    } else {+        guard tensor.shape.rank == 3 else {+            fatalError("Input tensor must be of rank 3 (was \(tensor.shape.rank), or a shape must be specified.)")+        }+        if tensor.shape[2] > channels {+            // Need to premultiply alpha channel before saving as RGB.

I think that this block of code is blending with a white background, not premultiplying.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

+// Copyright 2020 The TensorFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+//     http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++import Foundation+import TensorFlow++struct AnimatedImage {+  let frames: [Tensor<Float>]++  public init(_ frames: [Tensor<Float>]) {+    guard frames.count > 0 else { fatalError("No frames were provided to animated image.") }+    guard frames[0].rank == 3 else {+      fatalError("Rank-3 tensors are needed, and rank \(frames[0].rank) frames were provided.")+    }+    self.frames = frames+  }++  func quantize(_ frames: [Tensor<Float>]) -> (quantizedFrames: [[UInt8]], palette: [UInt8]) {+    // TODO: Adapt the following to the colors in the input image.+    let palette: [UInt8] = GIF.defaultPalette++    let colorComponents = frames.first!.shape[2]+    var quantizedFrames: [[UInt8]] = []+    for frame in frames {+      let scalars = frame.scalars+      var quantizedFrame: [UInt8] = []+      for index in stride(from: 0, to: scalars.count, by: colorComponents) {+        let red: UInt8+        let green: UInt8+        let blue: UInt8+        if colorComponents == 4 {+          // I'm placing values with an alpha channel on a white background.+          let alpha = scalars[index + 3]+          red = UInt8(max(min(round(scalars[index] + (255.0 - alpha)), 255.0), 0.0))+          green = UInt8(max(min(round(scalars[index + 1] + (255.0 - alpha)), 255.0), 0.0))+          blue = UInt8(max(min(round(scalars[index + 2] + (255.0 - alpha)), 255.0), 0.0))

Same comment here as my comment in Image.swift below about this assuming that the image has been premultiplied by alpha.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

+// Copyright 2020 The TensorFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+//     http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++import Foundation+import TensorFlow++struct AnimatedImage {+  let frames: [Tensor<Float>]++  public init(_ frames: [Tensor<Float>]) {

A doc comment explaining the shape and values would be very helpful. When I started using Image the first time, the first things I wanted to find out were:

  • What order to "height", "width", "channels" come in the shape?
  • Are the values in [0, 1) or [0, 255] or what?
BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {+        switch self.imageData {+        case let .uint8(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(Tensor<Float>(data)))+        case let .float(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(data))         }     } }  public func saveImage(-    _ tensor: Tensor<Float>, shape: (Int, Int), size: (Int, Int)? = nil,-    format: Image.Colorspace = .rgb, directory: String, name: String,-    quality: Int64 = 95+    _ tensor: Tensor<Float>, shape: (Int, Int)? = nil, size: (Int, Int)? = nil,+    colorspace: Image.Colorspace = .rgb, directory: String, name: String,+    format: Image.Format = .jpeg(quality: 95) ) throws {     try createDirectoryIfMissing(at: directory)      let channels: Int-    switch format {+    switch colorspace {     case .rgb: channels = 3+    case .rgba: channels = 4     case .grayscale: channels = 1     }+  +    let reshapedTensor: Tensor<Float>+    if let shape = shape {+        reshapedTensor = tensor.reshaped(to: [shape.0, shape.1, channels])+    } else {+        guard tensor.shape.rank == 3 else {+            fatalError("Input tensor must be of rank 3 (was \(tensor.shape.rank), or a shape must be specified.)")+        }+        if tensor.shape[2] > channels {

Many conversions are not handled, e.g. grayscale <-> rgb. Could you add an error, or add handling for those conversions?

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {+        switch self.imageData {+        case let .uint8(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(Tensor<Float>(data)))+        case let .float(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(data))         }     } }  public func saveImage(-    _ tensor: Tensor<Float>, shape: (Int, Int), size: (Int, Int)? = nil,-    format: Image.Colorspace = .rgb, directory: String, name: String,-    quality: Int64 = 95+    _ tensor: Tensor<Float>, shape: (Int, Int)? = nil, size: (Int, Int)? = nil,+    colorspace: Image.Colorspace = .rgb, directory: String, name: String,+    format: Image.Format = .jpeg(quality: 95)

Some things about this signature are confusing.

  • shape specifies the shape of the input image and size specifies a size that the image will be resized to before saving, but the argument names don't make that distinction clear.
  • When shape is specified, colorspace specifies the colorspace of the input image. When shape is not specified, colorspace specifies the colorspace that we will convert to before saving. So colorspace is playing two different roles.

I have a few different ideas how to make it clearer.

  1. Change the callers to use the instance method .save(to:) instead of this top level method. Some Image initializers and helper methods could make this just as convenient as saveImage, like: Image(x, size: (28, 28), colorspace: .grayscale).resized(to: (10, 10)).converted(to: .rgb).save(directory: xxx, name: yyy, format: zzz).

  2. Remove shape and make colorspace always specify the output colorspace. The caller is responsible for reshaping tensor properly.

  3. Have separate input/output arguments.

func saveImage(
  _ tensor: Tensor<Float>, inputSize: (Int, Int)? = nil, inputColorspace: Image.Colorspace? = nil,
  outputSize: (Int, Int)? = nil, outputColorspace: Image.Colorspace? = nil,
  ...
)

In all cases, a doc comment describing the behavior would be useful.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {

This doesn't depend on the Image instance, so it could be a top-level method. Also I'd suggest making it fileprivate unless you expect it to be used somewhere else in swift-models.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         }     } -    public func save(to url: URL, format: Colorspace = .rgb, quality: Int64 = 95) {+    public func save(to url: URL, colorspace: Colorspace = .rgb, format: Format = .jpeg(quality: 95)) {

Can you omit colorspace and infer the colorspace from the tensor shape? Or convert the image to colorspace before saving? I think that this method currently just reads past the end of the data when colorspace is specified incorrectly.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {+        switch self.imageData {+        case let .uint8(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(Tensor<Float>(data)))+        case let .float(data):+            guard data.shape[2] == 4  else { return self }
            guard data.shape[2] == 4 else { return self }
BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {+        switch self.imageData {+        case let .uint8(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(Tensor<Float>(data)))+        case let .float(data):+            guard data.shape[2] == 4  else { return self }+            return Image(premultiply(data))         }     } }  public func saveImage(-    _ tensor: Tensor<Float>, shape: (Int, Int), size: (Int, Int)? = nil,-    format: Image.Colorspace = .rgb, directory: String, name: String,-    quality: Int64 = 95+    _ tensor: Tensor<Float>, shape: (Int, Int)? = nil, size: (Int, Int)? = nil,+    colorspace: Image.Colorspace = .rgb, directory: String, name: String,+    format: Image.Format = .jpeg(quality: 95) ) throws {     try createDirectoryIfMissing(at: directory)      let channels: Int-    switch format {+    switch colorspace {     case .rgb: channels = 3+    case .rgba: channels = 4     case .grayscale: channels = 1     }+  +    let reshapedTensor: Tensor<Float>+    if let shape = shape {+        reshapedTensor = tensor.reshaped(to: [shape.0, shape.1, channels])+    } else {+        guard tensor.shape.rank == 3 else {+            fatalError("Input tensor must be of rank 3 (was \(tensor.shape.rank), or a shape must be specified.)")+        }+        if tensor.shape[2] > channels {+            // Need to premultiply alpha channel before saving as RGB.+            let alphaChannel = tensor.slice(+                lowerBounds: [0, 0, 3], sizes: [tensor.shape[0], tensor.shape[1], 1])+            let colorComponents = tensor.slice(+                lowerBounds: [0, 0, 0], sizes: [tensor.shape[0], tensor.shape[1], 3])+            reshapedTensor = (255.0 - alphaChannel) + colorComponents

This is correct if the tensor has already been premultiplied by alpha. Otherwise, colorComponents needs to be multiplied by alphaChannel in this expression. Mentioning this assumption in the doc comment for the function would be good. Or even have a flag so that this can handle both premultiplied and not-premultiplied tensors.

BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {+        switch self.imageData {+        case let .uint8(data):+            guard data.shape[2] == 4  else { return self }
            guard data.shape[2] == 4 else { return self }
BradLarson

comment created time in a month

Pull request review commenttensorflow/swift-models

Growing Neural Cellular Automata

 public struct Image {         switch self.imageData {         case let .uint8(data):             let resizedImage = resize(images: Tensor<Float>(data), size: size, method: .bilinear)-            return Image(tensor: Tensor<UInt8>(resizedImage))+            return Image(Tensor<UInt8>(resizedImage))         case let .float(data):             let resizedImage = resize(images: data, size: size, method: .bilinear)-            return Image(tensor: resizedImage)+            return Image(resizedImage)+        }+    }+  +    func premultiply(_ input: Tensor<Float>) -> Tensor<Float> {+        let alphaChannel = input.slice(+            lowerBounds: [0, 0, 3], sizes: [input.shape[0], input.shape[1], 1])+        let colorComponents = input.slice(+            lowerBounds: [0, 0, 0], sizes: [input.shape[0], input.shape[1], 3])+        let adjustedColorComponents = colorComponents * alphaChannel / 255.0+        return Tensor(concatenating: [adjustedColorComponents, alphaChannel], alongAxis: 2)+    }+    +    public func premultipliedAlpha() -> Image {

Could you add a doc comment?

BradLarson

comment created time in a month

PullRequestReviewEvent
PullRequestReviewEvent

issue commenttensorflow/swift-apis

What's the expected output from Device.allDevices ?

@xihui-wu will verify and close after #1059 is fixed.

xihui-wu

comment created time in a month

PullRequestReviewEvent

delete branch borglab/SwiftFusion

delete branch : fix_dependency

delete time in a month

PR closed borglab/SwiftFusion

Reviewers
fix Package.swift

A dependency published a new version that prevented swiftpm dependency resolution from working. I patched swift-models to fix the dependency, and this PR updates SwiftFusion to used the patched swift-models.

+8 -8

1 comment

2 changed files

marcrasi

pr closed time in a month

pull request commentborglab/SwiftFusion

fix Package.swift

Actually this doesn't fix the problem, never mind. There is a different way to deconfuse SwiftPM.

If you do get the problem:

error: the Package.resolved file is most likely severely out-of-date and is preventing correct resolution; delete the resolved file and try again

Then you can fix it by running swift build. (The error message's suggestion of deleting Package.resolved does not work for me.)

marcrasi

comment created time in a month

PR opened borglab/SwiftFusion

Reviewers
fix Package.swift

A dependency published a new version that prevented swiftpm dependency resolution from working. I patched swift-models to fix the dependency, and this PR updates SwiftFusion to used the patched swift-models.

+8 -8

0 comment

2 changed files

pr created time in a month

create barnchborglab/SwiftFusion

branch : fix_dependency

created branch time in a month

create barnchtensorflow/swift-models

branch : swiftfusion

created branch time in a month

delete branch tensorflow/swift-models

delete branch : allow_later_argument_parser

delete time in a month

push eventtensorflow/swift-models

Marc Rasi

commit sha e5dd47f292413610215833811eac2e9338384a8a

use swift-bencmark master

view details

push time in a month

create barnchtensorflow/swift-models

branch : allow_later_argument_parser

created branch time in a month

pull request commentapple/llvm-project

Merge 2020-09-14 into swift/tensorflow

LGTM.

Github won't let me actually "approve" because the "files" tab crashes github. (I guess because there are a lot of files.)

texasmichelle

comment created time in a month

PullRequestReviewEvent

issue commentborglab/SwiftFusion

Latest master failed to compile in Notebook

The bee notebook (https://colab.sandbox.google.com/drive/18uJvXwxSrahnqv16dVEwt66_qaOZVgp1) works for me, on both the latest nightly toolchain and the stable 0.11 release. (But not the tracking section, which looks like it hasn't been updated for the new bee videos yet).

Does it still break for you? Maybe try deleting the swift-install2 cache? Maybe some dependency had a problem that got fixed between when you posted and when I tried.

ProfFan

comment created time in a month

issue commentborglab/SwiftFusion

Latest master failed to compile in Notebook

Looking!

ProfFan

comment created time in a month

delete branch google/swift-jupyter

delete branch : fix_expression_value_showing

delete time in a month

push eventgoogle/swift-jupyter

marcrasi

commit sha 05aa29bcec72eb6bcf39a6a3b8fb9aa3dbf28aef

disable showing expression values (#113) The recent merge causes LLDB to crash when it tries to show an expression value (with `result.description`). This PR replaces all uses of `result.description` with a few different non-crashing alternatives: * When we know the type, of the value, use `GetSignedInt32()`. * When `GetDescription()` works, use that. * In a case where even `GetDescription()` crashes, print a message telling the user that they can show the value using `print()`. I made https://github.com/google/swift-jupyter/issues/112 to track fixing this.

view details

push time in a month

PR merged google/swift-jupyter

disable showing expression values

The recent merge causes LLDB to crash when it tries to show an expression value (with result.description).

This PR replaces all uses of result.description with a few different non-crashing alternatives:

  • When we know the type, of the value, use GetSignedInt32().
  • When GetDescription() works, use that.
  • In a case where even GetDescription() crashes, print a message telling the user that they can show the value using print(). I made https://github.com/google/swift-jupyter/issues/112 to track fixing this.
+23 -4

0 comment

2 changed files

marcrasi

pr closed time in a month

push eventgoogle/swift-jupyter

Marc Rasi

commit sha 1014ee0af867f5cb2e2d0c64096195cd016155ab

fix test

view details

push time in a month

more