|
4 | 4 | let(:y) { SymEngine::Symbol.new('y') } |
5 | 5 | let(:z) { SymEngine::Symbol.new('z') } |
6 | 6 |
|
| 7 | + def l(code) |
| 8 | + SymEngine::Utils::lambdify_code(code) |
| 9 | + end |
| 10 | + |
7 | 11 | it 'creates lambda codes' do |
8 | | - expect(SymEngine::lambdify_code( x + y + z )).to eq("lambda { | x,y,z | x + y + z }") |
9 | | - expect(SymEngine::lambdify_code( x + 5 )).to eq("lambda { | x | Rational(5,1) + x }") |
10 | | - expect(SymEngine::lambdify_code( SymEngine::sin(x) )).to eq("lambda { | x | Math.sin(x) }") |
11 | | - expect(SymEngine::lambdify_code( SymEngine::cos(x) )).to eq("lambda { | x | Math.cos(x) }") |
12 | | - expect(SymEngine::lambdify_code( SymEngine::tan(x) )).to eq("lambda { | x | Math.tan(x) }") |
13 | | - expect(SymEngine::lambdify_code( SymEngine::asin(x) )).to eq("lambda { | x | Math.asin(x) }") |
14 | | - expect(SymEngine::lambdify_code( SymEngine::acos(x) )).to eq("lambda { | x | Math.acos(x) }") |
15 | | - expect(SymEngine::lambdify_code( SymEngine::atan(x) )).to eq("lambda { | x | Math.atan(x) }") |
16 | | - expect(SymEngine::lambdify_code( SymEngine::sinh(x) )).to eq("lambda { | x | Math.sinh(x) }") |
17 | | - expect(SymEngine::lambdify_code( SymEngine::cosh(x) )).to eq("lambda { | x | Math.cosh(x) }") |
18 | | - expect(SymEngine::lambdify_code( SymEngine::tanh(x) )).to eq("lambda { | x | Math.tanh(x) }") |
19 | | - expect(SymEngine::lambdify_code( SymEngine::asinh(x) )).to eq("lambda { | x | Math.asinh(x) }") |
20 | | - expect(SymEngine::lambdify_code( SymEngine::acosh(x) )).to eq("lambda { | x | Math.acosh(x) }") |
21 | | - expect(SymEngine::lambdify_code( SymEngine::atanh(x) )).to eq("lambda { | x | Math.atanh(x) }") |
22 | | - expect(SymEngine::lambdify_code( SymEngine::gamma(x) )).to eq("lambda { | x | Math.gamma(x) }") |
23 | | - expect(SymEngine::lambdify_code( x + SymEngine::PI )).to eq("lambda { | x | x + Math::PI }") |
24 | | - expect(SymEngine::lambdify_code( x + SymEngine::E )).to eq("lambda { | x | x + Math::E }") |
25 | | - expect(SymEngine::lambdify_code( SymEngine::dirichlet_eta(x) )).to eq("lambda { | x | SymEngine::evalf_dirichlet_eta(x) }") |
26 | | - expect(SymEngine::lambdify_code( SymEngine::zeta(x) )).to eq("lambda { | x | SymEngine::evalf_zeta(x, Rational(1,1)) }") |
| 12 | + expect(l( x + y + z )).to eq("lambda { | x,y,z | x + y + z }") |
| 13 | + expect(l( x + 5 )).to eq("lambda { | x | Rational(5,1) + x }") |
| 14 | + expect(l( SymEngine::sin(x) )).to eq("lambda { | x | Math.sin(x) }") |
| 15 | + expect(l( SymEngine::cos(x) )).to eq("lambda { | x | Math.cos(x) }") |
| 16 | + expect(l( SymEngine::tan(x) )).to eq("lambda { | x | Math.tan(x) }") |
| 17 | + expect(l( SymEngine::asin(x) )).to eq("lambda { | x | Math.asin(x) }") |
| 18 | + expect(l( SymEngine::acos(x) )).to eq("lambda { | x | Math.acos(x) }") |
| 19 | + expect(l( SymEngine::atan(x) )).to eq("lambda { | x | Math.atan(x) }") |
| 20 | + expect(l( SymEngine::sinh(x) )).to eq("lambda { | x | Math.sinh(x) }") |
| 21 | + expect(l( SymEngine::cosh(x) )).to eq("lambda { | x | Math.cosh(x) }") |
| 22 | + expect(l( SymEngine::tanh(x) )).to eq("lambda { | x | Math.tanh(x) }") |
| 23 | + expect(l( SymEngine::asinh(x) )).to eq("lambda { | x | Math.asinh(x) }") |
| 24 | + expect(l( SymEngine::acosh(x) )).to eq("lambda { | x | Math.acosh(x) }") |
| 25 | + expect(l( SymEngine::atanh(x) )).to eq("lambda { | x | Math.atanh(x) }") |
| 26 | + expect(l( SymEngine::gamma(x) )).to eq("lambda { | x | Math.gamma(x) }") |
| 27 | + expect(l( x + SymEngine::PI )).to eq("lambda { | x | x + Math::PI }") |
| 28 | + expect(l( x + SymEngine::E )).to eq("lambda { | x | x + Math::E }") |
| 29 | + expect(l( SymEngine::dirichlet_eta(x) )).to eq("lambda { | x | SymEngine::Utils::evalf_dirichlet_eta(x) }") |
| 30 | + expect(l( SymEngine::zeta(x) )).to eq("lambda { | x | SymEngine::Utils::evalf_zeta(x, Rational(1,1)) }") |
27 | 31 |
|
28 | 32 |
|
29 | 33 | end |
|
52 | 56 | expect(lamb.call(1)).to eq(6) |
53 | 57 | expect(lamb.call(0)).to eq(5) |
54 | 58 | expect(lamb.call(-1)).to eq(4) |
55 | | - expect(lamb.call(Math::PI)).to be_within(0.000000000000001).of(8.141592653589793) |
| 59 | + expect(lamb.call(Math::PI)).to be_within(1e-15).of(8.141592653589793) |
56 | 60 | end |
57 | 61 | end |
58 | 62 |
|
59 | 63 | describe 'lambda for sin' do |
60 | 64 | let(:func) { SymEngine::sin(x) } |
61 | 65 | let(:lamb) { SymEngine::lambdify(func) } |
62 | 66 | it 'performs sin calculation with a lambda function' do |
63 | | - expect(lamb.call(0)).to be_within(0.000000000000001).of(0.0) |
64 | | - expect(lamb.call(Math::PI)).to be_within(0.000000000000001).of(0.0) |
65 | | - expect(lamb.call(Math::PI/2)).to be_within(0.000000000000001).of(1.0) |
| 67 | + expect(lamb.call(0)).to be_within(1e-15).of(0.0) |
| 68 | + expect(lamb.call(Math::PI)).to be_within(1e-15).of(0.0) |
| 69 | + expect(lamb.call(Math::PI/2)).to be_within(1e-15).of(1.0) |
66 | 70 | end |
67 | 71 | end |
68 | 72 |
|
|
0 commit comments