Skip to content

Commit

Permalink
Merge branch 'master' into jruby_port
Browse files Browse the repository at this point in the history
  • Loading branch information
prasunanand committed Sep 25, 2016
2 parents 3830c43 + 7f3fa5d commit a7d85ef
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 494 deletions.
109 changes: 109 additions & 0 deletions History.txt
Expand Up @@ -779,3 +779,112 @@

* Fixed undefined variable 'idefaults' in lapacke extconf
(by @agisga)

=== 0.2.2 / 2016-07-22

* No major enhancements.

* 15 minor enhancements:

* Added Hilbert and inverse Hilbert matrix functions
#hilbert and #inv_hilbert (by @arafatk)

* Added NMatrix.linspace constructor for generating a
vector with linearly spaced elements (by @gau27)

* Added NMatrix.logspace constructor for generating a
vector with logarithmically spaced elements (by @gau27)

* Improved Travis configs (by @v0dro)

* Added C API documentation and included ruby_constants.h
in C API include files (by @v0dro)

* Added #magic function to create magic square matrices
(by @shahsaurabh0605)

* Added NMatrix#last (by @gau27)

* Added QR factorization by exposing LAPACK functions
GEQRF, ORMQR, UNMQR (by @gau27)

* Made templates a little smarter for those functions
which require a separate return dtype by adding the
MagnitudeDType template typename; and added a magnitude
function to replace std::abs and abs to make complex
and real templates more generic (by @mohawkjohn)

* Added #adjugate and #adjugate! functions (by @sujithvm)

* Added #scale and #scale! methods by exposing BLAS SCAL
(by @lds56)

* Re-factored type comparisons to use RB_TYPE_P instead of
TYPE(obj) (by @mrkn)

* Updated license to BSD 3-clause (by @gau27)

* Cleaned up gem installation settings and dependencies
(by @mrkn)

* DRYed up extconf script (by @mrkn)

* 15 bug fixes:

* Fixed offsets and changed limits in TRSM to follow the
Fortran implementation (by @lokeshh), and adjusted
triangular #solve accordingly (by @agisga)

* Fixed NRM2 (CBLAS 2-norm) for complex types (by
@lokeshh)

* Fixed NRM2 divide-by-zero bug (by @arafatk)

* Fixed #reshape! to work when changing dimensionality (by
@wlevine)

* Fixed ambiguous references by making proper use of
namespace qualifiers for dtypes, allowing compilation in
Windows using the mingw64 toolchain available through
msys2 (by @preetpalS)

* Replaced all uses of u_int8_t with uint8_t and added static
assertions to prevent ambiguous use of u_intX_t types
(by @preetpalS)

* Added workaround in extconf script for Windows use of a
different name for the null device (by @preetpalS)

* Updated deprecated RSpec code and other miscellaneous
cleanups (by @yui-knk)

* Removed incomplete support of Hash as an argument for
NMatrix#[] (by @yui-knk)

* Fixed typo in slicing exception error message (by
@mohawkjohn)

* Fixed #concat implementation for case of differing
sizes along concatenation dimension (by @alno)

* Ensured dtype is preserved by #repeat (by @alno)

* Fixed #det_exact for :object dtype (by @isuruf)

* Stopped using deprecated register storage class
specifier (by @mrkn)

* Fixed clang/clang++ compiler selection by forcing use of
clang++ when clang is used (by @mrkn)

=== 0.2.3 / 2016-07-25

* No major enhancements.

* No minor enhancements.

* 1 bug fix:

* Fixed gem installation problem caused by mkmf
abstraction (by @mrkn)

