bigdl.util package¶
Submodules¶
bigdl.util.common module¶
-
class
bigdl.util.common.
JTensor
(storage, shape, bigdl_type='float')[source]¶ Bases:
object
A wrapper to easy our work when need to pass or return Tensor to/from Scala.
>>> import numpy as np >>> from bigdl.util.common import JTensor >>> np.random.seed(123) >>>
-
classmethod
from_ndarray
(a_ndarray, bigdl_type='float')[source]¶ Convert a ndarray to Tensor which would be used in Java side.
>>> import numpy as np >>> from bigdl.util.common import JTensor >>> from bigdl.util.common import callBigDlFunc >>> np.random.seed(123) >>> data = np.random.uniform(0, 1, (2, 3)).astype("float32") >>> result = JTensor.from_ndarray(data) >>> data_back = result.to_ndarray() >>> (data == data_back).all() True >>> tensor1 = callBigDlFunc("float", "testTensor", JTensor.from_ndarray(data)) # noqa >>> array_from_tensor = tensor1.to_ndarray() >>> (array_from_tensor == data).all() True
-
classmethod
-
class
bigdl.util.common.
Sample
(features, label, bigdl_type='float')[source]¶ Bases:
object
-
classmethod
from_ndarray
(features, label, bigdl_type='float')[source]¶ Convert a ndarray of features and label to Sample, which would be used in Java side.
>>> import numpy as np >>> from bigdl.util.common import callBigDlFunc >>> from bigdl.util.common import Sample >>> from numpy.testing import assert_allclose >>> sample = Sample.from_ndarray(np.random.random((2,3)), np.random.random((2,3))) >>> sample_back = callBigDlFunc("float", "testSample", sample) >>> assert_allclose(sample.features.to_ndarray(), sample_back.features.to_ndarray()) >>> assert_allclose(sample.label.to_ndarray(), sample_back.label.to_ndarray())
-
classmethod
-
class
bigdl.util.common.
TestResult
(result, total_num, method)[source]¶ A testing result used to benchmark the model quality.