小编Tob*_*ann的帖子

如何使用JpaRepository进行批量(多行)插入?

当从服务层调用long 的saveAll方法时,Hibernate的跟踪日志记录显示每个实体发出的单个SQL语句.JpaRepositoryList<Entity>

我可以强制它进行批量插入(即多行)而无需手动操作EntityManger,事务等甚至原始SQL语句字符串?

对于多行插入,我的意思不仅仅是从:

start transaction
INSERT INTO table VALUES (1, 2)
end transaction
start transaction
INSERT INTO table VALUES (3, 4)
end transaction
start transaction
INSERT INTO table VALUES (5, 6)
end transaction
Run Code Online (Sandbox Code Playgroud)

至:

start transaction
INSERT INTO table VALUES (1, 2)
INSERT INTO table VALUES (3, 4)
INSERT INTO table VALUES (5, 6)
end transaction
Run Code Online (Sandbox Code Playgroud)

而是:

start transaction
INSERT INTO table VALUES (1, 2), (3, 4), (5, 6)
end transaction
Run Code Online (Sandbox Code Playgroud)

在PROD中,我使用的是CockroachDB,性能差异很大.

下面是一个重现问题的简单示例(H2为简单起见). …

hibernate spring-data-jpa kotlin spring-boot cockroachdb

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

keras与tensorflow.python.keras - 使用哪一个?

哪一种是使用Keras的推荐(或更具前瞻性的)方式?

每个的优点/缺点是什么?

我想有更多的区别,而不仅仅是保存pip install一步而tensorflow.python.keras不是写keras.

python pip deep-learning keras tensorflow

26
推荐指数
2
解决办法
3952
查看次数

在转换为std :: optional <T>时,Clang和GCC的结果不同

给出以下代码:

#include <iostream>
#include <optional>

struct foo
{
    explicit operator std::optional<int>() {
        return std::optional<int>( 1 );
    }
    explicit operator int() {
        return 0;
    }
};