22 changes: 22 additions & 0 deletions Manifest.txt
Expand Up @@ -29,6 +29,7 @@ lib/nmatrix/blas.rb
lib/nmatrix/enumerate.rb
lib/nmatrix/homogeneous.rb
lib/nmatrix/math.rb
lib/nmatrix/mkmf.rb
lib/nmatrix/monkeys.rb
lib/nmatrix/nmatrix.rb
lib/nmatrix/rspec.rb
Expand All @@ -38,6 +39,7 @@ lib/nmatrix/yale_functions.rb
ext/nmatrix/math/cblas_enums.h
ext/nmatrix/math/cblas_templates_core.h
ext/nmatrix/math/util.h
ext/nmatrix/math/magnitude.h
ext/nmatrix_atlas/extconf.rb
ext/nmatrix_atlas/math_atlas.cpp
ext/nmatrix_atlas/math_atlas/cblas_templates_atlas.h
Expand Down Expand Up @@ -126,6 +128,26 @@ ext/nmatrix_lapacke/lapacke/src/lapacke_zpotri.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zpotri_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrs.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrs_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf.c
ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr.c
ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf.c
ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr.c
ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf.c
ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr.c
ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf_work.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr.c
ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr_work.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_c_nancheck.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_d_nancheck.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_s_nancheck.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_z_nancheck.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_cge_nancheck.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_cge_trans.c
ext/nmatrix_lapacke/lapacke/utils/lapacke_cpo_nancheck.c
Expand Down
145 changes: 9 additions & 136 deletions ext/nmatrix/extconf.rb
Expand Up @@ -25,80 +25,18 @@
# This file checks for ATLAS and other necessary headers, and
# generates a Makefile for compiling NMatrix.

require "mkmf"
require File.expand_path("../../../lib/nmatrix/mkmf", __FILE__)


# Function derived from NArray's extconf.rb.
def have_type(type, header=nil) #:nodoc:
printf "checking for %s... ", type
STDOUT.flush

src = <<"SRC"
#include <ruby.h>
SRC


src << <<"SRC" unless header.nil?
#include <#{header}>
SRC

r = try_link(src + <<"SRC")
int main() { return 0; }
int t() { #{type} a; return 0; }
SRC

unless r
print "no\n"
return false
end

$defs.push(format("-DHAVE_%s", type.upcase))

print "yes\n"

return true
end

# Function derived from NArray's extconf.rb.
def create_conf_h(file) #:nodoc:
print "creating #{file}\n"
File.open(file, 'w') do |hfile|
header_guard = file.upcase.sub(/\s|\./, '_')

hfile.puts "#ifndef #{header_guard}"
hfile.puts "#define #{header_guard}"
hfile.puts

# FIXME: Find a better way to do this:
hfile.puts "#define RUBY_2 1" if RUBY_VERSION >= '2.0'

for line in $defs
line =~ /^-D(.*)/
hfile.printf "#define %s 1\n", $1
end

hfile.puts
hfile.puts "#endif"
end
end

if RUBY_VERSION < '1.9'
raise(NotImplementedError, "Sorry, you need at least Ruby 1.9!")
else
$INSTALLFILES = [
['nmatrix.h' , '$(archdir)'],
['nmatrix.hpp' , '$(archdir)'],
['nmatrix_config.h', '$(archdir)'],
['nm_memory.h' , '$(archdir)'],
['ruby_constants.h', '$(archdir)']
]
if /cygwin|mingw/ =~ RUBY_PLATFORM
$INSTALLFILES << ['libnmatrix.a', '$(archdir)']
end
end
$INSTALLFILES = [
['nmatrix.h' , '$(archdir)'],
['nmatrix.hpp' , '$(archdir)'],
['nmatrix_config.h', '$(archdir)'],
['nm_memory.h' , '$(archdir)'],
['ruby_constants.h', '$(archdir)']
]

if /cygwin|mingw/ =~ RUBY_PLATFORM
CONFIG["DLDFLAGS"] << " --output-lib libnmatrix.a"
$INSTALLFILES << ['libnmatrix.a', '$(archdir)']
end

$DEBUG = true
Expand All @@ -111,73 +49,8 @@ def create_conf_h(file) #:nodoc:
$objs = basenames.map { |b| "#{b}.o" }
$srcs = basenames.map { |b| "#{b}.cpp" }

def find_newer_gplusplus #:nodoc:
print "checking for apparent GNU g++ binary with C++0x/C++11 support... "
[9,8,7,6,5,4,3].each do |minor|
ver = "4.#{minor}"
gpp = "g++-#{ver}"
result = `which #{gpp}`
next if result.empty?
CONFIG['CXX'] = gpp
puts ver
return CONFIG['CXX']
end
false
end

def gplusplus_version
# Workaround for Windows having a different name for null device
null_device = (system 'echo "Hi" </dev/null') ? '/dev/null' : 'nul'

cxxvar = proc { |n| `#{CONFIG['CXX']} -E -dM - <#{null_device} | grep #{n}`.chomp.split(' ')[2] }
major = cxxvar.call('__GNUC__')
minor = cxxvar.call('__GNUC_MINOR__')
patch = cxxvar.call('__GNUC_PATCHLEVEL__')

raise("unable to determine g++ version (match to get version was nil)") if major.nil? || minor.nil? || patch.nil?

"#{major}.#{minor}.#{patch}"
end


if CONFIG['CXX'] == 'clang++'
$CXX_STANDARD = 'c++11'

else
version = gplusplus_version
if version < '4.3.0' && CONFIG['CXX'] == 'g++' # see if we can find a newer G++, unless it's been overridden by user
if !find_newer_gplusplus
raise("You need a version of g++ which supports -std=c++0x or -std=c++11. If you're on a Mac and using Homebrew, we recommend using mac-brew-gcc.sh to install a more recent g++.")
end
version = gplusplus_version
end

if version < '4.7.0'
$CXX_STANDARD = 'c++0x'
else
$CXX_STANDARD = 'c++11'
end
puts "using C++ standard... #{$CXX_STANDARD}"
puts "g++ reports version... " + `#{CONFIG['CXX']} --version|head -n 1|cut -f 3 -d " "`
end

#$libs += " -lprofiler "

# For release, these next two should both be changed to -O3.
$CFLAGS += " -O3 "
#$CFLAGS += " -static -O0 -g "
$CXXFLAGS += " -O3 -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
#$CXXFLAGS += " -static -O0 -g -std=#{$CXX_STANDARD} "

CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)
CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')

