Giter Site home page Giter Site logo

linalg's People

Contributors

jtanderson avatar konovod avatar matthiaswinkelmann avatar rainbowzephyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

linalg's Issues

Flags feature discussion / request

I would have liked my sample in #7 to be a tiny bit more condensed

require "linalg"

m = LA::GMat[[3, -2],[4, -1]]
vals, vecs = m.eigs

res = (vecs.inv * m * vecs).detect
res.diagonal?
  1. It'd be nice if detect returned the input matrix, since it adds flags to that matrix. If a boolean would be a nicer return perhaps we could use detect? instead. But I suspect the only use of boolean is in checking the flags directly, detect seems to be for adjusting flags after a set of operations. And of course for that we can just use matrix.flags.property?

  2. It'd be nice if the Flags enum methods were forwarded to the matrix, so that instead of matrix.flags.diagonal? I could just call matrix.diagonal?.

eigs does not return complex eigenvalues if matrix is not complex

require "linalg"

m = LA::GMat[[3, -2],[4, -1]]
vals, vecs = m.eigs

res = vecs.inv * m * vecs
res.detect
res.flags.diagonal?

The last line of the above is false because it turns out that the vecs are all Float64 instead of complex as they should be. It seems this is because LAPACK method detection uses the type of the matrix, so only complex matrices are handed off to the complex solver.

By the way, the flags feature is awesome! I love that diagonal? sugar there ๐ŸŽ‰

Add "arange" matrix creation

This would be useful for creating range-based matrices. The basic functionality is to take a start, end, and delta, and return a row-vector. This should probably mimic the numpy.arange interface.

Here is my first pass at adding this to the Matrix class:

    def self.arange(start_val : T, end_val : T, delta = 1.0)
      unless (end_val - start_val).sign == delta.sign && delta.abs > 0
        raise IndexError.new("Range #{start_val}...#{end_val} invalid with step size #{delta}")
      end
      GeneralMatrix(T).new(1, ((end_val - start_val).abs.ceil / delta.abs).ceil.to_i) do |i,j|
        start_val + j*delta
      end
    end

One complaint I have with this code so far is that if you do Matrix.arange(5,4,1) it will return [[5]] instead of a {1,0} matrix. It's a matter of adding some extra edge-cases, but I'd like to clean it up to avoid clutter.

Pseudo Inverse of matrices

Hello,
First and foremost, great library we use it in production in some of our apps and has been going great so far. Regarding the future roadmap, you state that you wish to add Pseudo Inverse of matrices at some point. Is the pseudo inverse a dedicated call to LAPACK? Because we have implemented in pure Crystal using what we can call from the available APIs at this point and could create a merge request for it.

Keep up the great job

`sum` requires a `zero` method if no initial is given

Example program

require "linalg"

m = LA::GMat32.new(3, 3)
m1 = LA::GMat32.new(3, 3)
[m, m1].sum

throws

Error in line 5: instantiating 'Array(LA::GeneralMatrix(Float32))#sum()'

in /usr/local/Cellar/crystal/0.27.0/src/enumerable.cr:1112: undefined method 'zero' for LA::GeneralMatrix(Float32).class

    sum Reflect(T).first.zero

The idea is that if we don't pass an initial, then the sum has to start at zero (https://crystal-lang.org/api/0.27.2/Enumerable.html#sum-instance-method).

This issue is to discuss a possible solution. I'm guessing that we can overwrite sum to create a zeros to match the size of the first element (and even assert_same_size) when an initial is missing.

If you like that idea, or have a better one, let me know and I can probably put together a PR (unless you'd rather).

Init matrix row-wise

Awesome library!

I sorta expected to be able to do something like

m = GMat32.new(3, 4)
m.rows.map! do |row|
end

to initialize a matrix row by row instead of element by element. The motivation here is that I have a calculation that I need to do per row which is a little expensive, so it's a shame to have to repeat it.

By the way, just a simple m.rows breaks the crystal playground in the above

BUG: trying to downcast LA::SubMatrix(Float32) <- LA::Matrix(Float32)

Trying to downcast

m = GMat32.new(3, 4)
m.rows

triggers an error

BUG: trying to downcast

Implemented Features

Hello,
Is the features file Scipy.md updated? I would like to contribute more to the repository.

Thanks in advance

LAPACKE.sgesdd returned -5 (LA::LinAlgError)

So, I'm playing around with fairly large arrays and keep getting the following stacktrace while invoking svd when working with large but not super large matrixes (around 25k rows x 200-500 columns):

LAPACKE.sgesdd returned -5 (LA::LinAlgError)
  from /usr/share/crystal/src/crystal/main.cr:0:3 in 'main'
  from /usr/share/crystal/src/io/file_descriptor.cr:86:5 in 'seek'
  from _start
  from ???

I have tried reading both the code (linalg.cr) and sgesdd.f, but I havn't been able to figure out what the actual problem is. The actual point where it crashes seem to be very variable, I've seen everything from 150 to 500 columns both work and crash, but more crashes on large values.

Version bump

Hello,
Whenever I run shards install, it keeps installing an old version of the library specifically the one with commit 07a59a0aa444568aefef23eb914a457e1d38d2c5 from December of 2022. I don't know what needs to be done but a version bump may help?

Thanks in advance

Building application for Windows

I'm trying to build my linalg application using crystal build on ubuntu.. so that I can run it on Windows, but I can't get it right.
Here is what I did:
1- On Ubuntu, I build .obj file like this:
crystal build linalg-app.cr --target "x86_64-pc-windows-msvc" --cross-compile --static
2- I took the generated .obj file, together with the generated linker command, and run them on Windows, which looks like this
cl /nologo linalg-app.obj /Felinalg-app /link /DEBUG:FULL /PDBALTPATH:%_PDB% /INCREMENTAL:NO /STACK:0x800000 /LIBPATH:/usr/bin/../lib/crystal libopenblas.lib pcre.lib gc.lib /ENTRY:wmainCRTStartup iconv.lib advapi32.lib shell32.lib ole32.lib WS2_32.lib legacy_stdio_definitions.lib DbgHelp.lib libcmt.lib

but then I get that error:
fatal error lnk1181 cannot open input file 'libopenblas.lib

Any leads on how to compile a standalone executable that can run on windows?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.