def export_proto(self, f):
        """
        Export model parameters in protobuf format.
        """
        from .lopq_model_pb2 import LOPQModelParams
        from itertools import chain

        lopq_params = LOPQModelParams()
        lopq_params.D = 2 * self.Cs[0].shape[1]
        lopq_params.V = self.V
        lopq_params.M = self.M
        lopq_params.num_subquantizers = self.subquantizer_clusters

        def matrix_from_ndarray(m, a):
            m.values.extend(map(float, np.nditer(a, order='C')))
            m.shape.extend(a.shape)
            return m

        def vector_from_ndarray(m, a):
            m.values.extend(map(float, np.nditer(a, order='C')))
            return m

        for C in self.Cs:
            matrix_from_ndarray(lopq_params.Cs.add(), C)
        for R in chain(*self.Rs):
            matrix_from_ndarray(lopq_params.Rs.add(), R)
        for mu in chain(*self.mus):
            vector_from_ndarray(lopq_params.mus.add(), mu)
        for sub in chain(*self.subquantizers):
            matrix_from_ndarray(lopq_params.subs.add(), sub)

        if type(f) is str:
            f = open(f, 'wb')
        f.write(lopq_params.SerializeToString())
        f.close()
dataset/ETHPy150Open yahoo/lopq/python/lopq/model.py/LOPQModel.export_proto/original