Added tensor constructors and get_raw_data to work with pointers of p… by sohailreddy · Pull Request #202 · serizba/cppflow · GitHub
Skip to content

Added tensor constructors and get_raw_data to work with pointers of p…#202

Open
sohailreddy wants to merge 3 commits into
serizba:masterfrom
sohailreddy:master
Open

Added tensor constructors and get_raw_data to work with pointers of p…#202
sohailreddy wants to merge 3 commits into
serizba:masterfrom
sohailreddy:master

Conversation

@sohailreddy

Copy link
Copy Markdown

Since most scientific computing codes don't use std::vector and use their own containers, new tensor constructor and get_raw_data functions were added to work with pointers of primitive types.

@serizba

serizba commented Jul 21, 2022

Copy link
Copy Markdown
Owner

…y. Now also return the size of the raw pointer

 Committer: Sohail Reddy <sredd001@fiu.edu>
@sohailreddy

Copy link
Copy Markdown
Author

Hi @serizba , Great point!! I updated the tensor::get_data() to use tensor::get_raw_data(size_t &size). Had to make some more changes since we need to know the size of the pointer to convert to the std::vector.
Also added a default/empty constructor for cppflow::model, so that we can declare it without needing to initialize

Let me know what you think!

@serizba

serizba commented Sep 23, 2022

Copy link
Copy Markdown
Owner

Good work! Sorry for not attending this earlier. I will fix the conflicts myself and merge it. This is required.

@sohailreddy

Copy link
Copy Markdown
Author

Thanks for taking care of this @serizba
Any idea when it'll make it into the main branch? We have some projects that would like to use it

@DemO-O-On

Copy link
Copy Markdown

Hello, I'm a newbuy in C++ and I have a question: can I create cppflow::tensor from 2-dimensional vector or array? I've tried

std::vector<std::vector<int64_t>> data {{1,2,3}, {4,5,6}};

std::vector<int64_t> shape{2,3};

auto b = cppflow::tensor(data, shape);

but it dropped me

terminate called after throwing an instance of 'std::runtime_error'
  what():  Could not deduce type! type_name: St6vectorIxSaIxEE

What am I doing wrong?

@sohailreddy

Copy link
Copy Markdown
Author

It won't work with multi-dimensional vector/array as inputs. You would need to create a single vector containing all the elements of the multi-dim. vector (or tensor) and then pass the pointer to this raw data, along with the length of each dimension to the cppflow::tensor() constructor.

std::vector<int64_t> shape{2,3};
std::vector<int64_t> long_vector(6);  // Length should be product of all dims
auto b = cppflow::tensor(long_vector.data(), shape);

@DemO-O-On

DemO-O-On commented Aug 1, 2023

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants