Git Product home page Git Product logo

numgo's People

Contributors

kunde21 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

Watchers

 avatar  avatar  avatar  avatar  avatar

numgo's Issues

Code reorganisation and file naming

After issue #8 I though this might be a point to bring up.

How would you go about the naming of the files and distributing the code in them? I suppose the "general" stuff that applies to any array type would go into numgo.go. For the Arrayb-specific methods we have bool.go. Where would you like the Array64-specific code?

It might be clearer to just have

  • numgo.go: General stuff applying to any array type
  • array64.go: A new file that holds Array64-specific code
  • arrayb.go: bool.go renamed, containing Arrayb-specific code.

Just an idea, I'm open for any other suggestions

Implement Reflect method

For various mathematical applications it would be useful to have a reflection method that mirrors the array around a given axis.

For a 2D example:

1 2 3
4 5 6
7 8 9

reflected around the Y-axis, this should result in:

3 2 1
6 5 4 
9 8 7

I'm trying to implement this for n-dimensional objects. The operation is simple: leave all indices as they are, except the ones of the given axis which equal (size at that axis)-(original position)

For a 2D matrix that could be implemented as:

func (a *Array64) ReflectX() {
	tmp := a.C()
	for x := 0; x < int(a.shape[0]; x++ {
	        for y := 0; y < int(a.shape[1]; y++ {
		        val := a.Get( x,y)
		        tmp.Set( a.shape[0] - x ,y )
	        }
        }
	a = tmp
}

func (a *Array64) ReflectY() {
	tmp := a.C()
	for x := 0; x < int(a.shape[0]; x++ {
	        for y := 0; y < int(a.shape[1]; y++ {
		        val := a.Get( x,y)
		       tmp.Set(x,  a.shape[1] - y  )
	        }
        }
	a = tmp
}

Since I can't make a method for every axis (unknown number of axis), I need a general method that takes the axis to flip around as parameter. Also I can't add a nested for loop for every axis, since I don't know how many there are.

// Reflect mirrors the array at around a given axis
func (a *Array64) Reflect(axis int) {

        if len(a.shape) < axis {
                /*handle error, invalid axis */
        }

	tmp := a.C()

	for i := 0; i < int(a.shape[axis]); i++ {
		val := a.Get(/*other axis before*/, i, /*other axis following*/)
		tmp.Set(val, /*other axis before*/, a.shape[axis] - i /*other axis following*/)
	}

	a = tmp
}

I have trouble filling in the blanks (see comments in code above). How do I go about implementing this?
More generally: How do I loop through all axis with indexes?

Shape() should return a int

Hi,

All other methods work with ints, only Shape() returns a []uint64 which makes it unnessesary complicated to use.

Consider this code:

rows := myArr.Shape()[0]
collums :=myArr.Shape()[1]
depth :=myArr.Shape()[2]
newArr := numgo.NewArray64(nil,rows,collums,depth) //ERROR

It throws an error because NewArray64 expects ints, and Shape returns uint64.
To avoid using casts to int all the time, wouldn't it be easier if Shape just returns int so that it is directly compatible with the other functions?

If interested I would submit a pull request.
Let me know what you think!

Pablo

question about Arange function

Hi,
In numgo, fmt.Println(numgo.Arange(0, 10)) => [0 1 2 3 4 5 6 7 8 9 10].
In numpy, print(np.arange(0, 10)) => [0 1 2 3 4 5 6 7 8 9].
Both are ok, but I prefer to drop 'stop', like numpy.
Would you think about it?
Tks!

Unify Methods for Array64 and Arrayb

There is a lot of redundancy in the Array64 and Arrayb methods. Quite a few of them are exactly the same, except for the input/return type.

Consider e.g. the Reshape() method of Array64 and Arrayb: The are identical, the only difference beeing in the declaration:

func (a *Arrayb) Reshape(shape ...int) *Arrayb {
...
}

vs.

func (a *Array64) Reshape(shape ...int) *Array64 {
...
}

This is not specific to this example and applies for a lot of code.

To simplify the code it would be possible to add a general n-Dimensional structure independent to the underlying type. The type of data (bool for Arrayb and float64 for Array64) would be encapsulated in a interface.

This would be a possible implementation:

type nDimObject struct {
	shape        []int
	strides      []int
	err          error
	debug, stack string
	data         []nDimElement
}

type nDimElement interface {
}

// Array64 is an n-dimensional array of float64 data
type Array64 struct {
	nDimObject
}

// Arrayb is an n-dimensional array of boolean values
type Arrayb struct {
	nDimObject
}

Methods that are identical for both Array types could be implemented on nDimObject that way.
I will create a pull request on a separate branch. It sure removes a lot of code and simplifies it (in my opinion) a lot.

I understand this is a major change to the structure of the project and you me want to go in a different direction. Let me know what you think of the idea!

P.S. this approach would make it a lot easier to implement new types of array (maybe for ints?) in the future if needed.

Inconsistencies in Array64 creation methods

Hi,
I have been working with your package a while and noticed a few inconsistencies in the signatures of the functions used to create different types of arrays.

Consider these three functions:

func NewArray64(data []float64, shape ...int) (a *Array64)
func Full(val float64, shape ...int) (a *Array64)
func RandArray64(base, scale float64, shape []int) (a *Array64)
  • Arguments
    All Functions accept variadic inputs. Why is RandArray asking for a slice instead?

  • Naming:
    Why is the function for filled arrays not called FullArray64, like the others?

If you are iinterested in changing this, I would submit a pull request.
My proposal would be:

func NewArray64(data []float64, shape ...int) (a *Array64)
func NewFullArray64(val float64, shape ...int) (a *Array64)
func NewRandArray64(base, scale float64, shape ...int) (a *Array64)

Let me know what you think!

Use of internal package

Hi,
this is just for discussion, not a real bug or issue.

Is the use of a "internal" package needed/useful? I find it unnecessarily complicated to contribute, for every change I have to fork, pull fork, change package import path to my user, make changes, change package import back, push. Otherwise I get an error when trying to run the tests:

binaryplease➜github.com/binaryplease/numgo(master)» go test .                                                                                                                                            
package github.com/binaryplease/numgo
	imports github.com/Kunde21/numgo/internal: use of internal package not allowed

This might be a stupid mistake as I'm pretty new to go. Is there a common workaround for this rather than changing the import path in the code forth and back all the time? I must admit I don't really understand the code in that folder very well though.

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.