Created
February 3, 2019 10:31
-
-
Save kris-singh/ce5fbdb8aa242ed3357d27c3e8fdea5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <torch/torch.h> | |
#include <iostream> | |
#include <ATen/Parallel.h> | |
#include <ATen/Aten.h> | |
using namespace at; | |
// using namespace torch; | |
void submodular_select(Tensor candidate_points, Tensor features_done, Tensor features) | |
{ | |
int max_idx = -1; | |
float max_value = -1e-9; | |
for (int i=0; i < candidate_points.size(0); i++) | |
{ | |
std::vector<Tensor> temp; | |
if (candidate_points.item<int>() == 1) | |
{ | |
temp.push_back(features_done); | |
temp.push_back(features[candidate_points[i]]); | |
auto stacked_temp = stack(temp); | |
std::cout << std::get<0>(stacked_temp.max(1,false)) << std::endl; | |
float value = std::get<0>(stacked_temp.max(1,false)).sum().item<float>(); | |
if (value > max_value) | |
{ | |
max_value = value; | |
max_idx = i; | |
} | |
} | |
} | |
std::cout<<"Max Value" << max_value << std::endl; | |
std::cout << "Max Index" << max_idx << std::endl; | |
// return max_idx; | |
} | |
int main() | |
{ | |
int num_data_points = 6000; | |
int num_features = 256; | |
int batch_size = 64; | |
Tensor features = randn({num_data_points, num_features}, kFloat); | |
Tensor done = randint(0, num_data_points, batch_size*4, kLong); // Already Sampled Points | |
Tensor done_index = arange(0, batch_size*3, kLong).squeeze(); | |
Tensor features_done = features.index(done_index); | |
Tensor candidate_points = ones(num_data_points, kLong); | |
auto scatter_val = torch::zeros(num_data_points, kLong); | |
candidate_points = candidate_points.scatter_(0, done, scatter_val); | |
for (int batch=0; batch < batch_size; batch++) | |
{ | |
submodular_select(candidate_points, features_done, features); | |
// std::cout<<max_idx<<std::endl; | |
// done[batch_size*3+1] = max_idx; | |
// features_done = features[done[batch_size*3+batch+1]]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current executable set to './temp' (x86_64).
(lldb) run
Process 3387 launched: './temp' (x86_64)
libc++abi.dylib: terminating with uncaught exception of type c10::Error: Cannot use PyTorch operations on a half-constructed tensor. If this tensor came from Caffe2, please call GetMutableData on it first; otherwise, this is a bug, please report it. (THTensor_getStoragePtr at /Users/administrator/nightlies/2018_11_27/wheel_build_dirs/conda_3.6/conda/conda-bld/pytorch-nightly_1543314874223/work/aten/src/TH/THTensor.hpp:39)
frame #0: c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::_1::char_traits, std::1::allocator > const&) + 135 (0x103f8ae27 in libc10.dylib)
frame #1: THTensor_getStoragePtr(at::TensorImpl const*) + 213 (0x1016d4a85 in libcaffe2.dylib)
frame #2: THLongTensor_scatter + 2325 (0x101edfd05 in libcaffe2.dylib)
frame #3: at::CPULongType::th_scatter(at::Tensor&, long long, at::Tensor const&, at::Tensor const&) const + 155 (0x1018d9fcb in libcaffe2.dylib)
frame #4: at::native::scatter(at::Tensor&, long long, at::Tensor const&, at::Tensor const&) + 53 (0x101648965 in libcaffe2.dylib)
frame #5: at::TypeDefault::scatter(at::Tensor&, long long, at::Tensor const&, at::Tensor const&) const + 250 (0x1019a6aca in libcaffe2.dylib)
frame #6: at::Tensor::scatter(long long, at::Tensor const&, at::Tensor const&) + 94 (0x10000472e in temp)
frame #7: main + 722 (0x100003722 in temp)
frame #8: start + 1 (0x7fff654e8015 in libdyld.dylib)
Process 3387 stopped
frame #0: 0x00007fff65638b66 libsystem_kernel.dylib
__pthread_kill + 10 libsystem_kernel.dylib
__pthread_kill:-> 0x7fff65638b66 <+10>: jae 0x7fff65638b70 ; <+20>
0x7fff65638b68 <+12>: movq %rax, %rdi
0x7fff65638b6b <+15>: jmp 0x7fff6562fae9 ; cerror_nocancel
0x7fff65638b70 <+20>: retq
Target 0: (temp) stopped.