Skip to content
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

Support running specs without gsl or nmatrix installed #537

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ matrix:
true

env:
- DARU_TEST_NMATRIX=1 DARU_TEST_GSL=1
- DARU_TEST_NMATRIX=1 DARU_TEST_GSL=1 DARU_TEST_RSERVE=1

script:
- bundle add yard-junk
Expand Down
6 changes: 3 additions & 3 deletions spec/dataframe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@
end

context "#recast" do
it "recasts underlying vectors" do
it "recasts underlying vectors", :nmatrix do
@data_frame.recast a: :nmatrix, c: :nmatrix

expect(@data_frame.a.dtype).to eq(:nmatrix)
Expand Down Expand Up @@ -2875,7 +2875,7 @@
end
end

context "#to_nmatrix" do
context "#to_nmatrix", :nmatrix do
before do
@df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
c: [11,22,33,44,55], d: [5,4,nil,2,1], e: ['this', 'has', 'string','data','too']},
Expand Down Expand Up @@ -3274,7 +3274,7 @@
end
end

context "#to_gsl" do
context "#to_gsl", :gsl do
it "converts to GSL::Matrix" do
rows = [[1,2,3,4,5],[11,12,13,14,15],[11,22,33,44,55]].transpose
mat = GSL::Matrix.alloc *rows
Expand Down
2 changes: 1 addition & 1 deletion spec/extensions/rserve_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "rserve"
require 'daru/extensions/rserve'

describe "Daru rserve extension" do
describe "Daru rserve extension", :rserve do
before do
@r = Rserve::Connection.new
end
Expand Down
2 changes: 1 addition & 1 deletion spec/io/io_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@

context "#save" do
ALL_DTYPES.each do |dtype|
it "saves to a file and returns the same Vector of type #{dtype}" do
it "saves to a file and returns the same Vector of type #{dtype}", dtype do
vector = Daru::Vector.new(
[5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
dtype: dtype)
Expand Down
2 changes: 1 addition & 1 deletion spec/maths/statistics/vector_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe Daru::Vector do
[:array, :gsl].each do |dtype| #nmatrix still unstable
describe dtype do
describe dtype.to_s, dtype do
before do
@dv = Daru::Vector.new [323, 11, 555, 666, 234, 21, 666, 343, 1, 2], dtype: dtype
@dv_with_nils = Daru::Vector.new [323, 11, 555, nil, 666, 234, 21, 666, 343, nil, 1, 2]
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def expect_correct_df_in_delta df1, df2, delta
end
end

RSpec.configure do |c|
c.filter_run_excluding(:gsl) unless Daru.has_gsl?
c.filter_run_excluding(:nmatrix) unless Daru.has_nmatrix?
c.filter_run_excluding(:rserve) unless ENV['DARU_TEST_RSERVE']
end

RSpec::Matchers.define :be_all_within do |delta|
match do |actual|
expect(@expected).to_not be_nil
Expand Down
52 changes: 21 additions & 31 deletions spec/vector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Daru::Vector do
ALL_DTYPES.each do |dtype|
describe dtype.to_s do
describe dtype.to_s, dtype do
before do
@common_all_dtypes = Daru::Vector.new(
[5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
Expand Down Expand Up @@ -84,7 +84,7 @@
expect(dv.index.to_a).to eq(['a', 'b', :r, 0])
end

it "initializes array with nils with dtype NMatrix" do
it "initializes array with nils with dtype NMatrix", :nmatrix do
dv = Daru::Vector.new [2, nil], dtype: :nmatrix
expect(dv.to_a).to eq([2, nil])
expect(dv.index.to_a).to eq([0, 1])
Expand Down Expand Up @@ -1064,7 +1064,7 @@

context "#cast" do
ALL_DTYPES.each do |new_dtype|
it "casts from #{dtype} to #{new_dtype}" do
it "casts from #{dtype} to #{new_dtype}", new_dtype do
v = Daru::Vector.new [1,2,3,4], dtype: dtype
v.cast(dtype: new_dtype)
expect(v.dtype).to eq(new_dtype)
Expand Down Expand Up @@ -1360,18 +1360,13 @@
expect(a.dtype).to eq(:array)
end

it "maps and returns a vector of dtype gsl" do
a = @common_all_dtypes.recode(:gsl) { |v| v == -99 ? 1 : 0 }
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :gsl
expect(a).to eq(exp)
expect(a.dtype).to eq(:gsl)
end

it "maps and returns a vector of dtype nmatrix" do
a = @common_all_dtypes.recode(:nmatrix) { |v| v == -99 ? 1 : 0 }
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :nmatrix
expect(a).to eq(exp)
expect(a.dtype).to eq(:nmatrix)
ALL_DTYPES.each do |dtype|
it "maps and returns a vector of dtype #{dtype}", dtype do
a = @common_all_dtypes.recode(dtype) { |v| v == -99 ? 1 : 0 }
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: dtype
expect(a).to eq(exp)
expect(a.dtype).to eq(exp.dtype)
end
end
end

Expand All @@ -1389,18 +1384,13 @@
expect(@vector.dtype).to eq(dtype)
end

it "destructively maps and returns a vector of dtype gsl" do
@vector.recode!(:gsl) { |v| v == -99 ? 1 : 0 }
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :gsl
expect(@vector).to eq(exp)
expect(@vector.dtype).to eq(exp.dtype)
end

it "destructively maps and returns a vector of dtype nmatrix" do
@vector.recode!(:nmatrix) { |v| v == -99 ? 1 : 0 }
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :nmatrix
expect(@vector).to eq(exp)
expect(@vector.dtype).to eq(exp.dtype)
ALL_DTYPES.each do |dtype|
it "destructively maps and returns a vector of dtype #{dtype}", dtype do
@vector.recode!(dtype) { |v| v == -99 ? 1 : 0 }
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: dtype
expect(@vector).to eq(exp)
expect(@vector.dtype).to eq(exp.dtype)
end
end
end

Expand Down Expand Up @@ -1593,7 +1583,7 @@
its(:'index.to_a') { is_expected.to eq [] }
end

context 'works for gsl' do
context 'works for gsl', :gsl do
let(:dv) { Daru::Vector.new [1, 2, 3, Float::NAN], dtype: :gsl,
index: 11..14 }
subject { dv.reject_values Float::NAN }
Expand Down Expand Up @@ -1857,7 +1847,7 @@
expect(@multi.type).to eq(:object)
end

it "tells NMatrix data type in case of NMatrix wrapper" do
it "tells NMatrix data type in case of NMatrix wrapper", :nmatrix do
nm = Daru::Vector.new([1,2,3,4,5], dtype: :nmatrix)
expect(nm.type).to eq(:int32)
end
Expand Down Expand Up @@ -1908,7 +1898,7 @@
end
end

context '#to_nmatrix' do
context '#to_nmatrix', :nmatrix do
let(:dv) { Daru::Vector.new [1, 2, 3, 4, 5] }

context 'horizontal axis' do
Expand Down Expand Up @@ -1945,7 +1935,7 @@
end
end

context "#to_gsl" do
context "#to_gsl", :gsl do
it "returns a GSL::Vector of non-nil data" do
vector = Daru::Vector.new [1,2,3,4,nil,6,nil]
expect(vector.to_gsl).to eq(GSL::Vector.alloc(1,2,3,4,6))
Expand Down