simplify var creation
This commit is contained in:
parent
bae3b143c6
commit
e042a9f9d5
5 changed files with 23 additions and 11 deletions
|
|
@ -11,8 +11,8 @@ m2 = lgc.Const(1)
|
|||
r1 = lgc.Const(1)
|
||||
r2 = lgc.Const(1)
|
||||
|
||||
theta1 = lgc.Var("theta1")
|
||||
theta2 = lgc.Var("theta2")
|
||||
theta1 = lgc.Var()
|
||||
theta2 = lgc.Var()
|
||||
|
||||
x1 = r1 * lgc.cos(theta1)
|
||||
y1 = r1 * lgc.sin(theta1)
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ r20 = lgc.Const(1)
|
|||
k1 = lgc.Const(50)
|
||||
k2 = lgc.Const(50)
|
||||
|
||||
theta1 = lgc.Var("theta1")
|
||||
theta2 = lgc.Var("theta2")
|
||||
r1 = lgc.Var("r1")
|
||||
r2 = lgc.Var("r2")
|
||||
theta1 = lgc.Var()
|
||||
theta2 = lgc.Var()
|
||||
r1 = lgc.Var()
|
||||
r2 = lgc.Var()
|
||||
|
||||
x1 = r1 * lgc.cos(theta1)
|
||||
y1 = r1 * lgc.sin(theta1)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from enum import Enum
|
||||
import numpy as np
|
||||
from tqdm import tqdm
|
||||
import inspect
|
||||
import dis
|
||||
|
||||
class Operation(Enum):
|
||||
VAR = 1
|
||||
|
|
@ -178,10 +180,19 @@ class Const:
|
|||
|
||||
# var class
|
||||
class Var:
|
||||
def __init__(self, name, degree=0) -> None:
|
||||
self.name = name
|
||||
def __init__(self, name=None, degree=0) -> None:
|
||||
self.type = "Var"
|
||||
self.degree = degree
|
||||
if name == None:
|
||||
frame = inspect.currentframe().f_back
|
||||
instructions = list(dis.get_instructions(frame.f_code))
|
||||
lasti = frame.f_lasti
|
||||
for i, instr in enumerate(instructions):
|
||||
if instr.offset > lasti:
|
||||
if instr.opname in ("STORE_NAME", "STORE_FAST"):
|
||||
name = instr.argval
|
||||
break
|
||||
self.name = name
|
||||
|
||||
def copy(self):
|
||||
return Var(self.name, self.degree)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ m = lgc.Const(1)
|
|||
k = lgc.Const(10)
|
||||
r0 = lgc.Const(1)
|
||||
|
||||
theta = lgc.Var("theta")
|
||||
r = lgc.Var("r")
|
||||
theta = lgc.Var()
|
||||
r = lgc.Var()
|
||||
|
||||
x = r * lgc.cos(theta)
|
||||
y = r * lgc.sin(theta)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ g = lgc.Const(-10)
|
|||
m = lgc.Const(1)
|
||||
r = lgc.Const(1)
|
||||
|
||||
theta = lgc.Var("theta")
|
||||
theta = lgc.Var()
|
||||
print(theta.name)
|
||||
|
||||
x = r * lgc.cos(theta)
|
||||
y = r * lgc.sin(theta)
|
||||
|
|
|
|||
Loading…
Reference in a new issue