I was just playing with records, and am stuck trying to write a function that works with records. I think the problem is how to read the record definition into my module file.
The reocords.hrl file:
% Modeling a todo list
-record(todo, {status=reminder, who=joe, text}).
And then the use_records.erl file:
%% Use the records defined in "records.hrl"
-module(use_records).
-export([todo_to_tuple/1]).
rr("records.hrl").
todo_to_tuple(#todo{who=W, text=T} = R) -> {W, T}.
When I try to compile it, I get:
24> c(use_records).
use_records.erl:5: variable 'T' is unbound
use_records.erl:5: variable 'W' is unbound
use_records.erl:5: record todo undefined
use_records.erl:5: Warning: variable 'R' is unused
error
The error is the same if I remove the rr("records.hrl") line. So I suppose the real issue is being able to read the record definition (or not?). Please help!
rr/1 is used include record definition only in the shell.
In order to include record definition in your code use:
-include("records.hrl")
Related
I am new to F#/.NET and I am trying to run the F# example provided in the accepted answer of How to translate the intro ML.Net demo to F#? with the ML.NET library, using F# on Visual Studio, using Microsoft.ML (0.2.0).
When building it I get the error error FS0039: The type 'TextLoader' is not defined.
To avoid this, I added the line
open Microsoft.ML.Data
to the source.
Then, however, the line
pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))
triggers:
error FS0033: The non-generic type 'Microsoft.ML.Data.TextLoader' does not expect any type arguments, but here is given 1 type argument(s)
Changing to:
pipeline.Add(new TextLoader(dataPath,separator = ","))
yields:
error FS0495: The object constructor 'TextLoader' has no argument or settable return property 'separator'. The required signature is TextLoader(filePath: string) : TextLoader.
Changing to:
pipeline.Add(new TextLoader(dataPath))
makes the build successful, but the code fails when running with
ArgumentOutOfRangeException: Column #1 not found in the dataset (it only has 1 columns), I assume because the comma separator is not correctly picked up (incidentally, you can find and inspect the iris dataset at https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data).
Also
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
won't work.
I understand that there have been changes in TextLoader recently (see e.g. https://github.com/dotnet/machinelearning/issues/332), can somebody point me to what I am doing wrong?
F# just has a bit of a different syntax that can take some getting used to. It doesn't use the new keyword to instantiate a new class and to use named parameters it uses the = instead of : that you would in C#.
So for this line in C#:
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
It would be this in F#:
pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))
I am a newbie to Lua. Currently getting the following error message:
invalid argument type for argument -model (should be the model checkpoint
to use for sampling)
Usage: [options] <model>
I am sure it is something pretty easy to solve, but cannot manage to find the solution.
The 'model' is a file lm_checkpoint_epoch50.00_2.7196.t7, which is in the directory
/home/ubuntu/xxx/nn/cv
I am running the program from the parent directory (/home/ubuntu/xxx/nn)
I have tried out the following options to run the program (from one directory above the one the model is saved):
th sample.lua - model lm_chelm_checkpoint_epoch50.00_2.5344.t7
th sample.lua lm_chelm_checkpoint_epoch50.00_2.5344.t7
th sample.lua /cv/lm_chelm_checkpoint_epoch50.00_2.5344.t7
th sample.lua - /cv/model lm_chelm_checkpoint_epoch50.00_2.5344.t7
Also, the program has a torch.CmdLine() object where :argument equals '/cv/lm_checkpoint_epoch50.00_2.7196.t7'. The program prints the parameters, so that you see the following output on the screen:
Options
<model> /cv/lm_checkpoint_epoch50.00_2.7196.t7
so it finds a value for argument 'model', which is picked up from the .lua file, not the parameter in the command line. This file is a valid mode.
Pretty lost, hope someone relates to this issue. Thanks.
found the issue - it was a bug as smhx suggested. I inadvertently changed the source code from:
require 'torch'
cmd = torch.CmdLine()
cmd:argument('-model','model checkpoint to use for sampling')
Note that there is no argument in the source code. To:
cmd:argument('-model','/cv/model lm_chelm_checkpoint_epoch50.00_2.5344.t7'
'model checkpoint to use for sampling')
So the argument must be passed through the command line, not the source code. With parameters, it is different - you can include them in the source code.
So if I change back the source code and run the following from the command line:
th sample.lua cv/lm_chelm_checkpoint_epoch50.00_2.5344.t7
it works.
I've guessed a couple of the erlang:system_info/1 variants such as:
10> erlang:system_info(schedulers).
4
11> erlang:system_info(cpu).
** exception error: bad argument
in function erlang:system_info/1
called as erlang:system_info(cpu)
12> erlang:system_info(cpu_arch).
** exception error: bad argument
in function erlang:system_info/1
called as erlang:system_info(cpu_arch)
13> erlang:system_info(memory).
** exception error: bad argument
in function erlang:system_info/1
called as erlang:system_info(memory)
14> erlang:system_info(version).
"5.10.4"
But is there a way, either via introspection, or a global database of some sort, to list all the available system_info arguments ?
Refer to the documentation for erlang:system_info/1. It's listed over several sections with descriptions for what each atom represents. This is the most comprehensive list of supported atoms outside of the Erlang/OTP source itself (and there are a few undocumented parameters).
There is no language feature which would allow you to list all of the possible atoms.
The symbol # was seen in one the program ,But i could not find why it is used .
The syntax is
const unsigned char Array_name[] #(INFO_Array+1) = {................};
The meaning of # operator can be different for the particular compiler in which the code is compiled.
For example, in IAR Embedded Workbench's C/C++ compiler the # operator can be used for placing global and static variables at absolute addresses.
If you are using IAR C/C++ compiler, the compiler will place Array_name in the address (INFO_Array+1).
# operator can also be used to place a variable or object in a particular section of the object file:
uint32_t CTRL_OFFSET_x86 # "MY_RAM_SECTION";
The above line will place CTRL_OFFSET_x86 in the object file section MY_RAM_SECTION.
#pragma location can also be used for this purpose.
To me, it looks like a compiler flag to disable interpreting the string "INFO_Array+1" as an expression. In C# for example, you can use the #-Operator to tell the compiler to use the following expression as String without trying to evaluate it.
A quick googling showed:
For example, this line will fail to compile:
int new = 1776; // 'new' is a keyword
However, this line compiles without error:
int #new = 1776;
I'm using xdg-menu-to-awesome-wm to generate a Lua file containing the GNOME menu, for inclusion in Awesome WM. Since the generator script may not be installed, I need some way for Lua to only require the menu module if it exists.
I don't want to go looking through file names, since it could be anywhere in package.path. One option would be to ignore the exception created when the module does not exist, but I'd rather not ignore any other exceptions - I do want to know if the module contains any syntax or other errors. The reference unfortunately doesn't specify which exceptions can be generated, so I'm not sure how to do it.
If you need to distinguish between a missing module and a syntax error, you can directly access the searcher functions in package.searchers.
These functions will:
Return a loader function if successful
Return a string if the module is not found
Throw an error if there is a syntax error
So what you can do is mimic the way require searches for a module, calling each searcher in turn until one of them returns a function. Unlike require, we need not throw an error if the module is not found, i.e. if every searcher function returns a string.
function isModuleAvailable(name)
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
return true
end
end
return false
end
end
Look, I had the same problem with 'luafilesystem' module, I worked it out like this,
local haslfs,lfs = pcall(require,"lfs")
if haslfs then
configLines["PROJECT_HOME"] = lfs.currentdir()
else
configLines["PROJECT_HOME"] = prompt("Project path > ")
end
'lfs' here is the module handle . And pcall is used to know if the module is really loaded without propagating the error.
What I do is wrap the require in a pcall so that the module is loaded and a fail to load can be caught. There is a fully worked function which I use to download and install the missing modules from our servers here:
http://www.fhug.org.uk/wiki/doku.php?id=plugins:code_snippets:module_require_with_load
function loadrequire(module)
local function requiref(module)
require(module)
end
res = pcall(requiref,module)
if not(res) then
-- Do Stuff when no module
end
end
loadrequire('menu')