linear-algebra icon indicating copy to clipboard operation
linear-algebra copied to clipboard

Error ordinal type when echo Matrix

Open mratsim opened this issue 8 years ago • 2 comments

This might be related to https://github.com/nim-lang/Nim/issues/5199

Setup: Nim v0.16, linalg 0.6.6 on OSX

import linalg

## Training
let data = matrix([
                [1.2, 0.7],
                [-0.3, -0.5],
                [3.0, 0.1],
                [-0.1, -1.0],
                [-1.0, 1.1],
                [2.1, -3]
                ])
#echo data

Without echo data the code compiles

$  nim c -d:release -o:bin/karpathy4 --nimcache:nimcache playground/karpathy_tuto4.nim
Hint: used config file '/usr/local/Cellar/nim/0.16.0/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: karpathy_tuto4 [Processing]
Hint: linalg [Processing]
Hint: math [Processing]
Hint: sequtils [Processing]
Hint: nimblas [Processing]
--USING DEFAULT BLAS--
Hint: random [Processing]
Hint: times [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: algorithm [Processing]
Hint: nimlapack [Processing]
karpathy_tuto4.nim(4, 18) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/initialize.nim(295, 13) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/initialize.nim(166, 46) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/initialize.nim(160, 38) Warning: Cannot prove that 'result' is initialized. This will bec
ome a compile time error in the future. [ProveInit]
karpathy_tuto4.nim(4, 5) Warning: Cannot prove that 'data' is initialized. This will become a compile time error in the future. [ProveInit]
karpathy_tuto4.nim(4, 5) Hint: 'data' is declared but not used [XDeclaredButNotUsed]
Hint:  [Link]
Hint: operation successful (19026 lines compiled; 0.742 sec total; 27.949MiB; Release Build) [SuccessX]

If I add echo I get Error: ordinal type expected

$  nim c -d:release -o:bin/karpathy4 --nimcache:nimcache playground/karpathy_tuto4.nim
Hint: used config file '/usr/local/Cellar/nim/0.16.0/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: karpathy_tuto4 [Processing]
Hint: linalg [Processing]
Hint: math [Processing]
Hint: sequtils [Processing]
Hint: nimblas [Processing]
--USING DEFAULT BLAS--
Hint: random [Processing]
Hint: times [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: algorithm [Processing]
Hint: nimlapack [Processing]
karpathy_tuto4.nim(4, 18) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/initialize.nim(295, 13) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/initialize.nim(166, 46) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/initialize.nim(160, 38) Warning: Cannot prove that 'result' is initialized. This will bec
ome a compile time error in the future. [ProveInit]
karpathy_tuto4.nim(4, 5) Warning: Cannot prove that 'data' is initialized. This will become a compile time error in the future. [ProveInit]
karpathy_tuto4.nim(14, 6) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/display.nim(42, 35) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/access.nim(136, 18) template/generic instantiation from here
/Users/user/.nimble/pkgs/linalg-0.6.6/linalg/private/access.nim(50, 96) Error: ordinal type expected

mratsim avatar Mar 29 '17 12:03 mratsim

Adding Nim version: My report was done with Nim v0.16 release build

$  nim -v
Nim Compiler Version 0.16.0 (2017-01-09) [MacOSX: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf

active boot switches: -d:release -d:useLinenoise

I just retried with a rebuild from git source, same issue

$  nim -v
Nim Compiler Version 0.16.1 (2017-03-30) [MacOSX: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf

git hash: 875e344be0f0202885f0d5ed7f10188835a171d0
active boot switches: -d:release -d:useLinenoise

The example in the README works though

import linalg

let m = randomMatrix(3, 7)
echo m

Edit: further tests, it works when defined like this:

let data = matrix(@[
                @[1.2, 0.7],
                @[-0.3, -0.5],
                @[3.0, 0.1],
                @[-0.1, -1.0],
                @[-1.0, 1.1],
                @[2.1, -3]
                ], 6, 2)
echo data

From the README m7 works but not m8

  m7: Matrix64[2, 3] = matrix([
    [1.2, 3.5, 4.3],
    [1.1, 4.2, 1.7]
  ])
  m8: Matrix64[2, 3] = matrix(@[
    @[1.2, 3.5, 4.3],
    @[1.1, 4.2, 1.7]
  ], 2, 3)

mratsim avatar Mar 29 '17 22:03 mratsim

It seems the same issue indeed, I am going to reopen it

andreaferretti avatar Mar 30 '17 13:03 andreaferretti