我的应用程序中有一些循环依赖项。它不会影响生产,应用程序运行正常。但现在我开始使用 jest 编写单元测试,现在我的一些导入返回了undefined。因此我无法编写一个测试。
即使当我尝试渲染整个应用程序时,导入中也有一些未定义的内容。
我无法删除这些循环依赖项,因为这会花费很多时间。
我该如何处理?
以下是 Jest 给出的一些错误示例
TypeError: Cannot read properties of undefined (reading 'sensorTypeRenderer')
4 | import { Renderers, ColumnDescriptionGenerators } from '@components';
> 6 | import sensorTypeRenderer = Renderers.sensorTypeRenderer;
Run Code Online (Sandbox Code Playgroud)
这是找不到服务,因为EventsGroupsStore未定义
ServiceNotFoundError: Service with "<UNKNOWN_IDENTIFIER>" identifier was not found...
> 204 | return Container.get(EventsGroupsStore);
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个预提交挂钩。我希望它能够与用户交互。所以,我发现我可以使用
read -p "Enter info: " info
或者 只是
read info
我创建了一个文件:
预提交:
#!/bin/sh
read -r input
echo $input
Run Code Online (Sandbox Code Playgroud)
它只应该读取变量并输出它。但这不起作用。我的意思是它不能作为钩子使用。如果我使用终端运行它./.githooks/pre-commit,一切都好。但是当我使用 时git commit -am "Hook",它会回显空字符串并且不读取任何内容。难道我做错了什么?
Git版本是2.28.0.windows.1
这是张量流优化器的链接。您可以看到,RMSprop 将动量作为参数,而 Adam 没有这样做。所以我很困惑。Adam 优化假装是具有动量的 RMSprop 优化,如下所示:
Adam = RMSprop + 动量
但为什么 RMSprop 有动量参数而 Adam 没有呢?
ReferenceError: window is not defined
当 NextJS 尝试渲染页面时,服务器端会出现此错误。但您可以在此处编写的挂钩window中使用。useEffect
我的问题是如何创建自定义挂钩。我尝试过类似的事情:
export const useEventListener = (
target: EventTarget, event: string, listener: EventListenerOrEventListenerObject, trigger = true,
): void => {
useEffect(() => {
target.addEventListener(event, listener);
trigger && target.dispatchEvent(new Event(event));
return () => target.removeEventListener(event, listener);
});
};
Run Code Online (Sandbox Code Playgroud)
这里window用的是useEffect. 但我收到了错误,因为当我打电话时
useEventListener(window, 'scroll', () => {...});
Run Code Online (Sandbox Code Playgroud)
NextJS 无法识别它。
我该如何处理?
原始ARMA算法的公式如下:
在这里您可以看到,ARMA 需要p + q + 1 个数字来计算。所以,没有任何疑问,这是很清楚的。
但是谈论SARIMA算法我无法理解一件事。SARIMA 公式看起来像 ARMA 加上额外的:
其中S是一个数字,代表季节周期。S是常数。
因此,SARIMA 必须计算p + q + P + Q + 1数字。只是额外的P + Q数字。如果P = 1 且Q = 2 ,则不会太多。
但如果我们使用太长的时间段,例如日常时间序列为 365 天,SARIMA 就无法停止拟合。看看这个模型。第一个需要9秒才能贴合,而第二个则2小时后还没贴合完!
import statsmodels.api as sm
model = sm.tsa.statespace.SARIMAX(
df.meantemp_box,
order=(1, 0, 2),
seasonal_order=(1, 1, 1, 7)
).fit()
model = sm.tsa.statespace.SARIMAX(
df.meantemp_box,
order=(1, 0, 2),
seasonal_order=(1, 1, 1, 365)
).fit()
Run Code Online (Sandbox Code Playgroud)
我无法理解这一点。从数学上讲,这个模型是相同的 - 它们都采用相同的p、q、P和 …
我必须增加双数组的长度。我知道,如何用char数组来做,所以我尝试了这个:
int main() {
char * tmp = NULL;
for (int i = 1; i <= 4; i++) {
tmp = realloc(tmp, i * sizeof(char));
tmp[i] = 'i';
}
puts("char OK");
double * tmp1 = NULL;
for (int i = 1; i <= 4; i++) {
tmp1 = realloc(tmp1, i * sizeof(double));
tmp1[i] = 0;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
第一个数组工作正常。但是第二个消息粉碎了realloc(): invalid next size。
因此,有两个问题:
1.为什么这种方法不能在双数组中工作?
2.如何动态增加双精度数组的大小?
UPD:删除了错字
我有 ESLint 的配置
{
"env": {
"browser": true,
"node": true,
"es2020": true
},
"extends": [
"airbnb-typescript/base",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"modules": true,
"arrowFunctions": true,
"classes": true
},
"ecmaVersion": 11,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"react",
"react-hooks",
"@typescript-eslint",
"testing-library",
"jest-dom"
],
"settings": {
"import/resolver": {
"typescript": {}
},
"react": {
"version": "detect"
}
},
"rules": {
"class-methods-use-this": "off",
"no-restricted-syntax": "off",
"no-underscore-dangle": "off",
"no-return-assign": "off",
"linebreak-style": "off",
"no-continue": "off",
"no-plusplus": "off", …Run Code Online (Sandbox Code Playgroud) javascript ×3
reactjs ×3
typescript ×3
adam ×1
arima ×1
arrays ×1
bash ×1
c ×1
eslint ×1
git ×1
git-bash ×1
githooks ×1
jestjs ×1
keras ×1
memory ×1
next.js ×1
optimization ×1
python ×1
react-hooks ×1
realloc ×1
statsmodels ×1
tensorflow ×1
time-series ×1
unit-testing ×1