コード例 #1
0
    def test_noncentral_chisquare_for_invalid_params(self, param_dtype):
        df = cupy.full(self.df_shape, -1, dtype=param_dtype)
        nonc = cupy.full(self.nonc_shape, 1, dtype=param_dtype)
        with self.assertRaises(ValueError):
            _distributions.noncentral_chisquare(df, nonc, size=self.shape)

        df = cupy.full(self.df_shape, 1, dtype=param_dtype)
        nonc = cupy.full(self.nonc_shape, -1, dtype=param_dtype)
        with self.assertRaises(ValueError):
            _distributions.noncentral_chisquare(df, nonc, size=self.shape)
コード例 #2
0
    def test_triangular_for_invalid_params(self, param_dtype):
        left = cupy.full(self.left_shape, 1, dtype=param_dtype)
        mode = cupy.full(self.mode_shape, 0, dtype=param_dtype)
        right = cupy.full(self.right_shape, 2, dtype=param_dtype)
        with self.assertRaises(ValueError):
            _distributions.triangular(left, mode, right, size=self.shape)

        left = cupy.full(self.left_shape, -2, dtype=param_dtype)
        mode = cupy.full(self.mode_shape, 0, dtype=param_dtype)
        right = cupy.full(self.right_shape, -1, dtype=param_dtype)
        with self.assertRaises(ValueError):
            _distributions.triangular(left, mode, right, size=self.shape)

        left = cupy.full(self.left_shape, 0, dtype=param_dtype)
        mode = cupy.full(self.mode_shape, 0, dtype=param_dtype)
        right = cupy.full(self.right_shape, 0, dtype=param_dtype)
        with self.assertRaises(ValueError):
            _distributions.triangular(left, mode, right, size=self.shape)
コード例 #3
0
    def test_lo_hi_nonrandom(self):
        a = random.randint(-0.9, 1.1, size=3)
        numpy.testing.assert_array_equal(a, cupy.full((3,), 0))

        a = random.randint(-1.1, -0.9, size=(2, 2))
        numpy.testing.assert_array_equal(a, cupy.full((2, 2), -1))
コード例 #4
0
 def test_object(self):
     d = [1.] * 100
     k = [1.] * 3
     numpy.testing.assert_array_almost_equal(
         dpnp.convolve(d, k)[2:-2], dpnp.full(98, 3))
コード例 #5
0
    d1 = halfs + halfs * np.erf(w1)
    d2 = halfs + halfs * np.erf(w2)

    Se = np.exp(b) * S

    r = P * d1 - Se * d2
    call[:] = r  # temporary `r` is necessary for faster `put` computation
    put[:] = r - P + Se


np.random.seed(SEED)
price = np.random.uniform(PL, PH, SIZE)
strike = np.random.uniform(SL, SH, SIZE)
t = np.random.uniform(TL, TH, SIZE)

call = np.full(SIZE, 0, dtype=DTYPE)
put = np.full(SIZE, -1, dtype=DTYPE)

mrs = np.full(SIZE, -RISK_FREE, dtype=DTYPE)

vol = VOLATILITY
vol_vol_twos = np.full(SIZE, vol * vol * 2, dtype=DTYPE)

quarters = np.full(SIZE, 0.25, dtype=DTYPE)
ones = np.full(SIZE, 1, dtype=DTYPE)
halfs = np.full(SIZE, 0.5, dtype=DTYPE)

black_scholes(price, strike, t, mrs, vol_vol_twos, quarters, ones, halfs, call,
              put)
print(call[:10])
print(put[:10])
コード例 #6
0
 def check_distribution(self, dist_func, df_dtype, dtype):
     df = cupy.full(self.df_shape, 5, dtype=df_dtype)
     out = dist_func(df, self.shape, dtype)
     self.assertEqual(self.shape, out.shape)
     self.assertEqual(out.dtype, dtype)
コード例 #7
0
 def check_distribution(self, dist_func, lam_dtype, dtype):
     lam = cupy.full(self.lam_shape, 5, dtype=lam_dtype)
     out = dist_func(lam, self.shape, dtype)
     self.assertEqual(self.shape, out.shape)
     self.assertEqual(out.dtype, dtype)
コード例 #8
0
 def check_distribution(self, dist_func, df_dtype):
     df = cupy.full(self.df_shape, 5, dtype=df_dtype)
     out = dist_func(df, self.shape)
     self.assertEqual(self.shape, out.shape)
     # numpy and dpdp output dtype is float64
     self.assertEqual(out.dtype, numpy.float64)
コード例 #9
0
 def check_distribution(self, dist_func, lam_dtype):
     lam = cupy.full(self.lam_shape, 5, dtype=lam_dtype)
     out = dist_func(lam, self.shape)
     self.assertEqual(self.shape, out.shape)
     # numpy output dtype is int64, dpnp output is int32
     self.assertEqual(out.dtype, numpy.int64)
コード例 #10
0
ファイル: test_basic.py プロジェクト: shssf/dpnp
    def test_full_like_reshape_cupy_only(self, dtype):
        a = testing.shaped_arange((2, 3, 4), cupy, dtype)
        b = cupy.full_like(a, 1, shape=self.shape)
        c = cupy.full(self.shape, 1, dtype=dtype)

        testing.assert_array_equal(b, c)