Esempio n. 1
0
    static Matrix<char>* AllocateMatrix(const NDShape& viewShape, const DeviceDescriptor& device)
    {
        auto matrixDims = GetMatrixDimensions(viewShape);
        auto maskMatrix = new Matrix<char>(matrixDims.first, matrixDims.second, AsCNTKImplDeviceId(device));
        maskMatrix->SetValue(1);

        return maskMatrix;
    }
Esempio n. 2
0
    NDArrayViewPtr NDArrayView::RandomUniform(const NDShape& shape, double rangeStart, double rangeEnd, unsigned long seed, const DeviceDescriptor& device/* = DeviceDescriptor::DefaultDevice()*/)
    {
        auto matrixDims = GetMatrixDimensions(shape);
        auto randomUniformMatrix = std::make_shared<Matrix<ElementType>>(Matrix<ElementType>::RandomUniform(matrixDims.first, matrixDims.second, AsCNTKImplDeviceId(device), (ElementType)rangeStart, (ElementType)rangeEnd, seed));
        auto tensorView = new TensorView<ElementType>(randomUniformMatrix, AsTensorShape(shape));

        auto view = new NDArrayView(AsDataType<ElementType>(), device, StorageFormat::Dense, shape, false, tensorView);
        return NDArrayViewPtr(view, [](_ReferenceCounter* ptr) { delete ptr; });
    }
Esempio n. 3
0
 ConstSubMatrix ToBoomMatrixView(SEXP m) {
   if (!Rf_isMatrix(m)) {
     report_error("ToBoomMatrix called with a non-matrix argument");
   }
   std::pair<int,int> dims = GetMatrixDimensions(m);
   PROTECT(m = Rf_coerceVector(m, REALSXP));
   ConstSubMatrix ans(REAL(m), dims.first, dims.second);
   UNPROTECT(1);
   return ans;
 }
Esempio n. 4
0
 static TensorView<ElementType>* AllocateTensorView(const NDShape& viewShape,
                                                    CNTK::StorageFormat storageType,
                                                    const DeviceDescriptor& device)
 {
     auto matrixDims = GetMatrixDimensions(viewShape);
     std::shared_ptr<Matrix<ElementType>> matrix = std::make_shared<Matrix<ElementType>>(matrixDims.first,
                                                                                         matrixDims.second,
                                                                                         AsCNTKImplDeviceId(device),
                                                                                         IsSparseStorageFormat(storageType) ? MatrixType::SPARSE : MatrixType::DENSE,
                                                                                         AsCNTKMatrixFormat(storageType));
     return new TensorView<ElementType>(matrix, AsTensorShape(viewShape));
 }
Esempio n. 5
0
    static TensorView<ElementType>* AllocateTensorView(const NDShape& viewShape,
                                    const DeviceDescriptor& device,
                                    void* dataBuffer,
                                    size_t bufferSizeInBytes)
    {
        if (dataBuffer == nullptr)
            InvalidArgument("Cannot create a NDArrayView over a null data buffer");

        if (bufferSizeInBytes < (viewShape.TotalSize() * sizeof(ElementType)))
            InvalidArgument("Size of the specified buffer for creating the NDArrayView is smaller than the specified view shape");

        auto matrixDims = GetMatrixDimensions(viewShape);
        std::shared_ptr<Matrix<ElementType>> matrix = std::make_shared<Matrix<ElementType>>(matrixDims.first, matrixDims.second, (ElementType*)dataBuffer, AsCNTKImplDeviceId(device), matrixFlagDontOwnBuffer);
        return new TensorView<ElementType>(matrix, AsTensorShape(viewShape));
    }