Skip to content

Commit b4bf8df

Browse files
committed
Disabled list stoage element-wise ops, fixed Mat5 dense loading, added debugging statements for list storage element-wise operations. Updated Manifest, History. Fixed it so VERSION shows up. Updated README
1 parent 5760056 commit b4bf8df

File tree

10 files changed

+45
-19
lines changed

10 files changed

+45
-19
lines changed

History.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* Initial alpha release
66

7-
=== 0.0.2 / 2012-08-??
7+
=== 0.0.2 / 2012-09-21
88

99
* Numerous major enhancements
1010

@@ -33,3 +33,7 @@
3333
* `==` operator now used for matrix equality, `=~` and `!~` for element-wise comparisons
3434

3535
* Dense `each` returns an Enumerator when called without a block
36+
37+
* Sped up list storage item deletion, fixed bugs
38+
39+
* Note: Element-wise list operations current disabled

Manifest.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ spec/nmatrix_spec.rb
1111
spec/nmatrix_yale_spec.rb
1212
spec/nvector_spec.rb
1313
spec/slice_spec.rb
14-
spec/io_spec.rb
14+
spec/elementwise_spec.rb
15+
spec/blas_spec.rb
16+
spec/lapack_spec.rb
1517
spec/spec_helper.rb
1618
lib/nmatrix.rb
1719
lib/nmatrix/io/mat5_reader.rb
@@ -41,6 +43,7 @@ ext/nmatrix/util/math.h
4143
ext/nmatrix/util/sl_list.cpp
4244
ext/nmatrix/util/sl_list.h
4345
ext/nmatrix/util/util.h
46+
ext/nmatrix/util/lapack.h
4447
ext/nmatrix/nmatrix.cpp
4548
ext/nmatrix/nmatrix.h
4649
ext/nmatrix/ruby_constants.cpp

