nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: open-feature/java-sdk
Pull request #63 (2022-09-08 15:17:04)

!feat: Make evaluation accessors setters consistent
BREAKING: We had `setCtx()` on the global API and `setEvaluationContext()` on the client. This PR makes them both:  `setEvaluationContext()`

We don't have to do this, but since we already have breaking changes for the next release, I think it makes sense. Let me know if the previous was was intentional.


Patch:
diff --git a/src/main/java/dev/openfeature/javasdk/OpenFeatureAPI.java b/src/main/java/dev/openfeature/javasdk/OpenFeatureAPI.java
index 5f4c041..76bb3cb 100644
--- a/src/main/java/dev/openfeature/javasdk/OpenFeatureAPI.java
+++ b/src/main/java/dev/openfeature/javasdk/OpenFeatureAPI.java
@@ -19,7 +19,7 @@ public class OpenFeatureAPI {
     private FeatureProvider provider;
     @Getter
     @Setter
-    private EvaluationContext ctx;
+    private EvaluationContext evaluationContext;
     @Getter
     private List<Hook> apiHooks;
 
diff --git a/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java b/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java
index 4cddd80..6b8d7f2 100644
--- a/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java
+++ b/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java
@@ -78,7 +78,7 @@ public class OpenFeatureClient implements Client {
             // merge of: API.context, client.context, invocation.context
             EvaluationContext mergedCtx = EvaluationContext.merge(
                     EvaluationContext.merge(
-                            openfeatureApi.getCtx(),
+                            openfeatureApi.getEvaluationContext(),
                             this.getEvaluationContext()
                     ),
                     invocationCtx


Test patch:
diff --git a/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java b/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java
index be3e483..de58b4f 100644
--- a/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java
+++ b/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java
@@ -33,7 +33,7 @@ class FlagEvaluationSpecTest implements HookFixtures {
 
     @AfterEach void reset_ctx() {
         OpenFeatureAPI api = OpenFeatureAPI.getInstance();
-        api.setCtx(null);
+        api.setEvaluationContext(null);
     }
 
     @Specification(number="1.1.1", text="The API, and any state it maintains SHOULD exist as a global singleton, even in cases wherein multiple versions of the API are present at runtime.")
@@ -235,7 +235,7 @@ class FlagEvaluationSpecTest implements HookFixtures {
         apiCtx.add("common", "1");
         apiCtx.add("common2", "1");
         apiCtx.add("api", "2");
-        api.setCtx(apiCtx);
+        api.setEvaluationContext(apiCtx);
 
         Client c = api.getClient();
         EvaluationContext clientCtx = new EvaluationContext();
Repository: open-feature/java-sdk
Pull request #146 (2022-10-13 16:05:40)

chore: re-enable integration tests
Update test harness and re-enable integration test profile

closes: https://github.com/open-feature/java-sdk/issues/113

toddbaert: In most cases I would wait for approval from @justinabrahms but this is only re-enabling existing testing.

Patch:
diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml
index c771202..c0845d2 100644
--- a/.github/workflows/pullrequest.yml
+++ b/.github/workflows/pullrequest.yml
@@ -39,7 +39,7 @@ jobs:
             ${{ runner.os }}-maven-
 
       - name: Build with Maven
-        run: mvn --batch-mode --update-snapshots verify # -P integration-test - add this back once we have a compatible flagd
+        run: mvn --batch-mode --update-snapshots verify -P integration-test
 
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@e0fbd592d323cb2991fb586fdd260734fcb41fcb
diff --git a/pom.xml b/pom.xml
index 53284bd..ef772a3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -137,6 +137,13 @@
       <version>31.1-jre</version>
       <scope>test</scope>
     </dependency>
+
+    <dependency>
+      <groupId>dev.openfeature.contrib.providers</groupId>
+      <artifactId>flagd</artifactId>
+      <version>0.4.1</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <dependencyManagement>


Test patch:
diff --git a/src/test/java/dev/openfeature/sdk/integration/StepDefinitions.java b/src/test/java/dev/openfeature/sdk/integration/StepDefinitions.java
index 3513bdd..892dc34 100644
--- a/src/test/java/dev/openfeature/sdk/integration/StepDefinitions.java
+++ b/src/test/java/dev/openfeature/sdk/integration/StepDefinitions.java
@@ -3,7 +3,7 @@ package dev.openfeature.sdk.integration;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-// import dev.openfeature.contrib.providers.flagd.FlagdProvider;
+import dev.openfeature.contrib.providers.flagd.FlagdProvider;
 import dev.openfeature.sdk.Client;
 import dev.openfeature.sdk.FlagEvaluationDetails;
 import dev.openfeature.sdk.MutableStructure;
@@ -45,7 +45,7 @@ public class StepDefinitions {
 
     @BeforeAll()
     public static void setup() {
-        // OpenFeatureAPI.getInstance().setProvider(new FlagdProvider());
+        OpenFeatureAPI.getInstance().setProvider(new FlagdProvider());
         client = OpenFeatureAPI.getInstance().getClient();
     }
 
diff --git a/test-harness b/test-harness
index e7379cd..5153eac 160000
--- a/test-harness
+++ b/test-harness
@@ -1,1 +1,1 @@
-Subproject commit e7379cd0070f8907cacdc535184f8f626bf25e01
+Subproject commit 5153eac71dc47413da4326bdb49a94e573b99578
Repository: OpenMined/PySyft
Pull request #178 (2017-08-23 09:23:47)

Implemented Sign functionality on BaseTensor Object#95
1. added sign() and sign_() functionalities in syft/tensor.py
2. added class signTests() in tests/test_tensor.py


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index ad554b4890..608cbf7667 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -588,6 +588,19 @@ class TensorBase(object):
             return NotImplemented
         self.data = 1 / np.sqrt(self.data)
 
+    def sign(self):
+        """Return a tensor that contains sign of each element """
+        if self.encrypted:
+            return NotImplemented
+        out = np.sign(self.data)
+        return TensorBase(out)
+
+    def sign_(self):
+        """Computes the sign of each element of the Tensor inplace"""
+        if self.encrypted:
+            return NotImplemented
+        self.data = np.sign(self.data)
+
     def to_numpy(self):
         """Returns the tensor as numpy.ndarray"""
         if self.encrypted:


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index a2160b8b47..199480766d 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -454,6 +454,18 @@ class rsqrtTests(unittest.TestCase):
         self.assertTrue(np.allclose(t1.data, [0.70710678, 0.57735027, 0.5]))
 
 
+class signTests(unittest.TestCase):
+    def testsign(self):
+        t1 = TensorBase(np.array([1, 2, -1, -2]))
+        out = t1.sign()
+        self.assertTrue(np.array_equal(out.data, [1, 1, -1, -1]))
+
+    def testsign_(self):
+        t1 = TensorBase(np.array([1, 2, -1, -2]))
+        t1.sign_()
+        self.assertTrue(np.array_equal(t1.data, [1, 1, -1, -1]))
+
+
 class numpyTests(unittest.TestCase):
     def testnumpy(self):
         t1 = TensorBase(np.array([[1, 2], [3, 4]]))
Repository: OpenMined/PySyft
Pull request #182 (2017-08-24 06:56:22)

In-place ceiling, and associated test
I think ceil_ used to be there, but vanished somehow? Anyway, it is back with the associated test.  I took the chance to slighting enhance the test for ceil.


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index ee9cf8715d..84c243c5dd 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -224,6 +224,12 @@ class TensorBase(object):
         else:
             return self.data.sum(axis=dim)
 
+    def ceil(self):
+        """Returns the ceilling of the input tensor elementwise."""
+        if self.encrypted:
+            return NotImplemented
+        return syft.math.ceil(self.data)
+
     def ceil_(self):
         """Returns the ceilling of the input tensor elementwise."""
         if self.encrypted:
@@ -235,7 +241,7 @@ class TensorBase(object):
         """Inplace floor method"""
         if self.encrypted:
             return NotImplemented
-        self.data = syft.math.floor(self.data)
+        self.data = syft.math.floor(self.data).data
         return self
 
     def addmm(self, tensor2, mat, beta=1, alpha=1):


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index d73c443827..b121177577 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -33,12 +33,19 @@ class CeilTests(unittest.TestCase):
         t.ceil_()
         self.assertTrue(syft.equal(t.data, TensorBase([2, 3, 7])))
 
+    def testCeil(self):
+        t = TensorBase(np.array([1.4, 2.7, 6.2]))
+        self.assertTrue(syft.equal(t.ceil(), TensorBase([2, 3, 7])))
+        self.assertTrue(syft.equal(t.data, TensorBase([1.4, 2.7, 6.2])))
+
 
 class FloorTests(unittest.TestCase):
     def testFloor_(self):
         t = TensorBase(np.array([1.4, 2.7, 6.2]))
-        t.floor_()
-        self.assertTrue(syft.equal(t.data, TensorBase([1., 2., 6.])))
+
+        # Now we test in-place
+        self.assertTrue(syft.equal(t.floor_(), [1., 2., 6.]))
+        self.assertTrue(syft.equal(t.data, [1., 2., 6.]))
 
 
 class SubTests(unittest.TestCase):
@@ -393,3 +400,8 @@ class logTests(unittest.TestCase):
     def testLog1p_(self):
         t1 = TensorBase(np.array([1, 2, 3]))
         self.assertTrue(np.allclose((t1.log1p_()).data, [0.69314718, 1.09861229, 1.38629436]))
+
+
+if __name__ == "__main__":
+    if __name__ == '__main__':
+        unittest.main()
Repository: OpenMined/PySyft
Pull request #184 (2017-08-24 11:09:02)

Implemented numpy functionality for BaseTensor object#79
1 . added to_numpy() function in syft/tensor.py
2 . added class numpyTests() in tests/test_tensor.py


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index 227ab40028..f9eff20a64 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -500,6 +500,12 @@ class TensorBase(object):
             return NotImplemented
         self.data = 1 / np.sqrt(self.data)
 
+    def to_numpy(self):
+        """Returns the tensor as numpy.ndarray"""
+        if self.encrypted:
+            return NotImplemented
+        return np.array(self.data)
+
     def reciprocal(self):
         """Computes element wise reciprocal"""
         if self.encrypted:


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 3c31305fb6..1ae53eb8ce 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -358,6 +358,12 @@ class rsqrtTests(unittest.TestCase):
         self.assertTrue(np.allclose(t1.data, [0.70710678, 0.57735027, 0.5]))
 
 
+class numpyTests(unittest.TestCase):
+    def testnumpy(self):
+        t1 = TensorBase(np.array([[1, 2], [3, 4]]))
+        self.assertTrue(np.array_equal(t1.to_numpy(), np.array([[1, 2], [3, 4]])))
+
+
 class reciprocalTests(unittest.TestCase):
     def testreciprocal(self):
         t1 = TensorBase(np.array([2, 3, 4]))
Repository: OpenMined/PySyft
Pull request #185 (2017-08-24 15:07:06)

Implemented reciprocal functionality on BaseTensor Object#84
1. Added reciprocal() and reciprocal_() in syft/tensor/py
2. Added class reciprocalTests() in tests/test_tensor.py


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index d292dca92f..4364668717 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -470,3 +470,16 @@ class TensorBase(object):
         if self.encrypted:
             return NotImplemented
         self.data = 1 / np.sqrt(self.data)
+
+    def reciprocal(self):
+        """Computes element wise reciprocal"""
+        if self.encrypted:
+            return NotImplemented
+        out = 1 / np.array(self.data)
+        return TensorBase(out)
+
+    def reciprocal_(self):
+        """Computes element wise reciprocal"""
+        if self.encrypted:
+            return NotImplemented
+        self.data = 1 / np.array(self.data)


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 4bbc475971..e87deb1af5 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -329,3 +329,15 @@ class rsqrtTests(unittest.TestCase):
         t1 = TensorBase(np.array([2, 3, 4]))
         t1.rsqrt_()
         self.assertTrue(np.allclose(t1.data, [0.70710678, 0.57735027, 0.5]))
+
+
+class reciprocalTests(unittest.TestCase):
+    def testreciprocal(self):
+        t1 = TensorBase(np.array([2, 3, 4]))
+        out = t1.reciprocal()
+        self.assertTrue(np.allclose(out.data, [0.5, 0.33333333, 0.25]))
+
+    def testrsqrt_(self):
+        t1 = TensorBase(np.array([2, 3, 4]))
+        t1.reciprocal_()
+        self.assertTrue(np.allclose(t1.data, [0.5, 0.33333333, 0.25]))
Repository: OpenMined/PySyft
Pull request #193 (2017-08-29 20:25:47)

feat(view and view_as functions)
- view function added to tensor
- view_as function added
- tests for view functions added

kevinahuber: @anoff or @swaroopch, can you take a look at this? 
radicalrafi: The. Implementation is clean and simple using np. copy was smart 
aradhyamathur: @radicalrafi  can you please look into this what might have caused this error ? :(

Patch:
diff --git a/.travis.yml b/.travis.yml
index 0526581950..8a1dbf8b5b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,7 @@ python:
 
 # install server dependencies
 before_install:
-  - "sudo apt-get install musl-dev g++ libgmp3-dev libmpfr-dev libmpc-dev ca-certificates"
+  - "sudo apt-get -y install musl-dev g++ libgmp3-dev libmpfr-dev ca-certificates libmpc-dev"
 
 # install dependencies
 install:
diff --git a/syft/tensor.py b/syft/tensor.py
index c2de3a904f..82a38e7fc1 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 import numpy as np
 import syft
 
@@ -616,3 +617,18 @@ class TensorBase(object):
             return NotImplemented
         self.data = np.random.lognormal(mean, stdev, self.shape())
         return self
+
+    def view(self, *args):
+        """View the tensor."""
+        if self.encrypted:
+            return NotImplemented
+        else:
+            dt = np.copy(self.data)
+            return TensorBase(dt.reshape(*args))
+
+    def view_as(self, tensor):
+        """ View as another tensor's shape """
+        if self.encrypted:
+            return NotImplemented
+        else:
+            return self.view(tensor.shape())


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 148a0258c7..1ba6c36006 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -11,6 +11,16 @@ class DimTests(unittest.TestCase):
         t = TensorBase(np.array([1, 2, 3]))
         self.assertTrue(t.dim() == 1)
 
+    def testView(self):
+        t = TensorBase([1.0, 2.0, 3.0])
+        self.assertTrue(syft.equal(t.view(-1, 1), TensorBase(np.array([[1], [2], [3]]))))
+
+    def testAsView(self):
+        t = TensorBase(np.array([1.0, 2.0, 3.0]))
+        t1 = t.view([-1, 1])
+        print(t.data.dtype)
+        self.assertTrue(syft.equal(t.view_as(t1), TensorBase(np.array([[1.0], [2.0], [3.0]]))))
+
 
 class AddTests(unittest.TestCase):
     def testSimple(self):
Repository: OpenMined/PySyft
Pull request #199 (2017-09-01 03:39:50)

Implemented clamp() and clamp_() on TensorBase #32 


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index 6963de3675..cce9fa6fdb 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -621,6 +621,19 @@ class TensorBase(object):
         self.data = np.random.lognormal(mean, stdev, self.shape())
         return self
 
+    def clamp(self, minimum=None, maximum=None):
+        """Returns a clamped tensor into the range [min, max], elementwise"""
+        if self.encrypted:
+            return NotImplemented
+        return TensorBase(np.clip(self.data, a_min=minimum, a_max=maximum))
+
+    def clamp_(self, minimum=None, maximum=None):
+        """Clamp the tensor, in-place, elementwise into the range [min, max]"""
+        if self.encrypted:
+            return NotImplemented
+        self.data = np.clip(self.data, a_min=minimum, a_max=maximum)
+        return self
+
     def uniform_(self, low=0, high=1):
         """Fills the tensor in-place with numbers sampled unifromly
         over the half-open interval [low,high) or from the uniform distribution"""


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 3142b516d3..51bdebca9b 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -469,6 +469,32 @@ class logTests(unittest.TestCase):
         self.assertTrue(np.allclose((t1.log1p_()).data, [0.69314718, 1.09861229, 1.38629436]))
 
 
+class clampTests(unittest.TestCase):
+    def testClampInt(self):
+        t1 = TensorBase(np.arange(10))
+        t2 = t1.clamp(minimum=2, maximum=7)
+        expected_tensor = TensorBase(np.array([2, 2, 2, 3, 4, 5, 6, 7, 7, 7]))
+        self.assertEqual(t2, expected_tensor)
+
+    def testClampFloat(self):
+        t1 = TensorBase(np.arange(1, step=0.1))
+        t2 = t1.clamp(minimum=0.2, maximum=0.7)
+        expected_tensor = TensorBase(np.array([0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.7, 0.7]))
+        self.assertEqual(t2, expected_tensor)
+
+    def testClampIntInPlace(self):
+        t1 = TensorBase(np.arange(10))
+        t1.clamp_(minimum=2, maximum=7)
+        expected_tensor = TensorBase(np.array([2, 2, 2, 3, 4, 5, 6, 7, 7, 7]))
+        self.assertEqual(t1, expected_tensor)
+
+    def testClampFloatInPlace(self):
+        t1 = TensorBase(np.arange(1, step=0.1))
+        t1.clamp_(minimum=0.2, maximum=0.7)
+        expected_tensor = TensorBase(np.array([0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.7, 0.7]))
+        self.assertEqual(t1, expected_tensor)
+
+
 class uniformTests(unittest.TestCase):
     def testUniform(self):
         t1 = TensorBase(np.zeros(4))
Repository: OpenMined/PySyft
Pull request #204 (2017-09-01 21:50:00)

Resize functionality 
with reference to issue https://github.com/OpenMined/PySyft/issues/88 it is provides a basic resizing functionality.


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index 608cbf7667..7cbf980258 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -768,6 +768,30 @@ class TensorBase(object):
         else:
             return self.view(tensor.shape())
 
+    def resize_(self, *size):
+        input_size = np.prod(size)
+        extension = input_size - self.data.size
+        flattened = self.data.flatten()
+        if input_size >= 0:
+            if extension > 0:
+                data = np.append(flattened, np.zeros(extension))
+                self.data = data.reshape(*size)
+                print(self.data)
+            elif extension < 0:
+                size_ = self.data.size + extension
+                self.data = flattened[:size_]
+                self.data = self.data.reshape(*size)
+                print(self.data)
+            else:
+                self.data = self.data.reshape(*size)
+                print(self.data)
+        else:
+            raise ValueError('negative dimension not allowed')
+
+    def resize_as_(self, tensor):
+        size = tensor.data.shape
+        self.resize_(size)
+
     def round(self, decimals=0):
         """Returns a new tensor with elements rounded off to a nearest decimal place"""
         if self.encrypted:


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 199480766d..17a4cea776 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -21,6 +21,17 @@ class DimTests(unittest.TestCase):
         print(t.data.dtype)
         self.assertTrue(syft.equal(t.view_as(t1), TensorBase(np.array([[1.0], [2.0], [3.0]]))))
 
+    def testResize(self):
+        t = TensorBase(np.array([1.0, 2.0, 3.0]))
+        t.resize_([1, 2])
+        self.assertEqual(t.data.shape, (1, 2))
+
+    def testResizeAs(self):
+        t = TensorBase(np.array([1, 2, 3]))
+        t2 = TensorBase(np.array([[1], [2]]))
+        t.resize_as_(t2)
+        self.assertEqual(t.data.shape, (2, 1))
+
     def testSize(self):
         t = TensorBase([1, 2, 3])
         t1 = TensorBase([1.0, 2.0, 3.0])
Repository: OpenMined/PySyft
Pull request #208 (2017-09-02 19:47:36)

Implemented bernoulli functionality for TensorBase: #27
Implemented bernoulli() and it's in-place version bernoulli_() with tests


Patch:
diff --git a/syft/tensor.py b/syft/tensor.py
index 29b9d26a59..3f30b5eee8 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -645,6 +645,33 @@ class TensorBase(object):
         self.data = np.clip(self.data, a_min=minimum, a_max=maximum)
         return self
 
+    def bernoulli(self, p):
+        """
+        Returns a Tensor filled with binary random numbers (0 or 1) from a bernoulli distribution
+        with probability and shape specified by p(arr_like).
+
+        The p Tensor should be a tensor containing probabilities to be used for drawing the
+        binary random number. Hence, all values in p have to be in the range: 0<=p<=1
+        """
+        if self.encrypted:
+            return NotImplemented
+        p = _ensure_tensorbase(p)
+        return TensorBase(np.random.binomial(1, p.data))
+
+    def bernoulli_(self, p):
+        """
+        Fills the Tensor in-place with binary random numbers (0 or 1) from a bernoulli distribution
+        with probability and shape specified by p(arr_like)
+
+        The p Tensor should be a tensor containing probabilities to be used for drawing the
+        binary random number. Hence, all values in p have to be in the range: 0<=p<=1
+        """
+        if self.encrypted:
+            return NotImplemented
+        p = _ensure_tensorbase(p)
+        self.data = np.random.binomial(1, p.data)
+        return self
+
     def uniform_(self, low=0, high=1):
         """Fills the tensor in-place with numbers sampled unifromly
         over the half-open interval [low,high) or from the uniform distribution"""


Test patch:
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index c913b64440..1d61612b33 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -508,6 +508,22 @@ class clampTests(unittest.TestCase):
         self.assertEqual(t1, expected_tensor)
 
 
+class bernoulliTests(unittest.TestCase):
+    def testBernoulli(self):
+        p = TensorBase(np.random.uniform(size=(3, 2)))
+        t1 = TensorBase(np.zeros((5, 5)))
+        t2 = t1.bernoulli(p)
+        self.assertTupleEqual((3, 2), t2.shape())
+        self.assertTrue(np.all(t2.data >= 0) and np.all(t2.data <= 1))
+
+    def testBernoulli_(self):
+        p = TensorBase(np.random.uniform(size=(3, 2)))
+        t1 = TensorBase(np.zeros((5, 5)))
+        t1.bernoulli_(p)
+        self.assertTupleEqual((3, 2), t1.shape())
+        self.assertTrue(np.all(t1.data >= 0) and np.all(t1.data <= 1))
+
+
 class uniformTests(unittest.TestCase):
     def testUniform(self):
         t1 = TensorBase(np.zeros(4))