|
2 | 2 |
|
3 | 3 | describe Daru::Vector do
|
4 | 4 | ALL_DTYPES.each do |dtype|
|
5 |
| - describe dtype.to_s do |
| 5 | + describe dtype.to_s, dtype do |
6 | 6 | before do
|
7 | 7 | @common_all_dtypes = Daru::Vector.new(
|
8 | 8 | [5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
|
|
84 | 84 | expect(dv.index.to_a).to eq(['a', 'b', :r, 0])
|
85 | 85 | end
|
86 | 86 |
|
87 |
| - it "initializes array with nils with dtype NMatrix" do |
| 87 | + it "initializes array with nils with dtype NMatrix", :nmatrix do |
88 | 88 | dv = Daru::Vector.new [2, nil], dtype: :nmatrix
|
89 | 89 | expect(dv.to_a).to eq([2, nil])
|
90 | 90 | expect(dv.index.to_a).to eq([0, 1])
|
|
1064 | 1064 |
|
1065 | 1065 | context "#cast" do
|
1066 | 1066 | ALL_DTYPES.each do |new_dtype|
|
1067 |
| - it "casts from #{dtype} to #{new_dtype}" do |
| 1067 | + it "casts from #{dtype} to #{new_dtype}", new_dtype do |
1068 | 1068 | v = Daru::Vector.new [1,2,3,4], dtype: dtype
|
1069 | 1069 | v.cast(dtype: new_dtype)
|
1070 | 1070 | expect(v.dtype).to eq(new_dtype)
|
|
1360 | 1360 | expect(a.dtype).to eq(:array)
|
1361 | 1361 | end
|
1362 | 1362 |
|
1363 |
| - it "maps and returns a vector of dtype gsl" do |
1364 |
| - a = @common_all_dtypes.recode(:gsl) { |v| v == -99 ? 1 : 0 } |
1365 |
| - exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :gsl |
1366 |
| - expect(a).to eq(exp) |
1367 |
| - expect(a.dtype).to eq(:gsl) |
1368 |
| - end |
1369 |
| - |
1370 |
| - it "maps and returns a vector of dtype nmatrix" do |
1371 |
| - a = @common_all_dtypes.recode(:nmatrix) { |v| v == -99 ? 1 : 0 } |
1372 |
| - exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :nmatrix |
1373 |
| - expect(a).to eq(exp) |
1374 |
| - expect(a.dtype).to eq(:nmatrix) |
| 1363 | + ALL_DTYPES.each do |dtype| |
| 1364 | + it "maps and returns a vector of dtype #{dtype}", dtype do |
| 1365 | + a = @common_all_dtypes.recode(dtype) { |v| v == -99 ? 1 : 0 } |
| 1366 | + exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: dtype |
| 1367 | + expect(a).to eq(exp) |
| 1368 | + expect(a.dtype).to eq(exp.dtype) |
| 1369 | + end |
1375 | 1370 | end
|
1376 | 1371 | end
|
1377 | 1372 |
|
|
1389 | 1384 | expect(@vector.dtype).to eq(dtype)
|
1390 | 1385 | end
|
1391 | 1386 |
|
1392 |
| - it "destructively maps and returns a vector of dtype gsl" do |
1393 |
| - @vector.recode!(:gsl) { |v| v == -99 ? 1 : 0 } |
1394 |
| - exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :gsl |
1395 |
| - expect(@vector).to eq(exp) |
1396 |
| - expect(@vector.dtype).to eq(exp.dtype) |
1397 |
| - end |
1398 |
| - |
1399 |
| - it "destructively maps and returns a vector of dtype nmatrix" do |
1400 |
| - @vector.recode!(:nmatrix) { |v| v == -99 ? 1 : 0 } |
1401 |
| - exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :nmatrix |
1402 |
| - expect(@vector).to eq(exp) |
1403 |
| - expect(@vector.dtype).to eq(exp.dtype) |
| 1387 | + ALL_DTYPES.each do |dtype| |
| 1388 | + it "destructively maps and returns a vector of dtype #{dtype}", dtype do |
| 1389 | + @vector.recode!(dtype) { |v| v == -99 ? 1 : 0 } |
| 1390 | + exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: dtype |
| 1391 | + expect(@vector).to eq(exp) |
| 1392 | + expect(@vector.dtype).to eq(exp.dtype) |
| 1393 | + end |
1404 | 1394 | end
|
1405 | 1395 | end
|
1406 | 1396 |
|
|
1593 | 1583 | its(:'index.to_a') { is_expected.to eq [] }
|
1594 | 1584 | end
|
1595 | 1585 |
|
1596 |
| - context 'works for gsl' do |
| 1586 | + context 'works for gsl', :gsl do |
1597 | 1587 | let(:dv) { Daru::Vector.new [1, 2, 3, Float::NAN], dtype: :gsl,
|
1598 | 1588 | index: 11..14 }
|
1599 | 1589 | subject { dv.reject_values Float::NAN }
|
|
1857 | 1847 | expect(@multi.type).to eq(:object)
|
1858 | 1848 | end
|
1859 | 1849 |
|
1860 |
| - it "tells NMatrix data type in case of NMatrix wrapper" do |
| 1850 | + it "tells NMatrix data type in case of NMatrix wrapper", :nmatrix do |
1861 | 1851 | nm = Daru::Vector.new([1,2,3,4,5], dtype: :nmatrix)
|
1862 | 1852 | expect(nm.type).to eq(:int32)
|
1863 | 1853 | end
|
|
1908 | 1898 | end
|
1909 | 1899 | end
|
1910 | 1900 |
|
1911 |
| - context '#to_nmatrix' do |
| 1901 | + context '#to_nmatrix', :nmatrix do |
1912 | 1902 | let(:dv) { Daru::Vector.new [1, 2, 3, 4, 5] }
|
1913 | 1903 |
|
1914 | 1904 | context 'horizontal axis' do
|
|
1945 | 1935 | end
|
1946 | 1936 | end
|
1947 | 1937 |
|
1948 |
| - context "#to_gsl" do |
| 1938 | + context "#to_gsl", :gsl do |
1949 | 1939 | it "returns a GSL::Vector of non-nil data" do
|
1950 | 1940 | vector = Daru::Vector.new [1,2,3,4,nil,6,nil]
|
1951 | 1941 | expect(vector.to_gsl).to eq(GSL::Vector.alloc(1,2,3,4,6))
|
|
0 commit comments