小编use*_*833的帖子

将rcpp变量转换为标准C++变量

我的输入如下:

Rcpp::NumericMatrix data(dataMatrix);
Rcpp::NumericVector xSize(dataXsize);
Rcpp::NumericVector ySize(dataYsize);
Rcpp::NumericVector tIndexes(testIndexes);
Rcpp::NumericVector cIndexes(controlIndexes);
Run Code Online (Sandbox Code Playgroud)

我试图调用的外部库有这个签名

WilcoxonTest(float * _data, int _dataXsize, int _dataYsize, vector<int> * _testIndexes, vector<int> * _controlIndexes);
Run Code Online (Sandbox Code Playgroud)

如何将Rcpp数据类型转换为C++标准数据类型?

注意:

 float * _data
Run Code Online (Sandbox Code Playgroud)

是浮点值的矩阵.该库假定它是这样的:

 float * _data = new float[dataXsize * dataYsize];
Run Code Online (Sandbox Code Playgroud)

c++ r type-conversion rcpp

6
推荐指数
1
解决办法
2550
查看次数

读取Java Servlet中从Ajax发送的JQuery数据

这是我的Ajax代码:

    var myJSONObject = {"bindings": [
                                     {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}]
                             };
    $.ajax({
        url : "ships",
        data : myJSONObject,
        success : function(data){
            GLOBAL.player.startShooting(data);
        },
        error : function(data) {
            console.log("error:", data);
        },
        dataType : "json",
        timeout : 30000,
        type : "post"
    });
Run Code Online (Sandbox Code Playgroud)

这是我的Java Servlet代码:

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    System.out.println("im in PSOT");
    System.out.println(request.getParameter("myJSONObject"));

    StringBuilder sb = new StringBuilder();
    BufferedReader br = request.getReader();
    String str;
    while( (str = br.readLine()) != null ){
        sb.append(str);
    }   
    System.out.println(sb.toString());
    response.setContentType("application/json"); …
Run Code Online (Sandbox Code Playgroud)

javascript java ajax jquery servlets

4
推荐指数
1
解决办法
2万
查看次数

使用 gcc 链接和使用 netCDF

我试图在我的 C++ 项目中使用 netCDF 库,但由于某种原因我不能使用它。

这是我的make文件

NETCDF = -L/usr/lib -lnetcdf_c++
WILXAPP = -Lsrc src/wilxtest.cpp -o bin/Debug/WilxAstakTest

Debug:
    g++ -Wall -ggdb $(NETCDF) $(WILXAPP)
Run Code Online (Sandbox Code Playgroud)

在我的 cpp 文件中,我基本上有(删除了膨胀)

#include <iostream>
#include <netcdfcpp.h>

int main(int argc, char* argv[])
{
   NcFile dataFile("simple_xy.nc", NcFile::Replace);
}
Run Code Online (Sandbox Code Playgroud)

我明白了:

 undefined reference to `NcFile::NcFile(char const*, NcFile::FileMode, unsigned long*, unsigned long, NcFile::FileFormat)'|
Run Code Online (Sandbox Code Playgroud)

c++ linker makefile netcdf

4
推荐指数
1
解决办法
2703
查看次数

用gson解析JSON数组

我无法解析我从javascript获得的JSON.JSON的格式是这样的:

[{"positions":[{"x":50,"y":50},{"x":82,"y":50},{"x":114,"y":50},{"x":146,"y":50}]},{"positions":[{"x":210,"y":50},{"x":242,"y":50},{"x":274,"y":50}]}]
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经能够做到这一点:

{"positions":[{"x":50,"y":50},{"x":82,"y":50},{"x":114,"y":50},{"x":146,"y":50}]}
Run Code Online (Sandbox Code Playgroud)

但我现在还需要创建一个具有这些职位的课程.我一直在上课,因为我先尝试打印输出,但我无法进一步分解.我收到此错误消息:

java.lang.IllegalStateException:这不是JSON数组.

我的代码是这样的:

    JsonParser parser = new JsonParser();
    String ships = request.getParameter("JSONships");
    JsonArray array = parser.parse(ships).getAsJsonArray();

    System.out.println(array.get(0).toString());
    JsonArray array2 = parser.parse(array.get(0).toString()).getAsJsonArray();
    System.out.println(array2.get(0).toString());
Run Code Online (Sandbox Code Playgroud)

我也试过这样做:

    Gson gson = new Gson() ;
    String lol = (gson.fromJson(array.get(0), String.class));
    System.out.println(lol);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我得到:

com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期的STRING但是BEGIN_OBJECT

最后,我想循环遍历位置,为每个"位置"创建类,其中包含具有另一个类Position的List,其具有int x,y.

感谢您的时间.

java arrays json gson

3
推荐指数
1
解决办法
1万
查看次数

在rails中测试控制器助手重定向

我试图在辅助模块上编写一个rspec单元测试

我有SessionsControllerSessionsHelper

里面SessionsHelper我有

def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  session.delete(:return_to)
end
Run Code Online (Sandbox Code Playgroud)

我想做一个看起来像这样的测试:

describe "redirect_back_or(default)" do
  describe "with stored location" do
    before do
      helper.request.path = users_path
      helper.store_location
    end
    it do 
      expect(helper.redirect_back_or(user_path(@user))).to redirect_to(users_url)
      helper.session[:return_to].should eq(nil) 
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但我在Helper方法中得到一个例外

undefined method `redirect_to' for #<#<Class:0x00000006fc9940>:0x00000005322620>
# ./app/helpers/sessions_helper.rb:34:in `redirect_back_or'
# ./spec/helpers/sessions_helper_spec.rb:99:in `block (4 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails

2
推荐指数
1
解决办法
1609
查看次数

在类中对结构的c ++向量进行排序

我有一个基本上看起来像这样的类(我删除了不必要的代码):

class WilxList {
private:    
    struct Test{
        double number;
        int sign;
        int rank;
    };
    bool testSorter(const Test & x1, const Test & x2);
public: 
    WilxList(std::vector<double> &argNumbers, std::string argName, int numberOfTests);
};
Run Code Online (Sandbox Code Playgroud)

我试图对这样的测试结构进行排序:

WilxList::WilxList(std::vector<double> &argNumbers, std::string argName, int numberOfTests)
{
    //Omitted code
    std::vector<Test> sortedTests;
    //Omitted code where Tests are created and added to the vector inside for loop
    std::sort(sortedTests.begin(), sortedTests.end(), testSorter); //ERROR
Run Code Online (Sandbox Code Playgroud)

}

我得到的错误是:

error C3867: 'WilxList::testSorter': function call missing argument list; 
use '&WilxList::testSorter' to create a pointer to member
c:\users\stenver\documents\visual …
Run Code Online (Sandbox Code Playgroud)

c++ sorting struct class vector

0
推荐指数
1
解决办法
1088
查看次数