Skip to content

Commit

Permalink
Fix returned self in SylphideMath.i to satisfy equality
Browse files Browse the repository at this point in the history
  • Loading branch information
fenrir-naru committed Oct 7, 2024
1 parent a6b6b55 commit 2d9e9d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions tool/swig/SylphideMath.i
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ struct MatrixUtil {
std::string("Unknown enumerate direction: ").append(inspect_str($1)).c_str());
}
}
%typemap(out) const Matrix_Frozen<T, Array2D_Type, ViewType> & "$result = self;"
%catches(native_exception) each;
const Matrix_Frozen<T, Array2D_Type, ViewType> &each(
void (*each_func)(
Expand All @@ -970,6 +971,7 @@ struct MatrixUtil {
return *$self;
}
%alias each "each_with_index";
%typemap(out) const Matrix_Frozen<T, Array2D_Type, ViewType> &;

%catches(native_exception, std::invalid_argument) map;
Matrix<T, Array2D_Dense<T> > map(
Expand Down Expand Up @@ -1396,6 +1398,7 @@ INSTANTIATE_MATRIX_PARTIAL(type, Array2D_Dense<type >, MatView_pt, MatView_pt);
#endif
else{SWIG_exception(SWIG_TypeError, "$*1_ltype is expected");}
}
%typemap(out) Matrix<type, Array2D_Dense<type > > & "$result = self;"
Matrix<type, Array2D_Dense<type > > &resize(
const unsigned int *r_p, const unsigned int *c_p){
unsigned int r(r_p ? *r_p : $self->rows()), c(c_p ? *c_p : $self->columns());
Expand All @@ -1406,6 +1409,8 @@ INSTANTIATE_MATRIX_PARTIAL(type, Array2D_Dense<type >, MatView_pt, MatView_pt);
mat_new.partial(r_min, c_min).replace($self->partial(r_min, c_min), false);
return (*($self) = mat_new);
}
%clear Matrix<type, Array2D_Dense<type > > &;
//%typemap(in) unsigned int *r_p, unsigned int *c_p; // NG; remove custom typemap before Matrix::resize! generation
%clear unsigned int *r_p, unsigned int *c_p; // OK, work around version
};
Expand Down
10 changes: 6 additions & 4 deletions tool/swig/spec/SylphideMath_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
].each{|arg|
mat_orig = mat[0].copy
mat_replaced = arg.kind_of?(Proc) ? mat_orig.send(:replace!, &arg) : mat_orig.send(:replace!, arg)
expect(mat_replaced).to equal(mat_orig)
expect(mat_replaced).to be(mat_orig)
expect(mat_replaced).not_to equal(mat[1])
expect(mat_replaced.to_a).to eq(mat[1].to_a)
}
Expand All @@ -306,7 +306,7 @@
idxs[a], idxs[b] = [b, a]
mat_builtin = Matrix::columns(mat_builtin.column_vectors.values_at(*idxs))
end
expect(mat_mod).to equal(mat[0])
expect(mat_mod).to be(mat[0])
expect(mat[0].to_a).to eq(mat_builtin.to_a)
}
}
Expand Down Expand Up @@ -391,11 +391,12 @@
candidates = (func.to_s =~ /with_index$/) \
? indices.collect{|i, j| [compare_with[i][j], i, j]} \
: indices.collect{|i, j| [compare_with[i][j]]}
mat.send(*[func, k].compact){|*v|
mat2 = mat.send(*[func, k].compact){|*v|
i = candidates.find_index(v)
expect(i).not_to be(nil)
candidates.delete_at(i)
}
expect(mat2).to be(mat)
expect(candidates.empty?).to be(true)
}
}
Expand Down Expand Up @@ -449,7 +450,7 @@
v[0] * 2
}
expect(candidates.empty?).to be(true)
expect(mat2.to_a).to eq(mat.to_a)
expect(mat2).to be(mat)
expect(mat2.to_a).to eq(compare_with.collect.with_index{|values, i|
values.collect.with_index{|v, j|
indices.include?([i, j]) ? (v * 2) : v
Expand Down Expand Up @@ -541,6 +542,7 @@
}
mat_orig = mat[0].to_a
r, c = [:rows, :columns].collect{|f| mat[0].send(f)}
expect(mat[0].resize!(r, c)).to be(mat[0])
expect(mat[0].resize!(r, c).to_a).to eq(mat_orig)
expect(mat[0].resize!(r, nil).to_a).to eq(mat_orig)
expect(mat[0].resize!(nil, c).to_a).to eq(mat_orig)
Expand Down

0 comments on commit 2d9e9d7

Please sign in to comment.