コード例 #1
0
ファイル: theano_ops.hpp プロジェクト: ml-ai-nlp-ir/CUV
void flip_dims(cuv::tensor<float,cuv::dev_memory_space>& dst, const cuv::tensor<float,cuv::dev_memory_space>& src, const cuv::extent_gen<D>& pattern) {
    assert(D == dst.ndim());
    bool p[D];
    for (int i = 0; i < D; ++i)
    {
        p[i] = pattern.ranges_[i].finish();
    }
    flip_dims2(dst,src, p);
}
コード例 #2
0
ファイル: io.hpp プロジェクト: OnlySang/CUV
		void save(Archive& ar, const cuv::tensor<V,MS, ML>& t, const unsigned int version){
			ar <<  t.info().host_shape
                << t.info().host_stride;
            ar << t.mem();
			if(t.ndim()>0 && t.mem()){
                long int i = (long int)t.ptr() - (long int)t.mem()->ptr();
                ar << i;
			}
		}
コード例 #3
0
    void dstack_mat2tens(cuv::tensor<float, cuv::host_memory_space>& tens,
            const std::vector<cv::Mat>& src, bool reverse){
        assert(src.size() >= 1);
        int d = src.size();
        int h = src.front().rows;
        int w = src.front().cols;

        tens.resize(cuv::extents[d][h][w]);
        for (int i = 0; i < d; ++i)
        {
            int other = reverse ? d-1-i : i;
            if(src[0].type() == CV_8UC1){
                typedef unsigned char src_dtype;
                cuv::tensor<src_dtype, cuv::host_memory_space> wrapped(cuv::extents[h][w], (src_dtype*) src[other].data);
                cuv::tensor<float, cuv::host_memory_space> view = cuv::tensor_view<float, cuv::host_memory_space>(tens, cuv::indices[i][cuv::index_range()][cuv::index_range()]);
                cuv::convert(view, wrapped); // copies memory
            }else if(src[0].type() == CV_32FC1){
                typedef float src_dtype;
                cuv::tensor<src_dtype, cuv::host_memory_space> wrapped(cuv::extents[h][w], (src_dtype*) src[other].data);
                cuv::tensor_view<float, cuv::host_memory_space> view(tens, cuv::indices[i][cuv::index_range()][cuv::index_range()]);
                view = wrapped; // copies memory
            }
        }
    }