void GmresWrapper<Rank>::ApplyOperator(blitz::Array<cplx, 1> &input, blitz::Array<cplx, 1> &output) { if (Psi == 0) { throw std::runtime_error("Psi is 0"); } if (TempPsi == 0) { throw std::runtime_error("TempPsi is 0"); } //Map the 1d vectors to a a blitz array of correct shape DataVector shape = Psi->GetData().shape(); DataVector stride = Psi->GetData().stride(); DataArray inData(input.data(), shape, stride, blitz::neverDeleteData); DataArray inData2(input.data(), shape, stride, blitz::neverDeleteData); DataArray outData(output.data(), shape, stride, blitz::neverDeleteData); DataArray outData2(output.data(), shape, stride, blitz::neverDeleteData); outData = 0; //Set psi and tempPsi to point to correct vectorsbuffers DataArray oldData = Psi->GetData(); DataArray oldTempData = TempPsi->GetData(); Psi->SetData(inData); TempPsi->SetData(outData); OperatorCallback(Psi, TempPsi); //Restore the former buffers Psi->SetData(oldData); TempPsi->SetData(oldTempData); }
void netcdf_write_blitz(NcVar *nc_var, blitz::Array<T, rank> const &val) { long counts[rank]; for (int i=0; i<rank; ++i) counts[i] = val.extent(i); //printf("netcdf_write_blitz: %p %p\n", nc_var, val.data()); nc_var->put(val.data(), counts); }
double VectorInnerProduct(const blitz::Array<double, Rank> &u, const blitz::Array<double, Rank> &v) { if (u.size() != v.size()) { cout << "Vector u and v is of different size: " << u.size() << " != " << v.size() << endl; throw std::runtime_error("invalid vector sizes for inner product"); } if (!u.isStorageContiguous()) { throw std::runtime_error("Vector u is not contiguous"); } if (!v.isStorageContiguous()) { throw std::runtime_error("Vector v is not contiguous"); } int N = u.size(); int uStride = 1; //u.stride(0); int vStride = 1; //v.stride(0); return BLAS_NAME(ddot)(N, (double*)u.data(), uStride, (double*)v.data(), vStride); }
cplx VectorInnerProduct(const blitz::Array<cplx, Rank> &u, const blitz::Array<cplx, Rank> &v) { if (u.size() != v.size()) { cout << "Vector u and v is of different size: " << u.size() << " != " << v.size() << endl; throw std::runtime_error("invalid vector sizes for inner product"); } if (!u.isStorageContiguous()) { throw std::runtime_error("Vector u is not contiguous"); } if (!v.isStorageContiguous()) { throw std::runtime_error("Vector v is not contiguous"); } int N = u.size(); int uStride = 1; //u.stride(0); int vStride = 1; //v.stride(0); cplx result; acml::doublecomplex ret = BLAS_NAME(zdotc)(N, (acml::doublecomplex*)u.data(), uStride, (acml::doublecomplex*)v.data(), vStride); result = cplx(ret.real, ret.imag); return result; }