我已经阅读了几个关于Cython和Swig之间的一些差异的线索并且已经实现了这两种技术,但我仍然不确定哪条路线是最佳路线.基本上我一直在研究C++库,我想将这些函数暴露给Python.Cython似乎相当复杂,需要我为每个需要公开的C++类编写几个.pyx文件,而SWIG只为我做了工作.到目前为止,我对这些包装方法中的任何一种都没有很多经验,但似乎SWIG是包装我的C++代码的明显赢家.那么争议是什么?当我在SWIG中编写一个简单的.i文件时,为什么我要花几个小时在Cython中编写.pyx文件来包装我的C++?此外,我使用CMake作为我的构建工具,使用CMAKE比使用Cython更容易构建SWIG.我觉得我必须遗漏一些东西,因为即使像OpenCV这样的大型项目也没有使用SWIG,在我将项目专门用于SWIG之前,我想找出为什么我宁愿使用Cython或者根本不使用.以下是摘要:
我的项目:C++源代码是主要的
任何意见是极大的赞赏.此外,我对xdress.org很好奇 - 看起来这个项目已经死了.
我目前正在尝试计算一个增强融合适应结构中数据成员的偏移量,但我不确定是否有一种优雅的方法可以做到这一点.我想做类似以下的事情:
#include <iostream>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/at.hpp>
#include <cstddef.h>
struct test {
int a;
char c;
double b;
};
BOOST_FUSION_ADAPT_STRUCT(
test,
(int, a)
(char, c)
(double, b)
)
int main() {
test s{1, 2, 3.0};
// The following code doesn't work... I'm just trying to get my point across
std::cout << "offset is :" << offsetof(test, at<1>(s)) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
关键是我不想在offsetof函数中明确声明'a'或'b'或'c'.这本身并没有那么有用,但是我想在boost for_each循环中使用它,这样我就可以在编译时计算任何结构的所有数据成员的偏移量.
如果您有任何想法,我很乐意听到他们!
我想按值分组,然后使用PySpark在每个组中找到最大值.我有以下代码,但现在我有点不知道如何提取最大值.
# some file contains tuples ('user', 'item', 'occurrences')
data_file = sc.textData('file:///some_file.txt')
# Create the triplet so I index stuff
data_file = data_file.map(lambda l: l.split()).map(lambda l: (l[0], l[1], float(l[2])))
# Group by the user i.e. r[0]
grouped = data_file.groupBy(lambda r: r[0])
# Here is where I am stuck
group_list = grouped.map(lambda x: (list(x[1]))) #?
Run Code Online (Sandbox Code Playgroud)
返回类似于:
[[(u'u1', u's1', 20), (u'u1', u's2', 5)], [(u'u2', u's3', 5), (u'u2', u's2', 10)]]
Run Code Online (Sandbox Code Playgroud)
我想现在为每个用户找到最大'发生'.执行最大值后的最终结果将导致RDD看起来像这样:
[[(u'u1', u's1', 20)], [(u'u2', u's2', 10)]]
Run Code Online (Sandbox Code Playgroud)
其中只有最大数据集将保留给文件中的每个用户.换句话说,我想将RDD 的值更改为仅包含每个用户最多出现的一个三元组.
我试图在我的Angular 2应用程序中使用AWS SDK,但是我很困难.以下是我采取的步骤:
npm install aws-sdk npm install --save-dev @types/nodedeclare var AWS: any;,import AWS = require('aws-sdk');最后import * as AWS from 'aws-sdk';.当我尝试使用第一种和第三种类型的导入时,在尝试访问AWS对象中的库之前,我没有得到转换器错误,即AWS.config.region = 'us-west-2给我错误';' expected..当我尝试使用第二种方法时,我收到错误:
定位ECMAScript 2015模块时,无法使用导入分配.考虑使用'import*as ns from"mod"','import {a} from"mod"','import d from"mod"'或其他模块格式.)
我错过了一步吗?我看过github项目https://github.com/awslabs/aws-cognito-angular2-quickstart/blob/master/src/app/service/aws.service.ts但是他们的项目没有解释他们是怎么回事导入了SDK.
在 YouCompleteMe 文档中,有两个选项可用于设置对 C/C++ 语义支持的支持。第一个是使用带有 CMake 的编译数据库(例如文件 compile_commands.json),第二个是使用 .ycm_extra_conf.py。幸运的是,我正在使用 Cmake,所以我能够生成一个编译数据库。YouCompleteMe 适用于我的项目中的源,但是,它无法找到以下文件的头文件:系统头文件(例如 iostream)并且它找不到包含在我的项目中的外部项目中的头文件(即与 CMake 结合的 git 子模块ExternalProject_Add(...))。从文档中我不清楚的是我是否应该使用 ycm_extra_conf.py 和 compile_commands.json 的组合。有人能给我一些关于为什么我的编译数据库没有的建议吗?
我有以下用C++编写的类
#include "segmenter_interface.h"
#include "video_marker.cpp"
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <vector>
class UserDivide : public SegmenterInterface{
public:
virtual void SegmentVideo(cv::VideoCapture *vc,
std::vector<Segment> *indices);
}
Run Code Online (Sandbox Code Playgroud)
实施细节并不重要.理想情况下,我想使用Cython将此类暴露给python.VideoCapture对象已经可以通过python实例化,因为OpenCV已经包装了它的所有模块.根据我的阅读,vector已经是Cython的一部分,因为它支持大多数C++标准库.
目前,我写了这么多.pyx:
cdef extern from "<vector>" namespace "std":
cdef cppclass vector [T]:
pass
cdef extern from "<opencv2/videoio/videoio.hpp>" namespace "cv":
cdef cppclass VideoCapture:
pass # Don't care, just need a pointer
cdef extern from "segmenter_interface.h":
cdef struct Segment:
pass # I will need this eventually...
cdef extern from "user_divide.h":
cdef cppclass UserDivide:
UserDivide() …Run Code Online (Sandbox Code Playgroud) 似乎 Cython 的存储库中目前有一个拉取请求来包装 c++,std::array但在那之前,我可以使用一些帮助。我目前正在包装std::array这样的:
cdef extern from "<array>" namespace "std" nogil:
cdef cppclass array2 "std::array<double, 2>":
array2() except+
double& operator[](size_t)
Run Code Online (Sandbox Code Playgroud)
这有效,但我必须循环遍历 cython 内存视图,例如 double arr[:],并逐个复制值。有没有更简单的方法来做到这一点?基本上我想做以下事情:
cdef double arr[2]
arr[0] = 1.0
arr[1] = 2.0
cdef array2 array2_arr = arr
#and the reverse
cdef array2 reverse
reverse[0] = 1.0
reverse[1] = 2.0
cdef double reverse_arr[2] = reverse
Run Code Online (Sandbox Code Playgroud)
这完全不合理吗?因此,使用std::array它非常乏味,因为我有一个 for 循环来将值从 cython 复制到 c++ 以及从 c++ 复制到 cython。此外,由于 cython 不能让我们拥有非类型模板参数,我必须为std::array代码中的每个变体定义一个包装器。任何关于如何有效工作的建议std::array将不胜感激。
编辑:
我现在可以使用以下命令从内存视图转到 …
我正在尝试按照位于http://serverless-stack.com/chapters/create-a-cognito-identity-pool.html的教程来创建标识池,并使用cloudformation记录创建,以便我可以我完成后轻松撤消一切.但是,我无法找到任何显示如何使用模板语法有效执行此操作的示例.我现在拥有的是以下内容
ScratchUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: notes-user-pool
ScratchUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ClientName: notes-client
ExplicitAuthFlows: [ADMIN_NO_SRP_AUTH]
UserPoolId:
Ref: ScratchUserPool
ScratchIdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: ScratchIdentityPool
AllowUnauthenticatedIdentities: false
CognitoIdentityProviders:
- ClientId:
Ref: ScratchUserPoolClient
ProviderName:
Ref: ScratchUserPool
Run Code Online (Sandbox Code Playgroud)
部署步骤在尝试创建时失败ScratchIdentityPool.我得到一个错误说明:
配置堆栈时发生错误:ScratchIdentityPool - 无效的Cognito身份提供程序(服务:AmazonCognitoIdentity;状态代码:400;错误代码:InvalidParameterException;请求ID:bc058020-663b-11e7-9f2a-XXXXXXXXXX)
我没有正确引用客户端或提供商名称吗?
我有一个 bash 函数,我想使用 gnome 终端在新窗口中执行该函数。我该怎么做?我想在我的 blah.sh 脚本中做这样的事情:
my_func() {
// Do cool stuff
}
gnome-terminal -x my_func
Run Code Online (Sandbox Code Playgroud)
我现在正在做的是将 my_func() 放入脚本并调用 gnome-terminal -x ./my_func
从命令行或在线API,我可以轻松创建"复合主键",但当我尝试使用CloudFormation为我完成工作时,我没有看到任何JSON/YAML会让我设置一个名为"复合主键".语言完全不同,所以我希望有人可以指导我如何使用Cloudformation创建这样的密钥.
我最好的猜测是如下所示,我希望复合键包含userId和noteId:
Resources:
usersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: notes_serverless
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: noteId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: noteId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Run Code Online (Sandbox Code Playgroud) 看一下这里的例子:http://threejs.org/examples/#webgl_postprocessing
我很好奇是否有办法在原始数据集的副本上执行此后处理业务.换句话说,我想在一个容器中显示我的场景的原始渲染,然后想在另一个容器中显示后处理的场景.这是怎么做到的?
谢谢!