Matmul for sparse matrices with dense vector raising "Type mismatch inputs"
LMikeH opened this issue · comments
Hello I am struggling to do some basic operations with sparse arrays. I need to be able to create sparse arrays for solving PDEs without having to build a full dense matrix. Anyway, I'm quite confused about the error I get below.
My code below:
import arrayfire as af
import numpy as np
import array
rows = np.array([1,2,3,4,5])
cols = np.array([1,2,3,4,5])
vals = np.array([1.0,1.0,1.0,1.0,1.0])
spA = af.create_sparse_from_host(vals,rows,cols,5,5,storage=af.STORAGE.CSR)
b = af.Array(array.array('f',(2,3,4,5,6)))
ans = af.matmul(spA,b)
gives the following error:
Traceback (most recent call last):
File "C:/Users/User/UsrApps/FireTest/tinytest.py", line 14, in
ans = af.matmul(spA,b)
File "C:\Users\User\Dev\Python\Python35\lib\site-packages\arrayfire\blas.py", line 57, in matmul
lhs_opts.value, rhs_opts.value))
File "C:\Users\User\Dev\Python\Python35\lib\site-packages\arrayfire\util.py", line 79, in safe_call
raise RuntimeError(to_str(err_str))
RuntimeError: In function af_err __cdecl af_sparse_matmul(void **,void *const ,void *const ,const af_mat_prop,const af_mat_prop)
In file src\api\c\blas.cpp:76
Type mismatch inputs
Thanks,
Mike
vals
is float64
while b
is flaot32
. Try vals = np.array([1.0] * 5, dtype = np.float32)
Thanks alot! That worked.