have_func("rb_array_const_ptr", "ruby.h")
have_macro("FIX_CONST_VALUE_PTR", "ruby.h")
have_macro("RARRAY_CONST_PTR", "ruby.h")
have_macro("RARRAY_AREF", "ruby.h")

create_conf_h("nmatrix_config.h")
create_makefile("nmatrix")

Expand Down
6 changes: 3 additions & 3 deletions ext/nmatrix/math/laswp.h
Expand Up @@ -102,7 +102,7 @@ inline void laswp(const int N, DType* A, const int lda, const int K1, const int
DType *a0 = &(A[i]),
*a1 = &(A[ip]);

for (register int h = 32; h; h--) {
for (int h = 32; h; h--) {
DType r = *a0;
*a0 = *a1;
*a1 = r;
Expand Down Expand Up @@ -131,7 +131,7 @@ inline void laswp(const int N, DType* A, const int lda, const int K1, const int
DType *a0 = &(A[i]),
*a1 = &(A[ip]);

for (register int h = mr; h; h--) {
for (int h = mr; h; h--) {
DType r = *a0;
*a0 = *a1;
*a1 = r;
Expand Down Expand Up @@ -162,4 +162,4 @@ inline void clapack_laswp(const int n, void* a, const int lda, const int k1, con
}

} } // namespace nm::math
#endif // LASWP_H
#endif // LASWP_H
2 changes: 1 addition & 1 deletion ext/nmatrix/storage/dense/dense.cpp
Expand Up @@ -1018,7 +1018,7 @@ bool eqeq(const DENSE_STORAGE* left, const DENSE_STORAGE* right) {
template <typename DType>
bool is_hermitian(const DENSE_STORAGE* mat, int lda) {
unsigned int i, j;
register DType complex_conj;
DType complex_conj;

const DType* els = (DType*) mat->elements;

Expand Down

0 comments on commit a7d85ef

Please sign in to comment.