Skip to content

RubyGrant 2020 related work #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add nmatrix_buffer struct
  • Loading branch information
Uditgulati committed Mar 29, 2021
commit 1f6ac41c2452187b7584221147cfd84993646b53
35 changes: 35 additions & 0 deletions ext/ruby_nmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@ static const rb_data_type_t nm_data_type = {
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

typedef struct NMATRIX_BUFFER_STRUCT
{
size_t count;
size_t ndims;
size_t* shape;
void* buffer_ele_start_ptr;
nmatrix* mat;
}nmatrix_buffer;

void nm_buffer_free(void* ptr);
size_t nm_buffer_memsize(const void* ptr);

static const rb_data_type_t nm_buffer_data_type = {
"numruby/nmatrix_buffer",
{
0,
nm_buffer_free,
nm_buffer_memsize,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

nmatrix* nmatrix_new(
nm_dtype dtype,
nm_stype stype,
Expand Down Expand Up @@ -875,6 +897,19 @@ size_t nm_memsize(const void* ptr){
return size;
}

void nm_buffer_free(void* ptr){
nmatrix_buffer *mat_buf = (nmatrix_buffer*)ptr;
if (mat_buf->shape) xfree(mat_buf->shape);
xfree(mat_buf);
}

size_t nm_buffer_memsize(const void* ptr){
nmatrix_buffer *mat_buf = (nmatrix_buffer*)ptr;
size_t size = sizeof(mat_buf);
if (mat_buf->shape) size += mat_buf->ndims;
return size;
}

// Returns number of dimensions of matrix
VALUE nm_get_dim(VALUE self){
nmatrix* input;
Expand Down