警告:
src/BoardRep.h:49:12: warning: ‘BoardRep::BoardRep::Row::<anonymous struct>::a’
is too small to hold all values of ‘enum class BoardRep::Piece’
[enabled by default]
Piece a:2;
^
Run Code Online (Sandbox Code Playgroud)
枚举:
enum class Piece: unsigned char {
EMPTY,
WHITE,
BLACK
};
Run Code Online (Sandbox Code Playgroud)
使用:
union Row {
struct {
Piece a:2;
Piece b:2;
Piece c:2;
Piece d:2;
Piece e:2;
Piece f:2;
Piece g:2;
Piece h:2;
};
unsigned short raw;
};
Run Code Online (Sandbox Code Playgroud)
如果enum我同意GCC,它可能不得不截断,但这是因为enums与整数和预处理器定义并没有真正分开.然而,一个enum class更强大.如果它不够强大,不能假设所有Piece取整数值都在0到2之间,则警告是有意义的.否则海湾合作委员会将不必要地挑剔,可能值得邮寄清单说"看,这是一个愚蠢的警告"
您可以在2位数据中存储4个不同的值,我只需要3个不同的值,因此任何长度为4或更小的枚举应该很好地适合给定的2位(并且我的枚举确实"派生"(更好的术语?)来自无符号类型).如果我有5个或更多那么我会期待一个警告.
我试图了解 R 中的 s3 类系统。
文档说我需要为我想要创建的方法创建一个通用函数。
假设我想foo为 class创建一个方法XYZ。
有了 R 的所有包,我怎么能确定我没有覆盖以前创建的泛型方法?
总结是一个不好的例子,因为每个人都可能知道它已经存在,但是我的泛型可能已经定义在我已经加载或我将加载的包中。
当我尝试在Mac上安装scapy时,我收到此错误:
Collecting scapy
Downloading scapy-2.3.1.zip (1.1MB)
100% |????????????????????????????????| 1.1MB 436kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/tmp/pip-build-f7vu4fsp/scapy/setup.py", line 35
os.chmod(fname,0755)
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-f7vu4fsp/scapy
Run Code Online (Sandbox Code Playgroud)
我试过用pip install scapy和pip3 install scapy.
我试图在一台开发机器上同时处理多个(两个或三个)GitLab(甚至 GitHub)项目。因为在配置 IDE 和 git 服务时,当我尝试使用不同的用户名/密码签出或克隆另一个项目时,IDE 和 git 服务具有我的主要用户的数据,系统说要么找不到项目,要么我无权这样做。
如何在一台开发机器上配置和使用多个 git 用户?
我有点困惑:所有标签都有一种decompose()方法可以将标签从树中移除。但是如果我想删除 aNavigableString呢?它没有这样的方法:
>>> b = BeautifulSoup('<p>aaaa <span> bbbbb </span> ccccc</p>', 'html.parser')
>>> b.p.contents[0]
'aaaa '
>>> type(b.p.contents[0])
<class 'bs4.element.NavigableString'>
>>> b.p.contents[0].decompose()
Traceback (most recent call last):
...
AttributeError: 'NavigableString' object has no attribute 'decompose'
Run Code Online (Sandbox Code Playgroud)
有一种方法我设法NavigableString从树中删除了:通过从内容列表中删除它:
>>> b.p.contents.pop(0)
'aaaa '
>>> b
<p><span> bbbbb </span> ccccc</p>
Run Code Online (Sandbox Code Playgroud)
问题是它仍然存在于strings方法响应中:
>>> list(b.strings)
['aaaa ', ' bbbbb ', ' ccccc']
Run Code Online (Sandbox Code Playgroud)
这表明这是错误的做法。此外,我strings在我的代码中使用,所以这个 hacky 解决方案是不可接受的,唉。
所以问题是:如何NavigableString从树中删除特定对象?
在下面的C++源文件中,在函数中glfw_get_monitors如何设置对象每个元素的类属性monitor_ptrs?
该行monitor_ptrs[i].attr("class") = "GLFWmonitor";抛出编译错误:
\xe2\x80\x98Rcpp::Vector<19>::Proxy\xe2\x80\x99 {aka \xe2\x80\x98class Rcpp::internal::generic_proxy<19>\xe2\x80\x99} has no member named \xe2\x80\x98attr\xe2\x80\x99\nRun Code Online (Sandbox Code Playgroud)\n\n#ifndef RCPP_GLFW_TYPES_H\n#define RCPP_GLFW_TYPES_H\n\n#include <Rcpp.h>\n#include <GLFW/glfw3.h>\n\nvoid glfw_destroy_monitor(GLFWmonitor*);\n\n// /sf/ask/2884741681/\n\ntypedef Rcpp::XPtr<GLFWwindow, Rcpp::PreserveStorage, glfwDestroyWindow> GLFWwindow_ptr;\ntypedef Rcpp::XPtr<GLFWmonitor, Rcpp::PreserveStorage, glfw_destroy_monitor> GLFWmonitor_ptr;\n\n\n#endif\n\nRun Code Online (Sandbox Code Playgroud)\n\n#include "glfw_types.h"\nusing namespace Rcpp;\n\n// [[Rcpp::export]]\nGLFWmonitor_ptr glfw_get_primary_monitor() {\n\n GLFWmonitor_ptr new_monitor = GLFWmonitor_ptr(glfwGetPrimaryMonitor(), true);\n\n new_monitor.attr("class") = "GLFWmonitor";\n\n return new_monitor;\n}\n\n// [[Rcpp::export]]\nRcpp::List glfw_get_monitors() {\n\n int nr_monitors;\n GLFWmonitor** monitors = glfwGetMonitors(&nr_monitors);\n Rcpp::List monitor_ptrs(nr_monitors);\n\n for(int i = 0; i < nr_monitors; i++) {\n monitor_ptrs[i] …Run Code Online (Sandbox Code Playgroud) 我已经为下面的数据绘制了一个条形图
Total Monthly Actual Hours Total Monthly Work Hours
Activity Month
Apr-19 35381.25 42592
May-19 31722.50 44528
Jun-19 27708.50 38720
Jul-19 34283.50 44528
Aug-19 21359.90 42592
Run Code Online (Sandbox Code Playgroud)
.
我的代码到目前为止
display(dfWorkActual)
dfWorkActual.plot(kind='bar')
plt.ylabel('Work Hours')
plt.xlabel('Month')
plt.title("Total Monthly Work Hours & Total Actual Work Hours vs Month")
Run Code Online (Sandbox Code Playgroud)
现在我想添加每月总小时数的总实际小时数的百分比。
例如:
请指教
我想合并两个列表
list_1 <- list(LIST1 = list(list("a"), list("b"), list("c")))
list_2 <- list(LIST2 = list(list("1"), list("2"), list("3")))
Run Code Online (Sandbox Code Playgroud)
combined_list <- list()
combined_list[[1]] <- c("a", "1")
combined_list[[2]] <- c("b", "2")
combined_list[[3]] <- c("c", "3")
Run Code Online (Sandbox Code Playgroud)
我有一个讨厌的for循环方式,但是我想使用purrr清理它吗?任何帮助表示赞赏!
使用 Pybind11,我试图将一个 numpy 数组传递给 c++ 到 a 中std::vector,将其乘以 2,然后将其std::vector作为 numpy 数组返回给 python。
我已经完成了第一步,但第三步是在做一些奇怪的事情。为了将它传回,我使用了:py::array ret = py::cast(vect_arr);奇怪的是,我的意思是 Python 中返回的向量没有正确的维度和正确的顺序。
例如,我有数组:
[[ 0.78114362 0.06873818 1.00364053 0.93029671]
[ 1.50885413 0.38219005 0.87508337 2.01322396]
[ 2.19912915 2.47706644 1.16032292 -0.39204517]]
Run Code Online (Sandbox Code Playgroud)
代码返回:
array([[ 1.56228724e+000, 3.01770826e+000, 4.39825830e+000,
5.37804299e+161],
[ 1.86059342e+000, 4.02644793e+000, -7.84090347e-001,
1.38298992e-309],
[ 1.75016674e+000, 2.32064585e+000, 0.00000000e+000,
1.01370255e-316]])
Run Code Online (Sandbox Code Playgroud)
我已经阅读了文档,但我必须承认无法理解其中的大部分内容。因此,对于这个具体示例的任何帮助将不胜感激。提前致谢。
这是一个尝试的例子:
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <Python.h>
namespace py = pybind11;
py::module nn = py::module::import("iteration");
py::array nump(py::array arr){
auto arr_obj_prop = …Run Code Online (Sandbox Code Playgroud) 我正在尝试为基于图像的 R 应用程序创建多阶段构建rocker/r-ubuntu:20.04。
我基于该映像的原因是按照apt-get建议安装二进制包,以缩短构建时间。
如果我在没有多阶段构建的情况下构建图像,则最终图像大小为2.32GB,因此我需要通过多阶段构建来减小最终大小。
我遵循的方法是创建一个alpine:latest映像并从构建器复制app文件夹、安装的 R 库(/usr/local/lib/R/site-library/以及位于/usr/share/doc.
最终图像不起作用,因为没有安装执行应用程序的命令。
Dockerfile 如下:
FROM rocker/r-ubuntu:20.04 as builder
# # system libraries of general use
RUN apt-get update && apt-get install -y \
pandoc \
...
libxml2-dev
RUN apt-get update && \
apt-get install -y -qq \
r-cran-config \
...
r-cran-tidyverse
RUN R -e "install.packages(c('other-packages'), dependencies=T)"
# copy the app to the image
RUN mkdir -p /root/bloomapp/tmp
COPY . …Run Code Online (Sandbox Code Playgroud)