@@ -0,0 +1,2411 @@
+#%0A# Copyright 2018 Analytics Zoo Authors.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A#%0Afrom bigdl.util.common import Sample as BSample, JTensor as BJTensor%0Aimport numpy as np%0A%0A%0Adef to_list_of_numpy(elements):%0A%0A    if isinstance(elements, np.ndarray):%0A        return %5Belements%5D%0A    elif np.isscalar(elements):%0A        return %5Bnp.array(elements)%5D%0A    elif not isinstance(elements, list):%0A        raise ValueError(%22Wrong type: %25s%22 %25 type(elements))%0A%0A    results = %5B%5D%0A    for element in elements:%0A        if np.isscalar(element):%0A            results.append(np.array(element))%0A        elif isinstance(element, np.ndarray):%0A            results.append(element)%0A        else:%0A            raise ValueError(%22Wrong type: %25s%22 %25 type(element))%0A%0A    return results%0A%0A%0Aclass JTensor(BJTensor):%0A%0A    def __init__(self, storage, shape, bigdl_type=%22float%22, indices=None):%0A        super(JTensor, self).__init__(storage, shape, bigdl_type, indices)%0A%0A    @classmethod%0A    def from_ndarray(cls, a_ndarray, bigdl_type=%22float%22):%0A        %22%22%22%0A        Convert a ndarray to a DenseTensor which would be used in Java side.%0A        %22%22%22%0A        if a_ndarray is None:%0A            return None%0A        assert isinstance(a_ndarray, np.ndarray), %5C%0A            %22input should be a np.ndarray, not %25s%22 %25 type(a_ndarray)%0A        return cls(a_ndarray,%0A                   a_ndarray.shape,%0A                   bigdl_type)%0A%0A%0Aclass Sample(BSample):%0A%0A    def __init__(self, features, labels, bigdl_type=%22float%22):%0A        super(Sample, self).__init__(features, labels, bigdl_type)%0A%0A    @classmethod%0A    def from_ndarray(cls, features, labels, bigdl_type=%22float%22):%0A        features = to_list_of_numpy(features)%0A        labels = to_list_of_numpy(labels)%0A        return cls(%0A            features=%5BJTensor(feature, feature.shape) for feature in features%5D,%0A            labels=%5BJTensor(label, label.shape) for label in labels%5D,%0A            bigdl_type=bigdl_type)%0A

fix tfnet cannot handle scalar (#795)