Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linfa-kernel fails to compile #307

Closed
avs-origami opened this issue Jun 15, 2023 · 11 comments
Closed

linfa-kernel fails to compile #307

avs-origami opened this issue Jun 15, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@avs-origami
Copy link

avs-origami commented Jun 15, 2023

When I try to build the wine quality example for linfa-svm, I get the following error:

   Compiling linfa-kernel v0.6.1
error[E0599]: no method named `mul` found for reference `&CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>` in the current scope
  --> C:\Users\[username]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\linfa-kernel-0.6.1\src\inner.rs:64:14
   |
64 |         self.mul(rhs)
   |              ^^^ method not found in `&CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>`

error[E0599]: no method named `mul` found for reference `&CsMatBase<F, usize, &'a [usize], &'a [usize], &'a [F]>` in the current scope
   --> C:\Users\[username]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\linfa-kernel-0.6.1\src\inner.rs:109:14
    |
109 |         self.mul(rhs)
    |              ^^^ method not found in `&CsMatBase<F, usize, &[usize], &[usize], &[F]>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `linfa-kernel` (lib) due to 2 previous errors

I am on windows 10 with rustc version 1.70.0. I also tried version 0.5.1 which gives me the same error, and it also happens when I try it on my Arch Linux machine with rustc version 1.68.0.

I looked around in the source files, and it appears that this problem is related to the trait binding of the generic F:

impl<F: linfa::Float> Inner for CsMat<F>

and

impl<'a, F: linfa::Float> Inner for CsMatView<'a, F>

Any help would be appreciated.

@xosxos
Copy link

xosxos commented Jun 17, 2023

I have the same issue. Seems like CsMat which is imported from sprs cannot implement std::ops:Mul for some reason. Multiplication of a CsMat with an ArrayView2 is the issue which was handled by the std::ops::Mul trait previously from what I can see. But for some reason this is now broken.

@avs-origami
Copy link
Author

Yes. I tried creating a new CsMat in a test crate, and I was able to call mul() on it. So I think the issue is related to CsMat not liking linfa::Float as the generic.

@avs-origami
Copy link
Author

avs-origami commented Jun 17, 2023

I changed the start of the impl block to this:

impl<F: Float> Inner for CsMat<F> where 
    CsMat<F>: Mul {
        ...
}

which results in several errors that look like this:

error[E0277]: cannot multiply `CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>` by `CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>`
   --> algorithms/linfa-kernel/src/lib.rs:196:20
    |
196 | impl<'a, F: Float> Kernel<F> {
    |                    ^^^^^^^^^ no implementation for `CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>> * CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>`
    |
    = help: the trait `Mul` is not implemented for `CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>`
    = help: the following other types implement trait `Mul<Rhs>`:
              <&'a CsMatBase<N, I, IpS, IS, DS, Iptr> as Mul<&'b ndarray::ArrayBase<DS2, Dim<[usize; 1]>>>>
              <&'a CsMatBase<N, I, IpS, IS, DS, Iptr> as Mul<&'b ndarray::ArrayBase<DS2, Dim<[usize; 2]>>>>
              <&'a CsMatBase<N, I, IpS1, IS1, DS1, Iptr> as Mul<&'b CsMatBase<N, I, IpS2, IS2, DS2, Iptr>>>
              <&'a CsMatBase<N, I, IpS1, IS1, DS1, Iptr> as Mul<&'b CsVecBase<IS2, DS2, N, I>>>
              <&'a CsMatBase<f32, I, IpStorage, IStorage, DStorage, Iptr> as Mul<f32>>
              <&'a CsMatBase<f64, I, IpStorage, IStorage, DStorage, Iptr> as Mul<f64>>
              <&'a CsMatBase<i16, I, IpStorage, IStorage, DStorage, Iptr> as Mul<i16>>
              <&'a CsMatBase<i32, I, IpStorage, IStorage, DStorage, Iptr> as Mul<i32>>
            and 8 others
note: required for `CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>` to implement `Inner`
   --> algorithms/linfa-kernel/src/inner.rs:60:16
    |
60  | impl<F: Float> Inner for CsMat<F> where 
    |                ^^^^^     ^^^^^^^^
61  |     CsMat<F>: Mul {
    |               --- unsatisfied trait bound introduced here

Maybe this helps to diagnose the issue.

@bytesnake bytesnake added the bug Something isn't working label Jun 21, 2023
@bytesnake
Copy link
Member

Could be related to sparsemat/sprs#278

@bytesnake
Copy link
Member

bytesnake commented Jun 21, 2023

This is a regression introduced with the sprs::MulAcc trait in 0.11 https://github.com/sparsemat/sprs/blob/master/changelog.rst Can you try with latest commit?

@avs-origami
Copy link
Author

It works now. Thanks!

@jeff-hykin
Copy link

I still get this issue. What version is the fix on?
Screen Shot 2023-07-06 at 11 40 34 AM

@avs-origami
Copy link
Author

You need the latest commit. Instead of this:

linfa-kernel = "0.6.1"

Use this:

linfa-kernel = { git = "https://github.com/rust-ml/linfa.git" }

@jeff-hykin
Copy link

Thanks! @avs-origami

@clime
Copy link

clime commented Jul 8, 2023

I;ve just opened sparsemat/sprs#330

@cgubbin
Copy link

cgubbin commented Sep 26, 2024

I'm having this issue again today on linfa 0.7.0.

Thanks to the above I resolved by pinning sprs = "=0.11.1" and everything is compiling again. Would you accept a pull request to pin the sprs version?

dcjones added a commit to dcjones/proseg that referenced this issue Jan 24, 2025
Fix some minor bugs.

Output factorization.

Partial latent space mixture model implementation.

Use mixture model when factoring.

Add genewise offset parameters.

Attempts to debug the factorization model.

First attempt at new poisson matrix factorization model.

Purge old stuff from the NB model.

Sampling r

Fix bug in multinomial sampling.

A failed attempt at inducing sparsity.

Revert "A failed attempt at inducing sparsity."

This reverts commit 57b59dc.

Getting mixture model on phi working.

Tweak beta prior.

Gradual switch to gamma-gamma prior. Sampling phi and theta.

Sampling r using the crt trick.

Sampling s theta

Sampling s phi

Remove some dead code, fix a bug.

Solve collapsing components by using NB marginal.

Fix forgetting to sqrt variance.

Fix kmeans initialization getting lost.

Include missing prior means on s params. Lots of debugging junk.

Figure out reasonable priors, delete some diagnostic shit.

Optimization

Tinkering with priors.

Minor optimization.

Add arguments to set some hyperparameters.

Fix up clumsy rebase.

Remove unecessary layer dimension from foreground_counts array.

Faster sort on transcript repo.

Remove unused counts array.

PCA before Kmeans when initializing components assignments

Remove some dead code.

Debugging and tinkering with initialization.

A possible implementation of 'effective volume' parameters.

Different effective volume scheme, disabled for now.

Add argument to exclude genes with regex, with xenium defaults.

Dirichlet distributed theta, which seems to get better results.

Also fixing phi dispersion parameter for now. Not ideal, but seems to
get the best results.

Option to write factorization parameters.

Pin sprs at version 0.11.1 until compilation problems are resolved.

See: rust-ml/linfa#307

Fix compile errors from rebase.

Quantile transformation of z coordinates.

Revert "Quantile transformation of z coordinates."

This reverts commit cc39ad0223cb62ad50be0000860f61e07fb6af9b.

Add volume term when sampling z, fix log_effective_volume not updating with --no-cell-scales

Implement partial factorization scheme.

Use more unfactored genes by default.

Fix rebase, bump version.

Remove some more debugging code.

Replace some problematic dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants