我正在寻找一种方法来提供一个带模板(STL)容器的函数,但需要它的元素是某种类型(例如int).
这些函数调用应该是VALID:
std::vector<int> Argument;
void foo( Argument );
std::list<int> Argument
void foo( Argument );
std::deque<int> Argument
void foo( Argument );
...etc
Run Code Online (Sandbox Code Playgroud)
这些函数调用应该是INVALID:
std::vector<float> Argument;
void foo( Argument );
std::list<double> Argument
void foo( Argument );
std::deque<char> Argument
void foo( Argument );
...etc
Run Code Online (Sandbox Code Playgroud)
有没有办法模板"foo",以便int接受容器,但不接受具有不同元素类型的容器?
最好,本
尝试在Windows上使用CMAKE配置OpenCV时出现以下错误:
CMake Warning at cmake/OpenCVUtils.cmake:865 (message):
Download: Local copy of opencv_ffmpeg.dll has invalid MD5 hash:
d41d8cd98f00b204e9800998ecf8427e (expected:
89c783eee1c47bfc733f08334ec2e31c)
Call Stack (most recent call first):
3rdparty/ffmpeg/ffmpeg.cmake:10 (ocv_download)
cmake/OpenCVFindLibsVideo.cmake:193 (include)
CMakeLists.txt:527 (include)
Downloading opencv_ffmpeg.dll...
CMake Error at cmake/OpenCVUtils.cmake:888 (file):
file DOWNLOAD MD5 mismatch
for file: [C:/research/opencv300/sources/3rdparty/ffmpeg/downloads/89c783eee1c47bfc733f08334ec2e31c/opencv_ffmpeg.dll]
expected MD5 sum: [89c783eee1c47bfc733f08334ec2e31c]
actual MD5 sum: [d41d8cd98f00b204e9800998ecf8427e]
Call Stack (most recent call first):
3rdparty/ffmpeg/ffmpeg.cmake:10 (ocv_download)
cmake/OpenCVFindLibsVideo.cmake:193 (include)
CMakeLists.txt:527 (include)
CMake Error at cmake/OpenCVUtils.cmake:892 (message):
Failed to download opencv_ffmpeg.dll. Status=1;"unsupported protocol"
Call Stack (most recent call …Run Code Online (Sandbox Code Playgroud) 好吧,所以,我写了一些代码来检查,运行时有多少内存可用.整个(最小)cpp文件如下.
注意:代码并不完美而不是最佳实践,但我希望您可以专注于内存管理而不是代码.
它的作用(第一部分):
- >这很好用
它的作用(第二部分):
- >这表现得很奇怪!
问题是:如果我重复一遍,我只能为后续运行的secons分配522kb --->?
如果分配的块具有例如16MB的大小,则不会发生这种情况.
你有什么想法,为什么会这样?
// AvailableMemoryTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <list>
#include <limits.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
auto determineMaxAvailableMemoryBlock = []( void ) -> int
{
int nBytes = std::numeric_limits< int >::max();
while ( true )
{
try
{
std::vector< char >vec( nBytes );
break;
}
catch ( std::exception& ex )
{
nBytes …Run Code Online (Sandbox Code Playgroud) 是否有可能有一个using范围仅限于一个类的指令?
请注意,我想要"使用"的内容不包含在当前类的父级中.
为简单起见,假设以下例子:
#include<vector>
class foo
{
using std::vector; //Error, a class-qualified name is required
}
Run Code Online (Sandbox Code Playgroud)
另一个有趣的事情是,如果using包含指令,如果包含头:
MyClassFoo.h:
#include<vector>
using std::vector; //OK
class foo
{
}
Run Code Online (Sandbox Code Playgroud)
并在
NewHeader.h
#include "MyClassFoo.h"
...
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止" using std::vector"在这里可见?
If I extract a submatrix from a matrix using
cv::Mat A = cv::Mat::ones(4,4);
cv::Mat B = A( cv::Rect( 1, 1, 2, 2 ) );
Run Code Online (Sandbox Code Playgroud)
Is "B" a copy of those values from "A" or does it reference to those values?
Could you provide an example of how to get
(1)子矩阵的副本?
(2)对子矩阵的引用?
所以,我想设置一个__m256i寄存器的单个位。
说,我的__m256icontains: [ 1 0 1 0 | 1 0 1 0 | ... | 1 0 1 0 ],我如何设置和取消设置第 n 位?
我有相同的代码,但AVX版本比SSE版本低得多.有人可以解释一下吗?
我已经做过的是我尝试使用VerySleepy来分析代码,但这不能给我任何有用的结果,它只是证实它更慢......
我已经查看了SSE/AVX指南和我的CPU(Haswell)中的命令,他们需要相同的延迟/吞吐量,只需要水平添加需要AVX的附加命令...
**延迟和吞吐量**
_mm_mul_ps -> L 5, T 0.5
_mm256_mul_ps -> L 5, T 0.5
_mm_hadd_ps -> L 5, T 2
_mm256_hadd_ps -> L 5, T ?
_mm256_extractf128_ps -> L 1, T 1
Run Code Online (Sandbox Code Playgroud)
代码的作用摘要: Final1 = SUM(m_Array1*m_Array1*m_Array3*m_Array3)
Final2 = SUM(m_Array2*m_Array2*m_Array3*m_Array3)
Final3 = SUM(m_Array1*m_Array2*m_Array3*m_Array3)
在里面
float Final1 = 0.0f;
float Final2 = 0.0f;
float Final3 = 0.0f;
float* m_Array1 = (float*)_mm_malloc( 32 * sizeof( float ), 32 );
float* m_Array2 = (float*)_mm_malloc( 32 * sizeof( float ), 32 );
float* …Run Code Online (Sandbox Code Playgroud) 我想定义一个函数,它接受一个lambda函数(除了通常的输入参数).我想尽可能地限制该函数(它自己的输入和返回类型).
int myfunc( const int a, LAMBDA_TYPE (int, int) -> int mylamda )
{
return mylambda( a, a ) * 2;
}
Run Code Online (Sandbox Code Playgroud)
这样我可以调用函数如下:
int input = 5;
myfunc( input, [](int a, int b) { return a*b; } );
Run Code Online (Sandbox Code Playgroud)
定义的正确方法是myfunc什么?
有没有办法定义默认的lambda?像这样:
int myfunc( const int a, LAMBDA_TYPE = [](int a, int b) { return a*b; });
Run Code Online (Sandbox Code Playgroud) 我正在尝试在GTX 970上运行CNN网络"CAFFE".但是我收到了标题中提到的错误.
有人可以帮忙吗?
我发布了关于caffe组的更多细节的问题,但没有得到任何提示/答案!
https://groups.google.com/forum/#!topic/caffe-users/sVOfE0qhf_M
更新1
在我的Makefile.config中,我添加了 -gencode arch=compute_52,code=compute_52
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=compute_50 \
-gencode arch=compute_52,code=compute_52
Run Code Online (Sandbox Code Playgroud)
但是当我尝试制作时,它会返回:
$make
NVCC src/caffe/layers/cudnn_sigmoid_layer.cu
nvcc fatal : Unsupported gpu architecture 'compute_52'
Makefile:531: recipe for target '.build_release/cuda/src/caffe/layers/cudnn_sigmoid_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/cudnn_sigmoid_layer.o] Error 1
Run Code Online (Sandbox Code Playgroud)
更新2
NCC版本是:
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2014 NVIDIA Corporation
Built on Thu_Jul_17_21:41:27_CDT_2014
Cuda compilation tools, release 6.5, V6.5.12
Run Code Online (Sandbox Code Playgroud)
更新3
我正在使用带有346.96驱动程序的CUDA …
给出一个std :: list
std::list< int > myList
Run Code Online (Sandbox Code Playgroud)
以及该列表中元素的引用(或指针)
int& myElement | int* pElement
Run Code Online (Sandbox Code Playgroud)
所以,基本上我知道那个元素的地址
如何有效地获得std::list<int>::iterator该元素?
一个缓慢但有效的例子是
const_iterator it
for( it = myList.begin(); it != &myElement; ++it)
{
// do nothing, for loop terminates if "it" points to "myElem"
}
Run Code Online (Sandbox Code Playgroud)
有更快的方法吗?喜欢
const_iterator it = magicToIteratorConverter( myList, myElem )
Run Code Online (Sandbox Code Playgroud)
对于矢量,您可以执行以下操作:
const int* pStart = &myVector[0] // address of first element
const int* pElement = &myElem; // address of my element
const idx = static_cast< int >( pElement- pStart ); …Run Code Online (Sandbox Code Playgroud) 问题说明了一切:是
for( int k = 5; k--;)
Run Code Online (Sandbox Code Playgroud)
比...快
for( int k = 4; k > -1; --k)
Run Code Online (Sandbox Code Playgroud)
为什么?
编辑: 我在MSVC2012中生成了用于调试和发布的程序集.但是(这是我第一次分析汇编代码),我真的无法理解它.我alredy添加了"std :: cout"以防止编译器在发布优化期间删除这两个循环.有人可以帮我解决装配意味着什么吗?
调试:
; 10 : for( int k = 5; k--;){ std::cout << k; }
mov DWORD PTR _k$2[ebp], 5
$LN5@wmain:
mov eax, DWORD PTR _k$2[ebp]
mov DWORD PTR tv65[ebp], eax
mov ecx, DWORD PTR _k$2[ebp]
sub ecx, 1
mov DWORD PTR _k$2[ebp], ecx
cmp DWORD PTR tv65[ebp], 0
je SHORT $LN4@wmain
mov esi, esp
mov eax, DWORD PTR …Run Code Online (Sandbox Code Playgroud)