コード例 #1
0
ファイル: ND.doublemkl.cs プロジェクト: aidevnn/DustLore
        public static NDarray <double> GemmTATBC(NDarray <double> a, NDarray <double> b, NDarray <double> c = null)
        {
            if (a.Shape.Length != 2 || b.Shape.Length != 2 || (c != null && c.Shape.Length != 2))
            {
                throw new Exception();
            }

            (int wa, int ha) = (a.Shape[0], a.Shape[1]);
            (int wb, int hb) = (b.Shape[0], b.Shape[1]);

            if (wa != hb || (c != null && (c.Count != ha && c.Count != wb && c.Count != ha * wb)))
            {
                throw new Exception();
            }

            var nd = new NDarray <double>(ha, wb);

            if (c != null)
            {
                nd = ND.AddNDarray(nd, c);
            }

            MKL_dgemm(CMAT, TRANSPOSE_YES, TRANSPOSE_YES, ha, wb, wa, 1.0, a.Data, ha, b.Data, hb, 1.0, nd.Data, wb);

            return(nd);
        }
コード例 #2
0
ファイル: ND.doublesharp.cs プロジェクト: aidevnn/DustLore
        public static NDarray <double> GemmTABC(NDarray <double> a, NDarray <double> b, NDarray <double> c = null)
        {
            if (a.Shape.Length != 2 || b.Shape.Length != 2 || (c != null && c.Shape.Length != 2))
            {
                throw new Exception();
            }

            (int wa, int ha) = (a.Shape[0], a.Shape[1]);
            (int wb, int hb) = (b.Shape[0], b.Shape[1]);

            if (wa != wb || (c != null && (c.Count != ha && c.Count != hb && c.Count != ha * hb)))
            {
                throw new Exception();
            }

            var nd = new NDarray <double>(ha, hb);

            if (c != null)
            {
                nd = ND.AddNDarray(nd, c);
            }

            for (int i = 0; i < ha; ++i)
            {
                for (int j = 0; j < hb; ++j)
                {
                    double sum = 0.0;
                    for (int k = 0; k < wa; ++k)
                    {
                        sum += a.Data[k * ha + i] * b.Data[k * hb + j];
                    }

                    nd.Data[i * hb + j] += sum;
                }
            }

            return(nd);
        }