python - 我可以防止我的自定义类被简化吗?
问题描述
我正在构建我的自定义类,它是object
. (由于__r(operator)__
优先级,没有其他超类可供选择。)
由于这个类不是sympy
类,所以每当我尝试将它应用于 sympy 函数时,它都会被 sympified,这会造成麻烦。
当它被简化时,有没有办法让它自己返回?例如,就像sympify(sin(x))
返回一样sin(x)
,我希望我的类的实例以这样的方式运行:sympify(instance)
返回instance
。
解决方案
Try adding a def for _sympy_
in your class: def _sympy_(self): return self
or maybe Basic(self)
...but then SymPy won't be able to work with such expressions. Can you give an example of what you are trying to do? There is the CantSympify mixin available, too, but that will prevent the object from being sympified at all.
推荐阅读
- java - ThreadPoolExecutor 中的“活动线程”是什么意思?
- scala - Spark 提交 ClassNotFoundException
- java - 我的整数溢出如何携带更多数字
- workflow - 从外部触发 Prefect 工作流
- bazel - Genrule 不会在最终输出文件中输出“$@”符号
- r - 如何在 R 中对“...”函数参数进行惰性求值?
- javascript - 如何在更新父节点 Firebase RealTime 中的值时推送到子节点
- java - Spring控制器将对象返回给客户端
- python - 如何删除文本中多余的标点符号(只保留第一个)?
- c++ - 错误:聚合“HMAC_CTX ctx”类型不完整,无法定义