README.rdoc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ are working on a {patch for Ruby/GSL}[https://github.com/SciRuby/rb-gsl].
2727

2828
== Features
2929

30-
The following features exist in the version of NMatrix (0.0.2) currently under development, and may or may not exist in
31-
0.0.1 (the current gem):
30+
The following features exist in the current version of NMatrix (0.0.2):
3231

3332
* Matrix storage containers: dense, yale, list (more to come)
3433
* Data types: uint8, int8, int16, int32, int64, float32, float64, complex64, complex128, rational64, rational128
@@ -45,17 +44,9 @@ The following features exist in the version of NMatrix (0.0.2) currently under d
4544
* xTRSM
4645
* LAPACK ATLAS access:
4746
* xGETRF (experimental)
48-
49-
=== Planned Features (Very Short Term)
50-
51-
These features will exist in our second alpha release, 0.0.2 (incomplete, thus not yet available as a gem):
52-
53-
* Yale matrix slicing and referencing
54-
* LU decomposition
5547
* LAPACK internal implementations (no library needed):
5648
* xGETRF
57-
58-
The estimated release date for 0.0.2 is the end of August 2012.
49+
* LU decomposition
5950

6051
=== Planned Features (Short-to-Medium Term)
6152

@@ -99,13 +90,14 @@ If you get errors about clapack.h or cblas.h, figure out where your ATLAS header
9990
Then, tell your system:
10091

10192
export C_INCLUDE_PATH=/usr/local/atlas/include
93+
export CPLUS_INCLUDE_PATH=/usr/local/atlas/include
10294

10395
Finally, try compiling again.
10496

10597
== REQUIREMENTS:
10698

10799
* ATLAS and LAPACK, probably
108-
* GCC 4.2
100+
* GCC 4.3
109101
* Ruby 1.9
110102

111103
== INSTALLATION:

ext/nmatrix/data/complex.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434

3535
#include <type_traits>
36+
#include <iostream>
3637

3738
/*
3839
* Project Includes
@@ -352,6 +353,12 @@ inline bool operator>=(const NativeType left, const Complex<ComplexType>& right)
352353
return Complex<ComplexType>(left) >= right;
353354
}
354355

356+
template <typename Type>
357+
inline std::ostream& operator<<(std::ostream& out, const Complex<Type>& rhs) {
358+
out << "(" << rhs.r << "," << rhs.i << "i)" << std::flush;
359+
return out;
360+
}
361+
355362
} // end of namespace nm
356363

357364
namespace std {

ext/nmatrix/data/rational.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <type_traits>
3636
#include <ruby.h>
37+
#include <iostream>
3738

3839
/*
3940
* Project Includes
@@ -401,6 +402,12 @@ inline bool operator>=(const NativeType left, const Rational<RationalType>& righ
401402
return (left > right) or (left == right);
402403
}
403404

405+
template <typename Type>
406+
inline std::ostream& operator<<(std::ostream& out, const Rational<Type>& rhs) {
407+
out << rhs.n << "/" << rhs.d << std::flush;
408+
return out;
409+
}
410+
404411
} // end of namespace nm
405412

406413
namespace std {

ext/nmatrix/data/ruby_object.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434

3535
#include <ruby.h>
36-
36+
#include <iostream>
3737
#include <type_traits>
3838

3939
/*
@@ -430,6 +430,11 @@ inline bool operator>(const Rational<IntType>& left, const RubyObject& right) {
430430
return RubyObject(left) > right;
431431
}
432432

433+
inline std::ostream& operator<<(std::ostream& out, const RubyObject& rhs) {
434+
out << "RUBYOBJECT" << std::flush; // FIXME: Try calling inspect or something on the Ruby object if we really need to debug it.
435+
return out;
436+
}
437+
433438
} // end of namespace nm
434439

435440
namespace std {

ext/nmatrix/nmatrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ static VALUE nm_xslice(int argc, VALUE* argv, void* (*slice_func)(STORAGE*, SLIC
11181118

11191119
static VALUE elementwise_op(nm::ewop_t op, VALUE left_val, VALUE right_val) {
11201120
STYPE_MARK_TABLE(mark);
1121-
1121+
11221122
static STORAGE* (*ew_op[nm::NUM_STYPES])(nm::ewop_t, const STORAGE*, const STORAGE*) = {
11231123
nm_dense_storage_ew_op,
11241124
nm_list_storage_ew_op,

ext/nmatrix/storage/list.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <ruby.h>
3434
#include <algorithm> // std::min
35+
#include <iostream>
3536

3637
/*
3738
* Project Includes
@@ -341,6 +342,8 @@ bool nm_list_storage_eqeq(const STORAGE* left, const STORAGE* right) {
341342
* Element-wise operations for list storage.
342343
*/
343344
STORAGE* nm_list_storage_ew_op(nm::ewop_t op, const STORAGE* left, const STORAGE* right) {
345+
rb_raise(rb_eNotImpError, "elementwise operations for list storage currently broken");
346+
344347
OP_LR_DTYPE_TEMPLATE_TABLE(nm::list_storage::ew_op, void*, LIST* dest, const LIST* left, const void* l_default, const LIST* right, const void* r_default, const size_t* shape, size_t dim);
345348

346349
// We may need to upcast our arguments to the same type.
@@ -989,6 +992,7 @@ static void ew_op_prime(LIST* dest, LDType d_default, const LIST* left, LDType l
989992

990993
if (level == last_level) {
991994
tmp_result = ew_op_switch<op, LDType, RDType>(l_default, *reinterpret_cast<RDType*>(r_node->val));
995+
std::cerr << "1. tmp_result = " << tmp_result << std::endl;
992996

993997
if (tmp_result != d_default) {
994998
dest_node = nm::list::insert_helper(dest, dest_node, index, tmp_result);
@@ -1013,6 +1017,7 @@ static void ew_op_prime(LIST* dest, LDType d_default, const LIST* left, LDType l
10131017

10141018
if (level == last_level) {
10151019
tmp_result = ew_op_switch<op, LDType, RDType>(*reinterpret_cast<LDType*>(l_node->val), r_default);
1020+
std::cerr << "2. tmp_result = " << tmp_result << std::endl;
10161021

10171022
if (tmp_result != d_default) {
10181023
dest_node = nm::list::insert_helper(dest, dest_node, index, tmp_result);
@@ -1038,6 +1043,7 @@ static void ew_op_prime(LIST* dest, LDType d_default, const LIST* left, LDType l
10381043

10391044
if (level == last_level) {
10401045
tmp_result = ew_op_switch<op, LDType, RDType>(*reinterpret_cast<LDType*>(l_node->val),*reinterpret_cast<RDType*>(r_node->val));
1046+
std::cerr << "3. tmp_result = " << tmp_result << std::endl;
10411047

10421048
if (tmp_result != d_default) {
10431049
dest_node = nm::list::insert_helper(dest, dest_node, index, tmp_result);

lib/nmatrix.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# NMatrix
3939

4040
require 'nmatrix/nmatrix.rb'
41+
require 'nmatrix/version.rb'
4142
require 'nmatrix/nvector.rb'
4243
require 'nmatrix/blas.rb'
4344

lib/nmatrix/io/mat5_reader.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def unpacked_data real_mdtype=nil, imag_mdtype=nil
147147

148148
unpacked_real.zip(unpacked_imag).flatten
149149
else
150-
self.real_part.data.unpack(real_unpack_args)
150+
length = self.dimensions.inject(1) { |a,b| a * b } # get the product
151+
self.real_part.data.unpack(*(real_unpack_args*length))
151152
end
152153

153154
end
@@ -252,11 +253,11 @@ def to_nm(dtype = nil)
252253
# MATLAB always uses :miINT32 for indices according to the spec
253254
ia_ja = repacked_indices(to_itype)
254255
data_str, repacked_dtype = repacked_data(dtype)
255-
NMatrix.new(:yale, self.dimensions, repacked_dtype, ia_ja[0], ia_ja[1], data_str, repacked_dtype)
256+
NMatrix.new(:yale, self.dimensions.reverse, repacked_dtype, ia_ja[0], ia_ja[1], data_str, repacked_dtype)
256257

257258
else
258259
# Call regular dense constructor.
259-
NMatrix.new(:dense, self.dimensions, unpacked_data, dtype)
260+
NMatrix.new(:dense, self.dimensions.reverse, unpacked_data, dtype).transpose
260261
end
261262
end
262263

0 commit comments

Comments
 (0)