Skip to content

Instantly share code, notes, and snippets.

View tonyroberts's full-sized avatar

Tony Roberts tonyroberts

View GitHub Profile
class NN(nn.Module):
def __init__(self):
super(NN, self).__init__()
self.layers = nn.Sequential(nn.Linear(2, 128, bias=True),
nn.Tanh(),
nn.Linear(128, 64, bias=False),
nn.Tanh(),
nn.Linear(64, 32, bias=False),
nn.Tanh(),
from pyxll import xl_func
import torch.nn as nn
@xl_func
def nn_Linear(in_features: int, out_features: int, bias: bool=True):
"""Create a linear transformation layer."""
return nn.Linear(in_features, out_features, bias)
from pyxll import xl_func
import torch.nn as nn
class NN(nn.Module):
"""Neural networks with Sequential layers"""
def __init__(self, layers):
super(NN, self).__init__()
self.layers = nn.Sequential(*layers)
from pyxll import xl_func, xl_app
import matplotlib.pyplot as plt
import numpy as np
import torch
@xl_func
def nn_Run(net, image_name, scale=1, offset=-0.5, seed=None):
"""Run the neural network with random weights"""
from pyxll import xl_app, async_call
import win32gui, win32ui
import tempfile
import os
def get_image_size(image):
"""Return the size of an image in pixels as (width, height)."""
# Get the size of the input image in pixels (Excel sizes are in points,
# or 1/72th of an inch.
class MessageBroker:
def __init__(self):
self.__subscribers = {}
def publish(self, topic, message):
for callback in self.__subscribers.get(topic, []):
callback(message)
def subscribe(self, topic, callback):
# Use a single global message broker for all topics
_global_message_broker = MessageBroker()
def publish(topic, value):
"""Publishes a value on a topic for a subscriber to receive"""
_global_message_broker.publish(topic, value)
def subscribe(topic, callback):
from pyxll import xl_func
import pubsub
@xl_func
def publish(topic, value):
"""Publish a value on a topic to be picked up by another sheet"""
pubsub.publish(topic, value)
return f"[Published to {topic}]"
[PYXLL]
modules =
pubsub_example
from pyxll import RTD
import pubsub
class SubscriberRTD(RTD):
def __init__(self, topic):
super().__init__(value="Waiting...")
self.__topic = topic
def connect(self):