How to use to_expression method in Slash

Best Python code snippet using slash

matrix_calculus.py

Source:matrix_calculus.py Github

copy

Full Screen

...94 def _repr_latex_(self):95 s = self.symbol.strip('$')96 return "$$%s$$" % s9798 def to_expression(self):99 return Expression([self])100101102 # def __str__(self):103 # return "Matrix({}, is_symmetric={})".format(self.symbol, self.is_symmetric)104105 def __str__(self):106 return self.symbol107108 def transpose(self):109 other = deepcopy(self)110 if other.is_transposed:111 other.symbol = other.symbol.replace("'","")112 other.is_transposed = False113 else:114 other.symbol = other.symbol + "'"115 other.is_transposed = True116 return other117118 def __add__(self, other):119 this = self.to_expression()120 if type(other) is Expression:121 return Operators.add(this, other)122 other = Expression([other])123 return Operators.add(this, other)124125 def __radd__(self, other):126 this = self.to_expression()127 if type(other) is Expression:128 return Operators.add(other, this)129 other = Expression([other])130 return Operators.add(other, this)131132 def __sub__(self, other):133 this = self.to_expression()134 if type(other) is Expression:135 return Operators.minus(this, other)136 other = Expression([other])137 return Operators.minus(this, other)138139 def __rsub__(self, other):140 this = self.to_expression()141 if type(other) is Expression:142 return Operators.minus(other, this)143 other = Expression([other])144 return Operators.minus(other, this)145146 def __mul__(self, other):147 this = self.to_expression()148 if type(other) is Expression:149 return Operators.multiply(this, other)150 other = Expression([other])151 return Operators.multiply(this, other)152153 def __rmul__(self, other):154 this = self.to_expression()155 if type(other) is Expression:156 return Operators.multiply(other, this)157 other = Expression([other])158 return Operators.multiply(other, this)159160161 def __truediv__(self, other):162 this = self.to_expression()163 if type(other) is Expression:164 return Operators.divide(this, other)165 other = Expression([other])166 return Operators.divide(this, other)167168 def __rtruediv__(self, other):169 this = self.to_expression()170 if type(other) is Expression:171 return Operators.divide(other, this)172 other = Expression([other])173 return Operators.divide(other, this)174175 def __div__(self, other):176 this = self.to_expression()177 if type(other) is Expression:178 return Operators.divide(this, other)179 other = Expression([other])180 return Operators.divide(this, other)181182 def __rdiv__(self, other):183 this = self.to_expression()184 if type(other) is Expression:185 return Operators.divide(other, this)186 other = Expression([other])187 return Operators.divide(other, this)188189 190 def __pow__(self, other):191 this = self.to_expression()192 if type(other) is Expression:193 return Operators.power(this, other)194 other = Expression([other])195 return Operators.power(this, other)196197 def __rpow__(self, other):198 this = self.to_expression()199 if type(other) is Expression:200 return Operators.power(other, this)201 other = Expression([other])202 return Operators.power(other, this)203204 def elem_mult(self, other):205 this = self.to_expression()206 if type(other) is Expression:207 return Operators.element_wise_multiply(this, other)208 other = Expression([other])209 return Operators.element_wise_multiply(this, other)210211 def elem_div(self, other):212 this = self.to_expression()213 if type(other) is Expression:214 return Operators.element_wise_division(this, other)215 other = Expression([other])216 return Operators.element_wise_division(this, other)217218 def elem_pow(self, other):219 this = self.to_expression()220 if type(other) is Expression:221 return Operators.element_wise_power(this, other)222 other = Expression([other])223 return Operators.element_wise_power(this, other)224225class Vector(Matrix):226 def __init__(self, symbol, n_rows=None):227 super().__init__(symbol, False, n_rows, None, False)228 assert self.chars[0] in string.ascii_lowercase, "first letter in vector must be lowercase letter."229 self.var_type = 'vector'230 231 232class Scalar(Matrix):233 def __init__(self, symbol): ...

Full Screen

Full Screen

paired_links.py

Source:paired_links.py Github

copy

Full Screen

1"""2Two networks and heatmaps with coordinated node selection and layouts.3XXXX This is copy-pasted and edited from paired_networks.py.4At some point common functionality should be refactored, maybe.5Or perhaps the whole infrastructure should be generalized.6"""7from IPython.display import display8from jp_gene_viz import LExpression9from ipywidgets import widgets10import traitlets11# Call this once.12from dNetwork import load_javascript_support13class PairedLinks(traitlets.HasTraits):14 """15 Coordinated networks.16 """17 def __init__(self, *args, **kwargs):18 super(PairedLinks, self).__init__(*args, **kwargs)19 self.left_expression = LExpression.LinkedExpressionNetwork()20 self.right_expression = LExpression.LinkedExpressionNetwork()21 lb = self.left_sync_button = self.make_button(u"sync \u21DB", self.left_sync_click)22 rb =self.right_sync_button = self.make_button(u"\u21DA sync", self.right_sync_click)23 ib = self.intersect_button = self.make_button("intersect", self.intersect_click)24 db = self.difference_button = self.make_button("difference", self.difference_click)25 lbuttons = widgets.HBox(children=[ib, db, lb])26 left_stack = widgets.VBox(children=[lbuttons, self.left_expression.assembly])27 right_stack = widgets.VBox(children=[rb, self.right_expression.assembly])28 self.assembly = widgets.HBox(children=[left_stack, right_stack])29 def load_left(self, network_filename, heatmap_filename):30 "Load the left network and heatmap"31 self._load(self.left_expression, network_filename, heatmap_filename)32 def load_right(self, network_filename, heatmap_filename):33 "Load the right network and heatmap"34 self._load(self.right_expression, network_filename, heatmap_filename)35 def _load(self, expression, network_filename, heatmap_filename):36 expression.load_network(network_filename)37 expression.load_heatmap(heatmap_filename)38 def show(self):39 display(self.assembly)40 def make_button(self, description, on_click,41 disabled=False, width="200px"):42 "Create a button."43 # XXXX refactor to superclass.44 result = widgets.Button(description=description)45 result.on_click(on_click)46 result.disabled = disabled47 result.layout.width = width48 return result49 def right_sync_click(self, b):50 return self.sync_click(self.right_expression, self.left_expression)51 def left_sync_click(self, b):52 return self.sync_click(self.left_expression, self.right_expression)53 def sync_click(self, from_expression, to_expression):54 nodes = from_expression.network.get_selection()55 to_expression.network.set_selection(nodes)56 to_expression.network.display_positions = from_expression.network.display_positions.copy()57 to_expression.network.draw()58 def intersect_click(self, b):59 return self.combine_networks("intersect")60 def difference_click(self, b):61 return self.combine_networks("difference")62 def combine_networks(self, mode):63 left_edges = self.left_expression.network.visible_edges()64 right_edges = self.right_expression.network.visible_edges()65 if mode == "intersect":66 combined_edges = left_edges & right_edges67 elif mode == "difference":68 combined_edges = left_edges.symmetric_difference(right_edges)69 else:70 raise ValueError("bad mode: " + repr(mode))71 if not combined_edges:72 self.left_expression.network.alert("Network %s has no edges" % mode)73 return74 for network in (self.left_expression.network, self.right_expression.network):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful