Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cvxtorch/torch_numerics/elementwise/trig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import torch
from cvxpy.expressions.expression import Expression


class sin:
@staticmethod
def torch_numeric(expr: Expression, values: list[torch.Tensor]) -> torch.Tensor:
return torch.sin(values[0])

class cos:
@staticmethod
def torch_numeric(expr: Expression, values: list[torch.Tensor]) -> torch.Tensor:
return torch.cos(values[0])
16 changes: 15 additions & 1 deletion cvxtorch/utils/exp2tch.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,18 @@
minimum: minimum_tch.torch_numeric,
power: power_tch.torch_numeric,
xexp: xexp_tch.torch_numeric,
}
}

try:
# Atoms from cvxpy-ipopt
from cvxpy.atoms.elementwise.trig import cos, sin

from cvxtorch.torch_numerics.elementwise.trig import cos as cos_tch, sin as sin_tch
EXPR2TORCH.extend({
sin: sin_tch.torch_numeric,
cos: cos_tch.torch_numeric,
})
except ImportError:
pass


Loading