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)
|
r1 = lgc.Const(1)
|
||||||
r2 = lgc.Const(1)
|
r2 = lgc.Const(1)
|
||||||
|
|
||||||
theta1 = lgc.Var("theta1")
|
theta1 = lgc.Var()
|
||||||
theta2 = lgc.Var("theta2")
|
theta2 = lgc.Var()
|
||||||
|
|
||||||
x1 = r1 * lgc.cos(theta1)
|
x1 = r1 * lgc.cos(theta1)
|
||||||
y1 = r1 * lgc.sin(theta1)
|
y1 = r1 * lgc.sin(theta1)
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ r20 = lgc.Const(1)
|
||||||
k1 = lgc.Const(50)
|
k1 = lgc.Const(50)
|
||||||
k2 = lgc.Const(50)
|
k2 = lgc.Const(50)
|
||||||
|
|
||||||
theta1 = lgc.Var("theta1")
|
theta1 = lgc.Var()
|
||||||
theta2 = lgc.Var("theta2")
|
theta2 = lgc.Var()
|
||||||
r1 = lgc.Var("r1")
|
r1 = lgc.Var()
|
||||||
r2 = lgc.Var("r2")
|
r2 = lgc.Var()
|
||||||
|
|
||||||
x1 = r1 * lgc.cos(theta1)
|
x1 = r1 * lgc.cos(theta1)
|
||||||
y1 = r1 * lgc.sin(theta1)
|
y1 = r1 * lgc.sin(theta1)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
import inspect
|
||||||
|
import dis
|
||||||
|
|
||||||
class Operation(Enum):
|
class Operation(Enum):
|
||||||
VAR = 1
|
VAR = 1
|
||||||
|
|
@ -178,10 +180,19 @@ class Const:
|
||||||
|
|
||||||
# var class
|
# var class
|
||||||
class Var:
|
class Var:
|
||||||
def __init__(self, name, degree=0) -> None:
|
def __init__(self, name=None, degree=0) -> None:
|
||||||
self.name = name
|
|
||||||
self.type = "Var"
|
self.type = "Var"
|
||||||
self.degree = degree
|
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):
|
def copy(self):
|
||||||
return Var(self.name, self.degree)
|
return Var(self.name, self.degree)
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ m = lgc.Const(1)
|
||||||
k = lgc.Const(10)
|
k = lgc.Const(10)
|
||||||
r0 = lgc.Const(1)
|
r0 = lgc.Const(1)
|
||||||
|
|
||||||
theta = lgc.Var("theta")
|
theta = lgc.Var()
|
||||||
r = lgc.Var("r")
|
r = lgc.Var()
|
||||||
|
|
||||||
x = r * lgc.cos(theta)
|
x = r * lgc.cos(theta)
|
||||||
y = r * lgc.sin(theta)
|
y = r * lgc.sin(theta)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ g = lgc.Const(-10)
|
||||||
m = lgc.Const(1)
|
m = lgc.Const(1)
|
||||||
r = lgc.Const(1)
|
r = lgc.Const(1)
|
||||||
|
|
||||||
theta = lgc.Var("theta")
|
theta = lgc.Var()
|
||||||
|
print(theta.name)
|
||||||
|
|
||||||
x = r * lgc.cos(theta)
|
x = r * lgc.cos(theta)
|
||||||
y = r * lgc.sin(theta)
|
y = r * lgc.sin(theta)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue