Skip to content

Commit

Permalink
Merge pull request #33 from flipback/master
Browse files Browse the repository at this point in the history
Fixed list-to-yale copying.
  • Loading branch information
translunar committed Sep 7, 2012
2 parents 27f0b6e + 7b4cc28 commit 5068126
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
16 changes: 10 additions & 6 deletions ext/nmatrix/storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ namespace yale_storage { // FIXME: Move to yale.cpp
YALE_STORAGE* lhs = nm_yale_storage_create(l_dtype, shape, 2, shape[0] + ndnz + 1);

if (lhs->capacity < request_capacity)
rb_raise(nm_eStorageTypeError, "conversion failed; capacity of %d requested, max allowable is %d", request_capacity, lhs->capacity);
rb_raise(nm_eStorageTypeError, "conversion failed; capacity of %d requested, max allowable is %d", (int)request_capacity, (int)lhs->capacity);

LDType* lhs_a = reinterpret_cast<LDType*>(lhs->a);
LIType* lhs_ija = reinterpret_cast<LIType*>(lhs->ija);
Expand Down Expand Up @@ -552,7 +552,7 @@ namespace yale_storage { // FIXME: Move to yale.cpp
YALE_STORAGE* lhs = nm_yale_storage_create(l_dtype, shape, 2, request_capacity);

if (lhs->capacity < request_capacity)
rb_raise(nm_eStorageTypeError, "conversion failed; capacity of %d requested, max allowable is %d", request_capacity, lhs->capacity);
rb_raise(nm_eStorageTypeError, "conversion failed; capacity of %d requested, max allowable is %d", (int)request_capacity, (int)lhs->capacity);

// Initialize the A and IJA arrays
init<LDType,LIType>(lhs);
Expand All @@ -564,24 +564,28 @@ namespace yale_storage { // FIXME: Move to yale.cpp

for (NODE* i_curr = rhs->rows->first; i_curr; i_curr = i_curr->next) {

// indicate the beginning of a row in the IJA array
lhs_ija[i_curr->key] = ija;

for (NODE* j_curr = ((LIST*)(i_curr->val))->first; j_curr; j_curr = j_curr->next) {
LDType cast_jcurr_val = *reinterpret_cast<RDType*>(j_curr->val);

if (i_curr->key == j_curr->key)
lhs_a[i_curr->key] = cast_jcurr_val; // set diagonal
else {

lhs_ija[ija] = j_curr->key; // set column value

lhs_a[ija] = cast_jcurr_val; // set cell value

++ija;

// indicate the beginning of a row in the IJA array
for (size_t i = i_curr->key + 1; i < shape[0]; ++i) {
lhs_ija[i] = ija;
}

}
}

if (!i_curr->next) lhs_ija[i_curr->key] = ija; // indicate the end of the last row
if (!i_curr->next) lhs_ija[rhs->shape[0]] = ija; // indicate the end of the last row
}

lhs->ndnz = ndnz;
Expand Down
4 changes: 3 additions & 1 deletion spec/nmatrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,16 @@

it "converts from list to yale properly" do
m = NMatrix.new(:list, 3, 0)
m[0,2] = 333
m[2,2] = 777
n = m.cast(:yale, :int32)
puts n.capacity
n.extend NMatrix::YaleFunctions
puts n.yale_ija.inspect
puts n.yale_a.inspect
n[0,0].should == 0
n[0,1].should == 0
n[0,2].should == 0
n[0,2].should == 333
n[1,0].should == 0
n[1,1].should == 0
n[1,2].should == 0
Expand Down
2 changes: 1 addition & 1 deletion spec/slice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@

[:dense, :list, :yale].each do |cast_type|
it "should cast from #{stype.upcase} to #{cast_type.upcase}" do
nm_eql(@m[1..2, 1..2].cast(cast_type, :int32), @m[1..2,1..2]).should be_true
nm_eql(@m[1..2, 0..2].cast(cast_type, :int32), @m[1..2,0..2]).should be_true
end
end
end
Expand Down

0 comments on commit 5068126

Please sign in to comment.