Skip to content

Commit d23ea17

Browse files
authored
feat: add multi_margin_loss base (#346)
1 parent 17a1e0f commit d23ea17

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

src/base/multi_margin_loss.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef INFINI_OPS_BASE_MULTI_MARGIN_LOSS_H_
2+
#define INFINI_OPS_BASE_MULTI_MARGIN_LOSS_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class MultiMarginLoss : public Operator<MultiMarginLoss> {
9+
public:
10+
MultiMarginLoss(const Tensor input, const Tensor target, const double p,
11+
const double margin, const int64_t reduction, Tensor out)
12+
: input_shape_{input.shape()},
13+
input_strides_{input.strides()},
14+
input_type_{input.dtype()},
15+
target_shape_{target.shape()},
16+
target_strides_{target.strides()},
17+
target_type_{target.dtype()},
18+
out_shape_{out.shape()},
19+
out_strides_{out.strides()},
20+
out_type_{out.dtype()},
21+
p_{p},
22+
margin_{margin},
23+
reduction_{reduction},
24+
device_index_{out.device().index()} {}
25+
26+
virtual void operator()(const Tensor input, const Tensor target,
27+
const double p, const double margin,
28+
const int64_t reduction, Tensor out) const = 0;
29+
30+
protected:
31+
Tensor::Shape input_shape_;
32+
33+
Tensor::Strides input_strides_;
34+
35+
DataType input_type_;
36+
37+
Tensor::Shape target_shape_;
38+
39+
Tensor::Strides target_strides_;
40+
41+
DataType target_type_;
42+
43+
Tensor::Shape out_shape_;
44+
45+
Tensor::Strides out_strides_;
46+
47+
DataType out_type_;
48+
49+
double p_{};
50+
51+
double margin_{};
52+
53+
int64_t reduction_{};
54+
55+
int device_index_{0};
56+
};
57+
58+
} // namespace infini::ops
59+
60+
#endif

0 commit comments

Comments
 (0)