This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PYXLL] | |
modules = | |
pubsub_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyxll import RTD | |
import pubsub | |
class SubscriberRTD(RTD): | |
def __init__(self, topic): | |
super().__init__(value="Waiting...") | |
self.__topic = topic | |
def connect(self): |
OlderNewer