mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: - It's first prototype that includes simple unary test. - will probably need to iterate based on it to include more arches that we see promising offline results Differential Revision: D4208336 fbshipit-source-id: 5b2d2a5a0274a9dcad0fb169e43e78aa9d9a704d
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
from __future__ import unicode_literals
|
|
|
|
from caffe2.python import core, schema
|
|
from caffe2.python.layers.layers import (
|
|
ModelLayer,
|
|
)
|
|
|
|
|
|
class DotProduct(ModelLayer):
|
|
|
|
def __init__(self, model, input_record, name='dot_product', **kwargs):
|
|
super(DotProduct, self).__init__(model, name, input_record, **kwargs)
|
|
assert isinstance(input_record, schema.Struct),\
|
|
"Incorrect input type. Excpected Struct, but received: {0}".\
|
|
format(input_record)
|
|
assert len(input_record.get_children()) == 2, (
|
|
"DotProduct accept 2 inputs")
|
|
assert len(set(input_record.field_types())) == 1, (
|
|
"Inputs should be of the same field type")
|
|
|
|
for field_name, field_type in input_record.fields.items():
|
|
assert isinstance(field_type, schema.Scalar),\
|
|
"Incorrect input type. Excpected Scalar, but received: {0}".\
|
|
format(field_type)
|
|
|
|
self.output_schema = schema.Scalar(
|
|
(input_record.field_types()[0].base, ()),
|
|
core.ScopedBlobReference(model.net.NextName(self.name + '_output')))
|
|
|
|
def add_ops(self, net):
|
|
net.DotProduct(
|
|
self.input_record.field_blobs(),
|
|
self.output_schema(),
|
|
)
|