Example #1
0
def test_linalg_norm():
    """All that I'm asking of this test is that it doesn't error out."""
    x = cp.array([1, 2, 3])
    l2 = cp.linalg.norm(x)
Example #2
0
 def loss(w, x, y):
     preds = model(w, x)
     loss_score = cp.mean(cp.power(preds.ravel() - y.ravel(), cp.array(2)))
     return loss_score
Example #3
0
 def fun(x):
     return cp.array([[2 * x, x + 1], [x, x]])
def test_sparse_coo_matrix(eye):
    """This just has to not error out."""
    data = cp.array([1, 2, 3]).astype("float32")
    rows = cp.array([1, 2, 3]).astype("float32")
    cols = cp.array([1, 3, 4]).astype("float32")
    print(eye.shape)
Example #5
0
 def fun(x):
     return cp.array(x)
Example #6
0
 def fun(x):
     return cp.array([x, x])
Example #7
0
 def fun(x):
     A = cp.array([x, x * 1.0, x + 2.5])
     return A + A
Example #8
0
 def fun(x):
     A = cp.array([[x, x * 1.0, x + 2.5], [x**2, x, x / 2.0]])
     return A + A
Example #9
0
 def fun(x):
     # return cp.array([x, x * 1.0, x + 2.5])
     return cp.array([x, x, x])
Example #10
0
 def fun(x):
     return cp.array([[x, x * 1.0, x + 2.5], [x**2, x, x / 2.0]])
Example #11
0
def test_simple_append_arr():
    A = cp.array([1.0, 2.0, 3.0])
    b = 4.0
    check_grads(cp.append, argnum=(0, 1))(A, b)
Example #12
0
 def fun(x):
     return cp.maximum(cp.array([x, x, 0.5]),
                       cp.array([[x, 0.5, x], [x, x, 0.5]]))
Example #13
0
 def fun(x):
     return cp.min(
         cp.array([[x, x, x], [x, 0.5, 0.5], [0.5, 0.5, 0.5], [x, x, 0.5]]),
         axis=0,
     )
Example #14
0
 def fun(x):
     return cp.max(cp.array([[x, x], [x, 0.5]]), axis=1)
Example #15
0
def test_nan_to_num():
    y = cp.array([0.0, cp.nan, cp.inf, -cp.inf])
    fun = lambda x: cp.sum(cp.sin(cp.nan_to_num(x + y)))

    x = cp.random.randn(4)
    check_grads(fun)(x)