- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
= , =”、“>”的 6-6ren">
我正在使用自定义指标语法语言 (ISL) 来设计和评估交易规则。
我想为我的自定义类定义基本的二元运算符方法 indicator
.在 indicator
上的操作,例如 >=
, <=
等等,一旦评估,将有二进制输出(零或一),存储在类 signal
的另一个对象中. signal
对象还应包含用于延迟评估的操作(未评估的表达式)的定义。
我的尝试:
### define classes
indicator <- function () {
structure(NULL, class="indicator")
}
signal <- function (definition) {
structure(NULL, call=definition, class="signal")
}
`Ops.indicator` <- function(x, y, ...) {
.call <- match.call()
ret <- signal(definition=.call)
}
### create unevaluated definitions of indicators and signals
ind <- indicator()
sig <- ind <= 2
对象的结构str(sig)
是:
list()
- attr(*, "call")= language Ops.indicator(x = ind, y = 2)
- attr(*, "class")= chr "signal"
而我需要用 <=
存储特定的表达式, 稍后评估:
list()
- attr(*, "call")= language `<=.indicator`(x = ind, y = 2)
- attr(*, "class")= chr "signal"
如何重写Ops.indicator
为此,无需在“==”、“!=”、“<”、“<=”、“>=”、“>”的 6 个独立指标方法中重复代码?
最佳答案
我会这样做:
indicator <- function () {
structure(list(), class="indicator")
}
binary_op <- function(op, x, y) {
structure(list(op = op, x = x, y = y), class = "binary_signal")
}
`Ops.indicator` <- function(x, y, ...) {
binary_op(.Generic, substitute(x), substitute(y))
}
ind <- indicator()
sig <- ind <= 2
关键是使用特殊的 .Generic
值,但我还做了一些其他的小调整:
如果您将 S3 对象基于列表元素而不是属性,您会发现它们更易于使用
NULL 是一个单例,因此为其分配属性会默默地将其强制转换为 list()
我认为如果您存储单独的部分而不是完整的调用,对象可能会更容易使用。
最后,您可能想阅读更多关于 domain specific languages in R 的信息.
关于r - "Ops"组通用方法和 match.call 用于延迟评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20084974/
我正在KERAS CNN中工作,以检测视网膜图像中的糖尿病性视网膜病变。但是,当我尝试使用此代码预处理图像..: def estimate_radius(img): mx = img[img.
为什么这样实现: T& T::operator+=(const T&) { // ... implementation ... return *this; } T operator+(cons
这是我的图像混合代码,但 cv2.addweighted() 函数有问题: import cv2 import numpy as np img1 = cv2.imread('1.png') img2
我正在设置一个搜索API,就是搜索; id、type、originCity、destinationCity、departmentDate、reason、accommodation、approvalSt
这两个特征(std::ops::Add,core::ops::Add)提供相同的功能,并且它们都使用相同的示例(都使用std::ops::Add)。他们的实现者集有所不同。 应该默认使用std::op
我要提出条件 (A 和 B)和(C 或 D 或 E 或 F) 当我尝试做的时候 where: { [Op.and]: [{ A, B, [Op.or]: [{
我对 Sequelize 有这个问题: 我正在尝试进行 3 参数研究,如果其中一个参数为空,则不应考虑该参数。 const users = await User.findAll({ where:
Herb Sutter 的 Guru of the Week #4, "Class Mechanics" ,教导重载运算符的“a op b”形式应该根据“a op= b”形式实现(参见解决方案中的第
基准代码: func BenchmarkSth(b *testing.B) { var x []int b.ResetTimer() for i := 0; i < b.N;
我在使用 sequelize 获取正确的查询时遇到问题。 我有一个表示条目 id 的数组,可以这样说 - userVacationsIds = [1,2,3] 我做了这样的第一个查询
这两个特征(std::ops::Add,core::ops::Add)提供相同的功能,并且它们都使用相同的示例(都利用 std::ops::Add)。他们的一组实现者有些不同。 是否应该默认使用 st
为什么 std::numeric 算法似乎更喜欢 op 而不是 op=?例如,这里是 std::accumulate 在 LLVM 中的实现: template inline _LIBCPP_INL
这是基准测试的代码片段: // bench_test.go package main import ( "testing" ) func BenchmarkHello(b *testing.B
我使用 Sequelize 来查询我的数据库。 我在查询中使用 Op.and 和 Op.ne: const Op = require('sequelize'); let subLevels = awa
我有一个关于链表和模板的作业,其中有带有奇怪参数的函数,这些参数是强制性的。我找不到关于它的在线文档,感谢任何提供的 Material 。 我曾尝试为 op 分配另一个地址,然后它编译得很好,但我无法
cppreference说: the behavior of every builtin compound-assignment expression E1 op= E2 (where E1 is a
当我使用 go test -v -bench=. -benchmem 运行基准测试时,我看到以下结果。 f1 10000 120860 ns/op 2433 B/o
假设我有一个sympy 表达式 e1 op e2 哪里op是任何算术比较运算符,例如 , >> from sympy import symbols, Piecewise, ccode >>> x, y
在我的玩具包中,我定义了 %+%运算符作为 paste0() 的别名.试图减少与其他包的干扰,我通过以下方式实现: `%+%` <- function(...) UseMethod("%+%") `%
我正在尝试遵循 Scott Meyers 在 More Effective C++ 的第 22 项中的建议:“考虑使用 op= 而不是独立的 op”。他建议我们可以为 operator+ 创建一个模板
我是一名优秀的程序员,十分优秀!