Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11955 > unrolled thread
| Started by | Richard Palmer <rhpalmer@gmail.com> |
|---|---|
| First post | 2012-10-05 06:41 +0000 |
| Last post | 2012-10-08 06:51 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Trouble Loading Packages... Richard Palmer <rhpalmer@gmail.com> - 2012-10-05 06:41 +0000
Re: Trouble Loading Packages... awnl <awnl@gmx-topmail.de> - 2012-10-08 06:51 +0000
| From | Richard Palmer <rhpalmer@gmail.com> |
|---|---|
| Date | 2012-10-05 06:41 +0000 |
| Subject | Trouble Loading Packages... |
| Message-ID | <k4lvf6$d39$1@smc.vnet.net> |
...using the latest version of Mathematica on a 64 bit windows machine.
Here is the relevant code
In[1]:= Directory[]
Out[1]= "C:\\Users\\Richard\\Documents"
FileNames[{"*.m"}]
{"cellNeighbours.m", "myS.m"}
FileExistsQ["cellNeighbours.m"]
True
In[5]:= FindFile["cellNeighbours.m"]
Out[5]= "C:\\Users\\Richard\\Documents\\cellNeighbours.m"
In[6]:= << cellNeighbours`
In[7]:= ?cellNeighbours
During evaluation of In[7]:= Information::notfound: Symbol cellNeighbours
not found. >>
Needs["cellNeighbours`"]
Needs::nocont: Context cellNeighbours` was not created when Needs was
evaluated. >>
Same thing happens with the myS package. Why can't if find and load the
package?
--------------------------------------------------------------------------
This is the cellNeighbours Package
BeginPackage["cellNeighbours`"];
cellNeighbours::usage =
"cellNeighbours[r,c] sets up a function to quickly return a list of the n
\
nearest neighbours of a given cell in an r\[ScriptX]c matrix. By deafult, a
\
toroidal distance matrix is assumed.";
neighbourhoodList::usage =
"neighbourhoodList[rI,cI,k] returns a list of the k nearest cells to \
\!\(\*SubscriptBox[\(cell\), \(r1, c1\)]\) in an r\[ScriptX]c matrix. By \
deafult, a toroidal distance matrix is assumed";
toroidalDistance::usage =
"teroidalDistance[{r1,c1},{r2.c2}] returns a \!\(\*
StyleBox[\"wrap\",\nFontSlant->\"Italic\"]\)\!\(\*
StyleBox[\" \",\nFontSlant->\"Italic\"]\)\!\(\*
StyleBox[\"around\",\nFontSlant->\"Italic\"]\)\!\(\*
StyleBox[\" \",\nFontSlant->\"Italic\"]\)distance between two points";
distancefn::usage = "distance[a,b,len] computes a \!\(\*
StyleBox[\"wrap\",\nFontSlant->\"Italic\"]\)\!\(\*
StyleBox[\" \",\nFontSlant->\"Italic\"]\)\!\(\*
StyleBox[\"around\",\nFontSlant->\"Italic\"]\) distance from a to b
between \
two cells on the same row or column. \!\(\*
StyleBox[\"len\",\nFontSlant->\"Italic\"]\) is the length of the \
row/column.";
Begin["Private`"];
rows = -1;
cols = -1;
cellNeighbourhood = -1;
cellIndices = -1;
cellNeighbours[r_Integer, c_Integer] := Module[{},
rows = r;
cols = c;
cellIndices = Table[{i, j}, {i, 1, r}, {j, 1, c}];
cellNeighbourhood = Nearest[Flatten[cellIndices, 1]
DistanceFunction -> toroidalDistance]] /; r > 1 && c > 1;
distancefn =
Compile[{{a, _Integer}, {b, _Integer}, {len, _Integer}},
Module[{mn, mx, result},
If[a == b, Return[0]];
mx = Max[a, b];
mn = Min[a, b];
result = Min[mx - mn, mn + len - mx];
If[result < 0, Print[{"distance error", a, b, len, result}]];
Return[result]]];
toroidalDistance[p1_, p2_] :=
Module[{r, c}, r = distancefn[First[p1], First[p2], rows];
c = distancefn[Last[p1], Last[p2], cols]; r^2 + c^2];
neighbourhoodList[r_, c_, n_] :=
cellNeighbourhood[{r, c}, n];
End[];
EndPackage[];
--
Richard Palmer
Home 941 412 8828
Cell 508 982-7266
[toc] | [next] | [standalone]
| From | awnl <awnl@gmx-topmail.de> |
|---|---|
| Date | 2012-10-08 06:51 +0000 |
| Message-ID | <k4tt5e$sds$1@smc.vnet.net> |
| In reply to | #11955 |
Hello Richard,
> Here is the relevant code
>
>
> In[1]:= Directory[]
> Out[1]= "C:\\Users\\Richard\\Documents"
>
> FileNames[{"*.m"}]
> {"cellNeighbours.m", "myS.m"}
>
> FileExistsQ["cellNeighbours.m"]
> True
>
> In[5]:= FindFile["cellNeighbours.m"]
> Out[5]= "C:\\Users\\Richard\\Documents\\cellNeighbours.m"
> In[6]:= << cellNeighbours`
FindFile with only one argument uses the variable $Path to determine
which directories to search in, and so does Get (<< is a short for for
Get) and Needs. If you don't have changed it, $Path will usually contain
an entry "." which is expanded to the current working directory which is
what Directory[] returns. So, as FindFile finds the file so will Get --
and it indeed does, otherwise you'd get an error message when evaluating
<< cellNeighbours` (something like "Get::noopen: Cannot open
cellNeighbours`" ).
> In[7]:= ?cellNeighbours
> During evaluation of In[7]:= Information::notfound: Symbol cellNeighbours
> not found. >>
> Needs["cellNeighbours`"]
> Needs::nocont: Context cellNeighbours` was not created when Needs was
> evaluated. >>
the problem both of these messages indicate (if there are no others...)
is that the package file does not contain what you expect. You can use
FilePrint["C:\\Users\\Richard\\Documents\\cellNeighbours.m"]
to see what Mathematica is really reading. Your package content looks
correct and loads without problems for me, so I suspect that this isn't
really the content of the cellNeighbours.m that you are loading. There
are several things that can go wrong, e.g. when you 'Save As' and choose
package file without having set the cells containing the code to
initialization cells Mathematica will save the code in those cells just
as comments. I suspect that this or something similar has happend to
your file...
> Same thing happens with the myS package. Why can't if find and load the
> package?
from what you sent I'd conclude that it does find and load the package,
but that the file doesn't exactly contain what you think...
hth,
albert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web