rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.61k stars 306 forks source link

Dot product not working #1282

Closed wiseaidev closed 1 year ago

wiseaidev commented 1 year ago

Hey everyone. I am using the dot method to compute the dot product. However, this method is not working.

Code To Reproduce

use ndarray::arr2;

fn main() {
    let a = arr2(&[[1., 2.], [0., 1.]]);
    let b = arr2(&[[1., 2.], [2., 3.]]);

    assert!(a.dot(&b) == arr2(&[[5., 8.], [2., 3.]]));
}

Stack Trace

click me ma fren ```sh error: linking with `cc` failed: exit status: 1 | = note: LC_ALL="C" PATH="/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/mahmoud/.cosmo/bin:/home/mahmoud/.detaspace/bin:/home/mahmoud/.deta/bin:/home/mahmoud/.nvm/versions/node/v19.3.0/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/mahmoud/.cargo/bin:/home/mahmoud/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcUh3b8N/symbols.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.12yu26zysk3df3d9.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.13idazsshldjhrjt.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.18lmgucxtg208hk7.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.18xzm9xnqjsg87t6.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1bkvwpar9y5nxrcb.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1n16ilyrr950wz1c.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1n1swrb86r3sfiml.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1niny7rfbmzlzsup.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1qn2sz5ub6cqy1uc.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1tzlh3t4ii2qshyc.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1v5w0uva87czpe0h.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1vdbr23gy6cm9vwc.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.1vjtkhnv6qo8jp4c.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.20hokz1iqvyugyb9.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.21y6ev0kd7tb7met.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.221u725nik25p7jc.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.25pkg1rp8egoupbh.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.284v665fuong5z70.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.29xttlyopcwykw03.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2c5ik2hjl2vikpbl.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2hhtp6r3x8u4zo05.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2mxjyp99q3ky0woz.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2mxvfwowbbms4hro.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2n952brz75fz7w2t.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2qt0jblx2p7suhqv.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2tqyyz6s1zhd2r98.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.37vh5gxxm0y2jw1m.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3j382naukylw6zwt.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3pk6mo6qgvpxfguq.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3s1bh98ue30zpe92.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3tc66ht2tj6nbrgv.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3upr3vass1hxgsw7.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3va9qtm5ynqz6mj3.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3wsqcfpmzww7lsbm.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.3xlcrckqthv4y1di.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.40unu2u9wwbev0ib.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.44acbgffa0w8n054.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.47rv4u65v0zbzv85.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.49pm51y7tacvjibk.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4dk2jl8yc00fql95.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4dw1pwrkx5w7neoi.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4f869hryc8wtbmxo.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4fhn4cl555ooyskz.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4o6yvg9s112cb73f.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4omxwe8pth3fh0vq.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4srd4nj4iahvafu9.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4u27sk5odnsq4r44.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4zaf4u54581vym8o.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.52di5r1xfsyozgq9.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.57ykpxfnq1r0frym.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.5e22preglw7bzihk.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.5gri5roz5dnxrnzd.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.ah9a2ofaxjk5hz2.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.fc0q7nzlme36tq3.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.jmuvo1to4do4q5f.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.llf0ir6x1pelatf.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.nq3kduu6ze4az24.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.z6te4d5yxra376v.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.zquqsfk01wqwxpu.rcgu.o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.2kgyardvlq2pd2ds.rcgu.o" "-Wl,--as-needed" "-L" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps" "-L" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/build/openblas-src-e2b2ca1cebd309c9/out" "-L" "/usr/lib" "-L" "/usr/lib/gcc/x86_64-linux-gnu/11" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/linuxbrew/.linuxbrew/Cellar/gcc/12.2.0/lib/gcc/current" "-L" "/home/linuxbrew/.linuxbrew/Cellar/gcc/12.2.0/lib/gcc/current/gcc" "-L" "/home/linuxbrew/.linuxbrew/Cellar/gcc/12.2.0/lib/gcc/current/gcc/x86_64-pc-linux-gnu/12" "-L" "/home/linuxbrew/.linuxbrew/lib" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libndarray-1f8ad44f7dd877f7.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libmatrixmultiply-96fc95c23e57be3d.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libapprox-751308e70824ffca.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libnum_complex-5027853716e79619.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libserde-40dac5ebf0eda501.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/librand-23572683fa797c5d.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/librand_chacha-17ff4e6814f454c3.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libppv_lite86-77c24c11bb635843.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/librand_core-58cbfcf8986597e4.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libgetrandom-09ea8733eff9d543.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libcfg_if-305ff6ac5e1cfc5a.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libnum_integer-de32948740fa00ae.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libnum_traits-5ce664a8f931425b.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/librawpointer-4cc2202affffa316.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/libcblas_sys-32b4ebaa89f98cea.rlib" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/liblibc-4e5890aca5342948.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-bc6b80525d6b1f3b.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-dbb416fff97e9855.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-af60be54961a030f.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-1303bc5098cb2f44.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-96ca4807f9d03fdf.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-03b108942351d49a.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-b348df34b7d8ac11.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-26a06d9c5ec29d3a.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-b5295fdab67e4cf6.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-b257ed099e7f67d0.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-c27b5dca54e295d8.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-f6c8245d52afa66d.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-642c68f15c02cc52.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-eecd84150c4ad967.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-123ffa13a38501db.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-2177aff67f4e9999.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2298a66e03bd0fd2.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-f3c3b25345711552.rlib" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-10f041ff25bad5f3.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/mahmoud/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs" = note: /usr/bin/ld: /home/mahmoud/Desktop/Rust/article-3/proj/target/debug/deps/proj-735d0f4eaa722fae.4srd4nj4iahvafu9.rcgu.o: in function `ndarray::linalg::impl_linalg::mat_mul_impl': /home/mahmoud/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.15.6/src/linalg/impl_linalg.rs:480: undefined reference to `cblas_sgemm' /usr/bin/ld: /home/mahmoud/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.15.6/src/linalg/impl_linalg.rs:481: undefined reference to `cblas_dgemm' /usr/bin/ld: /home/mahmoud/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.15.6/src/linalg/impl_linalg.rs:483: undefined reference to `cblas_cgemm' /usr/bin/ld: /home/mahmoud/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.15.6/src/linalg/impl_linalg.rs:484: undefined reference to `cblas_zgemm' collect2: error: ld returned 1 exit status = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified = note: use the `-l` flag to specify native libraries to link = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname) warning: `proj` (bin "proj") generated 1 warning error: could not compile `proj` due to previous error; 1 warning emitted ```

It seems like this method requires a feature to be added that is not mentioned in the docs.

Edit: I tried adding this feature:

ndarray = { version = "0.15.6", features = ["blas"] }

Still not working!

bluss commented 1 year ago

Can you try the instructions and see if they work? https://github.com/rust-ndarray/ndarray#how-to-enable-blas-integration

however, blas is optional.

wiseaidev commented 1 year ago

Thanks for the response. I realized that I have to add the following crate:

extern crate blas_src;

IMO, this thing should be added to the example in the docs for beginners.