小编fbi*_*jec的帖子

CUDA与我的gcc版本不兼容

我在编译CUDA SDK附带的一些示例时遇到了麻烦.我已经安装了开发人员驱动程序(版本270.41.19)和CUDA工具包,最后是SDK(两者都是4.0.17版本).

最初它根本没有编译:

error -- unsupported GNU version! gcc 4.5 and up are not supported!
Run Code Online (Sandbox Code Playgroud)

我发现81行负责:/usr/local/cuda/include/host_config.h并将其更改为:

//#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)
Run Code Online (Sandbox Code Playgroud)

从那时起,我只得到了一些编译的例子,它停止了:

In file included from /usr/include/c++/4.6/x86_64-linux-gnu/bits/gthr.h:162:0,
             from /usr/include/c++/4.6/ext/atomicity.h:34,
             from /usr/include/c++/4.6/bits/ios_base.h:41,
             from /usr/include/c++/4.6/ios:43,
             from /usr/include/c++/4.6/ostream:40,
             from /usr/include/c++/4.6/iterator:64,
             from /usr/local/cuda/include/thrust/iterator/iterator_categories.h:38,
             from /usr/local/cuda/include/thrust/device_ptr.h:26,
             from /usr/local/cuda/include/thrust/device_malloc_allocator.h:27,
             from /usr/local/cuda/include/thrust/device_vector.h:26,
             from lineOfSight.cu:37:
/usr/include/c++/4.6/x86_64-linux-gnu/bits/gthr-default.h:251:1: error: pasting         "__gthrw_" and "/* Android's C library does not provide pthread_cancel, check …
Run Code Online (Sandbox Code Playgroud)

debian gcc cuda

86
推荐指数
8
解决办法
11万
查看次数

用mockito嘲笑一个单身人士

我需要测试一些遗留代码,它在方法调用中使用单例.测试的目的是确保clas sunder测试调用单例方法.我在SO上看到过类似的问题,但是所有的答案都需要其他依赖项(不同的测试框架) - 我很遗憾只能使用Mockito和JUnit,但这种流行的框架应该是完全可能的.

单身人士:

public class FormatterService {

    private static FormatterService INSTANCE;

    private FormatterService() {
    }

    public static FormatterService getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new FormatterService();
        }
        return INSTANCE;
    }

    public String formatTachoIcon() {
        return "URL";
    }

}
Run Code Online (Sandbox Code Playgroud)

被测试的课程:

public class DriverSnapshotHandler {

    public String getImageURL() {
        return FormatterService.getInstance().formatTachoIcon();
    }

}
Run Code Online (Sandbox Code Playgroud)

单元测试:

public class TestDriverSnapshotHandler {

    private FormatterService formatter;

    @Before
    public void setUp() {

        formatter = mock(FormatterService.class);

        when(FormatterService.getInstance()).thenReturn(formatter);

        when(formatter.formatTachoIcon()).thenReturn("MockedURL");

    }

    @Test
    public void testFormatterServiceIsCalled() { …
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing mocking mockito

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

Swing Worker中的优雅异常处理

我通过Swing Worker类在应用程序中使用线程.它工作正常,但我对在try-catch块中显示错误消息对话框感觉不好.它可能会阻止应用程序吗?这就是它现在的样子:

SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

    // Executed in background thread
    public Void doInBackground() {
        try {
            DoFancyStuff();
        } catch (Exception e) {

            e.printStackTrace();

            String msg = String.format("Unexpected problem: %s", e
                    .toString());

            //TODO: executed in background thread and should be executed in EDT?
            JOptionPane.showMessageDialog(Utils.getActiveFrame(),
                    msg, "Error", JOptionPane.ERROR_MESSAGE,
                    errorIcon);

        }//END: try-catch

        return null;
    }

    // Executed in event dispatch thread
    public void done() {
        System.out.println("Done");
    }
};
Run Code Online (Sandbox Code Playgroud)

可以使用Swing Worker框架以安全的方式完成吗?覆盖publish()方法在这里是一个很好的领导?

编辑:

它是这样的:

} catch (final Exception e) { …
Run Code Online (Sandbox Code Playgroud)

java swing exception-handling

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

在React TestUtils中模拟文件输入

我有一个具有以下渲染效果的组件:

  render: function() {
   <input
    type="file"
    name: this.props.name,
    className={this.props.className}
    onChange={this.props.handleChange}
    accept={this.props.accept}/>
 }
Run Code Online (Sandbox Code Playgroud)

State由一个容器管理,该容器使用jquery AJAX调用上传文件服务器端:

 getInitialState: function() {
   return {
     uploaded: false
  };
}

handleChange: function(event) {
event.preventDefault();

var file = event.target.files[0];
if (!file) {
  return;
}

var reader = new FileReader();
reader.readAsText(file, 'UTF-8');
var self = this;

reader.onload = function(e) {
  var content = e.target.result;

 var a =  $.ajax({
    type: 'PUT',
    url: 'http://localhost:8080/upload',
    contentType: 'application/json',
    dataType: "json",
    data: JSON.stringify({
      "input": content
    })
  })
  .fail(function(jqXHR, textStatus, errorThrown) {
    console.log("ERROR WHEN UPLOADING"); …
Run Code Online (Sandbox Code Playgroud)

unit-testing mocha.js fs reactjs reactjs-testutils

12
推荐指数
1
解决办法
1451
查看次数

Java 8流-合并地图集合

可以说我有一个带有以下签名的方法:

Map<String, String> merge (String[][] ... maps)
Run Code Online (Sandbox Code Playgroud)

它使用(可变)数量的二维映射数组来表示映射,例如:

        String[][] m1 = new String[][] {
            {"k1", "a"},
            {"k2", "b"}
        };

        String[][] m2 = new String[][] {
            {"k1", "a"},
            {"k2", "b"},
            {"k3", "c"}   
        };

        String[][] m3 = new String[][] {
            {"k1", "x"},
            {"k2", "b"}
        };
Run Code Online (Sandbox Code Playgroud)

现在,我可以像这样从左到右合并任意两个地图:

 Map<String, String> m1 = Stream.of(map1).collect(Collectors.toMap(k -> k[0], v -> v[1]));
 Map<String, String> m2 = Stream.of(map2).collect(Collectors.toMap(k -> k[0], v -> Optional.ofNullable(v[1]).orElse("null")));
 m1.forEach((key, value) -> m2.merge(key, value, (v1, v2) -> v1));
Run Code Online (Sandbox Code Playgroud)

但是我该如何合并各种数组映射的杂散数,以便在m1, m2, m3按照上面的定义通过之后,结果是:

        String[][] m3 …
Run Code Online (Sandbox Code Playgroud)

java java-8 java-stream

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