Quick Look for Tensors in Xcode Debugger

105 views
Skip to first unread message

Vojta Molda

unread,
Nov 4, 2020, 10:24:43 PM11/4/20
to Swift for TensorFlow
Hello everyone,

TL;DR: Does any of you know a way how to get Quick Look working for structs in Xcode? I managed to get it working only for classes with @objc binding.

A few weeks ago I saw this tweet from Jeremy Howard praising TensorSensor Python library. I really liked the diagrams of tensor shapes the library provides and I also vaguely knew about the Quick Look (aka the eye icon) feature in Xcode debugger. Quick Look allows one to have a visual representation of custom types during debugging. It can, for example, show images, bezier paths, UI views and more. My idea was to display a tensor shape diagram after clicking the "eye" icon on a Tensor variable.

Also, I wanted to learn SwiftUI and implementing a view for visualization of tensors is a great excuse to finally do it. So I connected the dots and wrote a small view that can visualize Tensors in a similar fashion as TensorSensor. It all went smoothly except for the very last step described below. Here is the GitHub repo and this is an example app:
Gallery.png
So the next logical step in the implementation is to have a little tensor thumbnail show up whenever you click the "eye" Quick Look icon in Xcode. And ideally do the same thing in Xcode Playgrounds. And that's the part of the story where the things go off the rails...

Despite banging my head on the keyboard the last few nights I wasn't able to figure out a way to make Xcode run the debugQuickLookObject() method on a struct. And unfortunately Tensor is a struct. There are good reasons for it so changing it makes no sense.

Xcode documentation is a bit sparse. But to my best knowledge there's nothing explicitly requiring the Quick Look-able object to be a class. However, my knowledge of Swift and Xcode has big gaps so I figured I'll ask here and see if anyone would know a trick to get it to work. Here's an issue that has a few more details and an example code.

Thanks for any comments and help!

 Cheers,

  Vojta

Dave Abrahams

unread,
Nov 6, 2020, 12:25:34 PM11/6/20
to Vojta Molda, Swift for TensorFlow
First, Vojta, this is awesome!

But I doubt you'll find much expertise about Xcode integration on this list.  Certainly, I don't have any insight.  Have you tried asking on forums.swift.org?

Very excited to see this come to fruition!

--
To unsubscribe from this group and stop receiving emails from it, send an email to swift+un...@tensorflow.org.


--
-Dave

Brennan Saeta

unread,
Nov 6, 2020, 1:51:40 PM11/6/20
to Dave Abrahams, Vojta Molda, Swift for TensorFlow
+1 to what Dave said. This looks awesome! -Brennan

Joaquin Alori

unread,
Nov 6, 2020, 2:45:36 PM11/6/20
to Swift for TensorFlow, Brennan Saeta, vojta...@gmail.com, Swift for TensorFlow, dabr...@google.com
This is super cool!

Vojta Molda

unread,
Nov 6, 2020, 5:09:29 PM11/6/20
to Swift for TensorFlow, joaqui...@gmail.com, Brennan Saeta, Vojta Molda, Swift for TensorFlow, dabr...@google.com
Thanks for the comments. I'm glad you all like the project. I was worried it's going to be dismissed as a gimmicky and useless.

The question is actually already posted on Swift forums. But there's no answer. I put a comment there to somehow "boost" it up the ranking but it didn't help. That's why I was hoping somebody here would know.

I reported the issue to Apple through their Feedback Assistant. I don't give it much of a chance to succeed but who knows. Maybe I poked the behemoth right in the "eye" and the Xcode team implements it in the next release :)

Unfortunately, at the moment it looks like there really is no way to have Quick Look for structs. So for the time being I'll put the project on shelve. It's frustrating to get stuck so close to the finish line but that's life... As the saying goes: "Sometimes you're the bug and sometimes you're the windshield."

Have a nice weekend!

Dave Abrahams

unread,
Nov 9, 2020, 12:36:18 PM11/9/20
to Vojta Molda, Swift for TensorFlow, joaqui...@gmail.com, Brennan Saeta
I added a suggestion on the Forums that might help
--
-Dave

Dan Zheng

unread,
Jan 7, 2021, 10:19:20 PM1/7/21
to Dave Abrahams, Vojta Molda, Swift for TensorFlow, joaqui...@gmail.com, Brennan Saeta
Happy New Year!

On the topic of visualizing tensors: I found github.com/HarisIqbal88/PlotNeuralNet (tweet), a library for drawing neural networks in a way that instantly reminded me of Vojta's Tensor Thumbnail. Neat stuff!

image.png
Dan

Vojta Molda

unread,
Jan 7, 2021, 11:37:05 PM1/7/21
to Swift for TensorFlow, danie...@google.com, Vojta Molda, Swift for TensorFlow, joaqui...@gmail.com, Brennan Saeta, dabr...@google.com
Thanks, Dan :) I wasn't aware of the PlotNeuralNet library. The diagrams really do look great!

It would be awesome to have something similar for any object conforming to the Layer protocol one day. If only one could clone himself and send the clones to pursue all those interesting ideas...

BTW, It still bugs me to this day that I can't get the previews (i.e. eye icon) working in Xcode debugger.

Happy New Year to you too!

Reply all
Reply to author
Forward
0 new messages