int main()
{
    foo my_foo;
    std::optional<int> my_opt( my_foo );
    std::cout << "value: " << my_opt.value() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

gcc 7.2.0写道 value: 1.

MSVC 2017(15.3)和clang 4.0.0然而写 value: 0.

根据C++标准,哪一个是正确的?

c++ g++ optional clang++ c++17

20
推荐指数
1
解决办法
529
查看次数

在travis上使用不同的libc ++版本进行clang

Travis使用Ubuntu Trusty和默认的libc ++版本svn199600.

但是,我想测试不同的(较新的)版本,因为我已经使用不同的clang版本.

我目前的情况.travis.yml如下:

language: generic

dist: trusty
sudo: required

matrix:
    include:
    - env: CXX=g++-7 CC=gcc-7
      addons:
        apt:
          packages:
            - g++-7
          sources: &sources
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise
            - llvm-toolchain-precise-3.9
            - llvm-toolchain-precise-3.8
            - llvm-toolchain-precise-3.7
            - llvm-toolchain-precise-3.6
            - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'
              key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'
    - env: CXX=g++-6 CC=gcc-6
      addons:
        apt:
          packages:
            - g++-6
          sources: *sources
    - env: CXX=g++-5 CC=gcc-5
      addons:
        apt:
          packages:
            - g++-5
          sources: *sources
    - env: CXX=g++-4.9 CC=gcc-4.9
      addons:
        apt:
          packages:
            - g++-4.9
          sources: …
Run Code Online (Sandbox Code Playgroud)

c++ makefile apt-get travis-ci libc++

20
推荐指数
1
解决办法
865
查看次数

lambda中引用捕获对象的类型

以下代码适用于gcc

#include <map>

int main() {
    std::map<int, double> dict;
    const auto lambda = [&]()
    {
        decltype(dict)::value_type bar;
    };
}
Run Code Online (Sandbox Code Playgroud)

但对于msvc我还要另外使用std::remove_reference

#include <map>
#include <type_traits>

int main() {
    std::map<int, double> dict;
    const auto lambda = [&]()
    {
        std::remove_reference_t<decltype(dict)>::value_type bar;
    };
}
Run Code Online (Sandbox Code Playgroud)

否则我收到一个错误:

error C2651: 'std::map<int,double,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>> &': left of '::' must be a class, struct or union
Run Code Online (Sandbox Code Playgroud)

哪个编译器根据标准显示正确的行为?

更新:

对于msvc decltype(dict)确实是一个参考,如下面的代码

#include <map>

int main()
{
    std::map<int, double> dict;
    const auto lambda = …
Run Code Online (Sandbox Code Playgroud)

c++ lambda decltype language-lawyer

17
推荐指数
1
解决办法
412
查看次数

检查一组类型是否是另一组的子集

如何检查一个参数包(解释为一组)是否是另一个参数包的子集?

到目前为止,我只有框架(使用std :: tuple),但没有功能.

#include <tuple>
#include <type_traits>

template <typename, typename>
struct is_subset_of : std::false_type
{
};

template <typename ... Types1, typename ... Types2>
struct is_subset_of<std::tuple<Types1...>, std::tuple<Types2...>>
    : std::true_type
{
    // Should only be true_type if Types1 is a subset of Types2
};

int main() {
    using t1 = std::tuple<int, double>;
    using t2 = std::tuple<double, int>;
    using t3 = std::tuple<int, double, char>;

    static_assert(is_subset_of<t1, t1>::value, "err");
    static_assert(is_subset_of<t1, t2>::value, "err");
    static_assert(is_subset_of<t2, t1>::value, "err");
    static_assert(is_subset_of<t2, t3>::value, "err");
    static_assert(!is_subset_of<t3, t2>::value, "err");
}
Run Code Online (Sandbox Code Playgroud)

每个类型不允许在一个集合中出现多次.

如果解决方案适用于C++ …

c++ templates template-meta-programming variadic-templates c++11

17
推荐指数
2
解决办法
2371
查看次数

寻找堆栈损坏错误的解释

以下问题是从一个庞大的项目中提炼出来的,这是我能够提出的最小问题的例子.

我知道,源于std::string它是坏的,它已经在我们的代码库中发生了变化,但我试图了解这里发生的事情.

代码在Visual C++ 2017上崩溃

Microsoft Visual Studio Community 2017 
Version 15.2 (26430.14) Release
Visual C++ 2017   00369-60000-00001-AA257
Run Code Online (Sandbox Code Playgroud)

仅在发布模式下(具有速度优化).没有速度优化,它不会在发布模式下崩溃.

#include <string>
#include <string_view>
#include <vector>

struct my_string : public std::string
{
    __declspec(noinline)
        my_string::my_string( const std::string_view& str ) :
        std::string( str.data(), str.size() )
    {}

    template <typename T>
    my_string& arg( T )
    {
        return *this;
    }
};

struct my_string_view : public std::string_view
{
    my_string_view( const std::string_view::value_type* val ) :
        std::string_view( val ) {}

    template <typename... PARAMS>
    my_string arg( PARAMS&&... prms …
Run Code Online (Sandbox Code Playgroud)

c++ optimization stack-corruption c++11 visual-studio-2017

16
推荐指数
1
解决办法
510
查看次数

最多3个值,左关联版本与右关联版本的性能

以下代码显示了min_3我的计算机上的两个版本(Windows 7,VC++ 2015,发行版)的巨大性能差异.

#include <algorithm>
#include <chrono>
#include <iostream>
#include <random>

template <typename X>
const X& max_3_left( const X& a, const X& b, const X& c )
{
    return std::max( std::max( a, b ), c );
}

template <typename X>
const X& max_3_right( const X& a, const X& b, const X& c )
{
    return std::max( a, std::max( b, c ) );
}

int main()
{
    std::random_device r;
    std::default_random_engine e1( r() );
    std::uniform_int_distribution<int> uniform_dist( 1, 6 );
    std::vector<int> …
Run Code Online (Sandbox Code Playgroud)

c++ performance visual-c++

15
推荐指数
1
解决办法
243
查看次数

返回的通用lambda的参数据称是自由函数的阴影参数

编译以下代码

template <typename X, typename F>
auto apply(X x, F f)
{
    return f(x);
}

template <typename Y>
auto add_value(Y y)
{
    return [y](auto x)
    {
        return x + y;
    };
}

int main()
{
    apply(1, add_value(2));
}
Run Code Online (Sandbox Code Playgroud)

用g ++(egv 5.4)给出阴影警告.

$ g++ -Wshadow -Werror -std=c++14 shadow_test.cpp 
shadow_test.cpp: In instantiation of ‘add_value(Y)::<lambda(auto:1)> [with auto:1 = int; Y = int]’:
shadow_test.cpp:4:13:   required from ‘auto apply(X, F) [with X = int; F = add_value(Y) [with Y = int]::<lambda(auto:1)>]’
shadow_test.cpp:18:26:   required …
Run Code Online (Sandbox Code Playgroud)

c++ gcc g++ gcc-warning c++14

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

查找并绘制回归平面到一组点

我想在一些数据点上安装一个平面并绘制它.我目前的代码是这样的:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

points = [(1.1,2.1,8.1),
          (3.2,4.2,8.0),
          (5.3,1.3,8.2),
          (3.4,2.4,8.3),
          (1.5,4.5,8.0)]

xs, ys, zs = zip(*points)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.scatter(xs, ys, zs)

point  = np.array([0.0, 0.0, 8.1])
normal = np.array([0.0, 0.0, 1.0])
d = -point.dot(normal)
xx, yy = np.meshgrid([-5,10], [-5,10])
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]
ax.plot_surface(xx, yy, z, alpha=0.2, color=[0,1,0])

ax.set_xlim(-10,10)
ax.set_ylim(-10,10)
ax.set_zlim(  0,10)

plt.show()
Run Code Online (Sandbox Code Playgroud)

这导致以下结果: 手动创建平面

正如您所看到的那样,我手动创建平面.我怎么计算呢?我猜这有可能以scipy.optimize.minimize …

python regression numpy matplotlib scipy

11
推荐指数
2
解决办法
8473
查看次数