如果我运行这段代码:
#include <iostream>
#include <cstdint>
int main()
{
double a = -2.0;
const double b = -2.0;
using std::cout;
cout << "Direct cast double -> uint16:\n";
cout << "a1: " << static_cast<std::uint16_t>(a) << "\n";
cout << "b1: " << static_cast<std::uint16_t>(b) << "\n";
auto a2 = static_cast<std::uint16_t>(a);
auto b2 = static_cast<std::uint16_t>(b);
cout << "a2: " << a2 << "\n";
cout << "b2: " << b2 << "\n";
cout << "Indirect cast double -> uint16:\n";
cout << "a3: " << static_cast<std::uint16_t>(static_cast<std::int16_t>(a)) << …Run Code Online (Sandbox Code Playgroud) WHERE INEF Core 8 现在使用和 的组合将值内联到 where 语句中,OPENJSON而不是以前的WHERE IN(...).
文档中记录了此更改,所述原因如下:
此处值的内联是以不存在 SQL 注入攻击的机会的方式完成的。下面描述的使用 JSON 的更改完全与性能有关,与安全性无关。
不幸的是,OPENJSON我们 2017 年 SQL Server 实例的性能很差。
下面的查询由 EF Core 8 生成,运行时间为1.8 秒,产生近400,000 次读取:
DECLARE @__scheduleTagIds_0 nvarchar(4000) = N'[5835,5970,6563,6564,6565,6645,6835,6850,7034,7127]';
SELECT [s].[ScheduleTagId]
,[s].[MustStartProdBy]
FROM [ScheduleTagMustStartBy] AS [s]
WHERE [s].[ScheduleTagId] IN (
SELECT [s0].[value]
FROM OPENJSON(@__scheduleTagIds_0) WITH ([value] int '$') AS [s0]
)
Run Code Online (Sandbox Code Playgroud)
如果我重构查询以使用标准WHERE IN(...),执行时间将降至120 毫秒和29,000 次读取:
SELECT [s].[ScheduleTagId]
,[s].[MustStartProdBy] …Run Code Online (Sandbox Code Playgroud) C++23 允许[[...]]lambda 表达式中的属性:
auto lambda = [] [[nodiscard]]
{
return 42;
};
Run Code Online (Sandbox Code Playgroud)
但是语法有两个属性列表,大致在参数列表之前和之后:
auto lambda = [] [[nodiscard]] () [[deprecated]]
// (1)~~~~~~~~~~ (2)~~~~~~~~~~~ // (2) seems to have no effect here
{
return 42;
};
Run Code Online (Sandbox Code Playgroud)
这两个列表适用于不同的事物,但我无法弄清楚第二个列表的用途,以及我可以在此处放置哪些属性。对于我在 (2) 中尝试的任何属性,Clang 警告:'...' attribute cannot be applied to types。
标准是这样说的:
... attribute-specifier-seq [位于位置 (2)] 属于相应函数调用运算符或运算符模板的类型。
attribute-specifier-seq [位于位置 (1)] 属于相应的函数调用运算符或运算符模板。
“属于相应函数调用运算符的类型”让我感到困惑。我可以在这里放置哪些属性?这是否仅适用于特定于编译器的属性?如果是,这里可以使用哪些非标准属性?
显然,列表 (2) 早在 C++23 之前就已存在(该提案添加了列表 (1))。
如果整数除法的余数不为零,我想继续将结果向上舍入。
例子:
5 / 2产量2. 但我想继续3(整数)。4 / 2产量2,这对于我的用例来说很好。我目前采用这种笨重的结构:
ceil(5 / 2.toDouble()).toInt()
Run Code Online (Sandbox Code Playgroud)
Kotlin 游乐场上的示例:https ://pl.kotl.in/eX0rYXnsH
有没有更惯用的方法来实现这一目标?
如果我创建一个虚拟线程的执行器服务
Executors.newVirtualThreadPerTaskExecutor()
Run Code Online (Sandbox Code Playgroud)
据我所知,每个任务都在虚拟线程上运行。这些虚拟线程通过平台线程进行调度(希望是交错的)。
这里使用了多少个平台线程?我没有看到任何其他 API 来指定我想要的线程数。我在 Macbook M1 Pro 上使用 Java 21 运行它。
我正在使用当前最新的 Kotlin 版本 ( 1.9.22) 并遇到了我无法解释的行为。
此代码会产生运行时错误 ( NullPointerException):
fun main() {
var name: String? = null
println(name!!.length)
}
Run Code Online (Sandbox Code Playgroud)
虽然此代码会产生编译错误 ( Unresolved reference: length)
fun main() {
var name: String? = "Joe"
name = null
println(name!!.length)
}
Run Code Online (Sandbox Code Playgroud)
为什么简单地对可为 null 的name变量进行重新分配就可以让我免于陷入困境NullPointerException?我希望这两个代码片段在功能上是相同的。
我正在尝试创建一个输出,按因子级别计算计数占总计数(在数据框中)的百分比,但似乎无法弄清楚如何在输出中保留分组结构。
\n我可以获得我想要除以的总计数...
\ndf %>% summarise(sum(num))\n# 15\nRun Code Online (Sandbox Code Playgroud)\n...以及按组划分的总数...
\ndf %>% group_by(species) %>% summarise(sum(num))\n# A tibble: 3 \xc3\x97 2\n# species `sum(num)`\n# <chr> <int>\n# 1 Farfantepenaeus duorarum 4\n# 2 Farfantepenaeus notialis 0\n# 3 Farfantepenaeus spp 11\nRun Code Online (Sandbox Code Playgroud)\n但我无法让它看起来像这样......
\n# ???\n# species Percent\n# <chr> <int>\n# 1 Farfantepenaeus duorarum 4 / 15 = 0.267\n# 2 Farfantepenaeus notialis 0 / 15 = 0.000\n# 3 Farfantepenaeus spp 11 / 15 = 0.733\nRun Code Online (Sandbox Code Playgroud)\n我得到的最接近的是这个,但是因为我使用了 reframe() 它返回了未分组的数据
\ndf %>% group_by(species) %>% \n …Run Code Online (Sandbox Code Playgroud) 团队,
自从我开始遵循这个flutter 文档以来,我一直像这样初始化 Firebase ,但由于某种原因,这会在调试器中引发错误,如下所示:
类型错误:如果没有“new”,则无法调用类构造函数 IndexedDBLocalPersistence
您能帮我纠正这个问题吗?
这是颤振代码:
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:pace/firebase_options.dart';
import 'package:pace/pages/auth_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: AuthPage(),
),
);
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下数据集:
我想用公式 n_j - (d_j+c_j) 计算第二行 n_j 列中的 NA。
创建数据:
df = structure(list(time_intervals = structure(1:8, levels = c("[0,12)",
"[12,24)", "[24,36)", "[36,48)", "[48,60)", "[60,72)", "[72,84)",
"[84,96]"), class = "factor"), d_j = c(16L, 10L, 1L, 3L, 2L,
2L, 0L, 2L), c_j = c(4L, 4L, 0L, 1L, 2L, 0L, 1L, 0L), n_j = c(48L,
NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA, -8L), class = c("tbl_df",
"tbl", "data.frame"))
Run Code Online (Sandbox Code Playgroud)
我设法用for循环来做到这一点:
for (i in 1:nrow(df)) {
df <- df |>
mutate(
n_j …Run Code Online (Sandbox Code Playgroud) 我的 TCGA 肿瘤样本 ID 列表如下:
SAMPLE_ID
TCGA.13.1407.01A.01R.1565.13
TCGA.24.2254.01A.01R.1568.13
TCGA.24.0982.01A.01R.1565.13
TCGA.24.1847.01A.01R.1566.13
TCGA.24.2289.01A.01R.1568.13
TCGA.31.1959.01A.01R.1568.13
Run Code Online (Sandbox Code Playgroud)
我想将样品 ID 拆分为:项目、TSS、参与者、样品、小瓶、部分、分析物、板、中心 例如,第一行为:
SAMPLE_ID Project TSS Participant Sample Vial Portion Analyte Plate Center
TCGA.13.1407.01A.01R.1565.13 TCGA 13 1407 01 A 01 R 0182 13
Run Code Online (Sandbox Code Playgroud)
我尝试如下:
library(tidyr)
library(dplyr)
df = data.frame(SAMPLE_ID = c("TCGA.13.1407.01A.01R.1565.13", "TCGA.24.2254.01A.01R.1568.13", "TCGA.24.0982.01A.01R.1565.13",
"TCGA.24.1847.01A.01R.1566.13", "TCGA.24.2289.01A.01R.1568.13", "TCGA.31.1959.01A.01R.1568.13"))
Run Code Online (Sandbox Code Playgroud)
然后,
result = data %>% separate(SAMPLE_ID,
into = c("Project", "TSS", "Participant", "Sample", "Vial",
"Portion", "Analyte", "Plate", "Center"),
sep = "\\.")
Run Code Online (Sandbox Code Playgroud)
但它给了我:
Project TSS Participant Sample Vial Portion Analyte Plate Center
<chr> …Run Code Online (Sandbox Code Playgroud)